summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Time/Timer_Helper.cpp
blob: 1d25195448a7946f8f17ebcbec761eb9133f106b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// -*- C++ -*-
// $Id$

#include "Timer_Helper.h"
#include "TAO_Time_Service_Clerk.h"

// Constructor.
Timer_Helper::Timer_Helper (void)
{
}

// Constructor that sets the clerk.
Timer_Helper::Timer_Helper (TAO_Time_Service_Clerk *clerk)
  : clerk_ (clerk)
{

}

// Destructor.
Timer_Helper::~Timer_Helper (void)
{
  delete this;
}

int
Timer_Helper::handle_timeout (const ACE_Time_Value &time,
			      const void *arg)
{
  int no_of_servers = 0;
  CORBA::ULongLong sum = 0;

  TAO_TRY
    {
      IORS::TYPE* value;
      for (IORS::ITERATOR server_iterator (this->clerk_->server_);
	   server_iterator.next (value) != 0;
	   server_iterator.advance ())
	{
	  // This is a remote call.
	  CosTime::UTO_var UTO_server =
	    (*value)->universal_time (TAO_TRY_ENV);

	  TAO_CHECK_ENV;

	  ACE_DEBUG ((LM_DEBUG,
		      "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n"
		      "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n",
		      UTO_server->time (TAO_TRY_ENV),
		      UTO_server->inaccuracy (TAO_TRY_ENV),
		      UTO_server->tdf (TAO_TRY_ENV),
		      (UTO_server->utc_time ()).time,
		      (UTO_server->utc_time ()).inacclo,
		      (UTO_server->utc_time ()).inacchi,
		      (UTO_server->utc_time ()).tdf));

	  // This is a remote call.
	  sum += (CORBA::ULongLong) UTO_server->time (TAO_TRY_ENV);

	  ++no_of_servers;
	}

      ACE_DEBUG ((LM_DEBUG,
		  "\nUpdated time from %d servers in the network",
		  no_of_servers));

      // Return the average of the times retrieved from the various
      // servers.
      clerk_->time_ = sum / no_of_servers ;

      // Record the current time in a timestamp to know when global
      // updation of time was done.
      clerk_->update_timestamp_ = ACE_OS::gettimeofday ().sec ();
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception in the handle_timeout ()\n");
      return -1;
    }
  TAO_ENDTRY;

  return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class ACE_Array_Base <CosTime::TimeService_var>;
template class ACE_Array_Iterator <CosTime::TimeService_var>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate ACE_Array_Base <CosTime::TimeService_var>
#pragma instantiate ACE_Array_Iterator <CosTime::TimeService_var>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */