#pragma once #include #include #include #include #include class EventBus { public: template using Bus = TypedEventBus::QueueDepth, EventBusConfig::MaxSubs, EventBusConfig::BatchSize>; template using Handle = typename Bus::Handle; template static bool publish(const Msg& msg, const char* source = nullptr) { if (_hasGlobalListeners.load(std::memory_order_acquire)) { notifyGlobalListeners(msg, source); } return Bus::publish(msg); } template static auto subscribe(Callback&& callback) { return Bus::subscribe(std::forward(callback)); } template static auto subscribe(uint32_t intervalMs, Callback&& callback) { return Bus::subscribe(intervalMs, std::forward(callback)); } template static void publishISR(const Msg& msg, BaseType_t* higherPriorityTaskWoken = nullptr) { Bus::publishISR(msg, higherPriorityTaskWoken); } template static bool peek(Msg& out) { return Bus::peek(out); } template static bool take(Msg& out) { return Bus::take(out); } template static bool hasSubscribers() { return Bus::hasSubscribers(); } using GlobalHandler = FixedFn; static size_t subscribeGlobal(GlobalHandler&& handler); static void unsubscribeGlobal(size_t id); private: static std::atomic _hasGlobalListeners; template static void notifyGlobalListeners(const Msg& msg, const char* source); };