chore: move header files to includes folder
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Updater.h>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include "NodeContext.h"
|
||||
#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);
|
||||
void begin();
|
||||
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler);
|
||||
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler,
|
||||
std::function<void(AsyncWebServerRequest*, const String&, size_t, uint8_t*, size_t, bool)> uploadHandler);
|
||||
private:
|
||||
AsyncWebServer server;
|
||||
NodeContext& ctx;
|
||||
TaskManager& taskManager;
|
||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||
void onClusterMembersRequest(AsyncWebServerRequest *request);
|
||||
void methodToStr(const std::tuple<String, int> &endpoint, ArduinoJson::V742PB22::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);
|
||||
void onRestartRequest(AsyncWebServerRequest *request);
|
||||
|
||||
// Task management endpoints
|
||||
void onTaskStatusRequest(AsyncWebServerRequest *request);
|
||||
void onTaskControlRequest(AsyncWebServerRequest *request);
|
||||
};
|
||||
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <map>
|
||||
|
||||
class ClusterManager {
|
||||
public:
|
||||
ClusterManager(NodeContext& ctx, TaskManager& taskMgr);
|
||||
void registerTasks();
|
||||
void sendDiscovery();
|
||||
void listenForDiscovery();
|
||||
void addOrUpdateNode(const String& nodeHost, IPAddress nodeIP);
|
||||
void updateAllNodeStatuses();
|
||||
void removeDeadNodes();
|
||||
void printMemberList();
|
||||
const std::map<String, NodeInfo>& getMemberList() const { return *ctx.memberList; }
|
||||
void fetchNodeInfo(const IPAddress& ip);
|
||||
void updateLocalNodeResources();
|
||||
void heartbeatTaskCallback();
|
||||
void updateAllMembersInfoTaskCallback();
|
||||
private:
|
||||
NodeContext& ctx;
|
||||
TaskManager& taskManager;
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "NodeContext.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
class NetworkManager {
|
||||
public:
|
||||
NetworkManager(NodeContext& ctx);
|
||||
void setupWiFi();
|
||||
void setHostnameFromMac();
|
||||
private:
|
||||
NodeContext& ctx;
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <map>
|
||||
#include "NodeInfo.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include "Config.h"
|
||||
|
||||
class NodeContext {
|
||||
public:
|
||||
NodeContext();
|
||||
~NodeContext();
|
||||
Scheduler* scheduler;
|
||||
WiFiUDP* udp;
|
||||
String hostname;
|
||||
IPAddress localIP;
|
||||
std::map<String, NodeInfo>* memberList;
|
||||
Config config;
|
||||
|
||||
using EventCallback = std::function<void(void*)>;
|
||||
std::map<std::string, std::vector<EventCallback>> eventRegistry;
|
||||
|
||||
void on(const std::string& event, EventCallback cb);
|
||||
void fire(const std::string& event, void* data);
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include <IPAddress.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
struct NodeInfo {
|
||||
String hostname;
|
||||
IPAddress ip;
|
||||
unsigned long lastSeen;
|
||||
enum Status { ACTIVE, INACTIVE, DEAD } status;
|
||||
struct Resources {
|
||||
uint32_t freeHeap = 0;
|
||||
uint32_t chipId = 0;
|
||||
String sdkVersion;
|
||||
uint32_t cpuFreqMHz = 0;
|
||||
uint32_t flashChipSize = 0;
|
||||
} resources;
|
||||
unsigned long latency = 0; // ms since lastSeen
|
||||
std::vector<std::tuple<String, int>> apiEndpoints; // List of registered endpoints
|
||||
};
|
||||
|
||||
const char* statusToStr(NodeInfo::Status status);
|
||||
void updateNodeStatus(NodeInfo &node, unsigned long now, unsigned long inactive_threshold, unsigned long dead_threshold);
|
||||
void updateNodeStatus(NodeInfo &node, unsigned long now = millis()); // Legacy overload for backward compatibility
|
||||
Reference in New Issue
Block a user