|
|
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_ms(100, callback(some_function, some_arg)); new_oneoff_after_ms(200, my_callback_b, my_parameter_a); while ( ! timer_list.empty() ) { timer_list.run(); }
<code>my_callback_a</code> is called 100ms after the XorpTimer object is created.
<code>my_callback_b</code> is never called because no XorpTimer references the underlying element on the TimerList after <code>TimerList::new_oneoff_after_ms()</code> is called.
TimerList (ClockBase* clock)
| TimerList |
Parameters:
clock | clock object to use to query time. |
~TimerList ()
| ~TimerList |
void run ()
| run |
Expire all pending XorpTimer objects associated with TimerList.
XorpTimer new_oneoff_at (const TimeVal& when,
const OneoffTimerCallback& ocb,
int priority = XorpTask::PRIORITY_DEFAULT)
| new_oneoff_at |
Create a XorpTimer that will be scheduled once.
Parameters:
when | the absolute time when the timer expires. |
ocb | callback object that is invoked when timer expires. |
Returns: the XorpTimer created.
XorpTimer new_oneoff_after (const TimeVal& wait,
const OneoffTimerCallback& ocb,
int priority = XorpTask::PRIORITY_DEFAULT)
| new_oneoff_after |
Create a XorpTimer that will be scheduled once.
Parameters:
wait | the relative time when the timer expires. |
ocb | callback object that is invoked when timer expires. |
Returns: the XorpTimer created.
XorpTimer new_oneoff_after_ms (int ms, const OneoffTimerCallback& ocb,
int priority = XorpTask::PRIORITY_DEFAULT)
| new_oneoff_after_ms |
Create a XorpTimer that will be scheduled once.
Parameters:
ms | the relative time in milliseconds when the timer expires. |
ocb | callback object that is invoked when timer expires. |
Returns: the XorpTimer created.
XorpTimer new_periodic (const TimeVal& wait,
const PeriodicTimerCallback& pcb,
int priority = XorpTask::PRIORITY_DEFAULT)
| new_periodic |
Create a XorpTimer that will invoke a callback periodically.
Parameters:
wait | the period when the timer expires. |
pcb | user callback object that is invoked when timer expires. If the callback returns false the periodic XorpTimer is unscheduled. |
Returns: the XorpTimer created.
XorpTimer new_periodic_ms (int ms, const PeriodicTimerCallback& pcb,
int priority = XorpTask::PRIORITY_DEFAULT)
| new_periodic_ms |
Create a XorpTimer that will invoke a callback periodically.
Parameters:
ms | the period in milliseconds when the timer expires. |
pcb | user callback object that is invoked when timer expires. If the callback returns false the periodic XorpTimer is unscheduled. |
Returns: the XorpTimer created.
XorpTimer set_flag_at (const TimeVal& when,
bool* flag_ptr,
bool to_value = true,
int priority = XorpTask::PRIORITY_DEFAULT)
| set_flag_at |
Create a XorpTimer to set a flag.
Parameters:
when | the absolute time when the timer expires. |
flag_ptr | pointer to a boolean variable that is set to to_value when the XorpTimer expires. |
Returns: the XorpTimer created.
XorpTimer set_flag_after (const TimeVal& wait,
bool* flag_ptr,
bool to_value = true,
int priority = XorpTask::PRIORITY_DEFAULT)
| set_flag_after |
Create a XorpTimer to set a flag.
Parameters:
wait | the relative time when the timer expires. |
flag_ptr | pointer to a boolean variable that is set to to_value when the XorpTimer expires. |
Returns: the XorpTimer created.
XorpTimer set_flag_after_ms (int ms,
bool* flag_ptr,
bool to_value = true,
int priority = XorpTask::PRIORITY_DEFAULT)
| set_flag_after_ms |
Create a XorpTimer to set a flag.
Parameters:
ms | the relative time in milliseconds when the timer expires. |
flag_ptr | pointer to a boolean variable that is set to to_value when the XorpTimer expires. |
Returns: the XorpTimer created.
XorpTimer new_timer (const BasicTimerCallback& cb)
| new_timer |
Custom XorpTimer creation method. The XorpTimer object created needs to be explicitly scheduled with the available XorpTimer methods.
Parameters:
hook | user function to be invoked when XorpTimer expires. |
thunk | user argument to be passed when user's function is invoked. |
Returns: the XorpTimer created.
bool empty ()
| empty |
[const]
Returns: true if there no XorpTimer objects currently scheduled on list.
size_t size ()
| size |
[const]
Returns: the number of scheduled objects.
bool get_next_delay (TimeVal& tv)
| get_next_delay |
[const]
Query the next XorpTimer Expiry time.
Parameters:
tv | reference 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.
int get_expired_priority ()
| 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.
void current_time (TimeVal& now)
| current_time |
[const]
Read the latest known value from the clock used by TimerList object.
Parameters:
now | the return-by-reference value with the current time. |
void advance_time ()
| 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 system_gettimeofday (TimeVal* tv)
| system_gettimeofday |
[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:
tv | a pointer to the TimeVal storage to store the current time. |
void system_sleep (const TimeVal& tv)
| system_sleep |
[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:
tv | the period of time to suspend execution. |
void set_observer (TimerListObserverBase& obs)
| set_observer |
Register an observer object with this class
Parameters:
obs | an observer object derived from TimerListObserverBase |
void remove_observer ()
| remove_observer |
Unregister the current observer
TimerList* instance ()
| instance |
[static]
Get pointer to sole TimerList instance.
Returns: pointer if TimerList has been constructed, NULL otherwise.