| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "Event.h" | ||
| 4 | #include <functional> | ||
| 5 | |||
| 6 | /** | ||
| 7 | * @brief Interface for event bus | ||
| 8 | * | ||
| 9 | * Provides publish-subscribe mechanism for event-driven architecture. | ||
| 10 | * Thread-safe implementation required for FreeRTOS multi-tasking. | ||
| 11 | */ | ||
| 12 | class IEventBus { | ||
| 13 | public: | ||
| 14 | 20 | virtual ~IEventBus() = default; | |
| 15 | |||
| 16 | /** | ||
| 17 | * @brief Subscribe to specific event type | ||
| 18 | * @param type Event type to subscribe to | ||
| 19 | * @param handler Callback function called when event occurs | ||
| 20 | */ | ||
| 21 | virtual void subscribe(EventType type, std::function<void(const Event&)> handler) = 0; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * @brief Publish event to all subscribers | ||
| 25 | * @param event Event to publish | ||
| 26 | */ | ||
| 27 | virtual void publish(const Event& event) = 0; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @brief Process all pending events (for synchronous testing) | ||
| 31 | */ | ||
| 32 | virtual void processAllPending() = 0; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @brief Wait for next event (blocking, for FreeRTOS tasks) | ||
| 36 | * @param outEvent Output event structure | ||
| 37 | * @param timeoutMs Timeout in milliseconds (portMAX_DELAY for infinite) | ||
| 38 | * @return true if event received, false on timeout | ||
| 39 | */ | ||
| 40 | [[nodiscard]] virtual bool waitForEvent(Event& outEvent, uint32_t timeoutMs) = 0; | ||
| 41 | }; | ||
| 42 |