68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <map>
|
|
#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<void()>;
|
|
|
|
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<Task*> tasks;
|
|
std::vector<TaskDefinition> taskDefinitions;
|
|
|
|
Task* findTask(const std::string& name) const;
|
|
void createTask(const TaskDefinition& taskDef);
|
|
|
|
// Static callback registry for all TaskManager instances
|
|
static std::map<std::string, std::function<void()>> callbackRegistry;
|
|
static void executeCallback(const std::string& taskName);
|
|
};
|