MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
EventSource.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <queue>
5
6namespace MayaFlux::Kriya {
7class EventAwaiter;
8}
9
10namespace MayaFlux::Vruta {
11
12/**
13 * @class EventSource
14 * @brief Awaitable event stream for window events
15 *
16 * Unlike clocks (SampleClock, FrameClock) which tick periodically,
17 * EventSource is signaled when discrete window events occur.
18 * Coroutines can suspend until events arrive.
19 */
20class MAYAFLUX_API EventSource {
21public:
22 EventSource() = default;
23 ~EventSource() = default;
24
25 EventSource(const EventSource&) = delete;
27 EventSource(EventSource&&) noexcept = default;
28 EventSource& operator=(EventSource&&) noexcept = default;
29
30 /**
31 * @brief Signals that an event occurred
32 * @param event The event data
33 *
34 * Called by GLFW callbacks. Queues event and resumes waiting coroutines.
35 */
36 void signal(Core::WindowEvent event);
37
38 /**
39 * @brief Creates awaiter for next event (any type)
40 */
41 Kriya::EventAwaiter next_event();
42
43 /**
44 * @brief Creates awaiter for specific event type
45 */
46 Kriya::EventAwaiter await_event(Core::WindowEventType type);
47
48 /**
49 * @brief Checks if events are pending
50 */
51 [[nodiscard]] bool has_pending() const { return !m_pending_events.empty(); }
52
53 /**
54 * @brief Gets number of pending events
55 */
56 [[nodiscard]] size_t pending_count() const { return m_pending_events.size(); }
57
58 /**
59 * @brief Clears all pending events
60 */
61 void clear() { m_pending_events = {}; }
62
63private:
64 std::queue<Core::WindowEvent> m_pending_events;
65 std::vector<Kriya::EventAwaiter*> m_waiters;
66
67 std::optional<Core::WindowEvent> pop_event(std::optional<Core::WindowEventType> filter);
68 void register_waiter(Kriya::EventAwaiter* awaiter);
69 void unregister_waiter(Kriya::EventAwaiter* awaiter);
70
71 friend class Kriya::EventAwaiter;
72};
73
74}
Awaiter for suspending on window events.
Definition Awaiters.hpp:280
void clear()
Clears all pending events.
size_t pending_count() const
Gets number of pending events.
EventSource(const EventSource &)=delete
std::vector< Kriya::EventAwaiter * > m_waiters
std::queue< Core::WindowEvent > m_pending_events
EventSource & operator=(const EventSource &)=delete
EventSource(EventSource &&) noexcept=default
Awaitable event stream for window events.