#include <Timer_Helper.h>
Inheritance diagram for Timer_Helper:
Public Member Functions | |
Timer_Helper (void) | |
Constructor. | |
~Timer_Helper (void) | |
Destructor. | |
Timer_Helper (TAO_Time_Service_Clerk *clerk) | |
Constructor that sets the clerk. | |
int | handle_timeout (const ACE_Time_Value &time, const void *arg) |
Protected Types | |
typedef ACE_Array_Base< CosTime::TimeService_var > | IORS |
The set of server IORs. | |
Protected Attributes | |
TAO_Time_Service_Clerk * | clerk_ |
Clerk's instance that this class helps to update time. |
The handle timeout method of this class is called periodically by the reactor. This method updates the clerk's notion of globally synchronized time by contacting the various Time Servers.
Definition at line 50 of file Timer_Helper.h.
|
The set of server IORs.
Definition at line 73 of file Timer_Helper.h. |
|
Constructor.
Definition at line 16 of file Timer_Helper.cpp.
00017 : clerk_ (0) 00018 { 00019 } |
|
Destructor.
Definition at line 27 of file Timer_Helper.cpp.
00028 { 00029 } |
|
Constructor that sets the clerk.
Definition at line 21 of file Timer_Helper.cpp.
00022 : clerk_ (clerk) 00023 { 00024 00025 } |
|
This method is called periodically by the Reactor to update the clerk's time. Reimplemented from ACE_Event_Handler. Definition at line 32 of file Timer_Helper.cpp. References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, ACE_U64_TO_U32, ACE_UINT64_LITERAL, clerk_, ACE_OS::gettimeofday(), TAO_Time_Service_Clerk::inaccuracy(), LM_DEBUG, ACE_Time_Value::sec(), TAO_debug_level, TAO_Time_Service_Clerk::time_, TAO_Time_Service_Clerk::time_displacement_factor(), ACE_OS::timezone(), ACE_OS::tzset(), TAO_Time_Service_Clerk::update_timestamp_, and ACE_Time_Value::usec().
00034 { 00035 int no_of_servers = 0; 00036 CORBA::ULongLong sum = 0; 00037 00038 // The following are used to keep a track of the inaccuracy 00039 // in synchronization. 00040 00041 #if defined (ACE_LACKS_LONGLONG_T) 00042 CORBA::ULongLong lowest_time (0xFFFFFFFF, 0xFFFFFFFF); 00043 #else 00044 CORBA::ULongLong lowest_time = ACE_UINT64_LITERAL (0xFFFFFFFFFFFFFFFF); 00045 #endif 00046 00047 CORBA::ULongLong highest_time = 0; 00048 00049 ACE_DECLARE_NEW_CORBA_ENV; 00050 ACE_TRY 00051 { 00052 IORS::TYPE* value; 00053 for (IORS::ITERATOR server_iterator (this->clerk_->server_); 00054 server_iterator.next (value) != 0; 00055 server_iterator.advance ()) 00056 { 00057 // This is a remote call. 00058 CosTime::UTO_var UTO_server = 00059 (*value)->universal_time (ACE_ENV_SINGLE_ARG_PARAMETER); 00060 ACE_TRY_CHECK; 00061 00062 #if defined (ACE_LACKS_LONGLONG_T) 00063 00064 if (TAO_debug_level > 0) 00065 ACE_DEBUG ((LM_DEBUG, 00066 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" 00067 "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", 00068 ACE_U64_TO_U32 (UTO_server->time ()), 00069 ACE_U64_TO_U32 (UTO_server->inaccuracy ()), 00070 UTO_server->tdf (), 00071 ACE_U64_TO_U32 ((UTO_server->utc_time ()).time), 00072 (UTO_server->utc_time ()).inacclo, 00073 (UTO_server->utc_time ()).inacchi, 00074 (UTO_server->utc_time ()).tdf)); 00075 00076 #else 00077 00078 if (TAO_debug_level > 0) 00079 ACE_DEBUG ((LM_DEBUG, 00080 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" 00081 "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", 00082 UTO_server->time (), 00083 UTO_server->inaccuracy (), 00084 UTO_server->tdf (), 00085 (UTO_server->utc_time ()).time, 00086 (UTO_server->utc_time ()).inacclo, 00087 (UTO_server->utc_time ()).inacchi, 00088 (UTO_server->utc_time ()).tdf)); 00089 #endif 00090 00091 CORBA::ULongLong curr_server_time = 00092 UTO_server->time (ACE_ENV_SINGLE_ARG_PARAMETER); 00093 ACE_TRY_CHECK; 00094 00095 sum += curr_server_time; 00096 00097 ++no_of_servers; 00098 00099 // Set the highest time to the largest time seen so far. 00100 if (curr_server_time > highest_time) 00101 highest_time = curr_server_time; 00102 00103 // Set the lowest time to the smallest time seen so far. 00104 if (curr_server_time < lowest_time) 00105 lowest_time = curr_server_time; 00106 00107 } 00108 00109 if (TAO_debug_level > 0) 00110 ACE_DEBUG ((LM_DEBUG, 00111 "\nUpdated time from %d servers in the network", 00112 no_of_servers)); 00113 00114 // Return the average of the times retrieved from the various 00115 // servers. 00116 clerk_->time_ = sum / no_of_servers ; 00117 00118 // Set the Time Displacement Factor. The TZ environment variable is 00119 // read to set the time zone. We convert the timezone value from seconds 00120 // to minutes. 00121 00122 ACE_OS::tzset (); 00123 long arg = ACE_OS::timezone () / 60; 00124 CORBA::Short goodarg = static_cast<CORBA::Short> (arg); 00125 clerk_->time_displacement_factor (goodarg); 00126 00127 // Set the inaccuracy. 00128 if (highest_time > lowest_time) 00129 clerk_->inaccuracy (highest_time - lowest_time); 00130 else 00131 clerk_->inaccuracy (0); 00132 00133 const ACE_Time_Value timeofday = ACE_OS::gettimeofday (); 00134 00135 // Record the current time in a timestamp to know when global 00136 // updation of time was done. 00137 clerk_->update_timestamp_ = 00138 static_cast<CORBA::ULongLong> (timeofday.sec ()) * 00139 static_cast<ACE_UINT32> (10000000) + 00140 static_cast<CORBA::ULongLong> (timeofday.usec () * 10); 00141 } 00142 ACE_CATCHANY 00143 { 00144 if (TAO_debug_level > 0) 00145 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, 00146 "Exception in handle_timeout()\n"); 00147 00148 return -1; 00149 } 00150 ACE_ENDTRY; 00151 ACE_CHECK_RETURN (-1); 00152 00153 return 0; 00154 } |
|
Clerk's instance that this class helps to update time.
Definition at line 70 of file Timer_Helper.h. Referenced by handle_timeout(). |