Parking Garage Control System
ESP32 Parking Garage – ESP-IDF/FreeRTOS
Loading...
Searching...
No Matches
FreeRtosEventBus.h
Go to the documentation of this file.
1#pragma once
2
3#include "IEventBus.h"
4#include "freertos/FreeRTOS.h"
5#include "freertos/queue.h"
6#include "freertos/semphr.h"
7#include "freertos/task.h"
8#include <map>
9#include <vector>
10
19 public:
24 explicit FreeRtosEventBus(size_t queueSize = 32);
25 ~FreeRtosEventBus() override;
26
27 // Prevent copying
30
31 void subscribe(EventType type, std::function<void(const Event&)> handler) override;
32 void publish(const Event& event) override;
33 void processAllPending() override;
34 [[nodiscard]] bool waitForEvent(Event& outEvent, uint32_t timeoutMs) override;
35
41 bool publishFromISR(const Event& event);
42
53 void startEventLoop(uint32_t stackSize = 4096, UBaseType_t priority = 5,
54 const char* taskName = "event_loop");
55
61 void stopEventLoop();
62
67 [[nodiscard]] bool isEventLoopRunning() const;
68
69 private:
70 void dispatchEvent(const Event& event);
71 static void eventLoopTask(void* pvParameters);
72
73 QueueHandle_t m_queue;
74 SemaphoreHandle_t m_mutex;
75 std::map<EventType, std::vector<std::function<void(const Event&)>>> m_subscribers;
76 TaskHandle_t m_eventLoopTask = nullptr;
77 volatile bool m_stopRequested = false;
78};
EventType
Event types in the parking system.
Definition Event.h:9
FreeRTOS implementation of event bus.
Definition FreeRtosEventBus.h:18
FreeRtosEventBus(const FreeRtosEventBus &)=delete
bool publishFromISR(const Event &event)
Publish event from ISR context.
Definition FreeRtosEventBus.cpp:58
void processAllPending() override
Process all pending events (for synchronous testing)
Definition FreeRtosEventBus.cpp:78
bool waitForEvent(Event &outEvent, uint32_t timeoutMs) override
Wait for next event (blocking, for FreeRTOS tasks)
Definition FreeRtosEventBus.cpp:85
void startEventLoop(uint32_t stackSize=4096, UBaseType_t priority=5, const char *taskName="event_loop")
Start the internal event loop task.
Definition FreeRtosEventBus.cpp:116
void publish(const Event &event) override
Publish event to all subscribers.
Definition FreeRtosEventBus.cpp:41
FreeRtosEventBus & operator=(const FreeRtosEventBus &)=delete
void stopEventLoop()
Stop the internal event loop task.
Definition FreeRtosEventBus.cpp:142
bool isEventLoopRunning() const
Check if event loop is running.
Definition FreeRtosEventBus.cpp:163
void subscribe(EventType type, std::function< void(const Event &)> handler) override
Subscribe to specific event type.
Definition FreeRtosEventBus.cpp:33
~FreeRtosEventBus() override
Definition FreeRtosEventBus.cpp:21
Interface for event bus.
Definition IEventBus.h:12
Event structure.
Definition Event.h:45
Coverage