chore: rename ClusterContext to NodeContext
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "ClusterManager.h"
|
||||
|
||||
ClusterManager::ClusterManager(ClusterContext& ctx) : ctx(ctx) {
|
||||
ClusterManager::ClusterManager(NodeContext& ctx) : ctx(ctx) {
|
||||
// Register callback for node_discovered event
|
||||
ctx.registerEvent("node_discovered", [this](void* data) {
|
||||
NodeInfo* node = static_cast<NodeInfo*>(data);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include "ClusterContext.h"
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
class ClusterManager {
|
||||
public:
|
||||
ClusterManager(ClusterContext& ctx);
|
||||
ClusterManager(NodeContext& ctx);
|
||||
void sendDiscovery();
|
||||
void listenForDiscovery();
|
||||
void addOrUpdateNode(const String& nodeHost, IPAddress nodeIP);
|
||||
@@ -22,5 +22,5 @@ public:
|
||||
void heartbeatTaskCallback();
|
||||
void updateAllMembersInfoTaskCallback();
|
||||
private:
|
||||
ClusterContext& ctx;
|
||||
NodeContext& ctx;
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const char* STA_SSID = "shroud";
|
||||
const char* STA_PASS = "th3r31sn0sp00n";
|
||||
|
||||
NetworkManager::NetworkManager(ClusterContext& ctx) : ctx(ctx) {}
|
||||
NetworkManager::NetworkManager(NodeContext& ctx) : ctx(ctx) {}
|
||||
|
||||
void NetworkManager::setHostnameFromMac() {
|
||||
uint8_t mac[6];
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
#include "ClusterContext.h"
|
||||
#include "NodeContext.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
class NetworkManager {
|
||||
public:
|
||||
NetworkManager(ClusterContext& ctx);
|
||||
NetworkManager(NodeContext& ctx);
|
||||
void setupWiFi();
|
||||
void setHostnameFromMac();
|
||||
private:
|
||||
ClusterContext& ctx;
|
||||
NodeContext& ctx;
|
||||
};
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
#include "ClusterContext.h"
|
||||
#include "NodeContext.h"
|
||||
|
||||
ClusterContext::ClusterContext() {
|
||||
NodeContext::NodeContext() {
|
||||
scheduler = new Scheduler();
|
||||
udp = new WiFiUDP();
|
||||
memberList = new std::vector<NodeInfo>();
|
||||
hostname = "";
|
||||
}
|
||||
|
||||
ClusterContext::~ClusterContext() {
|
||||
NodeContext::~NodeContext() {
|
||||
delete scheduler;
|
||||
delete udp;
|
||||
delete memberList;
|
||||
}
|
||||
|
||||
void ClusterContext::registerEvent(const std::string& event, EventCallback cb) {
|
||||
void NodeContext::registerEvent(const std::string& event, EventCallback cb) {
|
||||
eventRegistry[event].push_back(cb);
|
||||
}
|
||||
|
||||
void ClusterContext::triggerEvent(const std::string& event, void* data) {
|
||||
void NodeContext::triggerEvent(const std::string& event, void* data) {
|
||||
for (auto& cb : eventRegistry[event]) {
|
||||
cb(data);
|
||||
}
|
||||
@@ -7,10 +7,10 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class ClusterContext {
|
||||
class NodeContext {
|
||||
public:
|
||||
ClusterContext();
|
||||
~ClusterContext();
|
||||
NodeContext();
|
||||
~NodeContext();
|
||||
Scheduler* scheduler;
|
||||
WiFiUDP* udp;
|
||||
String hostname;
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "RestApiServer.h"
|
||||
|
||||
RestApiServer::RestApiServer(ClusterContext& ctx, uint16_t port) : server(port), ctx(ctx) {}
|
||||
RestApiServer::RestApiServer(NodeContext& ctx, uint16_t port) : server(port), ctx(ctx) {}
|
||||
|
||||
void RestApiServer::addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler) {
|
||||
serviceRegistry.push_back(std::make_tuple(uri, method));
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include "ClusterContext.h"
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
|
||||
#define DEBUG_UPDATER 1
|
||||
@@ -17,14 +17,14 @@ using namespace std::placeholders;
|
||||
|
||||
class RestApiServer {
|
||||
public:
|
||||
RestApiServer(ClusterContext& ctx, uint16_t port = 80);
|
||||
RestApiServer(NodeContext& ctx, 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;
|
||||
ClusterContext& ctx;
|
||||
NodeContext& ctx;
|
||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||
void getClusterMembersJson(AsyncWebServerRequest *request);
|
||||
void methodToStr(const std::tuple<String, int> &endpoint, ArduinoJson::V742PB22::JsonObject &apiObj);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <Arduino.h>
|
||||
#include "Globals.h"
|
||||
#include "ClusterContext.h"
|
||||
#include "NodeContext.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "ClusterManager.h"
|
||||
#include "RestApiServer.h"
|
||||
|
||||
ClusterContext ctx;
|
||||
NodeContext ctx;
|
||||
NetworkManager network(ctx);
|
||||
ClusterManager cluster(ctx);
|
||||
RestApiServer apiServer(ctx);
|
||||
|
||||
Reference in New Issue
Block a user