feat: bind tasks instead of passing fn ptrs when registering a task
This commit is contained in:
@@ -3,23 +3,24 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "NodeContext.h"
|
||||
|
||||
// Forward declarations to avoid multiple definition errors
|
||||
class Task;
|
||||
class Scheduler;
|
||||
|
||||
// Define the callback type that TaskScheduler expects
|
||||
using TaskCallback = void (*)();
|
||||
// Define our own callback type to avoid conflict with TaskScheduler
|
||||
using TaskFunction = std::function<void()>;
|
||||
|
||||
struct TaskDefinition {
|
||||
std::string name;
|
||||
unsigned long interval;
|
||||
TaskCallback callback;
|
||||
TaskFunction callback;
|
||||
bool enabled;
|
||||
bool autoStart;
|
||||
|
||||
TaskDefinition(const std::string& n, unsigned long intv, TaskCallback cb, bool en = true, bool autoS = true)
|
||||
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) {}
|
||||
};
|
||||
|
||||
@@ -29,7 +30,7 @@ public:
|
||||
~TaskManager();
|
||||
|
||||
// Task registration methods
|
||||
void registerTask(const std::string& name, unsigned long interval, TaskCallback callback, bool enabled = true, bool autoStart = true);
|
||||
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
|
||||
@@ -60,4 +61,8 @@ private:
|
||||
|
||||
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);
|
||||
};
|
||||
Reference in New Issue
Block a user