A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::Timer Class Reference

a simple Timer class More...

#include <timer.h>

+ Collaboration diagram for ns3::Timer:

Public Types

enum  DestroyPolicy { CANCEL_ON_DESTROY = (1 << 3), REMOVE_ON_DESTROY = (1 << 4), CHECK_ON_DESTROY = (1 << 5) }
 The policy to use to manager the internal timer when and instance of the Timer class is destroyed. More...
 
enum  State { RUNNING, EXPIRED, SUSPENDED }
 

Public Member Functions

 Timer ()
 create a timer with a default event lifetime management policy: More...
 
 Timer (enum DestroyPolicy destroyPolicy)
 
 ~Timer ()
 
void Cancel (void)
 Cancel the currently-running event if there is one. More...
 
Time GetDelay (void) const
 
Time GetDelayLeft (void) const
 
enum Timer::State GetState (void) const
 
bool IsExpired (void) const
 
bool IsRunning (void) const
 
bool IsSuspended (void) const
 
void Remove (void)
 Remove from the simulation event-list the currently-running event if there is one. More...
 
void Resume (void)
 Restart the timer to expire within the amount of time left saved during Suspend. More...
 
void Schedule (void)
 Schedule a new event using the currently-configured delay, function, and arguments. More...
 
void Schedule (Time delay)
 
template<typename T1 >
void SetArguments (T1 a1)
 
template<typename T1 , typename T2 >
void SetArguments (T1 a1, T2 a2)
 
template<typename T1 , typename T2 , typename T3 >
void SetArguments (T1 a1, T2 a2, T3 a3)
 
template<typename T1 , typename T2 , typename T3 , typename T4 >
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4)
 
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
 
template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 >
void SetArguments (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
 
void SetDelay (const Time &delay)
 
template<typename FN >
void SetFunction (FN fn)
 
template<typename MEM_PTR , typename OBJ_PTR >
void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
 
void Suspend (void)
 Cancel the timer and save the amount of time left until it was set to expire. More...
 

Private Types

enum  { TIMER_SUSPENDED = (1 << 7) }
 

Private Attributes

Time m_delay
 
Time m_delayLeft
 
EventId m_event
 
int m_flags
 
TimerImplm_impl
 

Detailed Description

a simple Timer class

A timer is used to hold together a delay, a function to invoke when the delay expires, and a set of arguments to pass to the function when the delay expires.

A timer can also be used to enforce a set of predefined event lifetime management policies. These policies are specified at construction time and cannot be changed after.

Definition at line 45 of file timer.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
TIMER_SUSPENDED 

Definition at line 233 of file timer.h.

The policy to use to manager the internal timer when and instance of the Timer class is destroyed.

Enumerator
CANCEL_ON_DESTROY 

This policy cancels the event from the destructor of the Timer to verify that the event has already expired.

REMOVE_ON_DESTROY 

This policy removes the event from the simulation event list when the destructor of the Timer is invoked.

CHECK_ON_DESTROY 

This policy enforces a check from the destructor of the Timer to verify that the timer has already expired.

Definition at line 52 of file timer.h.

Enumerator
RUNNING 
EXPIRED 
SUSPENDED 

Definition at line 70 of file timer.h.

Constructor & Destructor Documentation

ns3::Timer::Timer ( )

create a timer with a default event lifetime management policy:

  • CHECK_ON_DESTROY

Definition at line 29 of file timer.cc.

References NS_LOG_FUNCTION.

ns3::Timer::Timer ( enum DestroyPolicy  destroyPolicy)
Parameters
destroyPolicythe event lifetime management policies to use for destroy events

Definition at line 38 of file timer.cc.

References NS_LOG_FUNCTION.

ns3::Timer::~Timer ( )

Member Function Documentation

Time ns3::Timer::GetDelay ( void  ) const
Returns
the currently-configured delay for the next Schedule.

Definition at line 75 of file timer.cc.

References m_delay, and NS_LOG_FUNCTION.

Time ns3::Timer::GetDelayLeft ( void  ) const
Returns
the amount of time left until this timer expires.

This method returns zero if the timer is in EXPIRED state.

Definition at line 81 of file timer.cc.

References EXPIRED, ns3::Simulator::GetDelayLeft(), GetState(), m_delayLeft, m_event, NS_ASSERT, NS_LOG_FUNCTION, RUNNING, SUSPENDED, and ns3::TimeStep().

Referenced by ns3::dsdv::RoutingProtocol::RecvDsdv(), ns3::aodv::RoutingProtocol::SendRequest(), ns3::aodv::RoutingProtocol::SendRerrMessage(), and ns3::aodv::RoutingProtocol::SendRerrWhenNoRouteToForward().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

enum Timer::State ns3::Timer::GetState ( void  ) const
Returns
the current state of the timer.

Definition at line 133 of file timer.cc.

References EXPIRED, IsExpired(), IsRunning(), IsSuspended(), NS_ASSERT, NS_LOG_FUNCTION, RUNNING, and SUSPENDED.

Referenced by TimerStateTestCase::DoRun(), and GetDelayLeft().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::Timer::IsExpired ( void  ) const
Returns
true if there is no currently-running event, false otherwise.

Definition at line 115 of file timer.cc.

References ns3::EventId::IsExpired(), IsSuspended(), m_event, and NS_LOG_FUNCTION.

Referenced by TimerStateTestCase::DoRun(), and GetState().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ns3::Timer::IsRunning ( void  ) const
bool ns3::Timer::IsSuspended ( void  ) const
Returns
true if this timer was suspended and not yet resumed, false otherwise.

Definition at line 127 of file timer.cc.

References m_flags, NS_LOG_FUNCTION, and TIMER_SUSPENDED.

Referenced by ns3::dsr::DsrRouting::CheckSendBuffer(), TimerStateTestCase::DoRun(), GetState(), IsExpired(), and IsRunning().

+ Here is the caller graph for this function:

void ns3::Timer::Remove ( void  )

Remove from the simulation event-list the currently-running event if there is one.

Do nothing otherwise.

Definition at line 109 of file timer.cc.

References m_event, NS_LOG_FUNCTION, and ns3::Simulator::Remove().

+ Here is the call graph for this function:

void ns3::Timer::Resume ( void  )

Restart the timer to expire within the amount of time left saved during Suspend.

Calling Resume without a prior call to Suspend is an error.

Definition at line 181 of file timer.cc.

References m_delayLeft, m_event, m_flags, m_impl, NS_ASSERT, NS_LOG_FUNCTION, ns3::TimerImpl::Schedule(), and TIMER_SUSPENDED.

Referenced by ns3::dsr::DsrRouting::CheckSendBuffer(), and TimerStateTestCase::DoRun().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::Timer::Schedule ( Time  delay)
Parameters
delaythe delay to use

Schedule a new event using the specified delay (ignore the delay set by Timer::SetDelay), function, and arguments.

Definition at line 159 of file timer.cc.

References ns3::EventId::IsRunning(), m_event, m_impl, NS_ASSERT, NS_FATAL_ERROR, NS_LOG_FUNCTION, and ns3::TimerImpl::Schedule().

+ Here is the call graph for this function:

template<typename T1 >
void ns3::Timer::SetArguments ( T1  a1)
Parameters
a1the first argument

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

Definition at line 269 of file timer.h.

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

Referenced by TimerStateTestCase::DoRun(), TimerTemplateTestCase::DoRun(), and ns3::aodv::RoutingProtocol::SendReplyByIntermediateNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T1 , typename T2 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2 
)
Parameters
a1the first argument
a2the second argument

