2 * Changing the interval and canceling
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
13 int handle_timeout (const ACE_Time_Value
¤t_time
,
16 time_t epoch
= ((timespec_t
)current_time
).tv_sec
;
18 ACE_TEXT ("handle_timeout: %s"),
19 ACE_OS::ctime(&epoch
)));
24 #if !defined (ACE_LACKS_UNIX_SIGNALS)
26 // Listing 1 code/ch07
27 class SignalHandler
: public ACE_Event_Handler
30 SignalHandler (long timerId
, int currentInterval
)
31 : ACE_Event_Handler(),
33 currentInterval_(currentInterval
)
37 int handle_signal (int sig
, siginfo_t
* = 0, ucontext_t
* = 0)
42 ACE_TEXT ("Resetting interval of timer ")
43 ACE_TEXT ("%d to %d\n"),
45 ++this->currentInterval_
));
46 ACE_Time_Value
newInterval (this->currentInterval_
);
47 ACE_Reactor::instance ()->
48 reset_timer_interval (this->timerId_
, newInterval
);
50 else if (sig
== SIGTSTP
)
53 ACE_TEXT ("Canceling timer %d\n"),
55 ACE_Reactor::instance ()->cancel_timer (this->timerId_
);
67 #endif /* ACE_LACKS_UNIX_SIGNALS */
70 int ACE_TMAIN (int, ACE_TCHAR
*[])
72 ACE_Time_Value
initialDelay (3);
73 ACE_Time_Value
interval (5);
75 // Listing 2 code/ch07
76 MyTimerHandler
*handler
= new MyTimerHandler ();
78 ACE_Reactor::instance ()->schedule_timer (handler
,
84 #if !defined (ACE_LACKS_UNIX_SIGNALS)
86 // Listing 3 code/ch07
87 SignalHandler
*mutateTimer
=
88 new SignalHandler (timerId
, 5);
89 ACE_Reactor::instance ()->register_handler (SIGINT
,
91 ACE_Reactor::instance ()->register_handler (SIGTSTP
,
96 ACE_UNUSED_ARG (timerId
);
97 #endif /* ACE_LACKS_UNIX_SIGNALS */
99 ACE_Reactor::instance ()->run_reactor_event_loop ();