A very simple watchdog operating in virtual time. More...
#include "watchdog.h"
Public Member Functions | |
Watchdog () | |
Constructor. More... | |
~Watchdog () | |
Destructor. More... | |
void | Ping (Time delay) |
Delay the timer. More... | |
template<typename FN > | |
void | SetFunction (FN fn) |
Set the function to execute when the timer expires. More... | |
template<typename MEM_PTR , typename OBJ_PTR > | |
void | SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr) |
Set the function to execute when the timer expires. More... | |
template<typename... Ts> | |
void | SetArguments (Ts &&... args) |
Set the arguments to be used when invoking the expire function. More... | |
Private Member Functions | |
void | Expire () |
Internal callback invoked when the timer expires. More... | |
Private Attributes | |
Time | m_end |
The absolute time when the timer will expire. More... | |
EventId | m_event |
The future event scheduled to expire the timer. More... | |
TimerImpl * | m_impl |
The timer implementation, which contains the bound callback function and arguments. More... | |
A very simple watchdog operating in virtual time.
The watchdog timer is started by calling Ping with a delay value. Once started the timer cannot be suspended, cancelled or shortened. It can be lengthened (delayed) by calling Ping again: if the new expire time (current simulation time plus the new delay) is greater than the old expire time the timer will be extended to the new expire time.
Typical usage would be to periodically Ping the Watchdog, extending it's execution time. If the owning process fails to Ping before the Watchdog expires, the registered function will be invoked.
If you don't ping the watchdog sufficiently often, it triggers its listening function.
Definition at line 56 of file watchdog.h.
ns3::Watchdog::Watchdog | ( | ) |
ns3::Watchdog::~Watchdog | ( | ) |
Destructor.
Definition at line 42 of file watchdog.cc.
References ns3::EventId::Cancel(), m_event, m_impl, and NS_LOG_FUNCTION.
|
private |
Internal callback invoked when the timer expires.
Definition at line 63 of file watchdog.cc.
References ns3::TimerImpl::Invoke(), m_end, m_event, m_impl, ns3::Now(), ns3::Simulator::Now(), NS_LOG_FUNCTION, and ns3::Simulator::Schedule().
Referenced by Ping().
void ns3::Watchdog::Ping | ( | Time | delay | ) |
Delay the timer.
[in] | delay | The watchdog delay |
After a call to this method, the watchdog will not be triggered until the delay specified has been expired. This operation is sometimes named "re-arming" a watchdog in some operating systems.
Definition at line 50 of file watchdog.cc.
References Expire(), ns3::EventId::IsRunning(), m_end, m_event, max, ns3::Now(), ns3::Simulator::Now(), NS_LOG_FUNCTION, and ns3::Simulator::Schedule().
Referenced by ns3::tests::WatchdogTestCase::DoRun().
void ns3::Watchdog::SetArguments | ( | Ts &&... | args | ) |
Set the arguments to be used when invoking the expire function.
Ts | [deduced] Argument types. |
[in] | args | arguments |
Definition at line 154 of file watchdog.h.
References check-style-clang-format::args, m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().
Referenced by ns3::tests::WatchdogTestCase::DoRun().
void ns3::Watchdog::SetFunction | ( | FN | fn | ) |
Set the function to execute when the timer expires.
FN | [deduced] The type of the function. |
[in] | fn | The function |
Store this function in this Timer for later use by Timer::Schedule.
Definition at line 138 of file watchdog.h.
References m_impl, and ns3::MakeTimerImpl().
Referenced by ns3::tests::WatchdogTestCase::DoRun().
void ns3::Watchdog::SetFunction | ( | MEM_PTR | memPtr, |
OBJ_PTR | objPtr | ||
) |
Set the function to execute when the timer expires.
MEM_PTR | [deduced] Class method function type. |
OBJ_PTR | [deduced] Class type containing the function. |
[in] | memPtr | The member function pointer |
[in] | objPtr | The pointer to object |
Store this function and object in this Timer for later use by Timer::Schedule.
Definition at line 146 of file watchdog.h.
References m_impl, and ns3::MakeTimerImpl().
|
private |
The absolute time when the timer will expire.
Definition at line 122 of file watchdog.h.
|
private |
The future event scheduled to expire the timer.
Definition at line 120 of file watchdog.h.
Referenced by ~Watchdog(), Expire(), and Ping().
|
private |
The timer implementation, which contains the bound callback function and arguments.
Definition at line 118 of file watchdog.h.
Referenced by ~Watchdog(), Expire(), SetArguments(), and SetFunction().