From 2c9f4ac1451e62509a53c22891fe8dc7a4a7aaa9 Mon Sep 17 00:00:00 2001
From: Jochen Vothknecht <jochen3120@gmail.com>
Date: Wed, 1 Jun 2022 08:58:45 +0200
Subject: [PATCH] Remove getLongString()-API because somehow it won't work and
 is mostly useless

---
 CLC-qthing/SiliconTorch/NVSExplorer.cpp | 57 ++++++-------------------
 CLC-qthing/SiliconTorch/NVSExplorer.hpp |  2 +-
 2 files changed, 14 insertions(+), 45 deletions(-)

diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.cpp b/CLC-qthing/SiliconTorch/NVSExplorer.cpp
index d531752..9609e9e 100644
--- a/CLC-qthing/SiliconTorch/NVSExplorer.cpp
+++ b/CLC-qthing/SiliconTorch/NVSExplorer.cpp
@@ -571,7 +571,6 @@ namespace SiliconTorch {
       } ));
 
 
-
       qthing::add_binary_message_callback(requestTopic("get_str/+/+"), wrapMessageHandler(
         [&](std::vector<std::string>& topic, qthing::multipart_message_t msg) {
 
@@ -590,37 +589,6 @@ namespace SiliconTorch {
       } ));
 
 
-
-      // #######################################
-      // ###  TODO: remove after testing!!   ###
-      // #######################################
-
-      qthing::add_binary_message_callback(requestTopic("get_LONGstr/+/+"), wrapMessageHandler(
-        [&](std::vector<std::string>& topic, qthing::multipart_message_t msg) {
-
-        size_t testValue = 1337000;  // way too big for NVS
-
-        if ( getStringLength(topic[1], topic[2], testValue) < testValue ) {  // key exists and is of type string
-
-          char buffer[256];
-          std::memset(&buffer[0], 0x00, 256);
-
-          getLongString(topic[1], topic[2], &buffer[0]);
-
-          std::string value(&buffer[0]);
-          qthing::publish_message(responseTopic("get_LONGstr", topic[1], topic[2]), value);
-        } else {
-          // publish error…?
-
-          ESP_LOGW(TAG, "Retrieving str[] from  namespace[ %s ]  key[ %s ]  FAILED", topic[1].c_str(), topic[2].c_str());
-        }
-      } ));
-
-      // #######################################
-      // #######################################
-
-
-
       qthing::add_binary_message_callback(requestTopic("set_str/+/+"), wrapMessageHandler(
         [&](std::vector<std::string>& topic, qthing::multipart_message_t msg) {
 
@@ -957,6 +925,7 @@ namespace SiliconTorch {
           std::memset(&buffer[0], 0x00, size + 1);
 
           nvs_get_str(nvs, key.c_str(), &buffer[0], &size);
+
           nvs_close(nvs);
 
           std::string out(&buffer[0]);
@@ -968,18 +937,18 @@ namespace SiliconTorch {
     }
 
 
-    size_t NVSExplorer::getLongString(const std::string& nameSpace, const std::string& key, char* const buffer) {
-
-      size_t size = 0;
-
-      nvs_handle_t nvs;
-      if ( nvs_open(nameSpace.c_str(), NVS_READONLY, &nvs) == ESP_OK ) {
-        nvs_get_str(nvs, key.c_str(), buffer, &size);
-        nvs_close(nvs);
-      }
-
-      return size;
-    }
+//     size_t NVSExplorer::getLongString(const std::string& nameSpace, const std::string& key, char* const buffer) {
+// 
+//       size_t size = 0;
+// 
+//       nvs_handle_t nvs;
+//       if ( nvs_open(nameSpace.c_str(), NVS_READONLY, &nvs) == ESP_OK ) {
+//            nvs_get_str(nvs, key.c_str(), buffer, &size);
+//            nvs_close(nvs);
+//       }
+// 
+//       return size;
+//     }
 
 
     bool NVSExplorer::setString(const std::string& nameSpace, const std::string& key, const std::string& value) {
diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.hpp b/CLC-qthing/SiliconTorch/NVSExplorer.hpp
index 87a7b2a..8728eb3 100644
--- a/CLC-qthing/SiliconTorch/NVSExplorer.hpp
+++ b/CLC-qthing/SiliconTorch/NVSExplorer.hpp
@@ -83,7 +83,7 @@ namespace SiliconTorch {
 
         size_t getStringLength(const std::string& nameSpace, const std::string& key, size_t defaultValue = 0);
         std::string getString(const std::string& nameSpace, const std::string& key, const std::string& defaultValue = "");
-        size_t getLongString(const std::string& nameSpace, const std::string& key, char* const buffer);
+        // size_t getLongString(const std::string& nameSpace, const std::string& key, char* const buffer);
 
         bool setString(const std::string& nameSpace, const std::string& key, const std::string& value);
 
-- 
GitLab