3 //=============================================================================
5 * @file Custom_Handler.h
7 * This is a custom event handler to be used with the thread timer queue
8 * adapter, and its appropriate upcall.
10 * @author Alon Diamant <diamant.alon@gmail.com>
12 //=============================================================================
15 #ifndef _CUSTOM_HANDLER_H_
16 #define _CUSTOM_HANDLER_H_
18 #include "ace/Timer_Queue.h"
19 #include "ace/svc_export.h"
22 * @class Custom_Handler
24 * @brief Custom event handler for the timer queue timeout events.
26 * The <on_timeout> hook method prints out the current time,
27 * prints the time when this timer expired and deletes "this".
32 Custom_Handler (const ACE_Time_Value
&expiration_time
);
34 virtual ~Custom_Handler ();
36 // Set the custom handler's id
40 virtual int on_timeout(const ACE_Time_Value
¤t_time
,
44 // Store the expected time of expiration, it is used to print a nice
45 // message saying how much delay was at the actual expiration time.
46 ACE_Time_Value expires_
;
48 // Store an "id" for the Handler, which is only use to print better
54 /// CWorkItemAndParamTupleUpcall
56 /// Implements the Upcall interface used by the ACE_Timer_Queue, specifically for the
57 /// IWorkItem interface.
58 class ACE_Svc_Export Custom_Handler_Upcall
61 typedef ACE_Timer_Queue_T
<Custom_Handler
*,
62 Custom_Handler_Upcall
,
63 ACE_Null_Mutex
> TTimerQueue
;
65 // Default constructor
66 Custom_Handler_Upcall()
71 ~Custom_Handler_Upcall()
75 // This method is called when a timer is registered.
76 int registration(TTimerQueue
& timer_queue
,
77 Custom_Handler
* handler
,
80 // This method is called before the timer expires.
81 int preinvoke(TTimerQueue
& timer_queue
,
82 Custom_Handler
* handler
,
85 const ACE_Time_Value
& cur_time
,
86 const void*& upcall_act
);
88 // This method is called when the timer expires.
89 int timeout (TTimerQueue
& timer_queue
,
90 Custom_Handler
* handler
,
93 const ACE_Time_Value
& cur_time
);
95 // This method is called after the timer expires.
96 int postinvoke(TTimerQueue
& timer_queue
,
97 Custom_Handler
* handler
,
100 const ACE_Time_Value
& cur_time
,
101 const void* upcall_act
);
103 // This method is called when a handler is canceled
104 int cancel_type(TTimerQueue
& timer_queue
,
105 Custom_Handler
* handler
,
107 int& requires_reference_counting
);
109 // This method is called when a timer is canceled
110 int cancel_timer(TTimerQueue
& timer_queue
,
111 Custom_Handler
* handler
,
113 int requires_reference_counting
);
115 // This method is called when the timer queue is destroyed and
116 // the timer is still contained in it
117 int deletion(TTimerQueue
& timer_queue
,
118 Custom_Handler
* handler
,