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;
133 virtual Selector& selector() = 0;
140 virtual void onRun() = 0;
143 virtual void onExit() = 0;
155 virtual void onProcessEvents() = 0;
158 virtual void onAttachTimer(
Timer& timer) = 0;
161 virtual void onDetachTimer(
Timer& timer) = 0;
164 virtual void onAttachSelectable(
Selectable&) = 0;
167 virtual void onDetachSelectable(
Selectable&) = 0;
181 class PT_SYSTEM_API EventQueue
188 virtual ~EventQueue();
191 {
return *_usedalloc; }
195 void pushEvent(
const Event& event);
203 std::deque<Event*> _eventQueue;
208 class PT_SYSTEM_API TimerQueue
210 typedef std::multimap<Timespan, Timer*> TimerMap;
215 virtual ~TimerQueue();
217 void addTimer(Timer& timer);
219 void removeTimer(Timer& timer);
221 std::size_t processTimers();
231 #endif // PT_SYSTEM_EVENTLOOP_H
Core module.
Definition: Allocator.h:33
Base class for all event types.
Definition: Event.h:50
void run()
Starts the loop.
Notifies clients in constant intervals.
Definition: Timer.h:73
Signal & exited()
Emited when the eventloop is exited.
Definition: EventLoop.h:110
Multicast Signal to call multiple slots.
Definition: Api-Signal.h:111
void processEvents()
Process all queued events.
virtual void onQueueEvent(const Event &ev)=0
Only queues an event.
void setReady(Selectable &s)
Sets the Selectable as ready without waking the loop.
Definition: EventLoop.h:127
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:50
void exit()
Stops the loop.
virtual void onWake()=0
Triggers event processing.
Dispatches operations through an event loop.
Definition: Selectable.h:45
Allocator interface.
Definition: Allocator.h:82
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:74
virtual ~EventLoop()
Destructor.
virtual void onCommitEvent(const Event &ev)=0
Queues an event and triggers event processing.
void post(Selectable &s)
Posts the loop to run a selectable.
Definition: EventLoop.h:120
Receiver for events.
Definition: EventSink.h:46
Signal< const Event & > & eventReceived()
Reports all events.
Definition: EventLoop.h:105