A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
watchdog.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
#ifndef WATCHDOG_H
20
#define WATCHDOG_H
21
22
#include "
event-id.h
"
23
#include "
nstime.h
"
24
31
namespace
ns3
32
{
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
107
template
<
typename
... Ts>
108
void
SetArguments
(Ts&&...
args
);
111
private
:
113
void
Expire
();
118
TimerImpl
*
m_impl
;
120
EventId
m_event
;
122
Time
m_end
;
123
};
124
125
}
// namespace ns3
126
127
/********************************************************************
128
* Implementation of the templates declared above.
129
********************************************************************/
130
131
#include "
timer-impl.h
"
132
133
namespace
ns3
134
{
135
136
template
<
typename
FN>
137
void
138
Watchdog::SetFunction
(FN fn)
139
{
140
delete
m_impl
;
141
m_impl
=
MakeTimerImpl
(fn);
142
}
143
144
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
145
void
146
Watchdog::SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr)
147
{
148
delete
m_impl
;
149
m_impl
=
MakeTimerImpl
(memPtr, objPtr);
150
}
151
152
template
<
typename
... Ts>
153
void
154
Watchdog::SetArguments
(Ts&&...
args
)
155
{
156
if
(
m_impl
==
nullptr
)
157
{
158
NS_FATAL_ERROR
(
"You cannot set the arguments of a Watchdog before setting its function."
);
159
return
;
160
}
161
m_impl
->
SetArgs
(std::forward<Ts>(
args
)...);
162
}
163
164
}
// namespace ns3
165
166
#endif
/* WATCHDOG_H */
ns3::EventId
An identifier for simulation events.
Definition:
event-id.h:55
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
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:1085
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition:
watchdog.h:57
ns3::Watchdog::Expire
void Expire()
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:154
ns3::Watchdog::m_event
EventId m_event
The future event scheduled to expire the timer.
Definition:
watchdog.h:120
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:138
ns3::Watchdog::m_impl
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition:
watchdog.h:118
ns3::Watchdog::m_end
Time m_end
The absolute time when the timer will expire.
Definition:
watchdog.h:122
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:179
ns3::MakeTimerImpl
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition:
timer-impl.h:254
check-style-clang-format.args
args
Definition:
check-style-clang-format.py:754
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 Sun Mar 3 2024 17:10:56 for ns-3 by
1.9.1