156 bool singleShot =
false);
170 std::function<
void()> func,
171 bool singleShot =
false);
192 struct CallableItem { std::function<
void()> func; };
194 struct QuitItem {
int code; };
195 using Item = std::variant<CallableItem, EventItem, QuitItem>;
200 std::function<
void()> func;
201 unsigned int intervalMs;
214 bool dispatchItem(Item &
item);
215 void processTimers();
216 unsigned int nextTimerTimeout()
const;
T value() const
Loads the current value with acquire semantics.
Definition atomic.h:46
Per-thread event loop providing event dispatch, timers, and posted callables.
Definition eventloop.h:58
void stopTimer(int timerId)
Stops and removes a timer.
ProcessEventsFlag
Flags controlling processEvents() behavior.
Definition eventloop.h:61
@ ExcludeTimers
Skip timer processing.
Definition eventloop.h:62
@ WaitForMore
Block until at least one event is available.
Definition eventloop.h:64
@ ExcludePosted
Skip posted callables and events.
Definition eventloop.h:63
EventLoop()
Constructs an EventLoop and registers it as current for this thread.
static EventLoop * current()
Returns the EventLoop running on the current thread.
void postCallable(std::function< void()> func)
Posts a callable to be executed on this EventLoop's thread.
int startTimer(unsigned int intervalMs, std::function< void()> func, bool singleShot=false)
Starts a standalone callable timer.
void quit(int returnCode=0)
Signals the event loop to exit with the given return code.
int startTimer(ObjectBase *receiver, unsigned int intervalMs, bool singleShot=false)
Starts a timer that delivers TimerEvent to an ObjectBase.
void postEvent(ObjectBase *receiver, Event *event)
Posts an Event to this EventLoop for delivery to a receiver.
int exitCode() const
Returns the exit code set by the most recent quit().
Definition eventloop.h:189
~EventLoop()
Destroys the EventLoop.
bool isRunning() const
Returns whether the event loop is currently running.
Definition eventloop.h:183
void processEvents(uint32_t flags=0, unsigned int timeoutMs=0)
Processes pending events and returns.
int exec()
Blocks and processes events until quit() is called.
Base class for the event system.
Definition event.h:29
Dynamic array container wrapping std::vector.
Definition list.h:40
Base object for promeki.
Definition objectbase.h:129
A monotonic timestamp based on std::chrono::steady_clock.
Definition timestamp.h:32
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19