eventxx::dispatcher Struct Reference

Event dispatcher. More...

List of all members.

Public Member Functions

 dispatcher () throw ()
 Creates a default dispatcher (with just 1 priority).
 dispatcher (int npriorities) throw (std::bad_alloc)
 Creates a dispatcher with npriorities priorities.
 ~dispatcher () throw ()
 Free dispatcher resources, see Status section for details.
void add (basic_event &e, int priority=DEFAULT_PRIORITY) throw (invalid_priority)
 Adds an event to the dispatcher.
void add (basic_event &e, const time &to, int priority=DEFAULT_PRIORITY) throw (invalid_priority)
 Adds an event to the dispatcher with a timeout.
template<typename F >
void add_once (int fd, type ev, F &handler)
 Adds a temporary event.
void add_once (int fd, type ev, ccallback_type handler, void *arg)
 Adds a temporary event to with a C-style callback.
template<typename F >
void add_once (int fd, type ev, F &handler, const time &to)
 Adds a temporary event.
void add_once (int fd, type ev, ccallback_type handler, void *arg, const time &to)
 Adds a temporary event with a C-style callback.
template<typename F >
void add_once_timer (F &handler, const time &to)
 Adds a temporary timer.
void add_once_timer (ccallback_type handler, void *arg, const time &to)
 Adds a temporary timer with a C-style callback.
void del (basic_event &e) throw ()
 Removes an event.
int dispatch (int flags=0) throw ()
 Main dispatcher loop.
int exit (const time &to=time()) throw ()
 Exit the dispatch() loop.


Detailed Description

Event dispatcher.

This class is the responsible for looping and dispatching events. Every time you need an event loop you should create an instance of this class.

You can add events to the dispatcher, and you can remove them later or you can add events to be processed just once . You can loop once or forever (well, of course you can break that forever removing all the events or by exiting the loop ).

Examples:

bench.cpp, c-way.cpp, functor-way.cpp, mixed-way.cpp, prio-test.cpp, test-eof.cpp, test-time.cpp, test-weof.cpp, trivial.cpp, and wrapped-functor-way.cpp.


Constructor & Destructor Documentation

eventxx::dispatcher::dispatcher (  )  throw () [inline]

Creates a default dispatcher (with just 1 priority).

See also:
dispatcher(int) if you want to create a dispatcher with more priorities.

eventxx::dispatcher::dispatcher ( int  npriorities  )  throw (std::bad_alloc) [inline]

Creates a dispatcher with npriorities priorities.

Parameters:
npriorities Number of priority queues to use.

eventxx::dispatcher::~dispatcher (  )  throw () [inline]

Free dispatcher resources, see Status section for details.


Member Function Documentation

void eventxx::dispatcher::add ( basic_event e,
const time to,
int  priority = DEFAULT_PRIORITY 
) throw (invalid_priority) [inline]

Adds an event to the dispatcher with a timeout.

The event is fired when there is activity on e or when to has elapsed, whatever come first.

Parameters:
e Event to add.
to Timeout.
priority Priority of the event.

void eventxx::dispatcher::add ( basic_event e,
int  priority = DEFAULT_PRIORITY 
) throw (invalid_priority) [inline]

Adds an event to the dispatcher.

Parameters:
e Event to add.
priority Priority of the event.
Examples:
bench.cpp, c-way.cpp, mixed-way.cpp, test-eof.cpp, test-time.cpp, and test-weof.cpp.

void eventxx::dispatcher::add_once ( int  fd,
type  ev,
ccallback_type  handler,
void *  arg,
const time to 
) [inline]

Adds a temporary event with a C-style callback.

Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.

Parameters:
fd File descriptor to monitor for events.
ev Type of events to monitor.
handler Callback function.
arg Arbitrary pointer to pass to the handler as argument.
to Timeout.

template<typename F >
void eventxx::dispatcher::add_once ( int  fd,
type  ev,
F &  handler,
const time to 
) [inline]

Adds a temporary event.

Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.

Parameters:
fd File descriptor to monitor for events.
ev Type of events to monitor.
handler Callback function.
to Timeout.

void eventxx::dispatcher::add_once ( int  fd,
type  ev,
ccallback_type  handler,
void *  arg 
) [inline]

Adds a temporary event to with a C-style callback.

Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.

Parameters:
fd File descriptor to monitor for events.
ev Type of events to monitor.
handler Callback function.
arg Arbitrary pointer to pass to the handler as argument.

template<typename F >
void eventxx::dispatcher::add_once ( int  fd,
type  ev,
F &  handler 
) [inline]

Adds a temporary event.

Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.

Parameters:
fd File descriptor to monitor for events.
ev Type of events to monitor.
handler Callback function.

void eventxx::dispatcher::add_once_timer ( ccallback_type  handler,
void *  arg,
const time to 
) [inline]

Adds a temporary timer with a C-style callback.

Adds a temporary timer, without the need of instantiating a new timer object.

Parameters:
handler Callback function.
arg Arbitrary pointer to pass to the handler as argument.
to Timer's timeout.

template<typename F >
void eventxx::dispatcher::add_once_timer ( F &  handler,
const time to 
) [inline]

Adds a temporary timer.

Adds a temporary timer, without the need of instantiating a new timer object.

Parameters:
handler Callback function.
to Timer's timeout.

void eventxx::dispatcher::del ( basic_event e  )  throw () [inline]

Removes an event.

The event e will be no longer monitored by this dispatcher.

Parameters:
e Event to remove.
Examples:
bench.cpp, and test-time.cpp.

int eventxx::dispatcher::dispatch ( int  flags = 0  )  throw () [inline]

Main dispatcher loop.

This function takes the control of the program, waiting for an event and calling its callbacks when it's fired. It only returns under this conditions:

Parameters:
flags If eventxx::ONCE is specified, then just one event is processed, if eventxx::NONBLOCK is specified, then this function returns even if there are no pending events.
Returns:
0 if eventxx::NONBLOCK or eventxx::ONCE is set, 1 if there are no more events registered and EINTR if you use the libevent's event_gotsig and return -1 in your event_sigcb callback.
Examples:
bench.cpp, c-way.cpp, mixed-way.cpp, test-eof.cpp, test-time.cpp, test-weof.cpp, and trivial.cpp.

int eventxx::dispatcher::exit ( const time to = time()  )  throw () [inline]

Exit the dispatch() loop.

Parameters:
to If a timeout is given, the loop exits after the specified time is elapsed.
Returns:
Not very well specified by libevent :-/ that's why it doesn't throw an exception either.
Examples:
c-way.cpp, and mixed-way.cpp.


The documentation for this struct was generated from the following file:

Generated on Thu Apr 16 21:08:39 2009 for eventxx by  doxygen 1.5.8