Public Access
lib/core is hardware-independent and unit-tested on the host: - EventBus: fixed-size thread-safe queue, delivered on the UI task by dispatch(); drops newest when full and counts drops - Service / ServiceManager: cooperative ticking at per-service intervals, no catch-up bursts, safe across millis() wraparound - App / AppManager: one foreground App, Home always to Launcher, Back offered to the App first, hidden Apps, redraw requests - KeyEvent: logical keys for the upcoming input layer Firmware main loop now ticks services and dispatches events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <vector>
|
|
|
|
#include "event.h"
|
|
|
|
namespace roro {
|
|
|
|
// Services publish from any task; the UI task calls dispatch() to deliver events to subscribers.
|
|
// Subscribe only during setup, from the UI task.
|
|
class EventBus {
|
|
public:
|
|
using Handler = std::function<void(const Event&)>;
|
|
|
|
explicit EventBus(size_t capacity = 32);
|
|
|
|
// Thread-safe. Returns false (and counts a drop) if the queue is full.
|
|
bool publish(const Event& event);
|
|
|
|
void subscribe(EventType type, Handler handler);
|
|
|
|
// Delivers the events queued before this call; events published meanwhile wait for the next one.
|
|
// Returns how many events were delivered.
|
|
size_t dispatch();
|
|
|
|
uint32_t dropped() const;
|
|
|
|
private:
|
|
std::vector<Event> queue_;
|
|
size_t head_ = 0;
|
|
size_t count_ = 0;
|
|
uint32_t dropped_ = 0;
|
|
mutable std::mutex mutex_;
|
|
std::array<std::vector<Handler>, static_cast<size_t>(EventType::Count)> handlers_;
|
|
};
|
|
|
|
} // namespace roro
|