#pragma once #include #include #include #include #include "NodeContext.h" // Forward declarations to avoid multiple definition errors class Task; class Scheduler; // Define our own callback type to avoid conflict with TaskScheduler using TaskFunction = std::function; struct TaskDefinition { std::string name; unsigned long interval; TaskFunction callback; bool enabled; bool autoStart; TaskDefinition(const std::string& n, unsigned long intv, TaskFunction cb, bool en = true, bool autoS = true) : name(n), interval(intv), callback(cb), enabled(en), autoStart(autoS) {} }; class TaskManager { public: TaskManager(NodeContext& ctx); ~TaskManager(); // Task registration methods void registerTask(const std::string& name, unsigned long interval, TaskFunction callback, bool enabled = true, bool autoStart = true); void registerTask(const TaskDefinition& taskDef); // Task control methods void enableTask(const std::string& name); void disableTask(const std::string& name); void setTaskInterval(const std::string& name, unsigned long interval); void startTask(const std::string& name); void stopTask(const std::string& name); // Task status methods bool isTaskEnabled(const std::string& name) const; bool isTaskRunning(const std::string& name) const; unsigned long getTaskInterval(const std::string& name) const; // Management methods void initialize(); void enableAllTasks(); void disableAllTasks(); void printTaskStatus() const; // Task execution void execute(); private: NodeContext& ctx; std::vector tasks; std::vector taskDefinitions; Task* findTask(const std::string& name) const; void createTask(const TaskDefinition& taskDef); // Static callback registry for all TaskManager instances static std::map> callbackRegistry; static void executeCallback(const std::string& taskName); };