From 7bb2566cc5531f20ee35c55a9c4cff710165fff3 Mon Sep 17 00:00:00 2001
From: Fabian Peller <fabian.peller-konrad@kit.edu>
Date: Sun, 26 Nov 2023 18:29:03 +0100
Subject: [PATCH] fix properties of simpleWriter if no
 registerPropertyDefinitions is used

---
 .../armem/client/util/SimpleWriterBase.cpp    | 29 ++++++++++++++-----
 .../armem/client/util/SimpleWriterBase.h      |  3 +-
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp b/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp
index 3d8907a34..c46755e3d 100644
--- a/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp
+++ b/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp
@@ -16,25 +16,28 @@ namespace armarx::armem::client::util
 
         const std::string prefix = propertyPrefix();
 
-        props = defaultProperties();
+        if (not props.has_value())
+        {
+            props = defaultProperties();
+        }
 
-        def->optional(props.memoryName, prefix + "Memory");
-        def->optional(props.coreSegmentName, prefix + "CoreSegment");
+        def->optional(props->memoryName, prefix + "Memory");
+        def->optional(props->coreSegmentName, prefix + "CoreSegment");
 
         // TODO(fabian.reister): this might also be part of the subclass
         //  if the provider name has to be derived from e.g. the component name
-        def->optional(props.providerName, prefix + "Provider", "Name of this provider");
+        def->optional(props->providerName, prefix + "Provider", "Name of this provider");
     }
 
     void
     SimpleWriterBase::connect(armarx::armem::client::MemoryNameSystem& mns)
     {
         // Wait for the memory to become available and add it as dependency.
-        ARMARX_IMPORTANT << "SimpleWriterBase: Waiting for memory '" << props.memoryName << "' ...";
+        ARMARX_IMPORTANT << "SimpleWriterBase: Waiting for memory '" << properties().memoryName << "' ...";
         try
         {
-            memoryWriterClient = mns.useWriter(MemoryID().withMemoryName(props.memoryName));
-            ARMARX_IMPORTANT << "SimpleWriterBase: Connected to memory '" << props.memoryName
+            memoryWriterClient = mns.useWriter(MemoryID().withMemoryName(properties().memoryName));
+            ARMARX_IMPORTANT << "SimpleWriterBase: Connected to memory '" << properties().memoryName
                              << "'";
         }
         catch (const armem::error::CouldNotResolveMemoryServer& e)
@@ -53,7 +56,17 @@ namespace armarx::armem::client::util
     const SimpleWriterBase::Properties&
     SimpleWriterBase::properties() const
     {
-        return props;
+        if (not props.has_value())
+        {
+            const_cast<std::optional<Properties>&>(props) = defaultProperties();
+        }
+        return props.value();
+    }
+
+    void
+    SimpleWriterBase::setProperties(const Properties& p)
+    {
+        props = p;
     }
 
 } // namespace armarx::armem::client::util
diff --git a/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.h b/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.h
index 895376b0a..4950280b3 100644
--- a/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.h
+++ b/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.h
@@ -54,6 +54,7 @@ namespace armarx::armem::client::util
         };
 
         const Properties& properties() const;
+        void setProperties(const Properties& p);
 
         virtual std::string propertyPrefix() const = 0;
         virtual Properties defaultProperties() const = 0;
@@ -62,7 +63,7 @@ namespace armarx::armem::client::util
 
 
     private:
-        Properties props;
+        std::optional<Properties> props;
 
         armem::client::Writer memoryWriterClient;
     };
-- 
GitLab