PocketPutr/Desktop_Test/system_manager.h
2026-01-05 18:23:46 +01:00

43 lines
1.0 KiB
C++

#pragma once
#include "program.h"
#include <vector>
#include <unordered_map>
#include <string>
#include <functional>
// Forward declarations
class Shell;
class TFT_Handler;
class SystemManager {
private:
DISPLAY_STATE* _display_state;
Shell* _shell;
TFT_Handler* _tft;
int _next_program_id = 1;
// Factory function type: creates a new instance of a Program
using ProgramFactory = std::function<Program*()>;
// Map of program class names to factory functions
std::unordered_map<std::string, ProgramFactory> _program_factories;
public:
std::vector<Program*> _programs;
void init(DISPLAY_STATE* display_state, Shell* shell, TFT_Handler* tft);
// Register a program type with a factory function
template<typename T>
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(int id);
};