1 //=============================================================================
3 * @file Custom_Handler.cpp
5 * This is a custom event handler to be used with the thread timer queue
6 * adapter, and its appropriate upcall.
8 * @author Alon Diamant <diamant.alon@gmail.com
10 //=============================================================================
13 #include "Custom_Handler.h"
14 #include "ace/OS_NS_stdio.h"
16 Custom_Handler::Custom_Handler(const ACE_Time_Value
&expiration_time
)
17 : expires_ (expiration_time
),
22 Custom_Handler::~Custom_Handler ()
27 Custom_Handler::set_id (int id
)
32 // This is the method invoked when the Timer expires.
34 Custom_Handler::on_timeout (const ACE_Time_Value
¤t_time
,
37 ACE_Time_Value delay
= current_time
- this->expires_
;
39 // No need to protect this printf is always called from a Async safe
41 ACE_OS::printf ("\nexpiring timer %d at %lu.%7.7lu secs\n"
42 "\tthere was a %lu.%7.7lu secs delay\n",
44 static_cast<unsigned long> (current_time
.sec ()),
45 static_cast<unsigned long> (current_time
.usec ()),
46 static_cast<unsigned long> (delay
.sec ()),
47 static_cast<unsigned long> (delay
.usec ()));
49 // Notice this delete is protected.
55 int Custom_Handler_Upcall::registration(TTimerQueue
& , Custom_Handler
* , const void* )
57 ACE_TRACE("registration");
62 int Custom_Handler_Upcall::preinvoke(TTimerQueue
& , Custom_Handler
* , const void* , int , const ACE_Time_Value
& , const void*& )
64 ACE_TRACE("preinvoke");
69 int Custom_Handler_Upcall::timeout(TTimerQueue
& , Custom_Handler
* handler
, const void* arg
, int , const ACE_Time_Value
& cur_time
)
73 // Do the actual timer call
74 handler
->on_timeout(cur_time
, arg
);
79 int Custom_Handler_Upcall::postinvoke(TTimerQueue
& , Custom_Handler
* , const void* , int , const ACE_Time_Value
& , const void* )
81 ACE_TRACE("postinvoke");
86 int Custom_Handler_Upcall::cancel_type(TTimerQueue
& , Custom_Handler
* , int , int& )
88 ACE_TRACE("cancel_type");
93 int Custom_Handler_Upcall::cancel_timer(TTimerQueue
& , Custom_Handler
* handler
, int , int )
95 ACE_TRACE("cancel_timer");
100 int Custom_Handler_Upcall::deletion(TTimerQueue
& , Custom_Handler
* handler
, const void* )
102 ACE_TRACE("deletion");