~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "Timer_Helper.h"
2
 
#include "TAO_Time_Service_Clerk.h"
3
 
 
4
 
#include "tao/debug.h"
5
 
 
6
 
#include "ace/OS_NS_time.h"
7
 
#include "ace/OS_NS_sys_time.h"
8
 
 
9
 
ACE_RCSID (Time,
10
 
           Timer_Helper,
11
 
           "Timer_Helper.cpp,v 1.27 2003/11/05 03:59:58 dhinton Exp")
12
 
 
13
 
 
14
 
Timer_Helper::Timer_Helper (void)
15
 
  : clerk_ (0)
16
 
{
17
 
}
18
 
 
19
 
Timer_Helper::Timer_Helper (TAO_Time_Service_Clerk *clerk)
20
 
  : clerk_ (clerk)
21
 
{
22
 
 
23
 
}
24
 
 
25
 
Timer_Helper::~Timer_Helper (void)
26
 
{
27
 
}
28
 
 
29
 
int
30
 
Timer_Helper::handle_timeout (const ACE_Time_Value &,
31
 
                              const void *)
32
 
{
33
 
  int no_of_servers = 0;
34
 
  CORBA::ULongLong sum = 0;
35
 
 
36
 
  // The following are used to keep a track of the inaccuracy
37
 
  // in synchronization.
38
 
 
39
 
#if defined (ACE_LACKS_LONGLONG_T)
40
 
  CORBA::ULongLong lowest_time (0xFFFFFFFF, 0xFFFFFFFF);
41
 
#else
42
 
  CORBA::ULongLong lowest_time = ACE_UINT64_LITERAL (0xFFFFFFFFFFFFFFFF);
43
 
#endif
44
 
 
45
 
  CORBA::ULongLong highest_time  = 0;
46
 
 
47
 
  ACE_DECLARE_NEW_CORBA_ENV;
48
 
  ACE_TRY
49
 
    {
50
 
      IORS::TYPE* value;
51
 
      for (IORS::ITERATOR server_iterator (this->clerk_->server_);
52
 
           server_iterator.next (value) != 0;
53
 
           server_iterator.advance ())
54
 
        {
55
 
          // This is a remote call.
56
 
          CosTime::UTO_var UTO_server =
57
 
            (*value)->universal_time (ACE_ENV_SINGLE_ARG_PARAMETER);
58
 
          ACE_TRY_CHECK;
59
 
 
60
 
#if defined (ACE_LACKS_LONGLONG_T)
61
 
 
62
 
          if (TAO_debug_level > 0)
63
 
            ACE_DEBUG ((LM_DEBUG,
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 ()),
68
 
                        UTO_server->tdf (),
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));
73
 
 
74
 
#else
75
 
 
76
 
          if (TAO_debug_level > 0)
77
 
            ACE_DEBUG ((LM_DEBUG,
78
 
                        "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n"
79
 
                        "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
80
 
                        UTO_server->time (),
81
 
                        UTO_server->inaccuracy (),
82
 
                        UTO_server->tdf (),
83
 
                        (UTO_server->utc_time ()).time,
84
 
                        (UTO_server->utc_time ()).inacclo,
85
 
                        (UTO_server->utc_time ()).inacchi,
86
 
                        (UTO_server->utc_time ()).tdf));
87
 
#endif
88
 
 
89
 
          CORBA::ULongLong curr_server_time =
90
 
            UTO_server->time (ACE_ENV_SINGLE_ARG_PARAMETER);
91
 
          ACE_TRY_CHECK;
92
 
 
93
 
          sum += curr_server_time;
94
 
 
95
 
          ++no_of_servers;
96
 
 
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;
100
 
 
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;
104
 
 
105
 
        }
106
 
 
107
 
      if (TAO_debug_level > 0)
108
 
        ACE_DEBUG ((LM_DEBUG,
109
 
                    "\nUpdated time from %d servers in the network",
110
 
                    no_of_servers));
111
 
 
112
 
      // Return the average of the times retrieved from the various
113
 
      // servers.
114
 
      clerk_->time_ = sum / no_of_servers ;
115
 
 
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
118
 
      // to minutes.
119
 
 
120
 
      ACE_OS::tzset();
121
 
      clerk_->time_displacement_factor (ACE_OS::timezone () / 60);
122
 
 
123
 
      // Set the inaccuracy.
124
 
      if (highest_time > lowest_time)
125
 
        clerk_->inaccuracy (highest_time - lowest_time);
126
 
      else
127
 
        clerk_->inaccuracy (0);
128
 
 
129
 
      const ACE_Time_Value timeofday = ACE_OS::gettimeofday ();
130
 
 
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,
135
 
                         timeofday.sec ()) *
136
 
        ACE_static_cast (ACE_UINT32,
137
 
                         10000000) +
138
 
        ACE_static_cast (CORBA::ULongLong,
139
 
                         timeofday.usec () * 10);
140
 
    }
141
 
  ACE_CATCHANY
142
 
    {
143
 
      if (TAO_debug_level > 0)
144
 
        ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
145
 
                             "Exception in handle_timeout()\n");
146
 
 
147
 
      return -1;
148
 
    }
149
 
  ACE_ENDTRY;
150
 
  ACE_CHECK_RETURN (-1);
151
 
 
152
 
  return 0;
153
 
}
154
 
 
155
 
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
156
 
 
157
 
template class ACE_Array_Base <CosTime::TimeService_var>;
158
 
template class ACE_Array_Iterator <CosTime::TimeService_var>;
159
 
 
160
 
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
161
 
 
162
 
#pragma instantiate ACE_Array_Base <CosTime::TimeService_var>
163
 
#pragma instantiate ACE_Array_Iterator <CosTime::TimeService_var>
164
 
 
165
 
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */