libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
Timer.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// Timer.h
4
//------------------------------------------------------------------------------
5
// Copyright (c) 1999,2005 by Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------------
12
// Create: 09/27/1999
13
//------------------------------------------------------------------------------
14
#ifndef TIMER_H
15
#define TIMER_H
16
17
#if !defined(WIN32)
18
# include <sys/select.h>
19
#endif
20
21
#include <sys/time.h>
22
23
#include "
EventHandler.h
"
24
#include "
assa/TimeVal.h
"
25
26
namespace
ASSA {
27
28
class
TimerQueue;
// forward declaration
29
35
class
Timer
36
{
37
public
:
39
Timer
();
40
47
Timer
(
const
EventHandler
* eh_,
48
const
TimeVal
& tm_,
49
const
TimeVal
& delta_,
50
const
std::string& name_);
51
53
Timer
(
const
Timer
& t_);
54
56
~Timer
();
57
59
Timer
&
operator=
(
const
Timer
& t_);
60
62
bool
operator<
(
const
Timer
& t_)
const
;
63
65
bool
operator==
(
const
Timer
& t_)
const
;
66
68
EventHandler
*
getHandler
()
const
{
return
m_eh
; }
69
71
const
TimeVal
&
getExpirationTime
()
const
{
return
m_timer
; }
72
74
const
TimeVal
&
getDeltaTime
()
const
{
return
m_delta
; }
75
77
void
rescheduleExpirationTime
();
78
80
void
dump
(
void
);
81
85
void
set_id
(
const
std::string& id_) {
m_id
= id_; }
86
89
std::string
get_id
()
const
{
return
m_id
; }
90
91
private
:
93
EventHandler
*
m_eh
;
94
96
TimeVal
m_timer
;
97
99
TimeVal
m_delta
;
100
102
std::string
m_id
;
103
};
104
//------------------------------------------------------------------------------
105
// Timer class inlines
106
//------------------------------------------------------------------------------
107
108
inline
109
Timer::
110
Timer
()
111
: m_eh (NULL), m_id (
"<unknown>"
)
112
{
113
trace
(
"Timer::Timer"
);
114
}
115
116
inline
117
Timer::
118
Timer
(
const
EventHandler
* eh_,
const
TimeVal
& tm_,
119
const
TimeVal
& delta_,
const
std::string& name_)
120
: m_eh ((
EventHandler
*) eh_), m_timer (tm_), m_delta (delta_), m_id (name_)
121
{
122
trace
(
"Timer::Timer(EH*, TV&)"
);
123
}
124
125
inline
126
Timer::
127
Timer
(
const
Timer
& t_)
128
: m_eh (t_.m_eh), m_timer (t_.m_timer),
129
m_delta (t_.m_delta), m_id (t_.m_id)
130
{
131
trace
(
"Timer::Timer(Timer&)"
);
132
}
133
134
inline
135
Timer::
136
~Timer
()
137
{
138
trace
(
"Timer::~Timer"
);
139
}
140
141
inline
Timer
&
142
Timer::
143
operator=
(
const
Timer
& t_)
144
{
145
m_eh
= t_.
m_eh
;
146
m_timer
= t_.
m_timer
;
147
m_delta
= t_.
m_delta
;
148
m_id
= t_.
m_id
;
149
150
return
*
this
;
151
}
152
153
inline
bool
154
Timer::
155
operator<
(
const
Timer
& t_)
const
156
{
157
return
m_timer
< t_.
m_timer
;
158
}
159
160
inline
bool
161
Timer::
162
operator==
(
const
Timer
& t_)
const
163
{
164
return
m_timer
== t_.
m_timer
;
165
}
166
167
inline
void
168
Timer::
169
rescheduleExpirationTime
()
170
{
171
TimeVal
now (
TimeVal::gettimeofday
());
172
m_timer
= now +
m_delta
;
173
}
174
175
inline
void
176
Timer::
177
dump
(
void
)
178
{
179
DL
((
REACT
,
"Timer %s (EH=%s) expires at %s (delta=%s)\n"
,
180
get_id
().c_str (),
181
m_eh
->
get_id
().c_str (),
182
m_timer
.
fmtString
().c_str(),
183
m_delta
.
fmt_mm_ss_mls
().c_str()));
184
}
185
189
struct
TimerCompare
190
{
191
bool
operator()
(
const
Timer
* t1_,
const
Timer
* t2_)
const
192
{
193
return
(*t1_ < *t2_);
194
}
195
};
196
197
}
// end namespace ASSA
198
199
#endif
/* TIMER_H */
Generated on Tue Jun 19 2012 08:06:08 for libassa by
1.8.1.1