43 lines
1001 B
C++
43 lines
1001 B
C++
#pragma once
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/queue.h"
|
|
#include "GLOBALS.h"
|
|
#include <functional>
|
|
#include <algorithm>
|
|
#include <vector>
|
|
|
|
// Forward declare to avoid circular dependency
|
|
class IEventListener {
|
|
public:
|
|
virtual void on_click_event(const CLICK_EVENT& event) = 0;
|
|
virtual ~IEventListener() = default;
|
|
};
|
|
|
|
class EventManager {
|
|
private:
|
|
QueueHandle_t _event_queue;
|
|
std::vector<IEventListener*> _listeners;
|
|
TaskHandle_t _dispatcher_task;
|
|
|
|
EventManager() {
|
|
_event_queue = xQueueCreate(10, sizeof(CLICK_EVENT));
|
|
}
|
|
|
|
EventManager(const EventManager&) = delete;
|
|
EventManager& operator=(const EventManager&) = delete;
|
|
|
|
static void dispatch_task(void* pvParameters);
|
|
|
|
public:
|
|
static EventManager& getInstance() {
|
|
static EventManager instance;
|
|
return instance;
|
|
}
|
|
|
|
void init();
|
|
void publish(const CLICK_EVENT& event);
|
|
void subscribe(IEventListener* listener);
|
|
void unsubscribe(IEventListener* listener);
|
|
}; |