A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
watchdog.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
#ifndef WATCHDOG_H
9
#define WATCHDOG_H
10
11
#include "
event-id.h
"
12
#include "
nstime.h
"
13
14
/**
15
* \file
16
* \ingroup timer
17
* ns3::Watchdog timer class declaration.
18
*/
19
20
namespace
ns3
21
{
22
23
namespace
internal
24
{
25
26
class
TimerImpl;
27
28
}
// namespace internal
29
30
/**
31
* \ingroup timer
32
* \brief A very simple watchdog operating in virtual time.
33
*
34
* The watchdog timer is started by calling Ping with a delay value.
35
* Once started the timer cannot be suspended, cancelled or shortened.
36
* It _can_ be lengthened (delayed) by calling Ping again: if the new
37
* expire time (current simulation time plus the new delay)
38
* is greater than the old expire time the timer will be extended
39
* to the new expire time.
40
*
41
* Typical usage would be to periodically Ping the Watchdog, extending
42
* it's execution time. If the owning process fails to Ping before
43
* the Watchdog expires, the registered function will be invoked.
44
*
45
* If you don't ping the watchdog sufficiently often, it triggers its
46
* listening function.
47
*
48
* \see Timer for a more sophisticated general purpose timer.
49
*/
50
class
Watchdog
51
{
52
public
:
53
/** Constructor. */
54
Watchdog
();
55
/** Destructor. */
56
~Watchdog
();
57
58
/**
59
* Delay the timer.
60
*
61
* \param [in] delay The watchdog delay
62
*
63
* After a call to this method, the watchdog will not be triggered
64
* until the delay specified has been expired. This operation is
65
* sometimes named "re-arming" a watchdog in some operating systems.
66
*/
67
void
Ping
(
Time
delay);
68
69
/**
70
* Set the function to execute when the timer expires.
71
*
72
* \tparam FN \deduced The type of the function.
73
* \param [in] fn The function
74
*
75
* Store this function in this Timer for later use by Timer::Schedule.
76
*/
77
template
<
typename
FN>
78
void
SetFunction
(FN fn);
79
80
/**
81
* Set the function to execute when the timer expires.
82
*
83
* \tparam MEM_PTR \deduced Class method function type.
84
* \tparam OBJ_PTR \deduced Class type containing the function.
85
* \param [in] memPtr The member function pointer
86
* \param [in] objPtr The pointer to object
87
*
88
* Store this function and object in this Timer for later use by Timer::Schedule.
89
*/
90
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
91
void
SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr);
92
93
/**
94
* Set the arguments to be used when invoking the expire function.
95
*/
96
/**@{*/
97
/**
98
* \tparam Ts \deduced Argument types.
99
* \param [in] args arguments
100
*/
101
template
<
typename
... Ts>
102
void
SetArguments
(Ts&&... args);
103
/**@}*/
104
105
private
:
106
/** Internal callback invoked when the timer expires. */
107
void
Expire
();
108
/**
109
* The timer implementation, which contains the bound callback
110
* function and arguments.
111
*/
112
internal::TimerImpl
*
m_impl
;
113
/** The future event scheduled to expire the timer. */
114
EventId
m_event
;
115
/** The absolute time when the timer will expire. */
116
Time
m_end
;
117
};
118
119
}
// namespace ns3
120
121
/********************************************************************
122
* Implementation of the templates declared above.
123
********************************************************************/
124
125
#include "
timer-impl.h
"
126
127
namespace
ns3
128
{
129
130
template
<
typename
FN>
131
void
132
Watchdog::SetFunction
(FN fn)
133
{
134
delete
m_impl
;
135
m_impl
=
internal::MakeTimerImpl
(fn);
136
}
137
138
template
<
typename
MEM_PTR,
typename
OBJ_PTR>
139
void
140
Watchdog::SetFunction
(MEM_PTR memPtr, OBJ_PTR objPtr)
141
{
142
delete
m_impl
;
143
m_impl
=
internal::MakeTimerImpl
(memPtr, objPtr);
144
}
145
146
template
<
typename
... Ts>
147
void
148
Watchdog::SetArguments
(Ts&&... args)
149
{
150
if
(
m_impl
==
nullptr
)
151
{
152
NS_FATAL_ERROR
(
"You cannot set the arguments of a Watchdog before setting its function."
);
153
return
;
154
}
155
m_impl
->
SetArgs
(std::forward<Ts>(args)...);
156
}
157
158
}
// namespace ns3
159
160
#endif
/* WATCHDOG_H */
ns3::EventId
An identifier for simulation events.
Definition
event-id.h:45
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition
watchdog.h:51
ns3::Watchdog::m_impl
internal::TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
Definition
watchdog.h:112
ns3::Watchdog::Expire
void Expire()
Internal callback invoked when the timer expires.
Definition
watchdog.cc:52
ns3::Watchdog::SetArguments
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition
watchdog.h:148
ns3::Watchdog::m_event
EventId m_event
The future event scheduled to expire the timer.
Definition
watchdog.h:114
ns3::Watchdog::~Watchdog
~Watchdog()
Destructor.
Definition
watchdog.cc:31
ns3::Watchdog::Watchdog
Watchdog()
Constructor.
Definition
watchdog.cc:23
ns3::Watchdog::Ping
void Ping(Time delay)
Delay the timer.
Definition
watchdog.cc:39
ns3::Watchdog::SetFunction
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition
watchdog.h:132
ns3::Watchdog::m_end
Time m_end
The absolute time when the timer will expire.
Definition
watchdog.h:116
ns3::internal::TimerImpl
The timer implementation underlying Timer and Watchdog.
Definition
timer-impl.h:35
ns3::internal::TimerImpl::SetArgs
void SetArgs(Args... args)
Set the arguments to be used when invoking the expire function.
Definition
timer-impl.h:182
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:168
ns3::internal::MakeTimerImpl
TimerImpl * MakeTimerImpl(U(fn)(Ts...))
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition
timer-impl.h:92
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 Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0