1
#include "Timer_Helper.h"
2
#include "TAO_Time_Service_Clerk.h"
6
#include "ace/OS_NS_time.h"
7
#include "ace/OS_NS_sys_time.h"
11
"Timer_Helper.cpp,v 1.27 2003/11/05 03:59:58 dhinton Exp")
14
Timer_Helper::Timer_Helper (void)
19
Timer_Helper::Timer_Helper (TAO_Time_Service_Clerk *clerk)
25
Timer_Helper::~Timer_Helper (void)
30
Timer_Helper::handle_timeout (const ACE_Time_Value &,
33
int no_of_servers = 0;
34
CORBA::ULongLong sum = 0;
36
// The following are used to keep a track of the inaccuracy
37
// in synchronization.
39
#if defined (ACE_LACKS_LONGLONG_T)
40
CORBA::ULongLong lowest_time (0xFFFFFFFF, 0xFFFFFFFF);
42
CORBA::ULongLong lowest_time = ACE_UINT64_LITERAL (0xFFFFFFFFFFFFFFFF);
45
CORBA::ULongLong highest_time = 0;
47
ACE_DECLARE_NEW_CORBA_ENV;
51
for (IORS::ITERATOR server_iterator (this->clerk_->server_);
52
server_iterator.next (value) != 0;
53
server_iterator.advance ())
55
// This is a remote call.
56
CosTime::UTO_var UTO_server =
57
(*value)->universal_time (ACE_ENV_SINGLE_ARG_PARAMETER);
60
#if defined (ACE_LACKS_LONGLONG_T)
62
if (TAO_debug_level > 0)
64
"\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n"
65
"struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
66
ACE_U64_TO_U32 (UTO_server->time ()),
67
ACE_U64_TO_U32 (UTO_server->inaccuracy ()),
69
ACE_U64_TO_U32 ((UTO_server->utc_time ()).time),
70
(UTO_server->utc_time ()).inacclo,
71
(UTO_server->utc_time ()).inacchi,
72
(UTO_server->utc_time ()).tdf));
76
if (TAO_debug_level > 0)
78
"\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n"
79
"struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
81
UTO_server->inaccuracy (),
83
(UTO_server->utc_time ()).time,
84
(UTO_server->utc_time ()).inacclo,
85
(UTO_server->utc_time ()).inacchi,
86
(UTO_server->utc_time ()).tdf));
89
CORBA::ULongLong curr_server_time =
90
UTO_server->time (ACE_ENV_SINGLE_ARG_PARAMETER);
93
sum += curr_server_time;
97
// Set the highest time to the largest time seen so far.
98
if (curr_server_time > highest_time)
99
highest_time = curr_server_time;
101
// Set the lowest time to the smallest time seen so far.
102
if (curr_server_time < lowest_time)
103
lowest_time = curr_server_time;
107
if (TAO_debug_level > 0)
108
ACE_DEBUG ((LM_DEBUG,
109
"\nUpdated time from %d servers in the network",
112
// Return the average of the times retrieved from the various
114
clerk_->time_ = sum / no_of_servers ;
116
// Set the Time Displacement Factor. The TZ environment variable is
117
// read to set the time zone. We convert the timezone value from seconds
121
clerk_->time_displacement_factor (ACE_OS::timezone () / 60);
123
// Set the inaccuracy.
124
if (highest_time > lowest_time)
125
clerk_->inaccuracy (highest_time - lowest_time);
127
clerk_->inaccuracy (0);
129
const ACE_Time_Value timeofday = ACE_OS::gettimeofday ();
131
// Record the current time in a timestamp to know when global
132
// updation of time was done.
133
clerk_->update_timestamp_ =
134
ACE_static_cast (CORBA::ULongLong,
136
ACE_static_cast (ACE_UINT32,
138
ACE_static_cast (CORBA::ULongLong,
139
timeofday.usec () * 10);
143
if (TAO_debug_level > 0)
144
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
145
"Exception in handle_timeout()\n");
150
ACE_CHECK_RETURN (-1);
155
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
157
template class ACE_Array_Base <CosTime::TimeService_var>;
158
template class ACE_Array_Iterator <CosTime::TimeService_var>;
160
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
162
#pragma instantiate ACE_Array_Base <CosTime::TimeService_var>
163
#pragma instantiate ACE_Array_Iterator <CosTime::TimeService_var>
165
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */