diff --git a/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp b/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp index faa482e3da7616bc0cbe37cf0810390fd062ede0..05077d0fc7ca3a5b997ce53f03536cac5a8a8296 100644 --- a/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp +++ b/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp @@ -1,5 +1,20 @@ #include "CyanStripe.hpp" +// C++ system level +// #include <cstring> // memset, strncmp +// #include <cstdlib> // TODO: is this for memcpy? +// #include <functional> + +// ESP32 specific +#include "esp_log.h" + +// project specific +#include <Types.hpp> +#include "SiliconTorch/NVSExplorer.hpp" + +// qthing stuff +// #include <qthing> + @@ -25,3 +40,30 @@ + + + + +namespace SiliconTorch { + + namespace Service { + + void CyanStripe::init() { + setName("CyanStripe"); + setNameSpace("CyanStripe"); // TODO: "FxCyanF" + } + + void CyanStripe::start() { + ESP_LOGW(getName().c_str(), "Starting service[ %s ] with order[ %d ] *WHOOP* *WHOOP*", getName().c_str(), getStartOrder()); + } + + void CyanStripe::stop() { + ESP_LOGW(getName().c_str(), "Stopping service[ %s ] *sad service noises*", getName().c_str()); + } + + + + } +} + + diff --git a/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp b/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp index 1437ddc325a9215aec56ada11641680223eca287..b2969acbc3bfc1729a7aa8bb697afba42165f020 100644 --- a/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp +++ b/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp @@ -1,9 +1,42 @@ #pragma once +// C++ system level +// #include <cstring> // memset, strncmp +// #include <cstdlib> // TODO: is this for memcpy? +// #include <functional> +// ESP32 specific +#include "esp_log.h" -// TODO: implement! +// project specific +#include <Types.hpp> +#include "Service.hpp" +// qthing stuff +// #include <qthing> +namespace SiliconTorch { + namespace Service { + + class CyanStripe : public ServiceManager::Service { + + public: + + + void init(); + + void start(); + void stop(); + + + + + private: + + + }; + + } +} diff --git a/CLC-qthing/SiliconTorch/Service/FxPublish.cpp b/CLC-qthing/SiliconTorch/Service/FxPublish.cpp index dfcf126329258086b767c1c521645aaf1b76b4e5..1cb11070e18e93ece05df228839e1d72501b7400 100644 --- a/CLC-qthing/SiliconTorch/Service/FxPublish.cpp +++ b/CLC-qthing/SiliconTorch/Service/FxPublish.cpp @@ -1,5 +1,20 @@ #include "FxPublish.hpp" +// C++ system level +// #include <cstring> // memset, strncmp +// #include <cstdlib> // TODO: is this for memcpy? +// #include <functional> + +// ESP32 specific +#include "esp_log.h" + +// project specific +#include <Types.hpp> +#include "SiliconTorch/NVSExplorer.hpp" + +// qthing stuff +// #include <qthing> + @@ -15,3 +30,25 @@ + +namespace SiliconTorch { + + namespace Service { + + void FxPublish::init() { + setName("FxPublish"); + setNameSpace("FxPublish"); + } + + void FxPublish::start() { + ESP_LOGW(getName().c_str(), "Starting service[ %s ] with order[ %d ] *WHOOP* *WHOOP*", getName().c_str(), getStartOrder()); + } + + void FxPublish::stop() { + ESP_LOGW(getName().c_str(), "Stopping service[ %s ] *sad service noises*", getName().c_str()); + } + + + + } +} diff --git a/CLC-qthing/SiliconTorch/Service/FxPublish.hpp b/CLC-qthing/SiliconTorch/Service/FxPublish.hpp index 1437ddc325a9215aec56ada11641680223eca287..d89286ca2d53ed41d928f1f28096474c34d92468 100644 --- a/CLC-qthing/SiliconTorch/Service/FxPublish.hpp +++ b/CLC-qthing/SiliconTorch/Service/FxPublish.hpp @@ -1,9 +1,42 @@ #pragma once +// C++ system level +// #include <cstring> // memset, strncmp +// #include <cstdlib> // TODO: is this for memcpy? +// #include <functional> +// ESP32 specific +#include "esp_log.h" -// TODO: implement! +// project specific +#include <Types.hpp> +#include "Service.hpp" +// qthing stuff +// #include <qthing> +namespace SiliconTorch { + namespace Service { + + class FxPublish : public ServiceManager::Service { + + public: + + + void init(); + + void start(); + void stop(); + + + + + private: + + + }; + + } +} diff --git a/CLC-qthing/SiliconTorch/Service/Service.cpp b/CLC-qthing/SiliconTorch/Service/Service.cpp index 6cc519df8b01b02315bada7321765a853e51d613..ea39bed5289f51b0d117e4d88f999f021e0396de 100644 --- a/CLC-qthing/SiliconTorch/Service/Service.cpp +++ b/CLC-qthing/SiliconTorch/Service/Service.cpp @@ -45,7 +45,7 @@ namespace SiliconTorch { nvsState = (NVSState)state; } - bool Service::isEnabled() { + bool Service::isEnabled() const { return nvsState == Enabled; } @@ -99,15 +99,15 @@ namespace SiliconTorch { } - const str& Service::getName() { + const str& Service::getName() const { return name; } - const str& Service::getNameSpace() { + const str& Service::getNameSpace() const { return nameSpace; } - u16 Service::getStartOrder() { + u16 Service::getStartOrder() const { return startOrder; } diff --git a/CLC-qthing/SiliconTorch/Service/Service.hpp b/CLC-qthing/SiliconTorch/Service/Service.hpp index ac67758e35b9b3b2276e79b8cad9057e35939eec..668c1942efd291334ff0e027668e6902c3877190 100644 --- a/CLC-qthing/SiliconTorch/Service/Service.hpp +++ b/CLC-qthing/SiliconTorch/Service/Service.hpp @@ -41,18 +41,18 @@ namespace SiliconTorch { virtual void start() = 0; virtual void stop() = 0; - const str& getName(); - const str& getNameSpace(); + const str& getName() const; + const str& getNameSpace() const; // virtual str name() = 0; // virtual str nameSpace() = 0; - u16 getStartOrder(); + u16 getStartOrder() const; // enabled services will be started in this order. higher = later // virtual u16 startOrder(); // defaults to 1337 - bool isEnabled(); + bool isEnabled() const; void setEnabled(bool enabled); protected: diff --git a/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp b/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp index a956ff280e795559451c0e8676676a2620f4983e..dc47dc37fe2b66949474633ef6e639f58ee529f3 100644 --- a/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp +++ b/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp @@ -1,6 +1,8 @@ #include "ServiceManager.hpp" // C++ system level +#include <vector> +#include <algorithm> // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? // #include <functional> @@ -31,19 +33,57 @@ namespace SiliconTorch { registerSiliconTorchServices(this); - // TODO: implement! + registrationLocked = true; + } + void ServiceManager::startEnabledServices() { + std::vector<Service*> services; + + for (const auto& [key, value] : serviceMap) + services.push_back(value); + + std::sort(services.begin(), services.end(), [](const Service* x, const Service* y) { + return x->getStartOrder() < y->getStartOrder(); + }); + + for (const auto& service : services) + if (service->isEnabled()) service->start(); + } - void ServiceManager::registerService(Service* s) { - s->init(); - s->postInit(); - services[s->getName()] = s; + void ServiceManager::setServiceEnabled(const str& name, bool enabled) { + if (serviceMap.count(name) > 0) { + serviceMap.at(name)->setEnabled(enabled); + } else { + // Service not found + // TODO: logging…? + } + } + + bool ServiceManager::getServiceEnabled(const str& name) { + if (serviceMap.count(name) > 0) { + return serviceMap.at(name)->isEnabled(); + } else { + // Service not found + // TODO: logging…? + return false; + } + } + + + void ServiceManager::registerService(Service* s) { + if (!registrationLocked) { + s->init(); + s->postInit(); - ESP_LOGI(TAG, "Registered service[ %s ]", s->getName().c_str()); + serviceMap[s->getName()] = s; + ESP_LOGI(TAG, "Registered service[ %s ]", s->getName().c_str()); + } else { + ESP_LOGW(TAG, "Service registration is locked"); + } } diff --git a/CLC-qthing/SiliconTorch/Service/ServiceManager.hpp b/CLC-qthing/SiliconTorch/Service/ServiceManager.hpp index 7407949d67784f5595eeb479d1c5d580e8b434af..54cdeebcdc8693ea56fbf822a0368042a0f90fc5 100644 --- a/CLC-qthing/SiliconTorch/Service/ServiceManager.hpp +++ b/CLC-qthing/SiliconTorch/Service/ServiceManager.hpp @@ -32,12 +32,18 @@ namespace SiliconTorch { ServiceManager(); + void startEnabledServices(); + + void setServiceEnabled(const str& name, bool enabled); + bool getServiceEnabled(const str& name); + + void registerService(Service* s); private: bool registrationLocked = false; - ServiceMap services; + ServiceMap serviceMap; }; diff --git a/CLC-qthing/SiliconTorch/Service/__services__.cpp b/CLC-qthing/SiliconTorch/Service/__services__.cpp index 3141a1fe8417241e7e06c7a3fa41c470c33d4d43..f11bdcf0a7a7f17d0746dc3a0fab403b5c9ee99d 100644 --- a/CLC-qthing/SiliconTorch/Service/__services__.cpp +++ b/CLC-qthing/SiliconTorch/Service/__services__.cpp @@ -1,23 +1,9 @@ #include "ServiceManager.hpp" -// C++ system level -// #include <cstring> // memset, strncmp -// #include <cstdlib> // TODO: is this for memcpy? -// #include <functional> - -// ESP32 specific -// #include "esp_log.h" - -// project specific +// our services #include "FxCyanF.hpp" -// #include <Types.hpp> -// #include "SiliconTorch/NVSExplorer.hpp" - -// qthing stuff -// #include <qthing> - - -// const char* TAG = "ServiceManager"; +#include "FxPublish.hpp" +#include "CyanStripe.hpp" namespace SiliconTorch { @@ -28,6 +14,8 @@ namespace SiliconTorch { void registerSiliconTorchServices(ServiceManager* mgr) { mgr->registerService(new SiliconTorch::Service::FxCyanF()); + mgr->registerService(new SiliconTorch::Service::FxPublish()); + mgr->registerService(new SiliconTorch::Service::CyanStripe()); }