#include <cxxtools/selector.h>
Inheritance diagram for SelectorBase:

Public Member Functions | |
| virtual | ~SelectorBase () |
| Destructor. | |
| void | add (Selectable &s) |
| Adds an IOResult. | |
| void | remove (Selectable &s) |
| Cancel an IOResult. | |
| void | add (Timer &timer) |
| Adds a Timer. | |
| void | remove (Timer &timer) |
| Removes a Timer. | |
| bool | wait (std::size_t msecs=WaitInfinite) |
| Wait for activity. | |
| void | wake () |
| Wakes the selctor from waiting. | |
Static Public Attributes | |
| static const std::size_t | WaitInfinite = static_cast<const std::size_t>(-1) |
Protected Member Functions | |
| SelectorBase () | |
| Default constructor. | |
| void | onAddTimer (Timer &timer) |
| void | onRemoveTimer (Timer &timer) |
| void | onTimerChanged (Timer &timer) |
| virtual void | onAdd (Selectable &)=0 |
| A Selectable is added to this Selector. | |
| virtual void | onRemove (Selectable &)=0 |
| A Selectable is removed from this Selector. | |
| virtual void | onReinit (Selectable &)=0 |
| A Selectable is reinitialised and needs to be updated. | |
| virtual void | onChanged (Selectable &s)=0 |
| A Selectable in this Selector has changed. | |
| virtual bool | onWait (std::size_t msecs)=0 |
| virtual void | onWake ()=0 |
Friends | |
| class | Selectable |
| class | Timer |
The following example uses a Selector to wait on acitvity on a Timer, which is set to time-out after 1000 msecs.
// slot to handle timer activity void onTimer(); int main() { using cxxtools::System; Timer timer; timer.start(1000); connect(timer.timeout, ontimer); Selector selector; selector.addTimer(timer); selector wait(); return 0; }
A Selector is the heart of the EventLoop, which calls Selector::wait continously. The EventLoop and Application classes provide the same API as the Selector itself.
| void add | ( | Selectable & | s | ) |
Adds an IOResult to the selector. IOResult are removed automatically when they get destroyed.
| void add | ( | Timer & | timer | ) |
Adds a Timer to the selector. Timers are removed automatically when they get destroyed.
| timer | The device to add |
| void remove | ( | Timer & | timer | ) |
| timer | The timer to remove |
| bool wait | ( | std::size_t | msecs = WaitInfinite |
) |
This method will wait for activity on the registered Selectables and Timers. Use Selector::WaitInfinite to wait without timeout.
| msecs | timeout in miliseconds |
| void wake | ( | ) |
This method can be used to end a Selector::wait call before the timeout expires. It is supposed to be used from another thread and thus is thread-safe.
| virtual void onAdd | ( | Selectable & | ) | [protected, pure virtual] |
Do not throw exceptions.
Implemented in EventLoop.
| virtual void onRemove | ( | Selectable & | ) | [protected, pure virtual] |
Do not throw exceptions.
Implemented in EventLoop.
| virtual void onReinit | ( | Selectable & | ) | [protected, pure virtual] |
Do not throw exceptions.
Implemented in EventLoop.
| virtual void onChanged | ( | Selectable & | s | ) | [protected, pure virtual] |
Do not throw exceptions.
Implemented in EventLoop.