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. | |
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 ).
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.
| eventxx::dispatcher::dispatcher | ( | ) | throw () [inline] |
Creates a default dispatcher (with just 1 priority).
| eventxx::dispatcher::dispatcher | ( | int | npriorities | ) | throw (std::bad_alloc) [inline] |
Creates a dispatcher with npriorities priorities.
| npriorities | Number of priority queues to use. |
| eventxx::dispatcher::~dispatcher | ( | ) | throw () [inline] |
Free dispatcher resources, see Status section for details.
| 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.
| 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.
| e | Event to add. | |
| priority | Priority of the event. |
| 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.
| 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. |
| 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.
| 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.
| 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. |
| 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.
| 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] |
| void eventxx::dispatcher::add_once_timer | ( | F & | handler, | |
| const time & | to | |||
| ) | [inline] |
| void eventxx::dispatcher::del | ( | basic_event & | e | ) | throw () [inline] |
Removes an event.
The event e will be no longer monitored by this dispatcher.
| e | Event to remove. |
| 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:
| 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. |
event_gotsig and return -1 in your event_sigcb callback. Exit the dispatch() loop.
| to | If a timeout is given, the loop exits after the specified time is elapsed. |
1.5.8