ns3::Timer Class Reference
[Simulator]

a simple Timer class More...

#include <timer.h>

Collaboration diagram for ns3::Timer:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DestroyPolicy { CANCEL_ON_DESTROY = (1<<3), REMOVE_ON_DESTROY = (1<<4), CHECK_ON_DESTROY = (1<<5) }
enum  State { RUNNING, EXPIRED, SUSPENDED }

Public Member Functions

 Timer ()
 Timer (enum DestroyPolicy destroyPolicy)
 ~Timer ()
template<typename FN >
void SetFunction (FN fn)
template<typename MEM_PTR , typename OBJ_PTR >
void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
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)
Time GetDelay (void) const
Time GetDelayLeft (void) const
void Cancel (void)
void Remove (void)
bool IsExpired (void) const
bool IsRunning (void) const
bool IsSuspended (void) const
enum Timer::State GetState (void) const
void Schedule (void)
void Schedule (Time delay)
void Suspend (void)
void Resume (void)

Private Types

enum  { TIMER_SUSPENDED = (1<<7) }

Private Attributes

int m_flags
Time m_delay
EventId m_event
TimerImplm_impl
Time m_delayLeft

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 232 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 69 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 25 of file timer.cc.

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

Definition at line 32 of file timer.cc.

ns3::Timer::~Timer (  ) 

Member Function Documentation

void ns3::Timer::Cancel ( void   ) 

Cancel the currently-running event if there is one. Do nothing otherwise.

Definition at line 90 of file timer.cc.

References m_event.

Referenced by ns3::TimerTests::RunTests().

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

Definition at line 65 of file timer.cc.

References m_delay.

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 70 of file timer.cc.

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

Referenced by Suspend().

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

Definition at line 115 of file timer.cc.

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

Referenced by GetDelayLeft(), and ns3::TimerTests::RunTests().

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

Definition at line 100 of file timer.cc.

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

Referenced by GetState(), and ns3::TimerTests::RunTests().

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

Definition at line 105 of file timer.cc.

References ns3::EventId::IsRunning(), IsSuspended(), and m_event.

Referenced by GetState(), ns3::olsr::AgentImpl::QueueMessage(), ns3::TimerTests::RunTests(), and Suspend().

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

Definition at line 110 of file timer.cc.

References m_flags, and TIMER_SUSPENDED.

Referenced by GetState(), IsExpired(), IsRunning(), and ns3::TimerTests::RunTests().

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 95 of file timer.cc.

References m_event.

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

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 159 of file timer.cc.

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

Referenced by ns3::TimerTests::RunTests().

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

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

Definition at line 139 of file timer.cc.

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

void ns3::Timer::Schedule ( void   ) 
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 
) [inline]
Parameters:
a1 the first argument
a2 the second argument
a3 the third argument
a4 the fourth argument
a5 the fifth argument
a6 the sixth argument

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

Definition at line 326 of file timer.h.

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

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 
) [inline]
Parameters:
a1 the first argument
a2 the second argument
a3 the third argument
a4 the fourth argument
a5 the fifth argument

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

Definition at line 314 of file timer.h.

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

template<typename T1 , typename T2 , typename T3 , typename T4 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3,
T4  a4 
) [inline]
Parameters:
a1 the first argument
a2 the second argument
a3 the third argument
a4 the fourth argument

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

Definition at line 302 of file timer.h.

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

template<typename T1 , typename T2 , typename T3 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2,
T3  a3 
) [inline]
Parameters:
a1 the first argument
a2 the second argument
a3 the third argument

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

Definition at line 290 of file timer.h.

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

template<typename T1 , typename T2 >
void ns3::Timer::SetArguments ( T1  a1,
T2  a2 
) [inline]
Parameters:
a1 the first argument
a2 the second argument

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

Definition at line 278 of file timer.h.

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

template<typename T1 >
void ns3::Timer::SetArguments ( T1  a1  )  [inline]
Parameters:
a1 the first argument

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

Definition at line 267 of file timer.h.

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

Referenced by ns3::TimerTests::RunTests().

void ns3::Timer::SetDelay ( const Time delay  ) 
Parameters:
delay the delay

The next call to Schedule will schedule the timer with this delay.

Definition at line 60 of file timer.cc.

References m_delay.

Referenced by ns3::olsr::AgentImpl::QueueMessage(), ns3::TimerTests::RunTests(), and ns3::NscTcpL4Protocol::SetNode().

template<typename MEM_PTR , typename OBJ_PTR >
void ns3::Timer::SetFunction ( MEM_PTR  memPtr,
OBJ_PTR  objPtr 
) [inline]
Parameters:
memPtr the member function pointer
objPtr the pointer to object

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

Definition at line 259 of file timer.h.

References m_impl, and ns3::MakeTimerImpl().

template<typename FN >
void ns3::Timer::SetFunction ( FN  fn  )  [inline]
Parameters:
fn the function

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

Definition at line 252 of file timer.h.

References m_impl, and ns3::MakeTimerImpl().

Referenced by ns3::TimerTests::RunTests(), ns3::olsr::AgentImpl::SetNode(), and ns3::NscTcpL4Protocol::SetNode().

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 150 of file timer.cc.

References GetDelayLeft(), IsRunning(), m_delayLeft, m_event, m_flags, NS_ASSERT, Remove(), and TIMER_SUSPENDED.

Referenced by ns3::TimerTests::RunTests().


Member Data Documentation

Definition at line 237 of file timer.h.

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

Definition at line 240 of file timer.h.

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

Definition at line 238 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 236 of file timer.h.

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

Definition at line 239 of file timer.h.

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


The documentation for this class was generated from the following files:
Generated on Thu Dec 3 14:12:19 2009 for NS-3 by  doxygen 1.6.3