Files
tactility/Tactility/Source/kernel/SystemEvents.cpp
T
Ken Van Hoeylandt 9f721e6655 Refactor LVGL code into kernel module (#472)
* **New Features**
  * Added a standalone LVGL module and enabled LVGL support in the simulator for richer local UI testing.

* **Refactor**
  * HAL and LVGL split into distinct modules; startup and device attach/detach flows reorganized for clearer lifecycle management.
  * Public APIs tightened with clearer nullability/documentation.

* **Bug Fixes**
  * More consistent LVGL start/stop and device attach/detach behavior for improved stability.
2026-02-01 22:57:45 +01:00

85 lines
2.0 KiB
C++

#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/Logger.h>
#include <Tactility/Mutex.h>
#include <tactility/check.h>
#include <Tactility/CoreDefines.h>
#include <list>
namespace tt::kernel {
static const auto LOGGER = Logger("SystemEvents");
struct SubscriptionData {
SystemEventSubscription id;
SystemEvent event;
OnSystemEvent handler;
};
static Mutex mutex;
static SystemEventSubscription subscriptionCounter = 0;
static std::list<SubscriptionData> subscriptions;
static const char* getEventName(SystemEvent event) {
switch (event) {
using enum SystemEvent;
case BootInitHalBegin:
return TT_STRINGIFY(BootInitHalBegin);
case BootInitHalEnd:
return TT_STRINGIFY(BootInitHalEnd);
case BootSplash:
return TT_STRINGIFY(BootSplash);
case NetworkConnected:
return TT_STRINGIFY(NetworkConnected);
case NetworkDisconnected:
return TT_STRINGIFY(NetworkDisconnected);
case Time:
return TT_STRINGIFY(Time);
}
check(false); // Missing case above
}
void publishSystemEvent(SystemEvent event) {
LOGGER.info("{}", getEventName(event));
if (mutex.lock(MAX_TICKS)) {
for (auto& subscription : subscriptions) {
if (subscription.event == event) {
subscription.handler(event);
}
}
mutex.unlock();
}
}
SystemEventSubscription subscribeSystemEvent(SystemEvent event, OnSystemEvent handler) {
if (mutex.lock(MAX_TICKS)) {
auto id = ++subscriptionCounter;
subscriptions.push_back({
.id = id,
.event = event,
.handler = handler
});
mutex.unlock();
return id;
} else {
check(false);
}
}
void unsubscribeSystemEvent(SystemEventSubscription subscription) {
if (mutex.lock(MAX_TICKS)) {
std::erase_if(subscriptions, [subscription](auto& item) {
return (item.id == subscription);
});
mutex.unlock();
}
}
}