#include <timer.h>
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 |
TimerImpl * | m_impl |
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.
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. |
enum ns3::Timer::State |
ns3::Timer::Timer | ( | ) |
create a timer with a default event lifetime management policy:
Definition at line 29 of file timer.cc.
References NS_LOG_FUNCTION.
ns3::Timer::Timer | ( | enum DestroyPolicy | destroyPolicy | ) |
destroyPolicy | the event lifetime management policies to use for destroy events |
Definition at line 38 of file timer.cc.
References NS_LOG_FUNCTION.
ns3::Timer::~Timer | ( | ) |
Definition at line 47 of file timer.cc.
References ns3::EventId::Cancel(), CANCEL_ON_DESTROY, CHECK_ON_DESTROY, ns3::EventId::IsRunning(), m_event, m_flags, m_impl, NS_FATAL_ERROR, NS_LOG_FUNCTION, ns3::Simulator::Remove(), and REMOVE_ON_DESTROY.
void ns3::Timer::Cancel | ( | void | ) |
Cancel the currently-running event if there is one.
Do nothing otherwise.
Definition at line 103 of file timer.cc.
References ns3::Simulator::Cancel(), m_event, and NS_LOG_FUNCTION.
Referenced by TimerStateTestCase::DoRun(), ns3::aodv::RoutingProtocol::HelloTimerExpire(), ns3::aodv::RoutingProtocol::NotifyInterfaceDown(), ns3::aodv::RoutingProtocol::NotifyRemoveAddress(), ns3::aodv::Neighbors::Purge(), ns3::dsr::RouteCache::PurgeMac(), ns3::aodv::RoutingProtocol::RecvReplyAck(), ns3::aodv::Neighbors::ScheduleTimer(), ns3::dsr::RouteCache::ScheduleTimer(), ns3::dsr::DsrRouting::SendBuffTimerExpire(), ns3::Ipv6AutoconfiguredPrefix::StopPreferredTimer(), and ns3::Ipv6AutoconfiguredPrefix::StopValidTimer().
Time ns3::Timer::GetDelay | ( | void | ) | const |
Definition at line 75 of file timer.cc.
References m_delay, and NS_LOG_FUNCTION.
Time ns3::Timer::GetDelayLeft | ( | void | ) | const |
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().
enum Timer::State ns3::Timer::GetState | ( | void | ) | const |
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().
bool ns3::Timer::IsExpired | ( | void | ) | const |
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().
bool ns3::Timer::IsRunning | ( | void | ) | const |
Definition at line 121 of file timer.cc.
References ns3::EventId::IsRunning(), IsSuspended(), m_event, and NS_LOG_FUNCTION.
Referenced by TimerStateTestCase::DoRun(), GetState(), ns3::olsr::RoutingProtocol::QueueMessage(), ns3::dsr::DsrRouting::SendBuffTimerExpire(), ns3::aodv::RoutingProtocol::SendRerrMessage(), ns3::aodv::RoutingProtocol::SendRerrWhenNoRouteToForward(), ns3::Ipv6AutoconfiguredPrefix::StopPreferredTimer(), ns3::Ipv6AutoconfiguredPrefix::StopValidTimer(), and Suspend().
bool ns3::Timer::IsSuspended | ( | void | ) | const |
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().
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().
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().
void ns3::Timer::Schedule | ( | void | ) |
Schedule a new event using the currently-configured delay, function, and arguments.
Definition at line 152 of file timer.cc.
References m_delay, and NS_LOG_FUNCTION.
Referenced by TimerStateTestCase::DoRun(), TimerTemplateTestCase::DoRun(), ns3::dsr::DsrRouting::DsrRouting(), ns3::olsr::RoutingProtocol::HelloTimerExpire(), ns3::aodv::RoutingProtocol::HelloTimerExpire(), ns3::olsr::RoutingProtocol::HnaTimerExpire(), ns3::olsr::RoutingProtocol::MidTimerExpire(), ns3::aodv::Neighbors::Purge(), ns3::dsr::RouteCache::PurgeMac(), ns3::olsr::RoutingProtocol::QueueMessage(), ns3::aodv::RoutingProtocol::RerrRateLimitTimerExpire(), ns3::aodv::RoutingProtocol::RreqRateLimitTimerExpire(), ns3::aodv::Neighbors::ScheduleTimer(), ns3::dsr::RouteCache::ScheduleTimer(), ns3::dsr::DsrRouting::SendBuffTimerExpire(), ns3::dsdv::RoutingProtocol::SendPeriodicUpdate(), ns3::aodv::RoutingProtocol::SetIpv4(), ns3::NscTcpL4Protocol::SetNode(), ns3::NscTcpL4Protocol::SoftInterrupt(), ns3::dsdv::RoutingProtocol::Start(), ns3::aodv::RoutingProtocol::Start(), ns3::Ipv6AutoconfiguredPrefix::StartPreferredTimer(), ns3::Ipv6AutoconfiguredPrefix::StartValidTimer(), and ns3::olsr::RoutingProtocol::TcTimerExpire().
void ns3::Timer::Schedule | ( | Time | delay | ) |
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 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().
void ns3::Timer::SetArguments | ( | T1 | a1 | ) |
a1 | the 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().
void ns3::Timer::SetArguments | ( | T1 | a1, |
T2 | a2 | ||
) |
a1 | the first argument |
a2 | the 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().
void ns3::Timer::SetArguments | ( | T1 | a1, |
T2 | a2, | ||
T3 | a3 | ||
) |
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 292 of file timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().
void ns3::Timer::SetArguments | ( | T1 | a1, |
T2 | a2, | ||
T3 | a3, | ||
T4 | a4 | ||
) |
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 304 of file timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().
void ns3::Timer::SetArguments | ( | T1 | a1, |
T2 | a2, | ||
T3 | a3, | ||
T4 | a4, | ||
T5 | a5 | ||
) |
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 316 of file timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().
void ns3::Timer::SetArguments | ( | T1 | a1, |
T2 | a2, | ||
T3 | a3, | ||
T4 | a4, | ||
T5 | a5, | ||
T6 | a6 | ||
) |
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 328 of file timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().
void ns3::Timer::SetDelay | ( | const Time & | delay | ) |
delay | the delay |
The next call to Schedule will schedule the timer with this delay.
Definition at line 69 of file timer.cc.
References m_delay, and NS_LOG_FUNCTION.
Referenced by TimerStateTestCase::DoRun(), TimerTemplateTestCase::DoRun(), ns3::aodv::Neighbors::Neighbors(), ns3::olsr::RoutingProtocol::QueueMessage(), ns3::dsr::RouteCache::RouteCache(), ns3::aodv::RoutingProtocol::SendReplyByIntermediateNode(), ns3::NscTcpL4Protocol::SetNode(), ns3::Ipv6AutoconfiguredPrefix::StartPreferredTimer(), and ns3::Ipv6AutoconfiguredPrefix::StartValidTimer().
void ns3::Timer::SetFunction | ( | FN | fn | ) |
fn | the function |
Store this function in this Timer for later use by Timer::Schedule.
Definition at line 254 of file timer.h.
References m_impl, and ns3::MakeTimerImpl().
Referenced by TimerStateTestCase::DoRun(), TimerTemplateTestCase::DoRun(), ns3::dsr::DsrRouting::DsrRouting(), ns3::aodv::Neighbors::Neighbors(), ns3::dsr::RouteCache::RouteCache(), ns3::aodv::RoutingProtocol::SendReplyByIntermediateNode(), ns3::aodv::RoutingProtocol::SetIpv4(), ns3::olsr::RoutingProtocol::SetIpv4(), ns3::NscTcpL4Protocol::SetNode(), ns3::dsdv::RoutingProtocol::Start(), ns3::aodv::RoutingProtocol::Start(), ns3::Ipv6AutoconfiguredPrefix::StartPreferredTimer(), and ns3::Ipv6AutoconfiguredPrefix::StartValidTimer().
void ns3::Timer::SetFunction | ( | MEM_PTR | memPtr, |
OBJ_PTR | objPtr | ||
) |
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 261 of file timer.h.
References m_impl, and ns3::MakeTimerImpl().
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().
|
private |
Definition at line 239 of file timer.h.
Referenced by GetDelay(), Schedule(), and SetDelay().
|
private |
Definition at line 242 of file timer.h.
Referenced by GetDelayLeft(), Resume(), and Suspend().
|
private |
Definition at line 240 of file timer.h.
Referenced by Cancel(), GetDelayLeft(), IsExpired(), IsRunning(), Remove(), Resume(), Schedule(), Suspend(), and ~Timer().
|
private |
|
private |
Definition at line 241 of file timer.h.
Referenced by Resume(), Schedule(), SetArguments(), SetFunction(), and ~Timer().