Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Reactor / Schedule_Timers.cpp
blob06a66699ac9bf7072d85290674aea681e987acc5
1 /**
2 * Scheduling timers with the Reactor
3 */
5 #include "ace/OS_NS_time.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Reactor.h"
8 #include "ace/Event_Handler.h"
10 // Listing 1 code/ch07
11 class MyTimerHandler : public ACE_Event_Handler
13 public:
14 int handle_timeout (const ACE_Time_Value &current_time,
15 const void * = 0)
17 time_t epoch = ((timespec_t)current_time).tv_sec;
19 ACE_DEBUG ((LM_INFO,
20 ACE_TEXT ("handle_timeout: %s\n"),
21 ACE_OS::ctime (&epoch)));
23 return 0;
26 // Listing 1
28 // Create a SIGINT handler so that we can exit
29 // the program politely
30 class SigintHandler : public ACE_Event_Handler
32 public:
33 int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0)
35 if (signum == SIGINT)
37 ACE_Reactor::instance ()->end_reactor_event_loop ();
39 return 0;
43 int ACE_TMAIN (int, ACE_TCHAR *[])
45 // Listing 2 code/ch07
46 MyTimerHandler * timer = new MyTimerHandler ();
47 ACE_Time_Value initialDelay (3);
48 ACE_Time_Value interval (5);
49 ACE_Reactor::instance()->schedule_timer (timer,
51 initialDelay,
52 interval);
53 // Listing 2
55 // Exclude 1
56 SigintHandler * handleExit = new SigintHandler ();
57 ACE_Reactor::instance()->register_handler (SIGINT,
58 handleExit);
59 // Exclude 1
60 ACE_Reactor::instance ()->run_reactor_event_loop ();
61 return 0;