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 */
src
core
model
timer.h
Generated on Fri Dec 21 2012 19:00:33 for ns-3 by
1.8.1.2