feat: implement Spore framework class as main orchestration layer
- Add Spore class as unified interface for all core framework functionality - Implement setup() and begin() methods for flexible initialization pattern - Add service registration with addService() for both raw and smart pointers - Provide accessor methods for core components (getTaskManager, getContext, etc.) - Automatically include core services (Node, Network, Cluster, Task) - Update all examples to use simplified Spore framework approach - Fix circular dependency issues in include structure - Remove setHostname and setApiPort configuration methods - Add comprehensive documentation and usage examples The Spore class encapsulates all core functionality from the base example and provides a clean, unified API for the entire framework. Examples now use just spore.setup() -> add services -> spore.begin() -> spore.loop().
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include <IPAddress.h>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
51
include/Spore.h
Normal file
51
include/Spore.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
#include "NodeContext.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "ClusterManager.h"
|
||||
#include "ApiServer.h"
|
||||
#include "TaskManager.h"
|
||||
#include "services/Service.h"
|
||||
|
||||
class Spore {
|
||||
public:
|
||||
Spore();
|
||||
Spore(std::initializer_list<std::pair<String, String>> initialLabels);
|
||||
~Spore();
|
||||
|
||||
// Core lifecycle methods
|
||||
void setup();
|
||||
void begin();
|
||||
void loop();
|
||||
|
||||
// Service management
|
||||
void addService(std::shared_ptr<Service> service);
|
||||
void addService(Service* service);
|
||||
|
||||
// Access to core components
|
||||
NodeContext& getContext() { return ctx; }
|
||||
NetworkManager& getNetwork() { return network; }
|
||||
TaskManager& getTaskManager() { return taskManager; }
|
||||
ClusterManager& getCluster() { return cluster; }
|
||||
ApiServer& getApiServer() { return apiServer; }
|
||||
|
||||
|
||||
private:
|
||||
void initializeCore();
|
||||
void registerCoreServices();
|
||||
void startApiServer();
|
||||
|
||||
NodeContext ctx;
|
||||
NetworkManager network;
|
||||
TaskManager taskManager;
|
||||
ClusterManager cluster;
|
||||
ApiServer apiServer;
|
||||
|
||||
std::vector<std::shared_ptr<Service>> services;
|
||||
bool initialized;
|
||||
bool apiServerStarted;
|
||||
};
|
||||
Reference in New Issue
Block a user