45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#pragma once
|
|
#include "program.h"
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <functional>
|
|
#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<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, CALIBRATION_IDLE calibration_idle);
|
|
|
|
// 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(short int id);
|
|
}; |