MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
EventSource.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Kriya {
4class EventAwaiter;
5}
6
7namespace MayaFlux::Vruta {
8
9// =============================================================================
10// EventSource - base
11// =============================================================================
12
13/**
14 * @class EventSource
15 * @brief Abstract base for all awaitable signal sources.
16 *
17 * Manages the waiter list and dispatches to registered awaiters via the
18 * type-erased EventAwaiter interface. Has no knowledge of payload type,
19 * filter semantics, or threading model.
20 *
21 * Derived classes call dispatch() with a type-erased pointer to the current
22 * signal value. Each registered awaiter receives the pointer and decides
23 * independently whether to resume.
24 *
25 * @see WindowEventSource
26 * @see SignalSource
27 */
28class MAYAFLUX_API EventSource {
29public:
30 EventSource() = default;
31 virtual ~EventSource() = default;
32
33 EventSource(const EventSource&) = delete;
35 EventSource(EventSource&&) noexcept = default;
36 EventSource& operator=(EventSource&&) noexcept = default;
37
38 /**
39 * @brief Returns true if any signals are buffered and not yet consumed.
40 */
41 [[nodiscard]] virtual bool has_pending() const = 0;
42
43 /**
44 * @brief Discards all buffered signals.
45 */
46 virtual void clear() = 0;
47
48protected:
49 /**
50 * @brief Iterates the waiter list, passing the type-erased signal to each.
51 *
52 * Called by derived classes after committing a new signal value.
53 * Awaiters that match resume and unregister themselves.
54 *
55 * @param event Type-erased pointer to the current signal value.
56 */
57 void dispatch(const void* event);
58
59 void register_waiter(Kriya::EventAwaiter* awaiter);
60 void unregister_waiter(Kriya::EventAwaiter* awaiter);
61
62private:
63 std::vector<Kriya::EventAwaiter*> m_waiters;
64
65 friend class Kriya::EventAwaiter;
66};
67
68/**
69 * @class EventFilter
70 * @brief Base for event filters used by EventSources to match signals to awaiters.
71 *
72 * Concrete filter types (e.g. WindowEventFilter) derive from this and add
73 * specific criteria. EventSources use the base pointer to check if a filter is
74 * present and to pass it to awaiters, which then downcast as needed.
75 *
76 * @see WindowEventFilter
77 */
78class MAYAFLUX_API EventFilter {
79public:
80 virtual ~EventFilter() = default;
81};
82
83} // namespace MayaFlux::Vruta
virtual ~EventFilter()=default
Base for event filters used by EventSources to match signals to awaiters.
EventSource(const EventSource &)=delete
virtual ~EventSource()=default
EventSource & operator=(const EventSource &)=delete
EventSource(EventSource &&) noexcept=default
Abstract base for all awaitable signal sources.