Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
ersa::events::EventBus Class Reference

#include <event_bus.h>

Collaboration diagram for ersa::events::EventBus:
Collaboration graph
[legend]

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}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EventBus()

ersa::events::EventBus::EventBus ( )

Construct an empty bus with an empty queue and fresh subscription IDs.

Member Function Documentation

◆ clear()

void ersa::events::EventBus::clear ( )

Clear all subscriptions and queued events, primarily for reinitialization/tests.

◆ dispatchQueue()

size_t ersa::events::EventBus::dispatchQueue ( )

Dispatch queued events in FIFO order and return the number processed.

◆ instance()

EventBus & ersa::events::EventBus::instance ( )
static

Return the process-wide default bus used by system services.

◆ post()

bool ersa::events::EventBus::post ( const Event &  event)

Copy an event into the ring queue for later application-task delivery.

Returns
False if the bounded queue is full; callers should handle loss.

◆ publish()

void ersa::events::EventBus::publish ( const Event &  event)

Immediately call matching subscribers on the caller's thread.

◆ subscribe() [1/2]

SubscriptionId ersa::events::EventBus::subscribe ( EventType  type,
EventCallback  callback,
void *  userData = nullptr 
)

Register a C-style callback for an event type.

Parameters
typeEvent filter; None receives every event.
callbackFunction called synchronously during dispatch.
userDataOpaque context forwarded to the callback.
Returns
Nonzero subscription handle, or zero when no slot is available.

◆ subscribe() [2/2]

SubscriptionId ersa::events::EventBus::subscribe ( EventType  type,
IEventListener *  listener 
)

Register an object listener for an event type; see callback overload.

◆ unsubscribe()

bool ersa::events::EventBus::unsubscribe ( SubscriptionId  id)

Remove a registration by handle; unknown handles return false.

Member Data Documentation

◆ MAX_QUEUE

constexpr size_t ersa::events::EventBus::MAX_QUEUE = 32
staticconstexpr

Maximum queued events awaiting dispatchQueue().

◆ MAX_SUBSCRIBERS

constexpr size_t ersa::events::EventBus::MAX_SUBSCRIBERS = 24
staticconstexpr

Maximum simultaneous callback/listener registrations.

◆ nextSubId_

SubscriptionId ersa::events::EventBus::nextSubId_ {1}
private

◆ queue_

Event ersa::events::EventBus::queue_[MAX_QUEUE]
private

◆ queueCount_

size_t ersa::events::EventBus::queueCount_ {0}
private

◆ queueHead_

size_t ersa::events::EventBus::queueHead_ {0}
private

◆ queueTail_

size_t ersa::events::EventBus::queueTail_ {0}
private

◆ subscribers_

Subscription ersa::events::EventBus::subscribers_[MAX_SUBSCRIBERS]
private

The documentation for this class was generated from the following files: