refactor: simplify endpoint and capabilities
This commit is contained in:
@@ -30,14 +30,19 @@ public:
|
||||
const std::vector<ParamSpec>& params);
|
||||
|
||||
static const char* methodToStr(int method);
|
||||
|
||||
// Access to endpoints for endpoints endpoint
|
||||
const std::vector<EndpointInfo>& getEndpoints() const { return endpoints; }
|
||||
|
||||
private:
|
||||
AsyncWebServer server;
|
||||
NodeContext& ctx;
|
||||
TaskManager& taskManager;
|
||||
std::vector<std::reference_wrapper<Service>> services;
|
||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||
std::vector<EndpointInfo> endpoints; // Single source of truth for endpoints
|
||||
|
||||
// Internal helpers
|
||||
void registerServiceForLocalNode(const String& uri, int method);
|
||||
void registerEndpoint(const String& uri, int method,
|
||||
const std::vector<ParamSpec>& params,
|
||||
const String& serviceName);
|
||||
};
|
||||
|
||||
@@ -16,3 +16,22 @@ struct EndpointCapability {
|
||||
int method;
|
||||
std::vector<ParamSpec> params;
|
||||
};
|
||||
|
||||
struct EndpointInfo {
|
||||
String uri;
|
||||
int method;
|
||||
std::vector<ParamSpec> params;
|
||||
String serviceName; // Name of the service that registered this endpoint
|
||||
bool isLocal; // Whether this endpoint is on the local node
|
||||
|
||||
// Constructor for individual parameters
|
||||
EndpointInfo(const String& u, int m, const std::vector<ParamSpec>& p, const String& service, bool local)
|
||||
: uri(u), method(m), params(p), serviceName(service), isLocal(local) {}
|
||||
|
||||
// Constructor for easy conversion from EndpointCapability
|
||||
EndpointInfo(const EndpointCapability& cap, const String& service = "", bool local = true)
|
||||
: uri(cap.uri), method(cap.method), params(cap.params), serviceName(service), isLocal(local) {}
|
||||
|
||||
// Default constructor
|
||||
EndpointInfo() : isLocal(true) {}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,6 @@ public:
|
||||
NodeInfo self;
|
||||
std::map<String, NodeInfo>* memberList;
|
||||
Config config;
|
||||
std::vector<EndpointCapability> capabilities;
|
||||
|
||||
using EventCallback = std::function<void(void*)>;
|
||||
std::map<std::string, std::vector<EventCallback>> eventRegistry;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
#include "ApiTypes.h"
|
||||
|
||||
struct NodeInfo {
|
||||
String hostname;
|
||||
@@ -18,7 +19,7 @@ struct NodeInfo {
|
||||
uint32_t flashChipSize = 0;
|
||||
} resources;
|
||||
unsigned long latency = 0; // ms since lastSeen
|
||||
std::vector<std::tuple<String, int>> apiEndpoints; // List of registered endpoints
|
||||
std::vector<EndpointInfo> endpoints; // List of registered endpoints
|
||||
std::map<String, String> labels; // Arbitrary node labels (key -> value)
|
||||
};
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
|
||||
class NodeService : public Service {
|
||||
public:
|
||||
NodeService(NodeContext& ctx);
|
||||
NodeService(NodeContext& ctx, ApiServer& apiServer);
|
||||
void registerEndpoints(ApiServer& api) override;
|
||||
const char* getName() const override { return "Node"; }
|
||||
|
||||
private:
|
||||
NodeContext& ctx;
|
||||
ApiServer& apiServer;
|
||||
|
||||
void handleStatusRequest(AsyncWebServerRequest* request);
|
||||
void handleUpdateRequest(AsyncWebServerRequest* request);
|
||||
void handleUpdateUpload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final);
|
||||
void handleRestartRequest(AsyncWebServerRequest* request);
|
||||
void handleCapabilitiesRequest(AsyncWebServerRequest* request);
|
||||
void handleEndpointsRequest(AsyncWebServerRequest* request);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user