29 #ifndef PT_SYSTEM_EVENTLOOP_H
30 #define PT_SYSTEM_EVENTLOOP_H
33 #include <Pt/Signal.h>
34 #include <Pt/Timespan.h>
35 #include <Pt/Allocator.h>
36 #include <Pt/Connectable.h>
37 #include <Pt/System/Api.h>
38 #include <Pt/System/Mutex.h>
39 #include <Pt/System/Timer.h>
40 #include <Pt/System/EventSink.h>
81 static const std::size_t WaitInfinite =
static_cast<const std::size_t
>(-1);
85 static const std::size_t WaitMax = WaitInfinite - 1;
101 void processEvents();
122 { this->onReady(s); }
126 { this->onReady(s); }
129 virtual Selector& selector() = 0;
136 virtual void onRun() = 0;
139 virtual void onExit() = 0;
142 virtual void onCommitEvent(
const Event& ev) = 0;
145 virtual void onQueueEvent(
const Event& ev) = 0;
148 virtual void onWake() = 0;
151 virtual void onProcessEvents() = 0;
154 virtual void onAttachTimer(Timer& timer) = 0;
157 virtual void onDetachTimer(Timer& timer) = 0;
160 virtual void onAttachSelectable(Selectable&) = 0;
163 virtual void onDetachSelectable(Selectable&) = 0;
166 virtual void onReady(Selectable&) = 0;
169 virtual void onCancel(Selectable&) = 0;
177 class PT_SYSTEM_API EventQueue
182 EventQueue(Allocator& a);
184 virtual ~EventQueue();
186 Allocator& allocator()
187 {
return *_usedalloc; }
191 void pushEvent(
const Event& event);
193 bool processEvents(Signal<const Event&>& eventSignal);
197 Allocator _allocator;
198 Allocator* _usedalloc;
199 std::deque<Event*> _eventQueue;
204 class PT_SYSTEM_API TimerQueue
206 typedef std::multimap<Timespan, Timer*> TimerMap;
211 virtual ~TimerQueue();
213 void addTimer(Timer& timer);
215 void removeTimer(Timer& timer);
217 std::size_t processTimers();
227 #endif // PT_SYSTEM_EVENTLOOP_H
void post(Selectable &s)
Calls the selectables run function in the loop thread.
Definition: EventLoop.h:121
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:49
Receiver for events.
Definition: EventSink.h:45
Base class for all event types.
Definition: Event.h:49
Dispatches operations through an event loop.
Definition: Selectable.h:44
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Signal< const Event & > & eventReceived()
Reports all events.
Definition: EventLoop.h:105
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:72
Signal & exited()
Emited when the eventloop is exited.
Definition: EventLoop.h:110
Notifies clients in constant intervals.
Definition: Timer.h:72