class EventLoop

Event Loop. More...

Definition#include <eventloop.hh>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

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

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, and the descriptor_count method can be used to see if there are any select'able file descriptors.


     EventLoop e;

     ...

     while(e.timers_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(100, callback(wakeup_hook, 1));

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

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.

XorpTimer  new_oneoff_at (const TimeVal& when, const OneoffTimerCallback& ocb)

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)

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)

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 (int ms, const PeriodicTimerCallback& pcb)

new_periodic

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)

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 set to false when this function is called and will be set to true when the XorpTimer expires.

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

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

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 set to false when this function is called and will be set to true when the XorpTimer expires.

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

XorpTimer  set_flag_after_ms (int ms, bool* flag_ptr)

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.

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.

inline bool  add_selector (int fd, SelectorMask mask, const SelectorCallback& cb)

add_selector

Add a file descriptor and callback to be invoked when descriptor is ready for input or output. A SelectorMask 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.
maskthe SelectorMask of the event types to that will invoke hook.
cbobject to be invoked when file descriptor has I/O pending.

Returns: true on success.

void  remove_selector (int fd, SelectorMask event_mask = SEL_ALL)

remove_selector

Remove hooks associated with file descriptor.

Parameters:
fdthe file descriptor.
event_maskmask of event types to clear.

size_t  descriptor_count ()

descriptor_count

[const]

Returns: the number of file descriptors that have registered callbacks with the EventLoop SelectorList.

bool  timers_pending ()

timers_pending

[const]

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

size_t  timer_list_length ()

timer_list_length

[const]

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

inline void  current_time (TimeVal& now)

current_time

[const]

Get current time according to EventLoop's TimerList


Generated by: pavlin on possum.icir.org on Mon Jun 9 13:23:43 2003, using kdoc 2.0a54+XORP.