Store these arguments in this Timer for later use by Timer::Schedule.

Definition at line 280 of file timer.h.

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

+ Here is the call graph for this function:

template<typename T1 , typename T2 , typename T3 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3 
)
Parameters
a1the first argument
a2the second argument
a3the third argument

Store these arguments in this Timer for later use by Timer::Schedule.

Definition at line 292 of file timer.h.

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

+ Here is the call graph for this function:

template<typename T1 , typename T2 , typename T3 , typename T4 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3,
T4  a4 
)
Parameters
a1the first argument
a2the second argument
a3the third argument
a4the fourth argument

Store these arguments in this Timer for later use by Timer::Schedule.

Definition at line 304 of file timer.h.

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

+ Here is the call graph for this function:

template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3,
T4  a4,
T5  a5 
)
Parameters
a1the first argument
a2the second argument
a3the third argument
a4the fourth argument
a5the fifth argument

Store these arguments in this Timer for later use by Timer::Schedule.

Definition at line 316 of file timer.h.

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

+ Here is the call graph for this function:

template<typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3,
T4  a4,
T5  a5,
T6  a6 
)
Parameters
a1the first argument
a2the second argument
a3the third argument
a4the fourth argument
a5the fifth argument
a6the sixth argument

Store these arguments in this Timer for later use by Timer::Schedule.

Definition at line 328 of file timer.h.

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

+ Here is the call graph for this function:

void ns3::Timer::SetDelay ( const Time delay)
template<typename MEM_PTR , typename OBJ_PTR >
void ns3::Timer::SetFunction ( MEM_PTR  memPtr,
OBJ_PTR  objPtr 
)
Parameters
memPtrthe member function pointer
objPtrthe pointer to object

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

Definition at line 261 of file timer.h.

References m_impl, and ns3::MakeTimerImpl().

+ Here is the call graph for this function:

void ns3::Timer::Suspend ( void  )

Cancel the timer and save the amount of time left until it was set to expire.

Calling Suspend on a non-running timer is an error.

Definition at line 171 of file timer.cc.

References ns3::Simulator::GetDelayLeft(), IsRunning(), m_delayLeft, m_event, m_flags, NS_ASSERT, NS_LOG_FUNCTION, ns3::Simulator::Remove(), and TIMER_SUSPENDED.

Referenced by ns3::dsr::DsrRouting::CheckSendBuffer(), and TimerStateTestCase::DoRun().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

Time ns3::Timer::m_delay
private

Definition at line 239 of file timer.h.

Referenced by GetDelay(), Schedule(), and SetDelay().

Time ns3::Timer::m_delayLeft
private

Definition at line 242 of file timer.h.

Referenced by GetDelayLeft(), Resume(), and Suspend().

EventId ns3::Timer::m_event
private

Definition at line 240 of file timer.h.

Referenced by Cancel(), GetDelayLeft(), IsExpired(), IsRunning(), Remove(), Resume(), Schedule(), Suspend(), and ~Timer().

int ns3::Timer::m_flags
private

Definition at line 238 of file timer.h.

Referenced by IsSuspended(), Resume(), Suspend(), and ~Timer().

TimerImpl* ns3::Timer::m_impl
private

Definition at line 241 of file timer.h.

Referenced by Resume(), Schedule(), SetArguments(), SetFunction(), and ~Timer().


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