#include <Pt/System/EventLoop.h>
Thread-safe event loop supporting I/O multiplexing and Timers. More...
Inherits Connectable, and EventSink.
Inherited by MainLoop.
Public Member Functions | |
| virtual | ~EventLoop () |
| Destructor. | |
| void | run () |
| Starts the loop. | |
| void | exit () |
| Stops the loop. | |
| void | processEvents () |
| Process all queued events. | |
| Signal< const Event & > & | eventReceived () |
| Reports all events. | |
| Signal & | exited () |
| Emited when the eventloop is exited. | |
| void | post (Selectable &s) |
| Posts the loop to run a selectable. More... | |
| void | setReady (Selectable &s) |
| Sets the Selectable as ready without waking the loop. | |
| void | commitEvent (const Event &ev) |
| Queues an event and triggers event processing. | |
| void | queueEvent (const Event &ev) |
| Only queues an event. | |
| void | wake () |
| Triggers event processing. | |
Protected Member Functions | |
| virtual void | onCommitEvent (const Event &ev)=0 |
| Queues an event and triggers event processing. | |
| virtual void | onQueueEvent (const Event &ev)=0 |
| Only queues an event. | |
| virtual void | onWake ()=0 |
| Triggers event processing. | |
The EventLoop can be used as the central entity of a thread or process to dispatch application events and wait on multiple Selectables, IODevices or Timers for activity.
Events can be added to the internal event queue, even from other threads using the method commitEvent() or queueEvent(). The first method will add the event to the internal queue and wake the event loop, the latter allows queing multiple events and it is up to the caller to wake the event loop by calling wake() when all events are added. When the event loop processes its event, the signal eventReceived is send for each processed event. Events are processed in the order they were added.
To start the MainLoop the method run() must be executed. It blocks until the event loop is stopped. To stop the loop, exit() can be called. The delivery of the events occurs inside the thread that started the execution of the event loop.
| void post | ( | Selectable & | s | ) |
The event loop is woken up and the selectable's run function is called in the event loop thread. This function may be called from any thread, especially from a selectable, that is based on a parallel execution model e.g. using a worker thread.