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

ST: Verifying startAlgo() :smirk:

parent 88ac2fc5
No related branches found
No related tags found
No related merge requests found
......@@ -42,14 +42,37 @@ namespace SiliconTorch {
attrsLocked = true;
for (const auto& name : *wantedNames) {
Service* service = otherByName(name);
if (service != NULL) wantedServices.insert(service);
}
for (const auto& name : *requiredNames) {
Service* service = otherByName(name);
if (service != NULL) {
requiredServices.insert(service);
} else {
hasErrors = true; // service is errorneous because of unsatisfied dependency
ESP_LOGW(TAG, "Service[ %s ] is errorneous because of unsatisfied dependency[ %s ]", getName().c_str(), name.c_str());
}
}
delete wantedNames;
delete requiredNames;
wantedNames = NULL;
requiredNames = NULL;
u8 state = 0; // disabled -> 0 enabled -> 1
state = SiliconTorch::NVSExplorer::NVSExplorer::instance().getUnsignedInt(getNameSpace(), NVSStateKey, state);
if (state >= (u8)Invalid) state = (u8)Disabled;
nvsState = (NVSState)state;
ESP_LOGW(TAG, "Service[ %s ] may not start due to errorneous initialization", getName().c_str());
}
bool Service::isEnabled() const {
......@@ -96,10 +119,7 @@ namespace SiliconTorch {
void Service::addWantedService(const str& name) {
if (!attrsLocked) {
Service* service = otherByName(name);
if (service != NULL)
wantedServices.insert(service);
wantedNames->insert(name);
} else {
// TODO: report error somehow?
}
......@@ -107,14 +127,7 @@ namespace SiliconTorch {
void Service::addRequiredService(const str& name) {
if (!attrsLocked) {
Service* service = otherByName(name);
if (service != NULL) {
requiredServices.insert(service);
} else {
hasErrors = true;
ESP_LOGW(TAG, "Service[ %s ] requires unknown otherService[ %s ]", getName().c_str(), name.c_str());
}
requiredNames->insert(name);
} else {
// TODO: report error somehow?
}
......
......@@ -84,6 +84,9 @@ namespace SiliconTorch {
str name = "";
str nameSpace = "";
std::set<std::string>* wantedNames = new std::set<std::string>();
std::set<std::string>* requiredNames = new std::set<std::string>();
ServiceSet wantedServices;
ServiceSet requiredServices;
......
......@@ -39,6 +39,9 @@ namespace SiliconTorch {
registrationLocked = true;
for (auto& [ignored, service] : serviceMap)
service->postInit();
auto sers = startAlgo();
ESP_LOGI(TAG, "===== Services starting order =====");
......@@ -71,7 +74,7 @@ namespace SiliconTorch {
if (service->isEnabled()) {
bool reqsOK = true; // TODO: requirements_"zufriedengestellt" …? (naming)
bool reqsSatisfied = true;
ServiceSet deps;
ServiceSet wanted = service->getWantedServices();
......@@ -84,9 +87,9 @@ namespace SiliconTorch {
// copy required services
for (const auto& sr : required)
if (sr->isEnabled()) deps.insert(sr);
else reqsOK = false;
else reqsSatisfied = false;
if (reqsOK)
if (reqsSatisfied)
services[service] = deps;
}
......@@ -282,8 +285,9 @@ namespace SiliconTorch {
return byName(name);
};
s->preInit(serviceLookup);
s->init();
s->postInit();//serviceLookup);
// only do init() here to avoid name-lookup cycles in postInit() !
serviceMap[s->getName()] = s;
......
#include "TestServices.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>
namespace SiliconTorch {
namespace Service {
void Cycle0::init() {
addRequiredService("Cycle1");
setName("Cycle0");
setNameSpace("Cycle0");
}
void Cycle0::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void Cycle1::init() {
addRequiredService("Cycle0");
setName("Cycle1");
setNameSpace("Cycle1");
}
void Cycle1::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void AAA::init() {
setName("AAA");
setNameSpace("AAA");
}
void AAA::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void BBB::init() {
addRequiredService("AAA");
setName("BBB");
setNameSpace("BBB");
}
void BBB::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void CCC::init() {
addRequiredService("BBB");
setName("CCC");
setNameSpace("CCC");
}
void CCC::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void WantsAAA::init() {
addWantedService("AAA");
setName("WantsAAA");
setNameSpace("WantsAAA");
}
void WantsAAA::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void ABC::init() {
addRequiredService("AAA");
addRequiredService("BBB");
addRequiredService("CCC");
setName("ABC");
setNameSpace("ABC");
}
void ABC::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); }
void ABCD::init() {
addWantedService("AAA");
addRequiredService("BBB");
addRequiredService("CCC");
addRequiredService("ABC");
setName("ABCD");
setNameSpace("ABCD");
}
void ABCD::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", 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"
// project specific
#include <Types.hpp>
#include "Service.hpp"
// qthing stuff
// #include <qthing>
namespace SiliconTorch {
namespace Service {
class Cycle0 : public ServiceManager::Service {
public:
void init();
void start();
};
class Cycle1 : public ServiceManager::Service {
public:
void init();
void start();
};
class AAA : public ServiceManager::Service {
public:
void init();
void start();
};
class BBB : public ServiceManager::Service {
public:
void init();
void start();
};
class CCC : public ServiceManager::Service {
public:
void init();
void start();
};
class WantsAAA : public ServiceManager::Service {
public:
void init();
void start();
};
class ABC : public ServiceManager::Service {
public:
void init();
void start();
};
class ABCD : public ServiceManager::Service {
public:
void init();
void start();
};
}
}
......@@ -6,6 +6,8 @@
#include "CyanStripe.hpp"
#include "TestServices.hpp"
namespace SiliconTorch {
namespace ServiceManager {
......@@ -17,6 +19,17 @@ namespace SiliconTorch {
mgr->registerService(new SiliconTorch::Service::FxPublish());
mgr->registerService(new SiliconTorch::Service::CyanStripe());
mgr->registerService(new SiliconTorch::Service::ABC());
mgr->registerService(new SiliconTorch::Service::ABCD());
mgr->registerService(new SiliconTorch::Service::Cycle0());
mgr->registerService(new SiliconTorch::Service::Cycle1());
mgr->registerService(new SiliconTorch::Service::AAA());
mgr->registerService(new SiliconTorch::Service::BBB());
mgr->registerService(new SiliconTorch::Service::CCC());
mgr->registerService(new SiliconTorch::Service::WantsAAA());
}
......
......@@ -9,6 +9,7 @@
SiliconTorch::CyanBusInjector::CyanBusInjector* injector;
void device_main() {
qthing::Config cfg;
......@@ -21,6 +22,17 @@ void device_main() {
// #include <map>
// #include <string>
// std::map<int, std::string> x {
// { 42, "foo" },
// { 3, "bar" }
// };
// injector = new SiliconTorch::CyanBusInjector::CyanBusInjector(23, 34, 32, 33);
injector = new SiliconTorch::CyanBusInjector::CyanBusInjector_ProtoPCB();
......
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