From 7d6df3654518fea61792c85a17c8aec5a1539c9c Mon Sep 17 00:00:00 2001
From: Jochen Vothknecht <jochen3120@gmail.com>
Date: Tue, 28 Jun 2022 09:03:21 +0200
Subject: [PATCH] ST: Add fancy name rendering stuff

---
 CLC-qthing/SiliconTorch/Service/Service.cpp   | 41 +++++++++++++++++++
 CLC-qthing/SiliconTorch/Service/Service.hpp   |  8 ++++
 .../SiliconTorch/Service/ServiceManager.cpp   | 18 ++++----
 3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/CLC-qthing/SiliconTorch/Service/Service.cpp b/CLC-qthing/SiliconTorch/Service/Service.cpp
index ee68ad5..0fd0ac0 100644
--- a/CLC-qthing/SiliconTorch/Service/Service.cpp
+++ b/CLC-qthing/SiliconTorch/Service/Service.cpp
@@ -100,8 +100,17 @@ namespace SiliconTorch {
     }
 
 
+    void Service::setIcon(const str& icon) {
+      if (!attrsLocked) {
+        this->icon = icon;
+      } else {
+        // TODO: report error somehow?
+      }
+    }
+
     void Service::setName(const str& name) {
       if (!attrsLocked) {
+        // TODO: length check!!  (reason: NVS)
         this->name = name;
       } else {
         // TODO: report error somehow?
@@ -110,12 +119,22 @@ namespace SiliconTorch {
 
     void Service::setNameSpace(const str& nameSpace) {
       if (!attrsLocked) {
+        // TODO: length check!!  (reason: NVS)
         this->nameSpace = nameSpace;
       } else {
         // TODO: report error somehow?
       }
     }
 
+    void Service::setDisplayName(const str& displayName) {
+      if (!attrsLocked) {
+        this->displayName = displayName;
+      } else {
+        // TODO: report error somehow?
+      }
+    }
+
+
 
     void Service::addWantedService(const str& name) {
       if (!attrsLocked) {
@@ -162,6 +181,10 @@ namespace SiliconTorch {
     }
 
 
+    const str& Service::getIcon() const {
+      return icon;
+    }
+
     const str& Service::getName() const {
       return name;
     }
@@ -170,5 +193,23 @@ namespace SiliconTorch {
       return nameSpace;
     }
 
+    const str& Service::getDisplayName() const {
+      if (displayName.length() > 0) return displayName;
+      else                          return name;
+    }
+
+    str Service::getFancyName() const {
+
+      str out = getDisplayName();
+
+      if (icon.length() > 0) {
+        out += str("[");
+        out += icon;
+        out += str("]");
+      }
+
+      return out;
+    }
+
   }
 }
diff --git a/CLC-qthing/SiliconTorch/Service/Service.hpp b/CLC-qthing/SiliconTorch/Service/Service.hpp
index f5bdd54..3d82f60 100644
--- a/CLC-qthing/SiliconTorch/Service/Service.hpp
+++ b/CLC-qthing/SiliconTorch/Service/Service.hpp
@@ -48,8 +48,12 @@ namespace SiliconTorch {
         // ╚════════════════════════════╝
 
 
+        const str& getIcon() const;
         const str& getName() const;
         const str& getNameSpace() const;
+        const str& getDisplayName() const;
+
+        str getFancyName() const;  // <== Use this for logging!!
 
         bool isEnabled() const;
         void setEnabled(bool enabled);
@@ -65,8 +69,10 @@ namespace SiliconTorch {
 
       protected:
 
+        void setIcon(const str& icon);
         void setName(const str& name);
         void setNameSpace(const str& nameSpace);
+        void setDisplayName(const str& displayName);
 
         // Service will be started after the wanted one (if wanted is disabled this limitation is waived)    // TODO: (waived / raised / lowered?)
         void addWantedService(const str& name);
@@ -81,8 +87,10 @@ namespace SiliconTorch {
         bool hasErrors = false;  // Set if an error is detected. Prevents the service from being started
 
         bool attrsLocked = false;
+        str icon = "";
         str name = "";
         str nameSpace = "";
+        str displayName = "";
 
         std::set<std::string>* wantedNames   = new std::set<std::string>();
         std::set<std::string>* requiredNames = new std::set<std::string>();
diff --git a/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp b/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp
index 7235a48..02a86aa 100644
--- a/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp
+++ b/CLC-qthing/SiliconTorch/Service/ServiceManager.cpp
@@ -39,14 +39,14 @@ namespace SiliconTorch {
       registrationLocked = true;
 
 
-      for (auto& [ignored, service] : serviceMap)
+      for (auto& [name, service] : serviceMap)
         service->postInit();
 
       auto sers = startAlgo();
 
       ESP_LOGI(TAG, "=====   Services starting order   =====");
 
-      for (const auto& s : sers) ESP_LOGI(TAG, "Service: %s", s->getName().c_str());
+      for (const auto& s : sers) ESP_LOGI(TAG, "Service: %s", s->getFancyName().c_str());
 
       ESP_LOGI(TAG, "=======================================");
 
@@ -70,7 +70,7 @@ namespace SiliconTorch {
       std::map<Service*, ServiceSet> services;
 
       // prepare our data structures
-      for (const auto& [name, service] : serviceMap) {
+      for (const auto& [_, service] : serviceMap) {
 
         if (service->isEnabled()) {
 
@@ -103,11 +103,11 @@ namespace SiliconTorch {
       for (const auto& [service, deps] : services) {
 
         std::set<std::string> depsnames;
-        for (const auto& d : deps) depsnames.insert(d->getName());
+        for (const auto& d : deps) depsnames.insert(d->getFancyName());
 
         std::string sdeps = SpiderLib::Util::join(depsnames, "  ");
 
-        ESP_LOGI(TAG, "Service[ %s ] has deps{  %s  }", service->getName().c_str(), sdeps.c_str());
+        ESP_LOGI(TAG, "Service[ %s ] has deps{  %s  }", service->getFancyName().c_str(), sdeps.c_str());
       }
 
       ESP_LOGI(TAG, "=======================================");
@@ -136,7 +136,7 @@ namespace SiliconTorch {
 
 
         for (const auto& starting : startOrder)
-          for (auto& [ignored, deps] : services)
+          for (auto& [_, deps] : services)
             deps.erase(starting);
 
 
@@ -228,9 +228,9 @@ namespace SiliconTorch {
       std::vector<Service*> services = getServicesInStartOrder();
 
       for (const auto& service : services) {
-        u8 nameSize = service->getName().length();
+        u8 nameSize = service->getFancyName().length();
         ESP_LOGI(TAG, "│ %s %s│ % 5d %s│%s%s%s│",
-          service->getName().c_str(),
+          service->getFancyName().c_str(),
           strmul(" ", nameColSize - 2 - nameSize).c_str(),
           1337,                                                   // service->getStartOrder(),
           strmul(" ", startOrderColSize - 2 - 5).c_str(),
@@ -291,7 +291,7 @@ namespace SiliconTorch {
 
         serviceMap[s->getName()] = s;
 
-        ESP_LOGI(TAG, "Registered service[ %s ]", s->getName().c_str());
+        ESP_LOGI(TAG, "Registered service[ %s ]", s->getFancyName().c_str());
       } else {
         ESP_LOGW(TAG, "Service registration is locked");
       }
-- 
GitLab