1.10
eventloop.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_EVENTLOOP_H
7#define EGT_EVENTLOOP_H
8
14#include <egt/detail/meta.h>
15#include <functional>
16#include <memory>
17#include <vector>
18
19namespace egt
20{
21namespace asio
22{
23class io_context;
24}
25
26inline namespace v1
27{
28class Application;
29
30namespace detail
31{
32class PriorityQueue;
33}
34
38class EGT_API EventLoop
39{
40public:
41
42 explicit EventLoop(const Application& app) noexcept;
43 EventLoop(const EventLoop&) = delete;
44 EventLoop& operator=(const EventLoop&) = delete;
45 EventLoop(EventLoop&&) = delete;
47
51 asio::io_context& io();
52
59 void draw();
60
68 int run();
69
83 int step();
84
92 int poll();
93
100 void quit(int exit_value = 0);
101
105 using IdleCallback = std::function<void ()>;
106
111
113 detail::PriorityQueue& queue();
114
115 ~EventLoop() noexcept;
116
117protected:
118
120 int wait();
121
123 void invoke_idle_callbacks();
124
125 struct EventLoopImpl;
126
128 std::unique_ptr<EventLoopImpl> m_impl;
129
131 std::vector<IdleCallback> m_idle;
132
134 bool m_do_quit{false};
135
138
141};
142
143}
144}
145
146#endif
Application definition.
Definition app.h:49
Event loop interface.
Definition eventloop.h:39
EventLoop & operator=(EventLoop &&)=delete
void add_idle_callback(IdleCallback func)
Add a callback to be called any time the event loop is idle.
void draw()
Perform a draw.
int run()
Run the event loop.
int step()
Single step on the event loop.
EventLoop & operator=(const EventLoop &)=delete
int poll()
Run some pending events and return.
EventLoop(const EventLoop &)=delete
int m_exit_value
Return value when application quits.
Definition eventloop.h:137
void quit(int exit_value=0)
Quit the event loop.
std::function< void()> IdleCallback
Event callback function definition.
Definition eventloop.h:105
EventLoop(EventLoop &&)=delete
const Application & m_app
Application reference.
Definition eventloop.h:140
asio::io_context & io()
Get a reference to the internal ASIO io_context object.
~EventLoop() noexcept
EventLoop(const Application &app) noexcept
EGT framework namespace.
Definition animation.h:24