xorp

TimerList Class Reference

XorpTimer creation and scheduling entity. More...

#include <timer.hh>

List of all members.

Public Member Functions

 TimerList (ClockBase *clock)
void run ()
 Expire all pending XorpTimer objects associated with TimerList.
XorpTimer new_oneoff_at (const TimeVal &when, const OneoffTimerCallback &ocb, int priority=XorpTask::PRIORITY_DEFAULT)
 Create a XorpTimer that will be scheduled once.
XorpTimer new_oneoff_after (const TimeVal &wait, const OneoffTimerCallback &ocb, int priority=XorpTask::PRIORITY_DEFAULT)
 Create a XorpTimer that will be scheduled once.
void remove_timer (XorpTimer &t)
XorpTimer new_periodic (const TimeVal &wait, const PeriodicTimerCallback &pcb, int priority=XorpTask::PRIORITY_DEFAULT)
 Create a XorpTimer that will invoke a callback periodically.
XorpTimer set_flag_at (const TimeVal &when, bool *flag_ptr, bool to_value=true, int priority=XorpTask::PRIORITY_DEFAULT)
 Create a XorpTimer to set a flag.
XorpTimer set_flag_after (const TimeVal &wait, bool *flag_ptr, bool to_value=true, int priority=XorpTask::PRIORITY_DEFAULT)
 Create a XorpTimer to set a flag.
XorpTimer new_timer (const BasicTimerCallback &cb)
 Custom XorpTimer creation method.
bool empty () const
size_t size () const
bool get_next_delay (TimeVal &tv) const
 Query the next XorpTimer Expiry time.
int get_expired_priority () const
 Get the priority of the highest priority timer that has expired.
void current_time (TimeVal &now) const
 Read the latest known value from the clock used by TimerList object.
void advance_time ()
 Advance time.
void set_observer (TimerListObserverBase &obs)
 Register an observer object with this class.
void remove_observer ()
 Unregister the current observer.

Static Public Member Functions

static void system_gettimeofday (TimeVal *tv)
 Default time querier.
static void system_sleep (const TimeVal &tv)
 Suspend process execution for a defined interval.
static TimerListinstance ()
 Get pointer to sole TimerList instance.

Private Member Functions

void schedule_node (TimerNode *t)
void unschedule_node (TimerNode *t)
void acquire_lock () const
bool attempt_lock () const
void release_lock () const
Heapfind_heap (int priority)
bool expire_one (int worst_priority)
 Expire one timer.
 TimerList (const TimerList &)
TimerListoperator= (const TimerList &)

Private Attributes

map< int, Heap * > _heaplist
ClockBase_clock
TimerListObserverBase_observer

Friends

class TimerNode
class TimerListObserverBase

Detailed Description

XorpTimer creation and scheduling entity.

A TimerList is a scheduling entity that provides a means to create XorpTimer objects and run them.

XorpTimer objects created via TimerList methods contain pointers to reference counted elements maintained in the TimerList. The elements on the list need to be referenced by XorpTimer objects or the underlying timer callbacks are never made. For instance:

TimerList timer_list;
XorpTimer t = timer_list.new_oneoff_after(TimeVal(0, 100000),
			callback(some_function, some_arg));
new_oneoff_after(TimeVal(0, 200000), my_callback_b, my_parameter_a);
while ( ! timer_list.empty() ) {
	timer_list.run();
}

my_callback_a is called 100000us after the XorpTimer object is created.

my_callback_b is never called because no XorpTimer references the underlying element on the TimerList after TimerList::new_oneoff_after() is called.


Constructor & Destructor Documentation

TimerList::TimerList ( ClockBase clock)
Parameters:
clockclock object to use to query time.

Member Function Documentation

void TimerList::advance_time ( )

Advance time.

This method fetches the time from clock object associated with the TimerList and sets the TimerList current time to this value.

void TimerList::current_time ( TimeVal now) const

Read the latest known value from the clock used by TimerList object.

