|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#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 |
Simple publish/subscribe event bus
Definition at line 75 of file EventBus.h.
|
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().
| bool cdc::core::EventBus::init | ( | size_t | queueSize = DEFAULT_QUEUE_SIZE | ) |
Initializes event queue and internal state.
Initialize the event bus
| queueSize | Number of events that can be queued |
| queueSize | Queue capacity in number of Event objects. |
Definition at line 29 of file EventBus.cpp.
|
static |
Returns singleton event-bus instance.
Get singleton instance
Definition at line 19 of file EventBus.cpp.
References instance().
Referenced by cdc::ui::ViewStack::dispatchKey(), cdc::ui::ViewStack::dispatchLongPress(), host_event_publish(), host_event_subscribe(), initCoreServices(), instance(), cdc::ui::msgTransferUiInit(), cdc::ui::onBleNumericComparison(), cdc::core::ModuleRegistry::reportModuleError(), runMainLoopIteration(), cdc::mod_fido2::Fido2Module::start(), and cdc::ui::ui_init().
| void cdc::core::EventBus::process | ( | ) |
Drains queued events and dispatches matching handlers.
Process queued events (call from main loop)
Definition at line 125 of file EventBus.cpp.
References MAX_HANDLERS.
Referenced by runMainLoopIteration().
| bool cdc::core::EventBus::publish | ( | const Event & | event, |
| bool | fromISR = false ) |
Publishes an event to the queue.
Publish an event
| event | Event to publish |
| fromISR | true if called from interrupt context |
| event | Event object to queue. |
| fromISR | Set true when called from ISR context. |
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().
| bool cdc::core::EventBus::publish | ( | EventType | type, |
| uint8_t | value = 0 ) |
Publishes a lightweight value event.
Publish event (convenience)
| type | Event type. |
| value | Payload value. |
Definition at line 113 of file EventBus.cpp.
References publish(), and cdc::core::Event::type.
| uint8_t cdc::core::EventBus::subscribe | ( | EventHandler | handler, |
| uint32_t | mask = 0 ) |
Subscribes an event handler with optional type mask.
Subscribe to events
| handler | Function to call when event occurs |
| mask | Bitmask of EventTypes to receive (0 = all) |
| handler | Callback function. |
| mask | Event-type bitmask (0 = all events). |
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().
| void cdc::core::EventBus::unsubscribe | ( | uint8_t | id | ) |
Removes subscription by handler ID.
Unsubscribe handler
| id | Handler ID from subscribe() |
| id | 1-based handler subscription ID. |
Definition at line 74 of file EventBus.cpp.
References LOG_D, MAX_HANDLERS, and TAG.
|
staticconstexpr |
Definition at line 78 of file EventBus.h.
|
staticconstexpr |
Definition at line 77 of file EventBus.h.
Referenced by process(), subscribe(), and unsubscribe().