feat: services (#2)
This commit is contained in:
@@ -10,52 +10,33 @@
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
#include "ApiTypes.h"
|
||||
|
||||
class Service; // Forward declaration
|
||||
|
||||
class ApiServer {
|
||||
public:
|
||||
ApiServer(NodeContext& ctx, TaskManager& taskMgr, uint16_t port = 80);
|
||||
void begin();
|
||||
void addService(Service& service);
|
||||
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);
|
||||
|
||||
// Minimal capability spec types and registration overloads
|
||||
struct ParamSpec {
|
||||
String name;
|
||||
bool required;
|
||||
String location; // "query" | "body" | "path" | "header"
|
||||
String type; // e.g. "string", "number", "boolean"
|
||||
std::vector<String> values; // optional allowed values
|
||||
};
|
||||
struct EndpointCapability {
|
||||
String uri;
|
||||
int method;
|
||||
std::vector<ParamSpec> params;
|
||||
};
|
||||
void addEndpoint(const String& uri, int method, std::function<void(AsyncWebServerRequest*)> requestHandler,
|
||||
const std::vector<ParamSpec>& params);
|
||||
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,
|
||||
const std::vector<ParamSpec>& params);
|
||||
|
||||
static const char* methodToStr(int method);
|
||||
|
||||
private:
|
||||
AsyncWebServer server;
|
||||
NodeContext& ctx;
|
||||
TaskManager& taskManager;
|
||||
std::vector<std::reference_wrapper<Service>> services;
|
||||
std::vector<std::tuple<String, int>> serviceRegistry;
|
||||
std::vector<EndpointCapability> capabilityRegistry;
|
||||
void onClusterMembersRequest(AsyncWebServerRequest *request);
|
||||
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);
|
||||
void onRestartRequest(AsyncWebServerRequest *request);
|
||||
|
||||
// Task management endpoints
|
||||
void onTaskStatusRequest(AsyncWebServerRequest *request);
|
||||
void onTaskControlRequest(AsyncWebServerRequest *request);
|
||||
|
||||
// Capabilities endpoint
|
||||
void onCapabilitiesRequest(AsyncWebServerRequest *request);
|
||||
|
||||
// Internal helpers
|
||||
void registerServiceForLocalNode(const String& uri, int method);
|
||||
|
||||
Reference in New Issue
Block a user