A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
watchdog.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 WATCHDOG_H
21
#define WATCHDOG_H
22
23
#include "
nstime.h
"
24
#include "
event-id.h
"
25
32
namespace
ns3
{
33
34
class
TimerImpl;
35
56
class
Watchdog
57
{
58
public
:
60
Watchdog
();
62
~Watchdog
();
63
73
void
Ping
(
Time
delay);
74
83
template
<
typename
FN>
84
void
SetFunction
(FN fn);
85
96
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
97
void
SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr);
98
99
108
template
<
typename
... Ts>
109
void
SetArguments
(Ts&&... args);
112
private
:
114
void
Expire
(
void
);
119
TimerImpl
*
m_impl
;
121
EventId
m_event
;
123
Time
m_end
;
124
};
125
126
}
// namespace ns3
127
128
129
/********************************************************************
130
* Implementation of the templates declared above.
131
********************************************************************/
132
133
#include "
timer-impl.h
"
134
135
namespace
ns3
{
136
137
138
template
<
typename
FN>
139
void
140
Watchdog::SetFunction
(FN fn)
141
{
142
delete
m_impl
;
143
m_impl
=
MakeTimerImpl
(fn);
144
}
145
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
146
void
147
Watchdog::SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr)
148
{
149
delete
m_impl
;
150
m_impl
=
MakeTimerImpl
(memPtr, objPtr);
151
}
152
153
template
<
typename
... Ts>
154
void
155
Watchdog::SetArguments
(Ts&&... args)
156
{
157
if
(
m_impl
== 0)
158
{
159
NS_FATAL_ERROR
(
"You cannot set the arguments of a Watchdog before setting its function."
);
160
return
;
161
}
162
m_impl
->
SetArgs
(std::forward<Ts>(args)...);
163
}
164
165
}
// namespace ns3
166
167
168
#endif
/* WATCHDOG_H */
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:54
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:103
ns3::TimerImpl
The timer implementation underlying Timer and Watchdog.
Definition:
timer-impl.h:43
ns3::TimerImpl::SetArgs
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition:
timer-impl.h:959
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition:
watchdog.h:57
ns3::Watchdog::Expire
void Expire(void)
Internal callback invoked when the timer expires.
Definition:
watchdog.cc:63
ns3::Watchdog::SetArguments
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition:
watchdog.h:155
ns3::Watchdog::m_event
EventId m_event
The future event scheduled to expire the timer.
Definition:
watchdog.h:121
ns3::Watchdog::~Watchdog
~Watchdog()
Destructor.
Definition:
watchdog.cc:42
ns3::Watchdog::Watchdog
Watchdog()
Constructor.
Definition:
watchdog.cc:34
ns3::Watchdog::Ping
void Ping(Time delay)
Delay the timer.
Definition:
watchdog.cc:50
ns3::Watchdog::SetFunction
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition:
watchdog.h:140
ns3::Watchdog::m_impl
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition:
watchdog.h:119
ns3::Watchdog::m_end
Time m_end
The absolute time when the timer will expire.
Definition:
watchdog.h:123
event-id.h
ns3::EventId declarations.
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:165
ns3::MakeTimerImpl
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition:
timer-impl.h:252
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nstime.h
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
timer-impl.h
ns3::TimerImpl declaration and implementation.
src
core
model
watchdog.h
Generated on Tue Feb 6 2024 19:21:17 for ns-3 by
1.9.1