Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Reactor / Reschedule.cpp
blob807d76e6cb0cff58001ee7b06cd23aaf92ce29f7
1 /**
2 * Changing the interval
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 class MyTimerHandler : public ACE_Event_Handler
12 public:
13 int handle_timeout (const ACE_Time_Value &current_time,
14 const void * = 0 )
16 time_t epoch = ((timespec_t)current_time).tv_sec;
17 ACE_DEBUG ((LM_INFO,
18 ACE_TEXT ("handle_timeout: %s"),
19 ACE_OS::ctime(&epoch)));
20 return 0;
24 // Listing 1 code/ch07
25 class SigintHandler : public ACE_Event_Handler
27 public:
28 SigintHandler (long timerId, int currentInterval)
29 : ACE_Event_Handler(),
30 timerId_(timerId),
31 currentInterval_(currentInterval)
35 int handle_signal (int, siginfo_t * = 0, ucontext_t * = 0)
37 ACE_DEBUG ((LM_INFO,
38 ACE_TEXT ("Resetting interval of timer ")
39 ACE_TEXT ("%d to %d\n"),
40 this->timerId_,
41 ++this->currentInterval_));
42 ACE_Time_Value newInterval (this->currentInterval_);
43 ACE_Reactor::instance()->
44 reset_timer_interval (this->timerId_, newInterval);
45 return 0;
48 private:
49 long timerId_;
50 int currentInterval_;
52 // Listing 1
54 int ACE_TMAIN (int, ACE_TCHAR *[])
56 ACE_Time_Value initialDelay (3);
57 ACE_Time_Value interval (5);
59 // Listing 2 code/ch07
60 MyTimerHandler *handler = new MyTimerHandler ();
62 long timerId =
63 ACE_Reactor::instance ()->schedule_timer (handler,
65 initialDelay,
66 interval);
67 // Listing 2
69 // Listing 3 code/ch07
70 SigintHandler *handleSigint =
71 new SigintHandler (timerId, 5);
72 ACE_Reactor::instance ()->register_handler (SIGINT,
73 handleSigint);
74 // Listing 3
76 ACE_Reactor::instance ()->run_reactor_event_loop ();
77 return 0;