From 64542ab0ced336952f335e049300daa3fe58bd2c Mon Sep 17 00:00:00 2001 From: "fabian.peller-konrad@kit.edu" <fabian.peller-konrad@kit.edu> Date: Tue, 9 Feb 2021 10:51:19 +0100 Subject: [PATCH] Partially revert "ArMem helper functions and updates" (dont revert DebugMemory) This partially reverts commit e08aff4d433c0f0f4ab204dd4ab025c5174ae202. # Conflicts: # source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h # source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp --- .../ArMemExampleClient/ArMemExampleClient.cpp | 28 ++- .../ArMemExampleClient/ArMemExampleClient.h | 4 + .../ArMemExampleMemory/ArMemExampleMemory.cpp | 28 ++- .../ArMemExampleMemory/ArMemExampleMemory.h | 21 +- .../armem/client/ComponentPlugin.cpp | 80 +------ .../libraries/armem/client/ComponentPlugin.h | 32 +-- .../libraries/armem/client/Writer.cpp | 201 ++---------------- .../RobotAPI/libraries/armem/client/Writer.h | 34 +-- .../armem/server/ComponentPlugin.cpp | 48 +---- .../libraries/armem/server/ComponentPlugin.h | 25 +-- 10 files changed, 116 insertions(+), 385 deletions(-) diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp index 6fdd60959..07f8b22d7 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp @@ -44,6 +44,10 @@ namespace armarx armarx::PropertyDefinitionsPtr defs = new ArMemExampleClientPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); + + defs->optional(memoryName, "mem.MemoryName", "Name of the memory to use."); + // defs->component(memory, "ArMemExampleMemory"); + return defs; } @@ -63,8 +67,9 @@ namespace armarx createRemoteGuiTab(); RemoteGui_startRunningTask(); - waitForMemory(true); + waitForMemory(); ARMARX_CHECK_NOT_NULL(memory); + setMemory(memory); providerID = addProviderSegment(); entityID = providerID.withEntityName("example_entity"); @@ -229,6 +234,27 @@ namespace armarx } + void ArMemExampleClient::waitForMemory() + { + ARMARX_IMPORTANT << "Waiting for memory '" << memoryName << "'."; + armem::Time start = armem::Time::now(); + + armem::data::WaitForMemoryResult result = ClientPluginUserBase::waitForMemory(memoryName); + + if (result.success && result.proxy) + { + memory = result.proxy; + usingProxy(memory->ice_getIdentity().name); + + ARMARX_IMPORTANT << "Got memory '" << memoryName << "'" + << " (took " << armem::toStringMilliSeconds(armem::Time::now() - start) << ")."; + } + else + { + ARMARX_ERROR << result.errorMessage; + } + } + armem::MemoryID ArMemExampleClient::addProviderSegment() { armem::data::AddSegmentInput input; diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h index 0773a1f38..e216352dd 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h @@ -106,6 +106,7 @@ namespace armarx void example_entityUpdated(const armem::MemoryID& id); // Examples + void waitForMemory(); armem::MemoryID addProviderSegment(); armem::MemoryID commitSingleSnapshot(const armem::MemoryID& entityID); @@ -122,6 +123,9 @@ namespace armarx armarx::DebugObserverInterfacePrx debugObserver; + std::string memoryName = "Example"; + armem::server::MemoryInterfacePrx memory; + struct RemoteGuiTab : RemoteGui::Client::Tab { std::atomic_bool rebuild = false; diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp index 5da8c8a86..e7e53e191 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp +++ b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp @@ -39,19 +39,20 @@ namespace armarx { } - ArMemExampleMemory::ArMemExampleMemory() - { - memoryName = "Example"; - addCoreSegmentOnUsage = false; - defaultCoreSegments = {"ExampleData", "ExampleModality", "ExampleConcept"}; - defaultCoreSegmentTypes = {armem::aron::example::ExampleData::toInitialAronType()}; - } - armarx::PropertyDefinitionsPtr ArMemExampleMemory::createPropertyDefinitions() { armarx::PropertyDefinitionsPtr defs = new ArMemExampleMemoryPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); + + p.memoryName = "Example"; + defs->optional(p.memoryName, "memory.Name", "Name of this memory."); + + p.core._defaultSegmentsStr = simox::alg::join(p.core.defaultCoreSegments, ", "); + defs->optional(p.core._defaultSegmentsStr, "core.DefaultSegments", "Core segments to add on start up."); + defs->optional(p.core.addOnUsage, "core.AddOnUsage", + "If enabled, core segments are added when required by a new provider segment."); + return defs; } @@ -65,6 +66,14 @@ namespace armarx void ArMemExampleMemory::onInitComponent() { + memory.name() = p.memoryName; + + bool trim = true; + p.core.defaultCoreSegments = simox::alg::split(p.core._defaultSegmentsStr, ",", trim); + p.core._defaultSegmentsStr.clear(); + memory.addCoreSegments(p.core.defaultCoreSegments); + + memory.addCoreSegment("ExampleData", armem::aron::example::ExampleData::toInitialAronType()); } @@ -87,9 +96,10 @@ namespace armarx // WRITING + armem::data::AddSegmentsResult ArMemExampleMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) { - armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input); + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, p.core.addOnUsage); tab.rebuild = true; return result; } diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h index 6241569ac..b983f68a3 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h +++ b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h @@ -65,16 +65,17 @@ namespace armarx // , virtual public armarx::ArVizComponentPluginUser { public: - ArMemExampleMemory(); /// @see armarx::ManagedIceObject::getDefaultName() std::string getDefaultName() const override; + // WritingInterface interface public: armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; + // LightweightRemoteGuiComponentPluginUser interface public: void RemoteGui__createTab(); @@ -82,6 +83,7 @@ namespace armarx protected: + /// @see armarx::ManagedIceObject::onInitComponent() void onInitComponent() override; @@ -99,9 +101,26 @@ namespace armarx private: + /// Debug observer. Used to visualize e.g. time series. armarx::DebugObserverInterfacePrx debugObserver; + struct Properties + { + std::string memoryName; + + struct CoreSegments + { + std::vector<std::string> defaultCoreSegments = { "ExampleModality", "ExampleConcept" }; + std::string _defaultSegmentsStr; + bool addOnUsage = false; + }; + + CoreSegments core; + }; + Properties p; + + struct RemoteGuiTab : RemoteGui::Client::Tab { std::atomic_bool rebuild = false; diff --git a/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp index 7dd9c5eb3..16fd77624 100644 --- a/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp @@ -7,25 +7,10 @@ // RobotAPI #include <RobotAPI/libraries/armem/core/error.h> -namespace armarx::armem::client::plugins -{ - - ComponentPlugin::~ComponentPlugin() - {} - - - void ComponentPlugin::postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) - { - ClientPlugin::postCreatePropertyDefinitions(properties); - - std::string& defaultMemoryName = parent<ComponentPluginUser>().memoryNameToUse; - properties->optional(defaultMemoryName, "memory.Name", "Name of the memory you want to use."); - } -} armarx::armem::client::ComponentPluginUser::ComponentPluginUser() { - addPlugin(plugin); + // pass } @@ -38,69 +23,6 @@ armarx::armem::client::ComponentPluginUser::~ComponentPluginUser() void armarx::armem::client::ComponentPluginUser::setMemory(server::MemoryInterfacePrx memory) { - this->memory = memory; setReadingMemory(memory); setWritingMemory(memory); } - -void -armarx::armem::client::ComponentPluginUser::setMemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns) -{ - memoryNameSystem = mns; -} - -void -armarx::armem::client::ComponentPluginUser::waitForMemory(bool logging) -{ - if (logging) - { - ARMARX_INFO << "Waiting for memory '" << memoryNameToUse << "'."; - } - armem::Time start = armem::Time::now(); - - armem::data::WaitForMemoryResult result = ClientPluginUserBase::waitForMemory(memoryNameToUse); - - if (result.success && result.proxy) - { - memory = result.proxy; - usingProxy(memory->ice_getIdentity().name); - - setMemory(memory); - if (logging) - { - ARMARX_INFO << "Got memory '" << memoryNameToUse << "'" << " (took " << armem::toStringMilliSeconds(armem::Time::now() - start) << ")."; - } - } - else - { - ARMARX_ERROR << result.errorMessage; - } -} - -void -armarx::armem::client::ComponentPluginUser::resolveMemory(bool logging) -{ - if (logging) - { - ARMARX_INFO << "Trying to get memory '" << memoryNameToUse << "'."; - } - armem::data::ResolveMemoryNameResult result = ClientPluginUserBase::resolveMemoryName(memoryNameToUse); - - if (result.success && result.proxy) - { - memory = result.proxy; - usingProxy(memory->ice_getIdentity().name); - - if (logging) - { - ARMARX_INFO << "Got memory '" << memoryNameToUse << "'."; - } - } - else - { - if (logging) - { - ARMARX_WARNING << result.errorMessage; - } - } -} diff --git a/source/RobotAPI/libraries/armem/client/ComponentPlugin.h b/source/RobotAPI/libraries/armem/client/ComponentPlugin.h index 4fcdb5358..5a25d79e6 100644 --- a/source/RobotAPI/libraries/armem/client/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/client/ComponentPlugin.h @@ -9,30 +9,11 @@ #include <RobotAPI/libraries/armem/client/ReaderComponentPlugin.h> #include <RobotAPI/libraries/armem/client/WriterComponentPlugin.h> -namespace armarx::armem::client -{ - class ComponentPluginUser; -} - -namespace armarx::armem::client::plugins -{ - - class ComponentPlugin : public mns::plugins::ClientPlugin - { - public: - - using ClientPlugin::ClientPlugin; - virtual ~ComponentPlugin() override; - void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override; - - private: - }; - -} namespace armarx::armem::client { + /** * @brief Utility for connecting a Client via Ice to ArMem. */ @@ -48,17 +29,6 @@ namespace armarx::armem::client protected: void setMemory(server::MemoryInterfacePrx memory); - void setMemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns); - - void waitForMemory(bool logging = false); - void resolveMemory(bool logging = false); - - public: - armem::server::MemoryInterfacePrx memory; - std::string memoryNameToUse = "ExampleMemory"; - - private: - plugins::ComponentPlugin* plugin = nullptr; }; } diff --git a/source/RobotAPI/libraries/armem/client/Writer.cpp b/source/RobotAPI/libraries/armem/client/Writer.cpp index 8722e05d8..015d0773a 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.cpp +++ b/source/RobotAPI/libraries/armem/client/Writer.cpp @@ -12,120 +12,36 @@ namespace armarx::armem::client { } - data::AddSegmentResult Writer::addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName, bool logging) + data::AddSegmentResult Writer::addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName) { data::AddSegmentInput input; input.coreSegmentName = coreSegmentName; input.providerSegmentName = providerSegmentName; - return addSegment(input, logging); + return addSegment(input); } - data::AddSegmentResult Writer::addSegment(const std::pair<std::string, std::string>& names, bool logging) + data::AddSegmentResult Writer::addSegment(const std::pair<std::string, std::string>& names) { - return addSegment(names.first, names.second, logging); + return addSegment(names.first, names.second); } - data::AddSegmentResult Writer::addSegment(const data::AddSegmentInput& input, bool logging) + data::AddSegmentResult Writer::addSegment(const data::AddSegmentInput& input) { - data::AddSegmentsResult results = addSegments({input}, logging); + data::AddSegmentsResult results = addSegments({input}); ARMARX_CHECK_EQUAL(results.size(), 1); return results.at(0); } - data::AddSegmentsResult Writer::addSegments(const data::AddSegmentsInput& inputs, bool logging) + data::AddSegmentsResult Writer::addSegments(const data::AddSegmentsInput& inputs) { ARMARX_CHECK_NOT_NULL(memory); - - if (logging) - { - std::stringstream ss; - ss << "Adding segments: "; - for (const auto& input : inputs) - { - ss << "\n- core segment: \t'" << input.coreSegmentName << "'"; - ss << "\n- provider segment: \t'" << input.providerSegmentName << "'"; - ss << "\n----------------------"; - } - ARMARX_IMPORTANT << ss.str(); - } - data::AddSegmentsResult results = memory->addSegments(inputs); ARMARX_CHECK_EQUAL(results.size(), inputs.size()); - - if (logging) - { - std::stringstream ss; - ss << "Output: "; - for (const auto& result : results) - { - ss << "\n- success: \t" << result.success; - ss << "\n- segmentID: \t" << result.segmentID; - ss << "\n- errorMessage: \t" << result.errorMessage; - ss << "\n------------------"; - } - ARMARX_INFO << ss.str(); - } - return results; } - std::pair<bool, data::AddSegmentResult> Writer::addSegmentIfPossible(const std::string& coreSegmentName, const std::string& providerSegmentName, bool logging) - { - if (memory) - { - return {true, addSegment(coreSegmentName, providerSegmentName)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result!"; - } - return {false, {}}; - } - - std::pair<bool, data::AddSegmentResult> Writer::addSegmentIfPossible(const std::pair<std::string, std::string>& names, bool logging) - { - if (memory) - { - return {true, addSegment(names)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result!"; - } - return {false, {}}; - } - - std::pair<bool, data::AddSegmentResult> Writer::addSegmentIfPossible(const data::AddSegmentInput& input, bool logging) - { - if (memory) - { - return {true, addSegment(input)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result!"; - } - return {false, {}}; - } - - std::pair<bool, data::AddSegmentsResult> Writer::addSegmentsIfPossible(const data::AddSegmentsInput& inputs, bool logging) - { - if (memory) - { - return {true, addSegments(inputs)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result!"; - } - return {false, {}}; - } - CommitResult Writer::commit(const Commit& _commit, bool logging) + CommitResult Writer::commit(const Commit& _commit) { ARMARX_CHECK_NOT_NULL(memory); Commit commit = _commit; @@ -136,22 +52,6 @@ namespace armarx::armem::client update.timeSent = timeSent; } - if (logging) - { - std::stringstream ss; - ss << "Committing: "; - unsigned int i = 0; - for (const auto& update : commit.updates) - { - ss << "\n- [" << i++ << "]:"; - ss << "\n-- entityID: \t'" << update.entityID << "'"; - ss << "\n-- confidence: \t" << update.confidence; - ss << "\n-- dataSize: \t" << update.instancesData.size(); - ss << "\n------------------"; - } - ARMARX_INFO << ss.str(); - } - data::Commit commitIce; toIce(commitIce, commit); @@ -160,21 +60,6 @@ namespace armarx::armem::client armem::CommitResult result; fromIce(resultIce, result); - if (logging) - { - std::stringstream ss; - ss << "CommitResult: "; - unsigned int i = 0; - for (const auto& res : result.results) - { - ss << "\n- [" << i++ << "]:"; - ss << "\n-- success: \t'" << res.success << "'"; - ss << "\n-- snapshotID: \t" << res.snapshotID; - ss << "\n------------------"; - } - ARMARX_INFO << ss.str(); - } - return result; } @@ -215,53 +100,26 @@ namespace armarx::armem::client return result; } - EntityUpdateResult Writer::commit(const EntityUpdate& update, bool logging) + + EntityUpdateResult Writer::commit(const EntityUpdate& update) { armem::Commit commit; commit.updates.push_back(update); - armem::CommitResult result = this->commit(commit, logging); + armem::CommitResult result = this->commit(commit); ARMARX_CHECK_EQUAL(result.results.size(), 1); return result.results.at(0); } - std::pair<bool, CommitResult> Writer::commitIfPossible(const Commit& c, bool logging) - { - if (memory) - { - return {true, commit(c, logging)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result."; - } - return {false, {}}; - } - - std::pair<bool, EntityUpdateResult> Writer::commitIfPossible(const EntityUpdate& update, bool logging) - { - if (memory) - { - return {true, commit(update, logging)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result."; - } - return {false, {}}; - } - armarx::armem::MemoryID - Writer::commitAndGetID(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance, bool logging) + Writer::commit(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance) { std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr> data({instance}); - return commitAndGetIDs(entityID, data, logging)[0]; + return commit(entityID, data)[0]; } std::vector<armarx::armem::MemoryID> - Writer::commitAndGetIDs(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data, bool logging) + Writer::commit(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data) { armem::Commit c; armem::EntityUpdate& update = c.updates.emplace_back(); @@ -270,7 +128,7 @@ namespace armarx::armem::client update.timeCreated = armem::Time::now(); update.instancesData = data; - armem::CommitResult commitResult = commit(c, logging); + armem::CommitResult commitResult = commit(c); std::vector<armarx::armem::MemoryID> ret; for (const auto& res : commitResult.results) @@ -282,35 +140,6 @@ namespace armarx::armem::client return ret; } - std::pair<bool, armem::MemoryID> - Writer::commitIfPossibleAndGetID(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance, bool logging) - { - if (memory) - { - return {true, commitAndGetID(entityID, instance, logging)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result."; - } - return {false, {}}; - } - - std::pair<bool, std::vector<armarx::armem::MemoryID>> - Writer::commitIfPossibleAndGetIDs(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data, bool logging) - { - if (memory) - { - return {true, commitAndGetIDs(entityID, data, logging)}; - } - - if (logging) - { - ARMARX_WARNING << "The memory was not available. Returning empty result."; - } - return {false, {}}; - } void Writer::setWritingMemory(server::WritingMemoryInterfacePrx memory) diff --git a/source/RobotAPI/libraries/armem/client/Writer.h b/source/RobotAPI/libraries/armem/client/Writer.h index 759ada69e..6f8fbe876 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.h +++ b/source/RobotAPI/libraries/armem/client/Writer.h @@ -1,14 +1,9 @@ #pragma once -// STD/STL -#include <utility> - -// MemoryInterface #include <RobotAPI/interface/armem/server/WritingMemoryInterface.h> + #include <RobotAPI/libraries/armem/core/ice_conversions.h> -// Logging -#include <ArmarXCore/core/logging/Logging.h> namespace armarx::armem::client { @@ -27,31 +22,20 @@ namespace armarx::armem::client Writer(server::WritingMemoryInterfacePrx memory = nullptr); - data::AddSegmentResult addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName, bool logging = false); - data::AddSegmentResult addSegment(const std::pair<std::string, std::string>& names, bool logging = false); - data::AddSegmentResult addSegment(const data::AddSegmentInput& input, bool logging = false); - data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input, bool logging = false); - - // first bool indicates whether memory was available. Success can be obtained by second.success - std::pair<bool, data::AddSegmentResult> addSegmentIfPossible(const std::string& coreSegmentName, const std::string& providerSegmentName, bool logging = false); - std::pair<bool, data::AddSegmentResult> addSegmentIfPossible(const std::pair<std::string, std::string>& names, bool logging = false); - std::pair<bool, data::AddSegmentResult> addSegmentIfPossible(const data::AddSegmentInput& input, bool logging = false); - std::pair<bool, data::AddSegmentsResult> addSegmentsIfPossible(const data::AddSegmentsInput& input, bool logging = false); + data::AddSegmentResult addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName); + data::AddSegmentResult addSegment(const std::pair<std::string, std::string>& names); + data::AddSegmentResult addSegment(const data::AddSegmentInput& input); + data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input); /** * @brief Writes a `Commit` to the memory. */ - CommitResult commit(const Commit& commit, bool logging = false); - EntityUpdateResult commit(const EntityUpdate& update, bool logging = false); - - std::pair<bool, CommitResult> commitIfPossible(const Commit& commit, bool logging = false); - std::pair<bool, EntityUpdateResult> commitIfPossible(const EntityUpdate& update, bool logging = false); + CommitResult commit(const Commit& commit); + EntityUpdateResult commit(const EntityUpdate& update); - armem::MemoryID commitAndGetID(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance, bool logging = false); - std::vector<armarx::armem::MemoryID> commitAndGetIDs(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data, bool logging = false); + armem::MemoryID commit(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance); + std::vector<armarx::armem::MemoryID> commit(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data); - std::pair<bool, armem::MemoryID> commitIfPossibleAndGetID(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance, bool logging = false); - std::pair<bool, std::vector<armarx::armem::MemoryID>> commitIfPossibleAndGetIDs(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data, bool logging = false); void setWritingMemory(server::WritingMemoryInterfacePrx memory); diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp index 8be567ea3..0d35fd334 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp @@ -17,48 +17,12 @@ namespace armarx::armem::server::plugins void ComponentPlugin::postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) { ClientPlugin::postCreatePropertyDefinitions(properties); - - std::string& defaultMemoryName = parent<ComponentPluginUser>().memoryName; - bool& defaultAddOnUsage = parent<ComponentPluginUser>().addCoreSegmentOnUsage; - properties->topic(memoryListener, "MemoryUpdates"); - - properties->optional(defaultMemoryName, "memory.Name", "Name of this memory."); - - _defaultSegmentsStr = simox::alg::join(parent<ComponentPluginUser>().defaultCoreSegments, ", "); - properties->optional(_defaultSegmentsStr, "core.DefaultSegments", "Core segments to add on start up."); - properties->optional(defaultAddOnUsage, "core.AddOnUsage", "If enabled, core segments are added when required by a new provider segment."); - } - - - void ComponentPlugin::postOnInitComponent() - { - Memory& memory = parent<ComponentPluginUser>().memory; - memory.name() = parent<ComponentPluginUser>().memoryName; - - std::vector<std::string>& defaultCoreSegments = parent<ComponentPluginUser>().defaultCoreSegments; - defaultCoreSegments = simox::alg::split(_defaultSegmentsStr, ",", true); - _defaultSegmentsStr.clear(); - - std::vector<armarx::aron::typenavigator::AronObjectTypeNavigatorPtr>& defaultCoreSegmentTypes = parent<ComponentPluginUser>().defaultCoreSegmentTypes; - - for (unsigned int i = 0; i < defaultCoreSegments.size(); ++i) - { - if (i < defaultCoreSegmentTypes.size() && defaultCoreSegmentTypes[i]) - { - memory.addCoreSegment(defaultCoreSegments[i], defaultCoreSegmentTypes[i]); - } - else - { - memory.addCoreSegment(defaultCoreSegments[i]); - } - } } void ComponentPlugin::postOnConnectComponent() { - // Require memory name system is set! ComponentPluginUser& parent = this->parent<ComponentPluginUser>(); if (isMemoryNameSystemEnabled() && parent.memoryNameSystem) { @@ -87,7 +51,7 @@ namespace armarx::armem::server::plugins data::RegisterMemoryResult result = parent.memoryNameSystem->registerMemory(input); if (result.success) { - ARMARX_INFO << "Registered memory '" << input.name << "' in the Memory Name System (MNS)."; + ARMARX_DEBUG << "Registered memory '" << input.name << "' in the Memory Name System (MNS)."; } else { @@ -108,7 +72,7 @@ namespace armarx::armem::server::plugins result = parent.memoryNameSystem->removeMemory(input); if (result.success) { - ARMARX_INFO << "Removed memory '" << input.name << "' from the Memory Name System (MNS)."; + ARMARX_DEBUG << "Removed memory '" << input.name << "' from the Memory Name System (MNS)."; } else { @@ -140,9 +104,15 @@ namespace armarx::armem::server // WRITING data::AddSegmentsResult ComponentPluginUser::addSegments(const data::AddSegmentsInput& input, const Ice::Current&) + { + bool addCoreSegmentOnUsage = false; + return addSegments(input, addCoreSegmentOnUsage); + } + + data::AddSegmentsResult ComponentPluginUser::addSegments(const data::AddSegmentsInput& input, bool addCoreSegments) { std::scoped_lock lock(memoryMutex); - data::AddSegmentsResult result = iceMemory.addSegments(input, addCoreSegmentOnUsage); + data::AddSegmentsResult result = iceMemory.addSegments(input, addCoreSegments); return result; } diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h index 2efd5baf6..4ad1d4622 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h @@ -18,6 +18,7 @@ namespace armarx::armem::server class ComponentPluginUser; } + namespace armarx::armem::server::plugins { @@ -30,16 +31,15 @@ namespace armarx::armem::server::plugins void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override; - void postOnInitComponent() override; void postOnConnectComponent() override; void preOnDisconnectComponent() override; + /** * @brief Register the parent component in the MNS. * Called before onConnect() if MNS is enabled. */ data::RegisterMemoryResult registerMemory(ComponentPluginUser& parent); - /** * @brief Remove the parent component from the MNS. * Called before onDisconnect() if MNS is enabled. @@ -47,12 +47,11 @@ namespace armarx::armem::server::plugins data::RemoveMemoryResult removeMemory(ComponentPluginUser& parent); client::MemoryListenerInterfacePrx memoryListener; - - private: - std::string _defaultSegmentsStr; }; + } + namespace armarx::armem::server { @@ -60,17 +59,20 @@ namespace armarx::armem::server * @brief Base class of memory server components. */ class ComponentPluginUser : - virtual public ManagedIceObject, - virtual public MemoryInterface, - virtual public mns::plugins::ClientPluginUserBase + virtual public ManagedIceObject + , virtual public MemoryInterface + , virtual public mns::plugins::ClientPluginUserBase { public: ComponentPluginUser(); virtual ~ComponentPluginUser() override = default; + // WritingInterface interface virtual data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input, const Ice::Current& = Ice::emptyCurrent) override; + data::AddSegmentsResult addSegments(const data::AddSegmentsInput& input, bool addCoreSegments); + virtual data::CommitResult commit(const data::Commit& commit, const Ice::Current& = Ice::emptyCurrent) override; @@ -87,17 +89,12 @@ namespace armarx::armem::server /// Helps connecting `memory` to ice. Used to handle Ice callbacks. MemoryToIceAdapter iceMemory { &memory }; - /// Members for properties - std::string memoryName; - bool addCoreSegmentOnUsage = false; - - std::vector<std::string> defaultCoreSegments = { }; - std::vector<armarx::aron::typenavigator::AronObjectTypeNavigatorPtr> defaultCoreSegmentTypes = { }; private: plugins::ComponentPlugin* plugin = nullptr; + }; -- GitLab