refactor: reorganize project structure with modern C++ namespace organization

- Restructure include/ and src/ directories with logical grouping
- Move core components to spore/core/ (NodeContext, NetworkManager, TaskManager, ClusterManager, ApiServer)
- Move services to spore/services/ (NodeService, NetworkService, ClusterService, TaskService)
- Move types to spore/types/ (NodeInfo, ApiTypes, Config)
- Move internal components to spore/internal/ (Globals)
- Update all #include statements to use new namespace paths
- Update platformio.ini build filters for all environments
- Update all example files to use new include paths
- Maintain backward compatibility for public API
- Improve code organization, maintainability, and scalability

This reorganization follows modern C++ project structure patterns and provides
clear separation between public API, internal implementation, and utilities.
All examples compile successfully with the new structure.
This commit is contained in:
2025-09-13 21:30:07 +02:00
parent bf17684dc6
commit 554c6ff38d
38 changed files with 78 additions and 72 deletions

View File

@@ -0,0 +1,48 @@
#pragma once
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESPAsyncWebServer.h>
#include <Updater.h>
#include <functional>
#include <vector>
#include <tuple>
#include "spore/core/NodeContext.h"
#include "spore/types/NodeInfo.h"
#include "spore/core/TaskManager.h"
#include "spore/types/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);
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);
// 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<EndpointInfo> endpoints; // Single source of truth for endpoints
// Internal helpers
void registerEndpoint(const String& uri, int method,
const std::vector<ParamSpec>& params,
const String& serviceName);
};