Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Service_Configurator / Misc / Timer_Service.cpp
blob6415f164d979719822eea127bacc46aec8bb17d3
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"));
12 int
13 Timer_Service_1::init (int argc, ACE_TCHAR *argv[])
15 ACE_DEBUG ((LM_DEBUG,
16 ACE_TEXT ("in Timer_Service::init, argv[0] = %s, argc == %d\n"),
17 argv[0], argc));
19 // Printout the <argv> values for sanity's sake.
20 for (int i = 0; i < argc; i++)
21 ACE_DEBUG ((LM_DEBUG,
22 ACE_TEXT ("argv[%d] = %s\n"),
23 i, argv[i]));
25 int interval = Timer_Service_1::TIMEOUT;
27 if (argc > 1)
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]);
34 if (interval == 0)
35 interval = Timer_Service_1::TIMEOUT;
38 if (argc > 2)
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
51 // enable tracing.
52 #if defined (ACE_HAS_TRACE)
53 if (argc > 3)
54 ACE_Trace::start_tracing ();
55 else
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
62 (this,
64 ACE_Time_Value (1),
65 ACE_Time_Value (interval)) == -1)
66 return -1;
67 else
68 return 0;
71 int
72 Timer_Service_1::handle_timeout (const ACE_Time_Value &tv,
73 const void *)
75 ACE_DEBUG ((LM_DEBUG,
76 ACE_TEXT ("(%x) in %s::handle_timeout sec = %d, usec = %d")
77 ACE_TEXT (" cur_timeouts = %d, max_timeouts = %d\n"),
78 this,
79 this->name_,
80 tv.sec (),
81 tv.usec (),
82 this->cur_timeouts_,
83 this->max_timeouts_));
85 this->cur_timeouts_++;
87 if (this->cur_timeouts_ == this->max_timeouts_)
88 // Shutdown the test.
89 return -1;
90 else
91 return 0;
94 int
95 Timer_Service_1::handle_close (ACE_HANDLE,
96 ACE_Reactor_Mask)
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();
104 return 0;
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"),
122 ACE_SVC_OBJ_T,
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
129 // Services.
130 ACE_SVC_FACTORY_DEFINE (Timer_Service_1)
131 ACE_SVC_FACTORY_DEFINE (Timer_Service_2)
132 ACE_SVC_FACTORY_DEFINE (Timer_Service_3)