CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::core::EventBus Class Reference

#include <EventBus.h>

Public Member Functions

bool init (size_t queueSize=DEFAULT_QUEUE_SIZE)
 Initializes event queue and internal state.
uint8_t subscribe (EventHandler handler, uint32_t mask=0)
 Subscribes an event handler with optional type mask.
void unsubscribe (uint8_t id)
 Removes subscription by handler ID.
bool publish (const Event &event, bool fromISR=false)
 Publishes an event to the queue.
bool publish (EventType type, uint8_t value=0)
 Publishes a lightweight value event.
void process ()
 Drains queued events and dispatches matching handlers.

Static Public Member Functions

static EventBus & instance ()
 Returns singleton event-bus instance.
static constexpr uint32_t eventMask (EventType type)

Static Public Attributes

static constexpr size_t MAX_HANDLERS = 16
static constexpr size_t DEFAULT_QUEUE_SIZE = 32

Detailed Description

Simple publish/subscribe event bus

  • Supports ISR-safe publishing via FreeRTOS queue
  • Static allocation, no heap
  • Handlers are called from main loop (process())

Definition at line 75 of file EventBus.h.

Member Function Documentation

◆ eventMask()

constexpr uint32_t cdc::core::EventBus::eventMask ( EventType type)
inlinestaticconstexpr

Create event mask for subscribe()

Definition at line 127 of file EventBus.h.

Referenced by cdc::ui::msgTransferUiInit(), cdc::mod_fido2::Fido2Module::start(), and cdc::ui::ui_init().

◆ init()

bool cdc::core::EventBus::init ( size_t queueSize = DEFAULT_QUEUE_SIZE)

Initializes event queue and internal state.

Initialize the event bus

Parameters
queueSizeNumber of events that can be queued
Returns
true on success
Parameters
queueSizeQueue capacity in number of Event objects.
Returns
true on success.

Definition at line 29 of file EventBus.cpp.

References LOG_E, LOG_I, LOG_W, and TAG.

◆ instance()

◆ process()

void cdc::core::EventBus::process ( )

Drains queued events and dispatches matching handlers.

Process queued events (call from main loop)

Returns
void

Definition at line 125 of file EventBus.cpp.

References MAX_HANDLERS.

Referenced by runMainLoopIteration().

◆ publish() [1/2]

bool cdc::core::EventBus::publish ( const Event & event,
bool fromISR = false )

Publishes an event to the queue.

Publish an event

Parameters
eventEvent to publish
fromISRtrue if called from interrupt context
Returns
true if event was queued
Parameters
eventEvent object to queue.
fromISRSet true when called from ISR context.
Returns
true if queueing succeeded.

Definition at line 88 of file EventBus.cpp.

Referenced by cdc::ui::ViewStack::dispatchKey(), cdc::ui::ViewStack::dispatchLongPress(), host_event_publish(), publish(), and cdc::core::ModuleRegistry::reportModuleError().

◆ publish() [2/2]

bool cdc::core::EventBus::publish ( EventType type,
uint8_t value = 0 )

Publishes a lightweight value event.

Publish event (convenience)

Parameters
typeEvent type.
valuePayload value.
Returns
true if queueing succeeded.

Definition at line 113 of file EventBus.cpp.

References publish(), and cdc::core::Event::type.

◆ subscribe()

uint8_t cdc::core::EventBus::subscribe ( EventHandler handler,
uint32_t mask = 0 )

Subscribes an event handler with optional type mask.

Subscribe to events

Parameters
handlerFunction to call when event occurs
maskBitmask of EventTypes to receive (0 = all)
Returns
Handler ID (0 on failure)
Parameters
handlerCallback function.
maskEvent-type bitmask (0 = all events).
Returns
1-based subscription ID, or 0 on failure.

Definition at line 52 of file EventBus.cpp.

References LOG_D, LOG_E, MAX_HANDLERS, and TAG.

Referenced by host_event_subscribe(), cdc::ui::msgTransferUiInit(), and cdc::ui::ui_init().

◆ unsubscribe()

void cdc::core::EventBus::unsubscribe ( uint8_t id)

Removes subscription by handler ID.

Unsubscribe handler

Parameters
idHandler ID from subscribe()
id1-based handler subscription ID.
Returns
void

Definition at line 74 of file EventBus.cpp.

References LOG_D, MAX_HANDLERS, and TAG.

Member Data Documentation

◆ DEFAULT_QUEUE_SIZE

size_t cdc::core::EventBus::DEFAULT_QUEUE_SIZE = 32
staticconstexpr

Definition at line 78 of file EventBus.h.

◆ MAX_HANDLERS

size_t cdc::core::EventBus::MAX_HANDLERS = 16
staticconstexpr

Definition at line 77 of file EventBus.h.

Referenced by process(), subscribe(), and unsubscribe().


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