1 #include "ace/OS_NS_string.h"
2 #include "Timer_Service.h"
3 #include "ace/Log_Msg.h"
6 Timer_Service_1::Timer_Service_1 ()
8 ACE_OS::strcpy (this->name_
,
9 ACE_TEXT ("Timer_Service_1"));
13 Timer_Service_1::init (int argc
, ACE_TCHAR
*argv
[])
16 ACE_TEXT ("in Timer_Service::init, argv[0] = %s, argc == %d\n"),
19 // Printout the <argv> values for sanity's sake.
20 for (int i
= 0; i
< argc
; i
++)
22 ACE_TEXT ("argv[%d] = %s\n"),
25 int interval
= Timer_Service_1::TIMEOUT
;
29 // If the second argument exists use this as the interval for
30 // the periodic timer. Otherwise, go off every TIMEOUT seconds.
32 interval
= ACE_OS::atoi (argv
[1]);
35 interval
= Timer_Service_1::TIMEOUT
;
40 // If the third argument exists use it to control the maximum
41 // number of timeouts.
42 this->max_timeouts_
= ACE_OS::atoi (argv
[2]);
44 if (this->max_timeouts_
== 0)
45 this->max_timeouts_
= Timer_Service_1::MAX_TIMEOUTS
;
48 this->cur_timeouts_
= 0;
50 // If the fourth argument exists take this as an indication to
52 #if defined (ACE_HAS_TRACE)
54 ACE_Trace::start_tracing ();
56 ACE_Trace::stop_tracing ();
57 #endif /* ACE_HAS_TRACE */
59 // Register the timer to go off in 1 second, and then to go off
60 // every <interval> seconds.
61 if (ACE_Reactor::instance ()->schedule_timer
65 ACE_Time_Value (interval
)) == -1)
72 Timer_Service_1::handle_timeout (const ACE_Time_Value
&tv
,
76 ACE_TEXT ("(%x) in %s::handle_timeout sec = %d, usec = %d")
77 ACE_TEXT (" cur_timeouts = %d, max_timeouts = %d\n"),
83 this->max_timeouts_
));
85 this->cur_timeouts_
++;
87 if (this->cur_timeouts_
== this->max_timeouts_
)
95 Timer_Service_1::handle_close (ACE_HANDLE
,
98 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("closing down the timer test\n")));
100 // Remove ourselves from the timer queue.
101 ACE_Reactor::instance ()->cancel_timer (this);
103 ACE_Reactor::end_event_loop();
107 Timer_Service_2::Timer_Service_2 ()
109 ACE_OS::strcpy (this->name_
,
110 ACE_TEXT ("Timer_Service_2"));
113 Timer_Service_3::Timer_Service_3 ()
115 ACE_OS::strcpy (this->name_
,
116 ACE_TEXT ("Timer_Service_3"));
119 // Define the object that describes the service.
120 ACE_STATIC_SVC_DEFINE (Timer_Service_1
,
121 ACE_TEXT ("Timer_Service_1"),
123 &ACE_SVC_NAME (Timer_Service_1
),
124 ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ
,
127 // The following are "Factories" used by the <ACE_Service_Config> and
128 // svc.conf file to dynamically initialize the state of the Timer
130 ACE_SVC_FACTORY_DEFINE (Timer_Service_1
)
131 ACE_SVC_FACTORY_DEFINE (Timer_Service_2
)
132 ACE_SVC_FACTORY_DEFINE (Timer_Service_3
)