Files
roro9stack/lib/core/src/service_manager.cpp
T
twislaandClaude Opus 5.5 ae0726b7f9 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
2026-10-02 09:10:10 +02:00

34 lines
872 B
C++

#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