feat: task manager
This commit is contained in:
63
include/TaskManager.h
Normal file
63
include/TaskManager.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include "NodeContext.h"
|
||||
|
||||
// Forward declarations to avoid multiple definition errors
|
||||
class Task;
|
||||
class Scheduler;
|
||||
|
||||
// Define the callback type that TaskScheduler expects
|
||||
using TaskCallback = void (*)();
|
||||
|
||||
struct TaskDefinition {
|
||||
std::string name;
|
||||
unsigned long interval;
|
||||
TaskCallback callback;
|
||||
bool enabled;
|
||||
bool autoStart;
|
||||
|
||||
TaskDefinition(const std::string& n, unsigned long intv, TaskCallback 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, TaskCallback 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);
|
||||
};
|
||||
Reference in New Issue
Block a user