63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <map>
|
|
#include "NodeContext.h"
|
|
#include <ArduinoJson.h>
|
|
|
|
// 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;
|
|
|
|
// Get comprehensive task status information
|
|
std::vector<std::pair<std::string, JsonObject>> getAllTaskStatuses(JsonDocument& doc) const;
|
|
|
|
// Management methods
|
|
void initialize();
|
|
void enableAllTasks();
|
|
void disableAllTasks();
|
|
void printTaskStatus() const;
|
|
|
|
// Task execution
|
|
void execute();
|
|
|
|
private:
|
|
NodeContext& ctx;
|
|
std::vector<TaskDefinition> taskDefinitions;
|
|
std::vector<unsigned long> lastExecutionTimes;
|
|
|
|
int findTaskIndex(const std::string& name) const;
|
|
};
|