Parameters:
nowthe return-by-reference value with the current time.
bool TimerList::empty ( ) const
Returns:
true if there no XorpTimer objects currently scheduled on list.
bool TimerList::expire_one ( int  worst_priority) [private]

Expire one timer.

The timer we expire is the highest priority (lowest priority number) timer that is less than or equal to the the parameter worst_priority.

int TimerList::get_expired_priority ( ) const

Get the priority of the highest priority timer that has expired.

Returns:
the priority of the expired timer, or INFINITE_PRIORITY if no timer has expired.
bool TimerList::get_next_delay ( TimeVal tv) const

Query the next XorpTimer Expiry time.

Parameters:
tvreference that is assigned expiry time of next timer. If there is no XorpTimer pending, this value is assigned the maximum TimeVal::MAXIMUM(). The first function returns the absolute time at which the timer expires, where the second returns the difference between now and the expiry time.
Returns:
true if there is a XorpTimer awaiting expiry, false otherwise.
TimerList * TimerList::instance ( ) [static]

Get pointer to sole TimerList instance.

Returns:
pointer if TimerList has been constructed, NULL otherwise.
XorpTimer TimerList::new_oneoff_after ( const TimeVal wait,
const OneoffTimerCallback &  ocb,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Create a XorpTimer that will be scheduled once.

Parameters:
waitthe relative time when the timer expires.
ocbcallback object that is invoked when timer expires.
Returns:
the XorpTimer created.
XorpTimer TimerList::new_oneoff_at ( const TimeVal when,
const OneoffTimerCallback &  ocb,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Create a XorpTimer that will be scheduled once.

Parameters:
whenthe absolute time when the timer expires.
ocbcallback object that is invoked when timer expires.
Returns:
the XorpTimer created.
XorpTimer TimerList::new_periodic ( const TimeVal wait,
const PeriodicTimerCallback &  pcb,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Create a XorpTimer that will invoke a callback periodically.

Parameters:
waitthe period when the timer expires.
pcbuser callback object that is invoked when timer expires. If the callback returns false the periodic XorpTimer is unscheduled.
Returns:
the XorpTimer created.
XorpTimer TimerList::new_timer ( const BasicTimerCallback &  cb) [inline]

Custom XorpTimer creation method.

The XorpTimer object created needs to be explicitly scheduled with the available XorpTimer methods.

Parameters:
hookuser function to be invoked when XorpTimer expires.
thunkuser argument to be passed when user's function is invoked.
Returns:
the XorpTimer created.
XorpTimer TimerList::set_flag_after ( const TimeVal wait,
bool *  flag_ptr,
bool  to_value = true,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Create a XorpTimer to set a flag.

Parameters:
waitthe relative time when the timer expires.
flag_ptrpointer to a boolean variable that is set to to_value when the XorpTimer expires.
Returns:
the XorpTimer created.
XorpTimer TimerList::set_flag_at ( const TimeVal when,
bool *  flag_ptr,
bool  to_value = true,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Create a XorpTimer to set a flag.

Parameters:
whenthe absolute time when the timer expires.
flag_ptrpointer to a boolean variable that is set to to_value when the XorpTimer expires.
Returns:
the XorpTimer created.
void TimerList::set_observer ( TimerListObserverBase obs)

Register an observer object with this class.

Parameters:
obsan observer object derived from TimerListObserverBase
size_t TimerList::size ( ) const
Returns:
the number of scheduled objects.
void TimerList::system_gettimeofday ( TimeVal tv) [static]

Default time querier.

Get the current time. This method is analogous to calling the underlying operating system's 'get current system time' function and is implemented as a call to advance_time() followed by a call to current_time().

Parameters:
tva pointer to the TimeVal storage to store the current time.
void TimerList::system_sleep ( const TimeVal tv) [static]

Suspend process execution for a defined interval.

This methid is analogous to calling sleep(3) or usleep(3), and is implemented as a call to sleep(3) and/or usleep(3) followed by a call to advance_time().

Parameters:
tvthe period of time to suspend execution.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations