1 //=============================================================================
5 * Implementation of the server.
7 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
13 #include "tao/ORB_Core.h"
14 #include "tao/PortableServer/PortableServer.h"
15 #include "ace/Reactor.h"
16 #include "ace/Timer_Queue.h"
17 #include "ace/Time_Value.h"
18 #include "ace/OS_NS_sys_time.h"
19 #include "ace/High_Res_Timer.h"
20 #include "ace/Get_Opt.h"
22 #if (TAO_HAS_TIME_POLICY == 1) && \
23 (defined (ACE_HAS_HI_RES_TIMER) || \
24 defined (ACE_WIN32) || \
25 (defined (ghs) && defined (ACE_HAS_PENTIUM)) || \
26 ((defined (__GNUG__) || defined (__INTEL_COMPILER)) && !defined(ACE_VXWORKS) && defined (ACE_HAS_PENTIUM)) || \
27 (defined (ACE_HAS_POWERPC_TIMER) && (defined (ghs) || defined (__GNUG__))) || \
28 (defined (ACE_HAS_CLOCK_GETTIME) && defined (ACE_HAS_CLOCK_GETTIME_MONOTONIC)))
30 #if defined(TAO_USE_HR_TIME_POLICY_STRATEGY)
31 bool uses_hr_time
= true;
33 bool uses_hr_time
= false;
37 : public ACE_Event_Handler
40 TestHandler (CORBA::ORB_ptr orb
)
41 : orb_ (CORBA::ORB::_duplicate (orb
)),
42 timeout_triggered_ (false)
45 virtual int handle_timeout (const ACE_Time_Value
&tv
,
48 bool trigger_in(const ACE_Time_Value
&delay
);
50 bool timeout_triggered () { return this->timeout_triggered_
; }
54 bool timeout_triggered_
;
57 int TestHandler::handle_timeout (const ACE_Time_Value
&,
60 ACE_DEBUG ((LM_DEBUG
, "TestHandler::handle_timeout - timeout triggered\n"));
61 this->timeout_triggered_
= true;
62 this->orb_
->shutdown (false);
66 bool TestHandler::trigger_in(const ACE_Time_Value
&delay
)
68 return -1 != this->orb_
->orb_core ()->reactor ()->schedule_timer (this, 0, delay
, ACE_Time_Value (0));
72 parse_args (int argc
, ACE_TCHAR
*argv
[])
74 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("h"));
77 while ((c
= get_opts ()) != -1)
85 ACE_ERROR_RETURN ((LM_ERROR
,
89 "\t-h\t: uses highres time policy\n",
95 // Indicates successful parsing of the command line
100 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
105 CORBA::ORB_init (argc
, argv
);
107 CORBA::Object_var poa_object
=
108 orb
->resolve_initial_references("RootPOA");
110 if (CORBA::is_nil (poa_object
.in ()))
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 "Unable to initialize the POA.\n"),
115 PortableServer::POA_var root_poa
=
116 PortableServer::POA::_narrow (poa_object
.in ());
118 PortableServer::POAManager_var poa_manager
=
119 root_poa
->the_POAManager ();
121 if (parse_args (argc
, argv
) != 0)
124 poa_manager
->activate ();
126 TestHandler
test_handler (orb
.in ());
128 // trigger in 2 seconds
129 if (!test_handler
.trigger_in (ACE_Time_Value (2, 0)))
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "Unable to schedule trigger.\n"),
134 // reset system clock 4 seconds backwards
136 ACE_Time_Value curtime
= ACE_OS::gettimeofday ();
137 curtime
-= ACE_Time_Value (4, 0);
139 if (ACE_OS::clock_settime (CLOCK_REALTIME
, &curts
) != 0)
142 "Unable to reset OS time. Insufficient privileges or not supported.\n"));
144 root_poa
->destroy (true, // ethernalize objects
145 false); // wait for completion
153 // run for max. 4 seconds
154 ACE_Time_Value
timeout (4, 0);
157 root_poa
->destroy (true, // ethernalize objects
158 false); // wait for completion
162 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
164 // reset system clock to correct time
165 curtime
= ACE_OS::gettimeofday ();
166 curtime
+= ACE_Time_Value (4, 0);
168 ACE_OS::clock_settime (CLOCK_REALTIME
, &curts
);
170 if (!test_handler
.timeout_triggered ())
172 ACE_DEBUG ((LM_DEBUG
, "timer handler did not trigger\n"));
173 return uses_hr_time
? 1 : 0;
177 return uses_hr_time
? 0 : 1;
181 catch (const CORBA::Exception
& ex
)
183 ex
._tao_print_exception ("Caught exception:");
190 ACE_TMAIN(int , ACE_TCHAR
* [])
192 ACE_DEBUG ((LM_INFO
, "TAO built without Time Policy support\n"));
195 #endif /* TAO_HAS_TIME_POLICY != 1 */