From d36de899fd126942870cd797e12c400e6af5f231 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Mon, 11 Dec 2023 08:07:52 +0100 Subject: [PATCH] platform: implement commands for task management --- src/Platform.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Platform.h | 2 ++ 2 files changed, 74 insertions(+) diff --git a/src/Platform.cpp b/src/Platform.cpp index 7df8e5a..7b90b03 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -255,6 +255,78 @@ Platform::restart() { #endif } + +__attribute__((noreturn)) +void +doReboot(Args& args, Print& out) +{ + out.println("Rebooting"); + Platform::restart(); +} + +__attribute__((noreturn)) +void +doSafeMode(Args& args, Print& out) +{ + out.println("Rebooting into safe mode"); + Platform::bootopts.forceSafeMode(); + Platform::restart(); +} + +String s; + +void +doTaskStart(Args& args, Print& out) +{ + s = args[1]; + MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, s.c_str()}); +} + +void +doTaskStop(Args& args, Print& out) +{ + s = args[1]; + MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, s.c_str()}); +} + +void +doTaskList(Args& args, Print& out) +{ + auto sched = MainLoop::instance()->scheduler; + auto printer = Static::instance()->printer(); + out.println("Tasks:"); + for(auto task : sched.tasks) { + bool isFigment = task->isFigment(); + if (task->state == Task::Running) { + out.print("+"); + } else { + out.print("-"); + } + if (isFigment) { + out.print("F "); + } else { + out.print("T "); + } + out.println(task->name); + } +} + + + +const std::vector _commands = { + {"tasks", doTaskList}, + {"safe-mode", doSafeMode}, + {"reboot", doReboot}, + {"stop", doTaskStop}, + {"start", doTaskStart} +}; + +const std::vector& +Platform::commands() const +{ + return _commands; +} + BootOptions Platform::bootopts; diff --git a/src/Platform.h b/src/Platform.h index 9b767bc..1e5df6f 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -105,4 +105,6 @@ class Platform : public Task { } static void restart(); + + const std::vector& commands() const override; };