Skip to content
Snippets Groups Projects
Commit 97cff91e authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

added utility for memories to handle empty memory names

parent ef56d160
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,23 @@ namespace armarx::armem::server::ltm::disk
{
}
void Memory::setMemoryID(const MemoryID &id)
{
Base::setMemoryID(id);
escapedMemoryName = EscapeSegmentName(id.memoryName);
}
void Memory::setMemoryID(const MemoryID& id, const std::string& componentNameFallback)
{
MemoryID _id = id;
if (id.memoryName.empty())
{
ARMARX_WARNING << "ATTENTION: A memory id passed to some LTM is empty. Either you used the wrong setter (always use setMemoryName(..) before onInitComponent()) or you emptied the scenario parameter. Using a the component name as fallback.";
_id.memoryName = componentNameFallback;
}
setMemoryID(_id);
}
void Memory::init()
{
Base::init();
......@@ -47,12 +64,6 @@ namespace armarx::armem::server::ltm::disk
maxExportIndex = i;
}
}
void Memory::setMemoryID(const MemoryID& id)
{
Base::setMemoryID(id);
escapedMemoryName = EscapeSegmentName(id.memoryName);
}
bool Memory::forEachCoreSegment(std::function<void(CoreSegment&)>&& func) const
{
......
......@@ -25,6 +25,7 @@ namespace armarx::armem::server::ltm::disk
void init() final;
void setMemoryID(const MemoryID& id) final;
void setMemoryID(const MemoryID& id, const std::string& fallback);
void configure(const nlohmann::json& config) final;
......
......@@ -28,7 +28,16 @@ namespace armarx::armem::server::plugins
void Plugin::postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties)
{
const std::string prefix = "mem.";
if (not workingMemory.name().empty() and not properties->hasDefinition(prefix + "MemoryName"))
// set Memory name if not already set
if (workingMemory.name().empty())
{
Component& parent = this->parent<Component>();
workingMemory.name() = parent.getName();
}
// also add scenario param to overwrite the chosen name
if (not properties->hasDefinition(prefix + "MemoryName"))
{
properties->optional(workingMemory.name(), prefix + "MemoryName", "Name of this memory server.");
}
......@@ -43,15 +52,18 @@ namespace armarx::armem::server::plugins
ARMARX_TRACE;
memoryTopicName = client::util::MemoryListener::MakeMemoryTopicName(MemoryID(workingMemory.name()));
parent().offeringTopic(memoryTopicName);
ARMARX_TRACE;
longtermMemory.setMemoryID(workingMemory.id());
longtermMemory.init();
}
void Plugin::postOnInitComponent()
{
Component& parent = this->parent<Component>();
// activate LTM
ARMARX_TRACE;
longtermMemory.setMemoryID(workingMemory.id(), parent.getName());
longtermMemory.init();
initialized = true;
}
......
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