A Discrete-Event Network Simulator
API
ns3::Watchdog Class Reference

A very simple watchdog operating in virtual time. More...

#include "watchdog.h"

+ Collaboration diagram for ns3::Watchdog:

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 (void)
 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...
 
TimerImplm_impl
 The timer implementation, which contains the bound callback function and arguments. More...
 

Detailed Description

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.

See also
Timer for a more sophisticated general purpose Virtual Time Timer and Watchdog.

Definition at line 56 of file watchdog.h.

Constructor & Destructor Documentation

◆ Watchdog()

ns3::Watchdog::Watchdog ( )

Constructor.

Definition at line 34 of file watchdog.cc.

References NS_LOG_FUNCTION_NOARGS.

◆ ~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.

+ Here is the call graph for this function:

Member Function Documentation

◆ Expire()

void ns3::Watchdog::Expire ( void  )
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Ping()

void ns3::Watchdog::Ping ( Time  delay)

Delay the timer.

Parameters
[in]delayThe 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetArguments()

template<typename... Ts>
void ns3::Watchdog::SetArguments ( Ts &&...  args)

Set the arguments to be used when invoking the expire function.

Template Parameters
Ts[deduced] Argument types.
Parameters
[in]argsarguments

Definition at line 155 of file watchdog.h.

References m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().

Referenced by ns3::tests::WatchdogTestCase::DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetFunction() [1/2]

template<typename FN >
void ns3::Watchdog::SetFunction ( FN  fn)

Set the function to execute when the timer expires.

Template Parameters
FN[deduced] The type of the function.
Parameters
[in]fnThe function

Store this function in this Timer for later use by Timer::Schedule.

Definition at line 140 of file watchdog.h.

References m_impl, and ns3::MakeTimerImpl().

Referenced by ns3::tests::WatchdogTestCase::DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetFunction() [2/2]

template<typename MEM_PTR , typename OBJ_PTR >
void ns3::Watchdog::SetFunction ( MEM_PTR  memPtr,
OBJ_PTR  objPtr 
)

Set the function to execute when the timer expires.

Template Parameters
MEM_PTR[deduced] Class method function type.
OBJ_PTR[deduced] Class type containing the function.
Parameters
[in]memPtrThe member function pointer
[in]objPtrThe pointer to object

Store this function and object in this Timer for later use by Timer::Schedule.

Definition at line 147 of file watchdog.h.

References m_impl, and ns3::MakeTimerImpl().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_end

Time ns3::Watchdog::m_end
private

The absolute time when the timer will expire.

Definition at line 123 of file watchdog.h.

Referenced by Expire(), and Ping().

◆ m_event

EventId ns3::Watchdog::m_event
private

The future event scheduled to expire the timer.

Definition at line 121 of file watchdog.h.

Referenced by ~Watchdog(), Expire(), and Ping().

◆ m_impl

TimerImpl* ns3::Watchdog::m_impl
private

The timer implementation, which contains the bound callback function and arguments.

Definition at line 119 of file watchdog.h.

Referenced by ~Watchdog(), Expire(), SetArguments(), and SetFunction().


The documentation for this class was generated from the following files: