|
Ersa Wearable Platform
Embedded smartwatch firmware and application framework
|
#include <event_bus.h>

Public Member Functions | |
| EventBus () | |
| SubscriptionId | subscribe (EventType type, EventCallback callback, void *userData=nullptr) |
| SubscriptionId | subscribe (EventType type, IEventListener *listener) |
| bool | unsubscribe (SubscriptionId id) |
| void | publish (const Event &event) |
| bool | post (const Event &event) |
| size_t | dispatchQueue () |
| void | clear () |
Static Public Member Functions | |
| static EventBus & | instance () |
Static Public Attributes | |
| static constexpr size_t | MAX_SUBSCRIBERS = 24 |
| static constexpr size_t | MAX_QUEUE = 32 |
Private Attributes | |
| Subscription | subscribers_ [MAX_SUBSCRIBERS] |
| SubscriptionId | nextSubId_ {1} |
| Event | queue_ [MAX_QUEUE] |
| size_t | queueHead_ {0} |
| size_t | queueTail_ {0} |
| size_t | queueCount_ {0} |
Fixed-memory event distribution for services, HAL adapters, and apps.
publish dispatches synchronously; post copies into a bounded queue for later dispatch by the application task. This split lets interrupt/radio callbacks hand off normalized events without running UI code on their thread, while avoiding heap allocation in the event path.
| ersa::events::EventBus::EventBus | ( | ) |
Construct an empty bus with an empty queue and fresh subscription IDs.
| void ersa::events::EventBus::clear | ( | ) |
Clear all subscriptions and queued events, primarily for reinitialization/tests.
| size_t ersa::events::EventBus::dispatchQueue | ( | ) |
Dispatch queued events in FIFO order and return the number processed.
|
static |
Return the process-wide default bus used by system services.
| bool ersa::events::EventBus::post | ( | const Event & | event | ) |
Copy an event into the ring queue for later application-task delivery.
| void ersa::events::EventBus::publish | ( | const Event & | event | ) |
Immediately call matching subscribers on the caller's thread.
| SubscriptionId ersa::events::EventBus::subscribe | ( | EventType | type, |
| EventCallback | callback, | ||
| void * | userData = nullptr |
||
| ) |
Register a C-style callback for an event type.
| type | Event filter; None receives every event. |
| callback | Function called synchronously during dispatch. |
| userData | Opaque context forwarded to the callback. |
| SubscriptionId ersa::events::EventBus::subscribe | ( | EventType | type, |
| IEventListener * | listener | ||
| ) |
Register an object listener for an event type; see callback overload.
| bool ersa::events::EventBus::unsubscribe | ( | SubscriptionId | id | ) |
Remove a registration by handle; unknown handles return false.
|
staticconstexpr |
Maximum queued events awaiting dispatchQueue().
|
staticconstexpr |
Maximum simultaneous callback/listener registrations.
|
private |
|
private |
|
private |
|
private |
|
private |