From c36e4522a63191f2c286d7738b4cfb9922197f41 Mon Sep 17 00:00:00 2001 From: jtc Date: Tue, 24 May 2005 19:03:12 +0000 Subject: ChangeLogTag: Tue May 24 11:59:37 2005 J.T. Conklin --- TAO/ChangeLog | 11 ++++++ TAO/orbsvcs/orbsvcs/Time_Utilities.cpp | 9 +++++ TAO/orbsvcs/orbsvcs/Time_Utilities.h | 70 ++++++++++++++++++++++++---------- TAO/orbsvcs/orbsvcs/Time_Utilities.i | 34 ++++++++++++++++- 4 files changed, 103 insertions(+), 21 deletions(-) diff --git a/TAO/ChangeLog b/TAO/ChangeLog index b1868688c39..e9b7cd1142c 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,14 @@ +Tue May 24 11:59:37 2005 J.T. Conklin + + * orbsvcs/orbsvcs/Time_Utilities.cpp: + * orbsvcs/orbsvcs/Time_Utilities.h: + * orbsvcs/orbsvcs/Time_Utilities.i: + + Updated comments to Doxygen format. + + Added new methods for converting absolute timestamps between + ACE_Time_Value and TimeBase::TimeT. + Tue May 24 10:32:31 2005 J.T. Conklin * orbsvcs/orbsvcs/Makefile.am: diff --git a/TAO/orbsvcs/orbsvcs/Time_Utilities.cpp b/TAO/orbsvcs/orbsvcs/Time_Utilities.cpp index b0ee99afdbb..d47168b1212 100644 --- a/TAO/orbsvcs/orbsvcs/Time_Utilities.cpp +++ b/TAO/orbsvcs/orbsvcs/Time_Utilities.cpp @@ -7,3 +7,12 @@ #endif /* __ACE_INLINE__ */ ACE_RCSID(orbsvcs, Time_Utilities, "$Id$") + +// Number of nanoseconds between CORBA and POSIX epochs. +#ifdef ACE_LACKS_LONGLONG_T +const ACE_UINT64 +ORBSVCS_Time::Time_Base_Offset(0x82B60000, 0x0A990E2D6); +#else +const ACE_UINT64 +ORBSVCS_Time::Time_Base_Offset(ACE_UINT64_LITERAL(12218515200000000000)); +#endif diff --git a/TAO/orbsvcs/orbsvcs/Time_Utilities.h b/TAO/orbsvcs/orbsvcs/Time_Utilities.h index 86759d4ae66..f342e67b3df 100644 --- a/TAO/orbsvcs/orbsvcs/Time_Utilities.h +++ b/TAO/orbsvcs/orbsvcs/Time_Utilities.h @@ -22,50 +22,80 @@ #include "orbsvcs/svc_utils_export.h" #include "ace/OS_NS_time.h" +/** + * @class ORBSVCS_Time + * + * @brief Time conversion utilities. + * + * This class defines several static methods to convert between + * several ACE time structures and the CORBA TimeT structure. + * + * Recall that TimeBase::TimeT stores time in a 64-bit long long + * (or structure when that is not available) and uses hundreds of + * nanoseconds as time units (i.e. 1 second is 10^7 TimeT units). + * + * To convert between the CORBA and the UNIX epochs, we need to adjust + * absolute times by the difference between October 15th, 1582 (Julian + * Date 2299160.5) and January 1st, 1970 (Julian Date 2440578.5): + * 141418.0 days. + */ class TAO_Svc_Utils_Export ORBSVCS_Time { - // = TITLE - // Time conversion utilities. - // - // = DESCRIPTION - // This class define several static methods to convert between - // several time structures and the CORBA TimeT structure. - // - // Recall that TimeT stores time in a 64-bit long long (or - // structure when that is not available) and uses hundreds of - // nanoseconds as time units (i.e. 1 second is 10^7 TimeT units). public: - // = A helper constant, IDL does not have constant for structures. + /// @brief A helper constant, IDL does not have constant for structures. static TimeBase::TimeT zero (); - // = ACE_hrtime_t conversion routines. - + /** + * @name ACE_hrtime_t conversion routines + */ + //@{ // We interpret an ACE_hrtime_t as nanoseconds. + /// @brief Convert relative high-resolution time to a . static void hrtime_to_TimeT (TimeBase::TimeT &lhs, ACE_hrtime_t rhs); - // Convert high-resolution time to a . + /// @brief Convert relative to a high-resolution time. static void TimeT_to_hrtime (ACE_hrtime_t &lhs, const TimeBase::TimeT &rhs); - // Convert to a high-resolution time. + /// @brief Convert relative to a high-resolution time. static ACE_hrtime_t to_hrtime (const TimeBase::TimeT &t); - // Convert to a high-resolution time. + //@} - // = ACE_Time_Value conversion routines. + /** + * @name ACE_Time_Value conversion routines + */ + //@{ // Recall that s are pairs. + /// @brief Convert relative to a . static void Time_Value_to_TimeT (TimeBase::TimeT& lhs, const ACE_Time_Value& rhs); - // Convert an to a . + + /// @brief Convert relative to a . static void TimeT_to_Time_Value (ACE_Time_Value& lrs, const TimeBase::TimeT& rhs); - // Convert an to a . + /// @brief Convert relative to a . static ACE_Time_Value to_Time_Value (const TimeBase::TimeT &rhs); - // Convert an to a . + + /// @brief Convert absolute to a + static void Absolute_Time_Value_to_TimeT (TimeBase::TimeT& lhs, + const ACE_Time_Value& rhs); + + /// @brief Convert absolute to a + static void Absolute_TimeT_to_Time_Value (ACE_Time_Value& lrs, + const TimeBase::TimeT& rhs); + + /// @brief Convert absolute to a . + static ACE_Time_Value to_Absolute_Time_Value (const TimeBase::TimeT &rhs); + //@} + +private: + /// @brief Number of nanoseconds between the CORBA and UNIX epochs. + static const ACE_UINT64 Time_Base_Offset; }; #if defined (__ACE_INLINE__) diff --git a/TAO/orbsvcs/orbsvcs/Time_Utilities.i b/TAO/orbsvcs/orbsvcs/Time_Utilities.i index 00e274c0ed0..27ea1cdde34 100644 --- a/TAO/orbsvcs/orbsvcs/Time_Utilities.i +++ b/TAO/orbsvcs/orbsvcs/Time_Utilities.i @@ -4,7 +4,6 @@ #include "ace/Time_Value.h" - ACE_INLINE TimeBase::TimeT ORBSVCS_Time::zero () { @@ -65,3 +64,36 @@ ORBSVCS_Time::to_Time_Value (const TimeBase::TimeT& t) ORBSVCS_Time::TimeT_to_Time_Value (r, t); return r; } + +ACE_INLINE void +ORBSVCS_Time::Absolute_Time_Value_to_TimeT (TimeBase::TimeT& lhs, + const ACE_Time_Value& rhs) +{ + ACE_hrtime_t t = + static_cast (rhs.sec ()) * ACE_U_ONE_SECOND_IN_NSECS + + static_cast (rhs.usec ()) * 1000u; + + t += Time_Base_Offset; + ORBSVCS_Time::hrtime_to_TimeT (lhs, t); +} + +ACE_INLINE void +ORBSVCS_Time::Absolute_TimeT_to_Time_Value (ACE_Time_Value& lhs, + const TimeBase::TimeT& rhs) +{ + ACE_hrtime_t t; + + ORBSVCS_Time::TimeT_to_hrtime (t, rhs); + t -= Time_Base_Offset; + + lhs.set(static_cast (t / ACE_U_ONE_SECOND_IN_NSECS), + static_cast ((t % ACE_U_ONE_SECOND_IN_NSECS) / 1000)); +} + +ACE_INLINE ACE_Time_Value +ORBSVCS_Time::to_Absolute_Time_Value (const TimeBase::TimeT& t) +{ + ACE_Time_Value r; + ORBSVCS_Time::Absolute_TimeT_to_Time_Value (r, t); + return r; +} -- cgit v1.2.1