Manages the system-wide event queue and subscriptions. More...
#include <EventManager.h>
Classes | |
struct | Subscriber |
Public Member Functions | |
EventManager (size_t queueSize=0) | |
Constructor with optional queue size override. | |
void | subscribe (uint32_t eventMask, FrameworkController *controller) |
Subscribe a task to specific event types. | |
void | postEvent (const Event &e) |
Post a notification to the queue and notify matching subscribers. | |
void | postNotification (const Notification &n, FrameworkTask *target) |
Post a notification to the queue and notify matching subscribers. | |
void | enqueue (const Event &event) |
Post an event to the queue and notify matching subscribers. | |
bool | hasPendingEvents (FrameworkController *controller) const |
Returns true if there are any pending events for a given controller. | |
template<typename Enum , typename... Rest> | |
void | subscribeTo (FrameworkController *ctrl, Enum first, Rest... rest) |
Static Public Member Functions | |
static EventManager & | getInstance () |
Get the global EventManager instance. | |
Private Member Functions | |
void | withSubscribers (const std::function< void(std::vector< Subscriber > &)> &fn) |
void | withSubscribersFromISR (const std::function< void(std::vector< Subscriber > &)> &fn) |
Provides read-only access to subscribers from ISR context (no locking). | |
Private Attributes | |
SemaphoreHandle_t | lock |
std::vector< Subscriber > | subscribers_ |
Static Private Attributes | |
static StaticSemaphore_t | lockBuffer_ |
Allows tasks to:
onEvent()
Implemented as a singleton.
Definition at line 63 of file EventManager.h.
|
explicit |
Constructor with optional queue size override.
queueSize | Maximum number of events in the internal queue. |
queueSize | Maximum number of events in the internal queue. |
Definition at line 50 of file EventManager.cpp.
References configASSERT, lock, and lockBuffer_.
void EventManager::enqueue | ( | const Event & | event | ) |
Post an event to the queue and notify matching subscribers.
Safe to call from task or ISR context.
event | The event to post. |
Safe to call from task or ISR context.
event | The event to post. |
Definition at line 111 of file EventManager.cpp.
References debug_print(), is_in_interrupt(), withSubscribers(), and withSubscribersFromISR().
Referenced by postEvent().
|
inlinestatic |
Definition at line 69 of file EventManager.h.
bool EventManager::hasPendingEvents | ( | FrameworkController * | controller | ) | const |
controller | Pointer to the controller. |
void EventManager::postEvent | ( | const Event & | e | ) |
Safe to call from task or ISR context.
n | The notification to post. |
target | Optional specific controller to notify (nullptr for all). |
Definition at line 153 of file EventManager.cpp.
References enqueue(), Event::notification, postNotification(), and Event::target.
void EventManager::postNotification | ( | const Notification & | n, |
FrameworkTask * | target | ||
) |
Post a notification to the queue and notify matching subscribers.
Safe to call from task or ISR context.
n | The notification to post. |
target | Optional specific controller to notify (nullptr for all). |
Safe to call from task or ISR context.
n | The notification to post. |
target | Optional specific controller to notify (nullptr for all). |
Definition at line 80 of file EventManager.cpp.
References Notification::code(), is_in_interrupt(), withSubscribers(), and withSubscribersFromISR().
Referenced by postEvent().
void EventManager::subscribe | ( | uint32_t | mask, |
FrameworkController * | target | ||
) |
Subscribe a task to specific event types.
Each controller provides a bitmask of events it is interested in.
eventMask | Bitmask of (1 << event.notification.code()) . |
controller | Pointer to the FrameworkController to notify. |
Each controller provides a bitmask of events it is interested in.
eventMask | Bitmask of (1 << event.notification.code()) . |
controller | Pointer to the FrameworkController to notify. |
Definition at line 57 of file EventManager.cpp.
References withSubscribers().
Referenced by App::onStart(), and subscribeTo().
|
inline |
Definition at line 132 of file EventManager.h.
References eventMask(), and subscribe().
|
private |
Definition at line 64 of file EventManager.cpp.
References lock, and subscribers_.
Referenced by enqueue(), postNotification(), and subscribe().
|
private |
Provides read-only access to subscribers from ISR context (no locking).
WARNING: Call only from ISR context. Must not modify the list.
WARNING: Call only from ISR context. Must not modify the list.
Definition at line 72 of file EventManager.cpp.
References lock, and subscribers_.
Referenced by enqueue(), and postNotification().
|
private |
Definition at line 148 of file EventManager.h.
Referenced by EventManager(), withSubscribers(), and withSubscribersFromISR().
|
staticprivate |
Definition at line 149 of file EventManager.h.
Referenced by EventManager().
|
private |
Definition at line 151 of file EventManager.h.
Referenced by withSubscribers(), and withSubscribersFromISR().