1 #include "ace/OS_NS_sys_time.h"
2 #include "ace/Log_Msg.h"
4 #include "PTimerDispatcher.h"
7 // The signature of this method changed at ACE 5.4. The 'recurring_timer'
8 // parameter was added.
10 UpcallHandler::timeout (PTimerQueue
&,
13 int /* recurring_timer */,
14 const ACE_Time_Value
&)
16 ACE_TRACE ("UpcallHandler::timeout");
18 return (*handler
).handleEvent (arg
);
22 // This method was removed at ACE 5.4. Replaced by cancel_type() and
25 UpcallHandler::cancellation (PTimerQueue
&,
28 ACE_TRACE ("UpcallHandler::cancellation");
31 ACE_TEXT ("Handler %d has been cancelled\n"),
34 return handler
->handleCancel ();
38 // This method is called when the timer is canceled
40 UpcallHandler::deletion (PTimerQueue
&,
44 ACE_TRACE ("UpcallHandler::deletion");
47 ACE_TEXT ("Handler %d has been deleted\n"),
50 return handler
->handleClose ();
54 // *** The rest of the UpcallHandler methods were added for ACE 5.4 ***
56 // This method is called when a timer is registered.
58 UpcallHandler::registration (PTimerQueue
&,
62 ACE_TRACE ("UpcallHandler::registration");
65 ACE_TEXT ("Handler %d has been registered.\n"),
70 // This method is called at expiration time, before the actual upcall
71 // to the handler is made. ACE uses this to adjust reference counts
74 UpcallHandler::preinvoke (PTimerQueue
&,
78 const ACE_Time_Value
&,
81 ACE_TRACE ("UpcallHandler::preinvoke");
84 ACE_TEXT ("Handler %d is about to upcalled.\n"),
89 // This method is called at expiration time, after the actual upcall
90 // to the handler returns. ACE uses this to adjust reference counts
93 UpcallHandler::postinvoke (PTimerQueue
&,
97 const ACE_Time_Value
&,
100 ACE_TRACE ("UpcallHandler::postinvoke");
102 ACE_DEBUG ((LM_DEBUG
,
103 ACE_TEXT ("Handler %d returned from upcall.\n"),
108 // This method is called when a handler is cancelled
110 UpcallHandler::cancel_type (PTimerQueue
&,
115 ACE_TRACE ("UpcallHandler::cancel_type");
117 ACE_DEBUG ((LM_DEBUG
,
118 ACE_TEXT ("Handler %d has been cancelled\n"),
121 return handler
->handleCancel ();
125 // This method is called when a timer is cancelled
127 UpcallHandler::cancel_timer (PTimerQueue
&,
132 ACE_TRACE ("UpcallHandler::cancel_timer");
134 ACE_DEBUG ((LM_DEBUG
,
135 ACE_TEXT ("Handler %d has been cancelled\n"),
138 return handler
->handleCancel ();
143 // Listing 3 code/ch20
144 int ACE_TMAIN (int, ACE_TCHAR
*[])
149 int arg1
= 1, arg2
= 2;
151 PTimerQueue
*timerQueue
;
153 ACE_NEW_RETURN (timerQueue
, PTimerHeap (), -1);
155 PTimer::instance ()->set (timerQueue
);
157 ACE_Time_Value tv
= ACE_OS::gettimeofday ();
160 // Schedule two different timers to go off.
161 PTimer::instance ()->schedule (&cb1
, &arg1
, tv
, ACE_Time_Value (1));
162 PTimer::instance ()->schedule (&cb2
, &arg2
, tv
, ACE_Time_Value (2));
164 // Run the timer event loop forever.
165 PTimer::instance ()->wait_for_event ();