Skip to content
Snippets Groups Projects
Commit 0893f314 authored by fxk8y's avatar fxk8y :spider:
Browse files

Adding a few services

parent 8875dfd2
No related branches found
No related tags found
No related merge requests found
#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());
}
}
}
#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:
};
}
}
#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());
}
}
}
#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:
};
}
}
......@@ -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;
}
......
......@@ -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:
......
#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");
}
}
......
......@@ -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;
};
......
#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());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment