diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp b/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87e7a898fc65bd4a5f5114770c97d3ababc99b5d --- /dev/null +++ b/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp @@ -0,0 +1,133 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ArMemDebugMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "ArMemDebugMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + +namespace armarx +{ + ArMemDebugMemoryPropertyDefinitions::ArMemDebugMemoryPropertyDefinitions(std::string prefix) : + armarx::ComponentPropertyDefinitions(prefix) + { + } + + ArMemDebugMemory::ArMemDebugMemory() + { + memoryName = "DebugMemory"; + addCoreSegmentOnUsage = true; + defaultCoreSegments = {}; + defaultCoreSegmentTypes = {}; + } + + armarx::PropertyDefinitionsPtr ArMemDebugMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ArMemDebugMemoryPropertyDefinitions(getConfigIdentifier()); + + defs->topic(debugObserver); + return defs; + } + + + std::string ArMemDebugMemory::getDefaultName() const + { + return "ArMemDebugMemory"; + } + + + void ArMemDebugMemory::onInitComponent() + { + } + + + void ArMemDebugMemory::onConnectComponent() + { + RemoteGui__createTab(); + RemoteGui_startRunningTask(); + } + + + void ArMemDebugMemory::onDisconnectComponent() + { + } + + + void ArMemDebugMemory::onExitComponent() + { + } + + + + // WRITING + armem::data::AddSegmentsResult ArMemDebugMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) + { + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input); + tab.rebuild = true; + return result; + } + + + armem::data::CommitResult ArMemDebugMemory::commit(const armem::data::Commit& commit, const Ice::Current&) + { + armem::data::CommitResult result = ComponentPluginUser::commit(commit); + tab.rebuild = true; + return result; + } + + + // READING + + // Inherited from Plugin + + + + // REMOTE GUI + + void ArMemDebugMemory::RemoteGui__createTab() + { + using namespace armarx::RemoteGui::Client; + + armem::server::MemoryRemoteGui mrg; + { + std::scoped_lock lock(memoryMutex); + tab.memoryGroup = mrg.makeGroupBox(memory); + } + + VBoxLayout root = {tab.memoryGroup, VSpacer()}; + RemoteGui_createTab(getName(), root, &tab); + } + + + void ArMemDebugMemory::RemoteGui_update() + { + if (tab.rebuild.exchange(false)) + { + RemoteGui__createTab(); + } + } + +} diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h b/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h new file mode 100644 index 0000000000000000000000000000000000000000..0b3cee140c6e07f6859e5d7b621b959c8954d705 --- /dev/null +++ b/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h @@ -0,0 +1,112 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ArMemDebugMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <ArmarXCore/core/Component.h> + +#include <ArmarXCore/interface/observers/ObserverInterface.h> +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h> + +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + + +namespace armarx +{ + /** + * @class ArMemDebugMemoryPropertyDefinitions + * @brief Property definitions of `ArMemDebugMemory`. + */ + class ArMemDebugMemoryPropertyDefinitions : + public armarx::ComponentPropertyDefinitions + { + public: + ArMemDebugMemoryPropertyDefinitions(std::string prefix); + }; + + + /** + * @defgroup Component-ArMemDebugMemory ArMemDebugMemory + * @ingroup RobotAPI-Components + * A description of the component ArMemDebugMemory. + * + * @class ArMemDebugMemory + * @ingroup Component-ArMemDebugMemory + * @brief Brief description of class ArMemDebugMemory. + * + * Detailed description of class ArMemDebugMemory. + */ + class ArMemDebugMemory : + virtual public armarx::Component + , virtual public armem::server::ComponentPluginUser + , virtual public LightweightRemoteGuiComponentPluginUser + // , virtual public armarx::ArVizComponentPluginUser + { + public: + ArMemDebugMemory(); + + /// @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(); + void RemoteGui_update() override; + + + protected: + /// @see armarx::ManagedIceObject::onInitComponent() + void onInitComponent() override; + + /// @see armarx::ManagedIceObject::onConnectComponent() + void onConnectComponent() override; + + /// @see armarx::ManagedIceObject::onDisconnectComponent() + void onDisconnectComponent() override; + + /// @see armarx::ManagedIceObject::onExitComponent() + void onExitComponent() override; + + /// @see PropertyUser::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + + private: + /// Debug observer. Used to visualize e.g. time series. + armarx::DebugObserverInterfacePrx debugObserver; + + struct RemoteGuiTab : RemoteGui::Client::Tab + { + std::atomic_bool rebuild = false; + RemoteGui::Client::GroupBox memoryGroup; + }; + RemoteGuiTab tab; + + }; +} diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt b/source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..017e1709df01b4becba5b6aef90fa3dc031399a0 --- /dev/null +++ b/source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt @@ -0,0 +1,37 @@ +armarx_component_set_name("ArMemDebugMemory") + +find_package(IVT QUIET) +armarx_build_if(IVT_FOUND "IVT not available") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem + # RobotAPIComponentPlugins # for ArViz and other plugins + + ${IVT_LIBRARIES} +) + +set(SOURCES + ArMemDebugMemory.cpp +) +set(HEADERS + ArMemDebugMemory.h +) + + +armarx_add_component("${SOURCES}" "${HEADERS}") +if (IVT_FOUND) + target_include_directories(${ARMARX_COMPONENT_NAME} PUBLIC ${IVT_INCLUDE_DIRS}) +endif() + + +# add unit tests +# add_subdirectory(test) + +#generate the application +armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml b/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml new file mode 100644 index 0000000000000000000000000000000000000000..0cd92acebcb91a793a58a7ce09896ac8c2f91214 --- /dev/null +++ b/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml @@ -0,0 +1,86 @@ +<!--Some fancy comment --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + <Include include="<Image/ByteImage.h>" /> + </CodeIncludes> + <GenerateTypes> + <GenerateType name='armarx::armem::aron::example::ExampleData'> + <ObjectChild key='the_int'> + <Int /> + </ObjectChild> + <ObjectChild key='the_long'> + <Long /> + </ObjectChild> + <ObjectChild key='the_float'> + <Float /> + </ObjectChild> + <ObjectChild key='the_double'> + <Double /> + </ObjectChild> + <ObjectChild key='the_string'> + <String /> + </ObjectChild> + <ObjectChild key='the_bool'> + <Bool /> + </ObjectChild> + + + <ObjectChild key='the_eigen_position'> + <EigenMatrix rows="3" cols="1" type="float" /> + </ObjectChild> + <ObjectChild key='the_eigen_pose'> + <EigenMatrix rows="4" cols="4" type="float" /> + </ObjectChild> + <ObjectChild key='the_ivt_image'> + <IVTCByteImage type="GrayScale" /> + </ObjectChild> + + + <ObjectChild key='the_float_list'> + <List> + <Float /> + </List> + </ObjectChild> + <ObjectChild key='the_int_list'> + <List> + <Int /> + </List> + </ObjectChild> + <ObjectChild key='the_string_list'> + <List> + <String /> + </List> + </ObjectChild> + + <ObjectChild key='the_object_list'> + <List> + <Object name='ListClass'> + <ObjectChild key='element_int'> + <Int /> + </ObjectChild> + <ObjectChild key='element_float'> + <Float /> + </ObjectChild> + <ObjectChild key='element_string'> + <String /> + </ObjectChild> + </Object> + </List> + </ObjectChild> + + <ObjectChild key='the_float_dict'> + <Dict> + <Float /> + </Dict> + </ObjectChild> + <ObjectChild key='the_int_dict'> + <Dict> + <Int /> + </Dict> + </ObjectChild> + + </GenerateType> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp index 07f8b22d7be571effdb93b641d33fcd976a5da49..6fdd60959c3c84c5780542edf252a41dd6238a51 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp @@ -44,10 +44,6 @@ 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; } @@ -67,9 +63,8 @@ namespace armarx createRemoteGuiTab(); RemoteGui_startRunningTask(); - waitForMemory(); + waitForMemory(true); ARMARX_CHECK_NOT_NULL(memory); - setMemory(memory); providerID = addProviderSegment(); entityID = providerID.withEntityName("example_entity"); @@ -234,27 +229,6 @@ 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 e216352ddd6b0cba94d86b933745396e10d06683..0773a1f383d4b1289b7819581d83ff46356640c7 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h +++ b/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h @@ -106,7 +106,6 @@ namespace armarx void example_entityUpdated(const armem::MemoryID& id); // Examples - void waitForMemory(); armem::MemoryID addProviderSegment(); armem::MemoryID commitSingleSnapshot(const armem::MemoryID& entityID); @@ -123,9 +122,6 @@ 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 e7e53e191f6333988ea99537576012334057d2a7..5da8c8a86700805b16cb910874c5b860607d7115 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp +++ b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp @@ -39,20 +39,19 @@ 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; } @@ -66,14 +65,6 @@ 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()); } @@ -96,10 +87,9 @@ namespace armarx // WRITING - armem::data::AddSegmentsResult ArMemExampleMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) { - armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, p.core.addOnUsage); + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input); tab.rebuild = true; return result; } diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h index b983f68a3310f163a8e14a4bb183ecca6599a98f..6241569ac0a3b3a318b275f3311fe6f2c0d6df2f 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h +++ b/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h @@ -65,17 +65,16 @@ 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(); @@ -83,7 +82,6 @@ namespace armarx protected: - /// @see armarx::ManagedIceObject::onInitComponent() void onInitComponent() override; @@ -101,26 +99,9 @@ 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/components/armem/CMakeLists.txt b/source/RobotAPI/components/armem/CMakeLists.txt index dfd5208e5a20c95daf7ffa45d6966e98f2afc9ff..6d4b4b0bf0e91cff4278a646479140f9afd27b59 100644 --- a/source/RobotAPI/components/armem/CMakeLists.txt +++ b/source/RobotAPI/components/armem/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(ArMemExampleMemory) +add_subdirectory(ArMemDebugMemory) add_subdirectory(ArMemExampleClient) add_subdirectory(ArMemMemoryNameSystem) diff --git a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h index b3cbf9a3b1e43d262370fc3b6082d07612a9c7cc..ca4d277f2fc3334e788a213d2ee3f0d6b5d5ff8e 100644 --- a/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h +++ b/source/RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h @@ -24,12 +24,12 @@ namespace armarx void setRobotUnitName(const std::string& name); const std::string& getRobotUnitName() const; + private: static constexpr const char* PROPERTY_NAME = "RobotUnitName"; RobotUnitInterfacePrx _robotUnit; std::string _robotUnitName; }; - } } diff --git a/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp index 16fd77624e15e36200bea6db0e9ef1d011d003b3..7dd9c5eb3ca05f971a9db795411d293fb340d84a 100644 --- a/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/client/ComponentPlugin.cpp @@ -7,10 +7,25 @@ // 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() { - // pass + addPlugin(plugin); } @@ -23,6 +38,69 @@ 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 5a25d79e6336c995c33abc2d4ef4c5d537f1c92b..4fcdb5358cb01b55941412154236d7fd0cd95209 100644 --- a/source/RobotAPI/libraries/armem/client/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/client/ComponentPlugin.h @@ -9,11 +9,30 @@ #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. */ @@ -29,6 +48,17 @@ 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 015d0773aded333bc6f528f744c20989717f052e..8722e05d802a7a86e9b61158e713a4466cab7b24 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.cpp +++ b/source/RobotAPI/libraries/armem/client/Writer.cpp @@ -12,36 +12,120 @@ namespace armarx::armem::client { } - data::AddSegmentResult Writer::addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName) + data::AddSegmentResult Writer::addSegment(const std::string& coreSegmentName, const std::string& providerSegmentName, bool logging) { data::AddSegmentInput input; input.coreSegmentName = coreSegmentName; input.providerSegmentName = providerSegmentName; - return addSegment(input); + return addSegment(input, logging); } - data::AddSegmentResult Writer::addSegment(const std::pair<std::string, std::string>& names) + data::AddSegmentResult Writer::addSegment(const std::pair<std::string, std::string>& names, bool logging) { - return addSegment(names.first, names.second); + return addSegment(names.first, names.second, logging); } - data::AddSegmentResult Writer::addSegment(const data::AddSegmentInput& input) + data::AddSegmentResult Writer::addSegment(const data::AddSegmentInput& input, bool logging) { - data::AddSegmentsResult results = addSegments({input}); + data::AddSegmentsResult results = addSegments({input}, logging); ARMARX_CHECK_EQUAL(results.size(), 1); return results.at(0); } - data::AddSegmentsResult Writer::addSegments(const data::AddSegmentsInput& inputs) + data::AddSegmentsResult Writer::addSegments(const data::AddSegmentsInput& inputs, bool logging) { 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) + CommitResult Writer::commit(const Commit& _commit, bool logging) { ARMARX_CHECK_NOT_NULL(memory); Commit commit = _commit; @@ -52,6 +136,22 @@ 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); @@ -60,6 +160,21 @@ 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; } @@ -100,26 +215,53 @@ namespace armarx::armem::client return result; } - - EntityUpdateResult Writer::commit(const EntityUpdate& update) + EntityUpdateResult Writer::commit(const EntityUpdate& update, bool logging) { armem::Commit commit; commit.updates.push_back(update); - armem::CommitResult result = this->commit(commit); + armem::CommitResult result = this->commit(commit, logging); 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::commit(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance) + Writer::commitAndGetID(const armem::MemoryID& entityID, const armarx::aron::datanavigator::AronDictDataNavigatorPtr& instance, bool logging) { std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr> data({instance}); - return commit(entityID, data)[0]; + return commitAndGetIDs(entityID, data, logging)[0]; } std::vector<armarx::armem::MemoryID> - Writer::commit(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data) + Writer::commitAndGetIDs(const armem::MemoryID& entityID, const std::vector<armarx::aron::datanavigator::AronDictDataNavigatorPtr>& data, bool logging) { armem::Commit c; armem::EntityUpdate& update = c.updates.emplace_back(); @@ -128,7 +270,7 @@ namespace armarx::armem::client update.timeCreated = armem::Time::now(); update.instancesData = data; - armem::CommitResult commitResult = commit(c); + armem::CommitResult commitResult = commit(c, logging); std::vector<armarx::armem::MemoryID> ret; for (const auto& res : commitResult.results) @@ -140,6 +282,35 @@ 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 6f8fbe8769c15665b28959e2aaab21085214abd7..759ada69e1920f25d77f604a794f748618475d24 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.h +++ b/source/RobotAPI/libraries/armem/client/Writer.h @@ -1,9 +1,14 @@ #pragma once -#include <RobotAPI/interface/armem/server/WritingMemoryInterface.h> +// 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 { @@ -22,20 +27,31 @@ namespace armarx::armem::client Writer(server::WritingMemoryInterfacePrx memory = nullptr); - 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); + 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); /** * @brief Writes a `Commit` to the memory. */ - CommitResult commit(const Commit& commit); - EntityUpdateResult commit(const EntityUpdate& update); + 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); - 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); + 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); + 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/core/MemoryID.cpp b/source/RobotAPI/libraries/armem/core/MemoryID.cpp index 73d92995e3a24d15bd3593ea8f0ec1314cefe2e2..e56fc4144940c0ed57a73d313b79bad447b258d7 100644 --- a/source/RobotAPI/libraries/armem/core/MemoryID.cpp +++ b/source/RobotAPI/libraries/armem/core/MemoryID.cpp @@ -84,6 +84,27 @@ namespace armarx::armem return latest; } + bool MemoryID::hasInterruption() const + { + bool emptyFound = false; + std::vector<std::string> items = getAllItems(); + for (const std::string& name : items) + { + if (name.empty()) + { + emptyFound = true; + } + else + { + if (emptyFound) + { + return true; + } + } + } + return false; + } + MemoryID MemoryID::fromString(const std::string& string) { diff --git a/source/RobotAPI/libraries/armem/core/MemoryID.h b/source/RobotAPI/libraries/armem/core/MemoryID.h index d92197c96bf08a0dfcabf22e4effe7f54d697762..52290457ec4aa2bda4575a39086e3e96fc177ef9 100644 --- a/source/RobotAPI/libraries/armem/core/MemoryID.h +++ b/source/RobotAPI/libraries/armem/core/MemoryID.h @@ -108,6 +108,7 @@ namespace armarx::armem MemoryID withInstanceIndex(int index) const; std::string getLastNameSet() const; + bool hasInterruption() const; std::string timestampStr() const; std::string instanceIndexStr() const; diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp index d0a5d9d3fc002b759c385c61037eef0291436fc2..f996440e9f20d3892398033d9631999694ba1215 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp @@ -308,5 +308,4 @@ namespace armarx::armem::io historyTimestampsError.insert(historyTimestampsError.end(), o.historyTimestampsError.begin(), o.historyTimestampsError.end()); entityInstancesError.insert(entityInstancesError.end(), o.entityInstancesError.begin(), o.entityInstancesError.end()); } - } diff --git a/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp b/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp index 3ecd25a856c018b75a007af78f57d41401fdc432..02a7a8410f38e65faeb1fa9f95c9cd08b38f1522 100644 --- a/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp +++ b/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp @@ -19,20 +19,19 @@ namespace armarx::armem::mns::plugins { properties->defineOptionalProperty<std::string>( makePropertyName(PROPERTY_MNS_NAME_NAME), - PROPERTY_MNS_NAME_DEFAULT, + parent<ClientPluginUserBase>().memoryNameSystemName, "Name of the Memory Name System (MNS) component."); } if (!properties->hasDefinition(makePropertyName(PROPERTY_MNS_ENABLED_NAME))) { properties->defineOptionalProperty<bool>( makePropertyName(PROPERTY_MNS_ENABLED_NAME), - PROPERTY_MNS_ENABLED_DEFAULT, + parent<ClientPluginUserBase>().memoryNameSystemEnabled, "Whether to use (and depend on) the Memory Name System (MNS)." "\nSet to false to use this memory as a stand-alone."); } } - void ClientPlugin::preOnInitComponent() { if (isMemoryNameSystemEnabled()) @@ -49,19 +48,18 @@ namespace armarx::armem::mns::plugins } } - bool ClientPlugin::isMemoryNameSystemEnabled() { return parentDerives<Component>() ? parent<Component>().getProperty<bool>(makePropertyName(PROPERTY_MNS_ENABLED_NAME)) : - PROPERTY_MNS_ENABLED_DEFAULT; + parent<ClientPluginUserBase>().memoryNameSystemEnabled; } std::string ClientPlugin::getMemoryNameSystemName() { return parentDerives<Component>() ? parent<Component>().getProperty<std::string>(makePropertyName(PROPERTY_MNS_NAME_NAME)) : - std::string{PROPERTY_MNS_NAME_DEFAULT}; + std::string{parent<ClientPluginUserBase>().memoryNameSystemName}; } mns::MemoryNameSystemInterfacePrx ClientPlugin::getMemoryNameSystem() @@ -71,9 +69,12 @@ namespace armarx::armem::mns::plugins : nullptr; } - armem::data::WaitForMemoryResult ClientPluginUserBase::waitForMemory(const std::string& memoryName) { + if (!memoryNameSystem) + { + return {}; + } armem::data::WaitForMemoryInput input; input.name = memoryName; return memoryNameSystem->waitForMemory(input); @@ -81,6 +82,10 @@ namespace armarx::armem::mns::plugins armem::data::ResolveMemoryNameResult ClientPluginUserBase::resolveMemoryName(const std::string& memoryName) { + if (!memoryNameSystem) + { + return {}; + } armem::data::ResolveMemoryNameInput input; input.name = memoryName; return memoryNameSystem->resolveMemoryName(input); diff --git a/source/RobotAPI/libraries/armem/mns/ClientPlugin.h b/source/RobotAPI/libraries/armem/mns/ClientPlugin.h index 074ec2ef023bc9286276dfe07229f822ea3f5b88..6f90b8262baca15e3d2bf93edaa91d0f8c7bd16d 100644 --- a/source/RobotAPI/libraries/armem/mns/ClientPlugin.h +++ b/source/RobotAPI/libraries/armem/mns/ClientPlugin.h @@ -44,12 +44,9 @@ namespace armarx::armem::mns::plugins */ mns::MemoryNameSystemInterfacePrx getMemoryNameSystem(); - - private: + public: static constexpr const char* PROPERTY_MNS_ENABLED_NAME = "mns.MemoryNameSystemEnabled"; - static constexpr const bool PROPERTY_MNS_ENABLED_DEFAULT = true; static constexpr const char* PROPERTY_MNS_NAME_NAME = "mns.MemoryNameSystemName"; - static constexpr const char* PROPERTY_MNS_NAME_DEFAULT = "ArMemMemoryNameSystem"; }; @@ -68,5 +65,8 @@ namespace armarx::armem::mns::plugins /// Only set when enabled. mns::MemoryNameSystemInterfacePrx memoryNameSystem = nullptr; + bool memoryNameSystemEnabled = true; + std::string memoryNameSystemName = "ArMemMemoryNameSystem"; + }; } diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp index 0d35fd3346f7a3f8ec4fc89c9551e1edb16ec827..8be567ea3ca8630ee96c7c0bad5f15e05ffcdace 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp @@ -17,12 +17,48 @@ 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) { @@ -51,7 +87,7 @@ namespace armarx::armem::server::plugins data::RegisterMemoryResult result = parent.memoryNameSystem->registerMemory(input); if (result.success) { - ARMARX_DEBUG << "Registered memory '" << input.name << "' in the Memory Name System (MNS)."; + ARMARX_INFO << "Registered memory '" << input.name << "' in the Memory Name System (MNS)."; } else { @@ -72,7 +108,7 @@ namespace armarx::armem::server::plugins result = parent.memoryNameSystem->removeMemory(input); if (result.success) { - ARMARX_DEBUG << "Removed memory '" << input.name << "' from the Memory Name System (MNS)."; + ARMARX_INFO << "Removed memory '" << input.name << "' from the Memory Name System (MNS)."; } else { @@ -104,15 +140,9 @@ 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, addCoreSegments); + data::AddSegmentsResult result = iceMemory.addSegments(input, addCoreSegmentOnUsage); return result; } diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h index 4ad1d462251a488316d0e4153a26bc5b246d58bb..2efd5baf62ffd3ec8aa38309950dc6839f9ec0d2 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h @@ -18,7 +18,6 @@ namespace armarx::armem::server class ComponentPluginUser; } - namespace armarx::armem::server::plugins { @@ -31,15 +30,16 @@ 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,11 +47,12 @@ namespace armarx::armem::server::plugins data::RemoveMemoryResult removeMemory(ComponentPluginUser& parent); client::MemoryListenerInterfacePrx memoryListener; - }; + private: + std::string _defaultSegmentsStr; + }; } - namespace armarx::armem::server { @@ -59,20 +60,17 @@ 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; @@ -89,12 +87,17 @@ 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; - };