#pragma once #include "program.h" #include #include #include #include #include "GLOBALS.h" // Forward declarations class Shell; class TFT_Handler; class SystemManager { private: DISPLAY_STATE* _display_state; Shell* _shell; TFT_Handler* _tft; short int _next_program_id = 1; CALIBRATION_IDLE _calibration_idle; // Factory function type: creates a new instance of a Program using ProgramFactory = std::function; // Map of program class names to factory functions std::unordered_map _program_factories; public: std::vector _programs; void init(DISPLAY_STATE* display_state, Shell* shell, TFT_Handler* tft, CALIBRATION_IDLE calibration_idle); // Register a program type with a factory function template void register_program(const std::string& class_name) { _program_factories[class_name] = []() -> Program* { return new T(); }; } // Spawn a program by its class name bool spawn_program(Window* window, const std::string& program_class); // Close a running program void close_program(short int id); };