feat: improve task handling, refactoring
This commit is contained in:
@@ -11,9 +11,6 @@
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
class ApiServer {
|
||||
public:
|
||||
ApiServer(NodeContext& ctx, TaskManager& taskMgr, uint16_t port = 80);
|
||||
@@ -47,7 +44,7 @@ private:
|
||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||
std::vector<EndpointCapability> capabilityRegistry;
|
||||
void onClusterMembersRequest(AsyncWebServerRequest *request);
|
||||
void methodToStr(const std::tuple<String, int> &endpoint, ArduinoJson::V742PB22::JsonObject &apiObj);
|
||||
void methodToStr(const std::tuple<String, int> &endpoint, JsonObject &apiObj);
|
||||
void onSystemStatusRequest(AsyncWebServerRequest *request);
|
||||
void onFirmwareUpdateRequest(AsyncWebServerRequest *request);
|
||||
void onFirmwareUpload(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||
@@ -59,4 +56,7 @@ private:
|
||||
|
||||
// Capabilities endpoint
|
||||
void onCapabilitiesRequest(AsyncWebServerRequest *request);
|
||||
|
||||
// Internal helpers
|
||||
void registerServiceForLocalNode(const String& uri, int method);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
#include <map>
|
||||
#include "NodeInfo.h"
|
||||
@@ -11,7 +11,6 @@ class NodeContext {
|
||||
public:
|
||||
NodeContext();
|
||||
~NodeContext();
|
||||
Scheduler* scheduler;
|
||||
WiFiUDP* udp;
|
||||
String hostname;
|
||||
IPAddress localIP;
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
#include "NodeContext.h"
|
||||
#include <ArduinoJson.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()>;
|
||||
|
||||
@@ -60,13 +56,8 @@ public:
|
||||
|
||||
private:
|
||||
NodeContext& ctx;
|
||||
std::vector<Task*> tasks;
|
||||
std::vector<TaskDefinition> taskDefinitions;
|
||||
std::vector<unsigned long> lastExecutionTimes;
|
||||
|
||||
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);
|
||||
int findTaskIndex(const std::string& name) const;
|
||||
};
|
||||
Reference in New Issue
Block a user