diff --git a/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp b/source/RobotAPI/libraries/armem/client/util/SimpleWriterBase.cpp index 3d8907a348bad7051e3fc88239f3b816899acd5e..c46755e3d9a3c94f6e8634b15884604db71226b9 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 895376b0a2f3ff1f30fdd070c2e50c62b9aa2968..4950280b340f15c293fdd84d9c9fe25e7b19bf9d 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; };