A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
timer.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef TIMER_H
21
#define TIMER_H
22
23
#include "
fatal-error.h
"
24
#include "
nstime.h
"
25
#include "
event-id.h
"
26
#include "
int-to-type.h
"
27
28
namespace
ns3 {
29
30
class
TimerImpl;
31
45
class
Timer
46
{
47
public
:
52
enum
DestroyPolicy
53
{
58
CANCEL_ON_DESTROY
= (1 << 3),
63
REMOVE_ON_DESTROY
= (1 << 4),
68
CHECK_ON_DESTROY
= (1 << 5)
69
};
70
enum
State
71
{
72
RUNNING
,
73
EXPIRED
,
74
SUSPENDED
,
75
};
80
Timer
();
84
Timer
(
enum
DestroyPolicy
destroyPolicy);
85
~Timer
();
86
92
template
<
typename
FN>
93
void
SetFunction
(FN fn);
94
101
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
102
void
SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr);
103
104
110
template
<
typename
T1>
111
void
SetArguments
(T1 a1);
118
template
<
typename
T1,
typename
T2>
119
void
SetArguments
(T1 a1, T2 a2);
127
template
<
typename
T1,
typename
T2,
typename
T3>
128
void
SetArguments
(T1 a1, T2 a2, T3 a3);
137
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4>
138
void
SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4);
148
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5>
149
void
SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
160
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5,
typename
T6>
161
void
SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6);
162
168
void
SetDelay
(
const
Time
&delay);
172
Time
GetDelay
(
void
)
const
;
178
Time
GetDelayLeft
(
void
)
const
;
183
void
Cancel
(
void
);
188
void
Remove
(
void
);
192
bool
IsExpired
(
void
)
const
;
196
bool
IsRunning
(
void
)
const
;
201
bool
IsSuspended
(
void
)
const
;
205
enum
Timer::State
GetState
(
void
)
const
;
210
void
Schedule
(
void
);
217
void
Schedule
(
Time
delay);
218
224
void
Suspend
(
void
);
230
void
Resume
(
void
);
231
232
private
:
233
enum
234
{
235
TIMER_SUSPENDED
= (1 << 7)
236
};
237
238
int
m_flags
;
239
Time
m_delay
;
240
EventId
m_event
;
241
TimerImpl
*
m_impl
;
242
Time
m_delayLeft
;
243
};
244
245
}
// namespace ns3
246
247
#include "
timer-impl.h
"
248
249
namespace
ns3 {
250
251
252
template
<
typename
FN>
253
void
254
Timer::SetFunction
(FN fn)
255
{
256
delete
m_impl
;
257
m_impl
=
MakeTimerImpl
(fn);
258
}
259
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
260
void
261
Timer::SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr)
262
{
263
delete
m_impl
;
264
m_impl
=
MakeTimerImpl
(memPtr, objPtr);
265
}
266
267
template
<
typename
T1>
268
void
269
Timer::SetArguments
(T1 a1)
270
{
271
if
(
m_impl
== 0)
272
{
273
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
274
return
;
275
}
276
m_impl
->
SetArgs
(a1);
277
}
278
template
<
typename
T1,
typename
T2>
279
void
280
Timer::SetArguments
(T1 a1, T2 a2)
281
{
282
if
(
m_impl
== 0)
283
{
284
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
285
return
;
286
}
287
m_impl
->
SetArgs
(a1, a2);
288
}
289
290
template
<
typename
T1,
typename
T2,
typename
T3>
291
void
292
Timer::SetArguments
(T1 a1, T2 a2, T3 a3)
293
{
294
if
(
m_impl
== 0)
295
{
296
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
297
return
;
298
}
299
m_impl
->
SetArgs
(a1, a2, a3);
300
}
301
302
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4>
303
void
304
Timer::SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4)
305
{
306
if
(
m_impl
== 0)
307
{
308
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
309
return
;
310
}
311
m_impl
->
SetArgs
(a1, a2, a3, a4);
312
}
313
314
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5>
315
void
316
Timer::SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
317
{
318
if
(
m_impl
== 0)
319
{
320
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
321
return
;
322
}
323
m_impl
->
SetArgs
(a1, a2, a3, a4, a5);
324
}
325
326
template
<
typename
T1,
typename
T2,
typename
T3,
typename
T4,
typename
T5,
typename
T6>
327
void
328
Timer::SetArguments
(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
329
{
330
if
(
m_impl
== 0)
331
{
332
NS_FATAL_ERROR
(
"You cannot set the arguments of a Timer before setting its function."
);
333
return
;
334
}
335
m_impl
->
SetArgs
(a1, a2, a3, a4, a5, a6);
336
}
337
338
}
// namespace ns3
339
340
#endif
/* TIMER_H */
fatal-error.h
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
ns3::Timer
a simple Timer class
Definition:
timer.h:45
ns3::Timer::Timer
Timer()
Definition:
timer.cc:29
ns3::Timer::EXPIRED
Definition:
timer.h:73
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition:
fatal-error.h:72
ns3::Timer::IsRunning
bool IsRunning(void) const
Definition:
timer.cc:121
ns3::Timer::TIMER_SUSPENDED
Definition:
timer.h:235
ns3::Timer::m_delay
Time m_delay
Definition:
timer.h:239
ns3::Timer::CHECK_ON_DESTROY
Definition:
timer.h:68
ns3::Timer::Schedule
void Schedule(void)
Definition:
timer.cc:152
ns3::Timer::Remove
void Remove(void)
Definition:
timer.cc:109
ns3::Timer::SetFunction
void SetFunction(FN fn)
Definition:
timer.h:254
ns3::Timer::m_delayLeft
Time m_delayLeft
Definition:
timer.h:242
nstime.h
int-to-type.h
ns3::Timer::SetDelay
void SetDelay(const Time &delay)
Definition:
timer.cc:69
ns3::Timer::m_flags
int m_flags
Definition:
timer.h:238
ns3::Timer::GetState
enum Timer::State GetState(void) const
Definition:
timer.cc:133
ns3::Timer::CANCEL_ON_DESTROY
Definition:
timer.h:58
ns3::Timer::REMOVE_ON_DESTROY
Definition:
timer.h:63
ns3::Timer::SetArguments
void SetArguments(T1 a1)
Definition:
timer.h:269
ns3::Timer::Resume
void Resume(void)
Definition:
timer.cc:181
ns3::Timer::State
State
Definition:
timer.h:70
ns3::TimerImpl
Definition:
timer-impl.h:30
ns3::Timer::GetDelay
Time GetDelay(void) const
Definition:
timer.cc:75
ns3::Timer::SUSPENDED
Definition:
timer.h:74
ns3::Timer::~Timer
~Timer()
Definition:
timer.cc:47
ns3::EventId
an identifier for simulation events.
Definition:
event-id.h:46
ns3::Timer::m_impl
TimerImpl * m_impl
Definition:
timer.h:241
ns3::Timer::m_event
EventId m_event
Definition:
timer.h:240
ns3::Timer::Cancel
void Cancel(void)
Definition:
timer.cc:103
ns3::MakeTimerImpl
TimerImpl * MakeTimerImpl(FN fn)
Definition:
timer-impl.h:100
ns3::Timer::DestroyPolicy
DestroyPolicy
Definition:
timer.h:52
ns3::Timer::IsExpired
bool IsExpired(void) const
Definition:
timer.cc:115
ns3::Timer::Suspend
void Suspend(void)
Definition:
timer.cc:171
ns3::TimerImpl::SetArgs
void SetArgs(T1 a1)
Definition:
timer-impl.h:725
ns3::Timer::IsSuspended
bool IsSuspended(void) const
Definition:
timer.cc:127
ns3::Timer::GetDelayLeft
Time GetDelayLeft(void) const
Definition:
timer.cc:81
timer-impl.h
ns3::Timer::RUNNING
Definition:
timer.h:72
event-id.h
src
core
model
timer.h
Generated on Sat Nov 16 2013 12:55:24 for ns-3 by
1.8.5