Files
spore/include/spore/core/TaskManager.h
Patrick Balsiger 554c6ff38d refactor: reorganize project structure with modern C++ namespace organization
- Restructure include/ and src/ directories with logical grouping
- Move core components to spore/core/ (NodeContext, NetworkManager, TaskManager, ClusterManager, ApiServer)
- Move services to spore/services/ (NodeService, NetworkService, ClusterService, TaskService)
- Move types to spore/types/ (NodeInfo, ApiTypes, Config)
- Move internal components to spore/internal/ (Globals)
- Update all #include statements to use new namespace paths
- Update platformio.ini build filters for all environments
- Update all example files to use new include paths
- Maintain backward compatibility for public API
- Improve code organization, maintainability, and scalability

This reorganization follows modern C++ project structure patterns and provides
clear separation between public API, internal implementation, and utilities.
All examples compile successfully with the new structure.
2025-09-13 21:30:07 +02:00

63 lines
1.9 KiB
C++

#pragma once
#include <vector>
#include <functional>
#include <string>
#include <map>
#include "spore/core/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;
};