1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
//=============================================================================
/**
* @file Custom_Handler.cpp
*
* $Id$
*
* This is a custom event handler to be used with the thread timer queue
* adapter, and its appropriate upcall.
*
*
* @author Alon Diamant <diamant.alon@gmail.com
*/
//=============================================================================
#include "Custom_Handler.h"
#include "ace/OS_NS_stdio.h"
Custom_Handler::Custom_Handler(const ACE_Time_Value &expiration_time)
: expires_ (expiration_time),
id_ (0)
{
}
Custom_Handler::~Custom_Handler (void)
{
}
void
Custom_Handler::set_id (int id)
{
this->id_ = id;
}
// This is the method invoked when the Timer expires.
int
Custom_Handler::on_timeout (const ACE_Time_Value ¤t_time,
const void *)
{
ACE_Time_Value delay = current_time - this->expires_;
// No need to protect this printf is always called from a Async safe
// point.
ACE_OS::printf ("\nexpiring timer %d at %lu.%7.7lu secs\n"
"\tthere was a %lu.%7.7lu secs delay\n",
this->id_,
static_cast<unsigned long> (current_time.sec ()),
static_cast<unsigned long> (current_time.usec ()),
static_cast<unsigned long> (delay.sec ()),
static_cast<unsigned long> (delay.usec ()));
// Notice this delete is protected.
delete this;
return 0;
}
int Custom_Handler_Upcall::registration(TTimerQueue& , Custom_Handler* , const void* )
{
ACE_TRACE("registration");
return 0;
}
int Custom_Handler_Upcall::preinvoke(TTimerQueue& , Custom_Handler* , const void* , int , const ACE_Time_Value& , const void*& )
{
ACE_TRACE("preinvoke");
return 0;
}
int Custom_Handler_Upcall::timeout(TTimerQueue& , Custom_Handler* handler, const void* arg, int , const ACE_Time_Value& cur_time)
{
ACE_TRACE("timeout");
// Do the actual timer call
handler->on_timeout(cur_time, arg);
return 0;
}
int Custom_Handler_Upcall::postinvoke(TTimerQueue& , Custom_Handler* , const void* , int , const ACE_Time_Value& , const void* )
{
ACE_TRACE("postinvoke");
return 0;
}
int Custom_Handler_Upcall::cancel_type(TTimerQueue& , Custom_Handler* , int , int& )
{
ACE_TRACE("cancel_type");
return 0;
}
int Custom_Handler_Upcall::cancel_timer(TTimerQueue& , Custom_Handler* handler, int , int )
{
ACE_TRACE("cancel_timer");
delete handler;
return 0;
}
int Custom_Handler_Upcall::deletion(TTimerQueue& , Custom_Handler* handler, const void* )
{
ACE_TRACE("deletion");
delete handler;
return 0;
}
|