class EventLoop

Event Loop. More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods


Detailed Description

Co-ordinates interactions between a TimerList and a SelectorList for Xorp processes. All XorpTimer and select operations should be co-ordinated through this interface.

 EventLoop ()

EventLoop

Constructor

 ~EventLoop ()

~EventLoop

Destructor.

void  run ()

run

Invoke all pending callbacks relating to XorpTimer and file descriptor activity. This function may block if there are no selectors ready. It may block forever if there are no timers pending. The timers_pending method can be used to detect whether there are timers pending, while the events_pending method can be used to detect whether there any events pending. An event can be either timer or task. The descriptor_count method can be used to see if there are any select'able file descriptors.


     EventLoop e;

     ...

     while(e.events_pending() || e.descriptor_count() > 0) {
         e.run();
     }


Non-xorp processes which use Xorp code should create a periodic timer to prevent the run() function from blocking indefinitely when there are no pending XorpTimer or SelectList objects. The period of the timer will depend on the application's existing needs.


     static bool wakeup_hook(int n) {
        static int count = 0;
	count += n;
	printf("count = %d\n", n);
     	return true;
     }

     int main() {
     	... // Program initialization

    	// Add a Xorp EventLoop
	EventLoop e;
	XorpTimer wakeywakey = e.new_periodic_ms(100, callback(wakeup_hook, 1));

	// Program's main loop
	for(;;) {
		... do what program does in its main loop ...
		e.run(); // process events
	}
     }

void  set_debug (bool v)

set_debug

bool  is_debug ()

is_debug

[const]

TimerList&  timer_list ()

timer_list

Returns: reference to the TimerList used by the EventLoop instance.

SelectorList&  selector_list ()

selector_list

Returns: reference to the SelectorList used by the EventLoop instance. XXX: Deprecated.

XorpTimer  new_oneoff_at (const TimeVal& when, const OneoffTimerCallback& ocb, int priority = XorpTask::PRIORITY_DEFAULT)

new_oneoff_at

Add a new one-off timer to the EventLoop.

Parameters:

whenthe absolute time when the timer expires.
ocbcallback object that is invoked when timer expires.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  new_oneoff_after (const TimeVal& wait, const OneoffTimerCallback& ocb, int priority = XorpTask::PRIORITY_DEFAULT)

new_oneoff_after

Add a new one-off timer to the EventLoop.

Parameters:

waitthe relative time when the timer expires.
ocbcallback object that is invoked when timer expires.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  new_oneoff_after_ms (int ms, const OneoffTimerCallback& ocb, int priority = XorpTask::PRIORITY_DEFAULT)

new_oneoff_after_ms

Add a new one-off timer to the EventLoop.

Parameters:

msthe relative time in milliseconds when the timer expires.
ocbcallback object that is invoked when timer expires.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  new_periodic (const TimeVal& wait, const PeriodicTimerCallback& pcb, int priority = XorpTask::PRIORITY_DEFAULT)

new_periodic

Add periodic timer to the EventLoop.

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: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  new_periodic_ms (int ms, const PeriodicTimerCallback& pcb, int priority = XorpTask::PRIORITY_DEFAULT)

new_periodic_ms

Add periodic timer to the EventLoop.

Parameters:

msthe period in milliseconds when the timer expires.
pcbuser callback object that is invoked when timer expires. If the callback returns false the periodic XorpTimer is unscheduled.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  set_flag_at (const TimeVal& when, bool* flag_ptr, bool to_value = true)

set_flag_at

Add a flag setting timer to the EventLoop.

Parameters:

whenthe absolute time when the timer expires.
flag_ptrpointer to a boolean variable that is to be set when the timer expires.
to_valuevalue to set the boolean variable to. Default value is true.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  set_flag_after (const TimeVal& wait, bool* flag_ptr, bool to_value = true)

set_flag_after

Add a flag setting timer to the EventLoop.

Parameters:

waitthe relative time when the timer expires.
flag_ptrpointer to a boolean variable that is to be set when the timer expires.
to_valuevalue to set the boolean variable to. Default value is true.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  set_flag_after_ms (int ms, bool* flag_ptr, bool to_value = true)

set_flag_after_ms

Add a flag setting timer to the EventLoop.

Parameters:

msthe relative time in millisecond when the timer expires.
flag_ptrpointer to a boolean variable that is set to false when this function is called and will be set to true when the XorpTimer expires.
flag_ptrpointer to a boolean variable that is to be set when the timer expires.
to_valuevalue to set the boolean variable to. Default value is true.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTimer  new_timer (const BasicTimerCallback& cb)

new_timer

Create a custom timer associated with the EventLoop.

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

Parameters:

cbuser callback object that is invoked when timer expires.

Returns: a XorpTimer object that must be assigned to remain scheduled.

XorpTask  new_oneoff_task (const OneoffTaskCallback& cb, int priority = XorpTask::PRIORITY_DEFAULT, int weight = XorpTask::WEIGHT_DEFAULT)

new_oneoff_task

Create a new one-time task to be scheduled with the timers and file handlers.

Parameters:

cbcallback object that is invoked when task is run.
prioritythe scheduling priority for the task.
scheduler_classthe scheduling class within the priority level.

Returns: a XorpTask object that must be assigned to remain scheduled.

XorpTask  new_task (const RepeatedTaskCallback& cb, int priority = XorpTask::PRIORITY_DEFAULT, int weight = XorpTask::WEIGHT_DEFAULT)

new_task

Create a new repeated task to be scheduled with the timers and file handlers.

Parameters:

cbcallback object that is invoked when task is run. If the callback returns true, the task will continue to run, otherwise it will be unscheduled.
prioritythe scheduling priority for the task.
scheduler_classthe scheduling class within the priority level.

Returns: a XorpTask object that must be assigned to remain scheduled.

bool  add_ioevent_cb (XorpFd fd, IoEventType type, const IoEventCb& cb, int priority = XorpTask::PRIORITY_DEFAULT)

add_ioevent_cb

Add a file descriptor and callback to be invoked when descriptor is ready for input or output. An IoEventType determines what type of I/O event will cause the callback to be invoked.

Only one callback may be associated with each event type, e.g. one callback for read pending, one callback for write pending.

If multiple event types in are associated with the same callback, the callback is only invoked once, but the mask argument passed to the callback shows multiple event types.

Parameters:

fdthe file descriptor.
typethe IoEventType of the event.
cbobject to be invoked when file descriptor has I/O pending.

Returns: true on success, false if any error occurred.

bool  remove_ioevent_cb (XorpFd fd, IoEventType type = IOT_ANY)

remove_ioevent_cb

Remove callbacks associated with file descriptor.

Parameters:

fdthe file descriptor.
typethe event type to clear. The special value IOT_ANY means clear any kind of callback.

Returns: true on success, false if any error occurred.

bool  timers_pending ()

timers_pending

[const]

Returns: true if any XorpTimers are present on EventLoop's TimerList.

bool  events_pending ()

events_pending

[const]

Returns: true if any XorpTimers are present on EventLoop's TimerList or any XorpTasks are present on the TaskList.

size_t  timer_list_length ()

timer_list_length

[const]

Returns: the number of XorpTimers present on EventLoop's TimerList.

void  current_time (TimeVal& now)

current_time

[const]

Get current time according to EventLoop's TimerList

size_t  descriptor_count ()

descriptor_count

[const]

Get the count of the descriptors that have been added.

Returns: the count of the descriptors that have been added.

void  set_aggressiveness (int num)

set_aggressiveness


Generated by: pavlin on kobe.xorp.net on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.