A very simple watchdog operating in virtual time. More...
#include "watchdog.h"
Public Member Functions | |
Watchdog () | |
Constructor. | |
~Watchdog () | |
Destructor. | |
void | Ping (Time delay) |
Delay the timer. | |
template<typename FN > | |
void | SetFunction (FN fn) |
Set the function to execute when the timer expires. | |
template<typename MEM_PTR , typename OBJ_PTR > | |
void | SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr) |
Set the function to execute when the timer expires. | |
template<typename... Ts> | |
void | SetArguments (Ts &&... args) |
Set the arguments to be used when invoking the expire function. | |
Private Member Functions | |
void | Expire () |
Internal callback invoked when the timer expires. | |
Private Attributes | |
Time | m_end |
The absolute time when the timer will expire. | |
EventId | m_event |
The future event scheduled to expire the timer. | |
internal::TimerImpl * | m_impl |
The timer implementation, which contains the bound callback function and arguments. | |
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 50 of file watchdog.h.
ns3::Watchdog::Watchdog | ( | ) |
ns3::Watchdog::~Watchdog | ( | ) |
Destructor.
Definition at line 31 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 52 of file watchdog.cc.
References Expire(), ns3::internal::TimerImpl::Invoke(), m_end, m_event, m_impl, ns3::Now(), ns3::Simulator::Now(), NS_LOG_FUNCTION, and ns3::Simulator::Schedule().
Referenced by Expire(), and 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 39 of file watchdog.cc.
References Expire(), ns3::EventId::IsPending(), m_end, m_event, 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 148 of file watchdog.h.
References m_impl, NS_FATAL_ERROR, and ns3::internal::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 132 of file watchdog.h.
References m_impl, and ns3::internal::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 140 of file watchdog.h.
References m_impl, and ns3::internal::MakeTimerImpl().
|
private |
The absolute time when the timer will expire.
Definition at line 116 of file watchdog.h.
|
private |
The future event scheduled to expire the timer.
Definition at line 114 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 112 of file watchdog.h.
Referenced by ~Watchdog(), Expire(), SetArguments(), SetFunction(), and SetFunction().