Public Access
Add core runtime: event bus, services, app lifecycle
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
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include "service_manager.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
void ServiceManager::add(Service& service) { entries_.push_back({&service, 0, true}); }
|
||||
|
||||
void ServiceManager::startAll(uint32_t nowMs) {
|
||||
for (auto& e : entries_) {
|
||||
e.service->start();
|
||||
e.lastTickMs = nowMs;
|
||||
e.due = true;
|
||||
}
|
||||
running_ = true;
|
||||
}
|
||||
|
||||
void ServiceManager::stopAll() {
|
||||
for (auto it = entries_.rbegin(); it != entries_.rend(); ++it) it->service->stop();
|
||||
running_ = false;
|
||||
}
|
||||
|
||||
void ServiceManager::tick(uint32_t nowMs) {
|
||||
if (!running_) return;
|
||||
for (auto& e : entries_) {
|
||||
// Unsigned subtraction keeps working across the 49-day millis() wraparound.
|
||||
if (e.due || nowMs - e.lastTickMs >= e.service->tickIntervalMs()) {
|
||||
e.due = false;
|
||||
e.lastTickMs = nowMs;
|
||||
e.service->tick(nowMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user