diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 621f11585bb9bc08a4e1167d7693aa99624553e0..22399191b3ec0ad3e87468f615662fefdf8e7dd9 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -62,6 +62,8 @@ set(LIB_FILES core/error/mns.cpp client/ComponentPlugin.cpp + client/MemoryNameSystem.cpp + client/MemoryNameSystemComponentPlugin.cpp client/Reader.cpp client/ReaderComponentPlugin.cpp client/Writer.cpp @@ -95,8 +97,6 @@ set(LIB_FILES server/query_proc/longtermmemory/MemoryQueryProcessor.cpp mns/MemoryNameSystem.cpp - mns/Client.cpp - mns/ClientPlugin.cpp mns/ComponentPlugin.cpp util/util.cpp @@ -161,6 +161,8 @@ set(LIB_HEADERS client.h client/ComponentPlugin.h + client/MemoryNameSystem.h + client/MemoryNameSystemComponentPlugin.h client/Reader.h client/ReaderComponentPlugin.h client/Writer.h @@ -200,8 +202,6 @@ set(LIB_HEADERS mns.h mns/MemoryNameSystem.h - mns/Client.h - mns/ClientPlugin.h mns/ComponentPlugin.h util/util.h diff --git a/source/RobotAPI/libraries/armem/mns/Client.cpp b/source/RobotAPI/libraries/armem/client/MemoryNameSystem.cpp similarity index 56% rename from source/RobotAPI/libraries/armem/mns/Client.cpp rename to source/RobotAPI/libraries/armem/client/MemoryNameSystem.cpp index 12d2ac976f710774e4473eb49e67ec6c35fac9af..98c6f0cca82b20f14618b0655d724397587bce78 100644 --- a/source/RobotAPI/libraries/armem/mns/Client.cpp +++ b/source/RobotAPI/libraries/armem/client/MemoryNameSystem.cpp @@ -1,4 +1,4 @@ -#include "Client.h" +#include "MemoryNameSystem.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <ArmarXCore/core/ManagedIceObject.h> @@ -8,21 +8,21 @@ #include <RobotAPI/libraries/armem/client/Writer.h> -namespace armarx::armem::mns +namespace armarx::armem::client { - Client::Client() + MemoryNameSystem::MemoryNameSystem() { } - Client::Client(MemoryNameSystemInterfacePrx mns, ManagedIceObject* component) : + MemoryNameSystem::MemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns, ManagedIceObject* component) : mns(mns), component(component) { } - void Client::update() + void MemoryNameSystem::update() { ARMARX_CHECK_NOT_NULL(mns); data::GetAllRegisteredMemoriesResult result = mns->getAllRegisteredMemories(); @@ -38,7 +38,7 @@ namespace armarx::armem::mns } - server::MemoryInterfacePrx Client::resolveServer(const MemoryID& memoryID) + server::MemoryInterfacePrx MemoryNameSystem::resolveServer(const MemoryID& memoryID) { if (auto it = servers.find(memoryID.memoryName); it != servers.end()) { @@ -59,7 +59,7 @@ namespace armarx::armem::mns } - server::MemoryInterfacePrx Client::waitForServer(const MemoryID& memoryID, Time timeout) + server::MemoryInterfacePrx MemoryNameSystem::waitForServer(const MemoryID& memoryID, Time timeout) { if (auto it = servers.find(memoryID.memoryName); it != servers.end()) { @@ -84,19 +84,19 @@ namespace armarx::armem::mns } } - server::MemoryInterfacePrx Client::useServer(const MemoryID& memoryID) + server::MemoryInterfacePrx MemoryNameSystem::useServer(const MemoryID& memoryID) { ARMARX_CHECK_NOT_NULL(component) << "Owning component not set when using a memory server. \n" - << "When calling `armem::mns::Client::useServer()`, the owning component which should " + << "When calling `armem::mns::MemoryNameSystem::useServer()`, the owning component which should " << "receive the dependency to the memory server must be set beforehand. \n\n" - << "Use `armem::mns::Client::setComponent()` or pass the component on construction " + << "Use `armem::mns::MemoryNameSystem::setComponent()` or pass the component on construction " << "before calling useServer()."; return useServer(memoryID, *component); } - server::MemoryInterfacePrx Client::useServer(const MemoryID& memoryID, ManagedIceObject& component) + server::MemoryInterfacePrx MemoryNameSystem::useServer(const MemoryID& memoryID, ManagedIceObject& component) { server::MemoryInterfacePrx server = waitForServer(memoryID); // Add dependency. @@ -105,50 +105,50 @@ namespace armarx::armem::mns } - server::MemoryInterfacePrx Client::useServer(const std::string& memoryName) + server::MemoryInterfacePrx MemoryNameSystem::useServer(const std::string& memoryName) { return useServer(MemoryID().withMemoryName(memoryName)); } - server::MemoryInterfacePrx Client::useServer(const std::string& memoryName, ManagedIceObject& component) + server::MemoryInterfacePrx MemoryNameSystem::useServer(const std::string& memoryName, ManagedIceObject& component) { return useServer(MemoryID().withMemoryName(memoryName), component); } - client::Reader Client::getReader(const MemoryID& memoryID) + Reader MemoryNameSystem::getReader(const MemoryID& memoryID) { - return client::Reader(resolveServer(memoryID)); + return Reader(resolveServer(memoryID)); } - client::Reader Client::useReader(const MemoryID& memoryID) + Reader MemoryNameSystem::useReader(const MemoryID& memoryID) { - return client::Reader(useServer(memoryID)); + return Reader(useServer(memoryID)); } - client::Reader Client::useReader(const MemoryID& memoryID, ManagedIceObject& component) + Reader MemoryNameSystem::useReader(const MemoryID& memoryID, ManagedIceObject& component) { - return client::Reader(useServer(memoryID, component)); + return Reader(useServer(memoryID, component)); } - client::Reader Client::useReader(const std::string& memoryName) + Reader MemoryNameSystem::useReader(const std::string& memoryName) { return useReader(MemoryID().withMemoryName(memoryName)); } - client::Reader Client::useReader(const std::string& memoryName, ManagedIceObject& component) + Reader MemoryNameSystem::useReader(const std::string& memoryName, ManagedIceObject& component) { return useReader(MemoryID().withMemoryName(memoryName), component); } template <class ClientT> - std::map<std::string, ClientT> Client::_getAllClients() const + std::map<std::string, ClientT> MemoryNameSystem::_getAllClients() const { std::map<std::string, ClientT> result; for (const auto& [name, server] : servers) @@ -160,71 +160,71 @@ namespace armarx::armem::mns template <class ClientT> - std::map<std::string, ClientT> Client::_getAllClients(bool update) + std::map<std::string, ClientT> MemoryNameSystem::_getAllClients(bool update) { if (update) { this->update(); } - return const_cast<const Client&>(*this)._getAllClients<ClientT>(); + return const_cast<const MemoryNameSystem&>(*this)._getAllClients<ClientT>(); } - std::map<std::string, client::Reader> Client::getAllReaders(bool update) + std::map<std::string, Reader> MemoryNameSystem::getAllReaders(bool update) { - return _getAllClients<client::Reader>(update); + return _getAllClients<Reader>(update); } - std::map<std::string, client::Reader> Client::getAllReaders() const + std::map<std::string, Reader> MemoryNameSystem::getAllReaders() const { - return _getAllClients<client::Reader>(); + return _getAllClients<Reader>(); } - client::Writer Client::getWriter(const MemoryID& memoryID) + Writer MemoryNameSystem::getWriter(const MemoryID& memoryID) { - return client::Writer(resolveServer(memoryID)); + return Writer(resolveServer(memoryID)); } - client::Writer Client::useWriter(const MemoryID& memoryID) + Writer MemoryNameSystem::useWriter(const MemoryID& memoryID) { - return client::Writer(useServer(memoryID)); + return Writer(useServer(memoryID)); } - client::Writer Client::useWriter(const MemoryID& memoryID, ManagedIceObject& component) + Writer MemoryNameSystem::useWriter(const MemoryID& memoryID, ManagedIceObject& component) { - return client::Writer(useServer(memoryID, component)); + return Writer(useServer(memoryID, component)); } - client::Writer Client::useWriter(const std::string& memoryName) + Writer MemoryNameSystem::useWriter(const std::string& memoryName) { return useWriter(MemoryID().withMemoryName(memoryName)); } - client::Writer Client::useWriter(const std::string& memoryName, ManagedIceObject& component) + Writer MemoryNameSystem::useWriter(const std::string& memoryName, ManagedIceObject& component) { return useWriter(MemoryID().withMemoryName(memoryName), component); } - std::map<std::string, client::Writer> Client::getAllWriters(bool update) + std::map<std::string, Writer> MemoryNameSystem::getAllWriters(bool update) { - return _getAllClients<client::Writer>(update); + return _getAllClients<Writer>(update); } - std::map<std::string, client::Writer> Client::getAllWriters() const + std::map<std::string, Writer> MemoryNameSystem::getAllWriters() const { - return _getAllClients<client::Writer>(); + return _getAllClients<Writer>(); } - void Client::registerServer(const MemoryID& memoryID, server::MemoryInterfacePrx proxy) + void MemoryNameSystem::registerServer(const MemoryID& memoryID, server::MemoryInterfacePrx proxy) { data::RegisterMemoryInput input; input.name = memoryID.memoryName; @@ -240,7 +240,7 @@ namespace armarx::armem::mns } - void Client::removeServer(const MemoryID& memoryID) + void MemoryNameSystem::removeServer(const MemoryID& memoryID) { data::RemoveMemoryInput input; input.name = memoryID.memoryName; @@ -254,18 +254,18 @@ namespace armarx::armem::mns } - mns::MemoryNameSystemInterfacePrx Client::getMemoryNameSystem() const + mns::MemoryNameSystemInterfacePrx MemoryNameSystem::getMemoryNameSystem() const { return mns; } - void Client::getMemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns) + void MemoryNameSystem::getMemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns) { this->mns = mns; } - void Client::setComponent(ManagedIceObject* component) + void MemoryNameSystem::setComponent(ManagedIceObject* component) { this->component = component; } diff --git a/source/RobotAPI/libraries/armem/mns/Client.h b/source/RobotAPI/libraries/armem/client/MemoryNameSystem.h similarity index 84% rename from source/RobotAPI/libraries/armem/mns/Client.h rename to source/RobotAPI/libraries/armem/client/MemoryNameSystem.h index 5253030801f120bb5a6cc223900f912e0aae83d9..0d6a3f3b604d3d5fa41f4d1724db52081262ef76 100644 --- a/source/RobotAPI/libraries/armem/mns/Client.h +++ b/source/RobotAPI/libraries/armem/client/MemoryNameSystem.h @@ -38,7 +38,7 @@ namespace armarx::armem::client class Writer; } -namespace armarx::armem::mns +namespace armarx::armem::client { /** @@ -56,11 +56,11 @@ namespace armarx::armem::mns * memory servers, as well as retrieving the data for arbitrary entity or * entity snapshot IDs. */ - class Client + class MemoryNameSystem { public: - Client(); + MemoryNameSystem(); /** * @brief Construct an MNS client. @@ -69,8 +69,8 @@ namespace armarx::armem::mns * @param component The owning component. When `using` a memory server, * dependencies will be added to this component. */ - Client(MemoryNameSystemInterfacePrx mns, - ManagedIceObject* component = nullptr); + MemoryNameSystem(mns::MemoryNameSystemInterfacePrx mns, + ManagedIceObject* component = nullptr); mns::MemoryNameSystemInterfacePrx getMemoryNameSystem() const; @@ -124,7 +124,7 @@ namespace armarx::armem::mns server::MemoryInterfacePrx useServer(const std::string& memoryName, ManagedIceObject& component); - // Client reader/writer construction + // Reader/Writer construction /** * @brief Get a reader to the given memory name. @@ -134,13 +134,13 @@ namespace armarx::armem::mns * * @throw `error::CouldNotResolveMemoryServer` If the memory name could not be resolved. */ - client::Reader getReader(const MemoryID& memoryID); + Reader getReader(const MemoryID& memoryID); /// Use a memory server and get a reader for it. - client::Reader useReader(const MemoryID& memoryID); - client::Reader useReader(const MemoryID& memoryID, ManagedIceObject& component); - client::Reader useReader(const std::string& memoryName); - client::Reader useReader(const std::string& memoryName, ManagedIceObject& component); + Reader useReader(const MemoryID& memoryID); + Reader useReader(const MemoryID& memoryID, ManagedIceObject& component); + Reader useReader(const std::string& memoryName); + Reader useReader(const std::string& memoryName, ManagedIceObject& component); /** * @brief Get Readers for all registered servers. @@ -148,13 +148,13 @@ namespace armarx::armem::mns * @param update If true, perform an update first. * @return The readers. */ - std::map<std::string, client::Reader> getAllReaders(bool update = true); + std::map<std::string, Reader> getAllReaders(bool update = true); /** * @brief Get Readers for all registered servers (without updating). * * @return The readers. */ - std::map<std::string, client::Reader> getAllReaders() const; + std::map<std::string, Reader> getAllReaders() const; /** @@ -165,13 +165,13 @@ namespace armarx::armem::mns * * @throw `error::CouldNotResolveMemoryServer` If the memory name could not be resolved. */ - client::Writer getWriter(const MemoryID& memoryID); + Writer getWriter(const MemoryID& memoryID); /// Use a memory server and get a writer for it. - client::Writer useWriter(const MemoryID& memoryID); - client::Writer useWriter(const MemoryID& memoryID, ManagedIceObject& component); - client::Writer useWriter(const std::string& memoryName); - client::Writer useWriter(const std::string& memoryName, ManagedIceObject& component); + Writer useWriter(const MemoryID& memoryID); + Writer useWriter(const MemoryID& memoryID, ManagedIceObject& component); + Writer useWriter(const std::string& memoryName); + Writer useWriter(const std::string& memoryName, ManagedIceObject& component); /** * @brief Get Writers for all registered servers. @@ -179,13 +179,13 @@ namespace armarx::armem::mns * @param update If true, perform an update first. * @return The readers. */ - std::map<std::string, client::Writer> getAllWriters(bool update = true); + std::map<std::string, Writer> getAllWriters(bool update = true); /** * @brief Get Writers for all registered servers (without updating). * * @return The readers. */ - std::map<std::string, client::Writer> getAllWriters() const; + std::map<std::string, Writer> getAllWriters() const; // ToDo: commit() and query() @@ -233,7 +233,7 @@ namespace armarx::armem::mns /// The MNS proxy. - MemoryNameSystemInterfacePrx mns = nullptr; + mns::MemoryNameSystemInterfacePrx mns = nullptr; /// The component to which dependencies will be added. ManagedIceObject* component = nullptr; diff --git a/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp b/source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.cpp similarity index 63% rename from source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp rename to source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.cpp index d470a05de5d87cb7a03839193f53a6fd3d35c8b5..23c02df23011fadc2e052e9fe9f7a638a4279bcb 100644 --- a/source/RobotAPI/libraries/armem/mns/ClientPlugin.cpp +++ b/source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.cpp @@ -1,4 +1,4 @@ -#include "ClientPlugin.h" +#include "MemoryNameSystemComponentPlugin.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> @@ -9,30 +9,30 @@ namespace armarx::armem::mns::plugins { - ClientPlugin::~ClientPlugin() + MemoryNameSystemComponentPlugin::~MemoryNameSystemComponentPlugin() {} - void ClientPlugin::postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr& properties) + void MemoryNameSystemComponentPlugin::postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr& properties) { if (!properties->hasDefinition(makePropertyName(PROPERTY_MNS_NAME_NAME))) { properties->defineOptionalProperty<std::string>( makePropertyName(PROPERTY_MNS_NAME_NAME), - parent<ClientPluginUser>().memoryNameSystemName, + parent<MemoryNameSystemComponentPluginUser>().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), - parent<ClientPluginUser>().memoryNameSystemEnabled, + parent<MemoryNameSystemComponentPluginUser>().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() + void MemoryNameSystemComponentPlugin::preOnInitComponent() { if (isMemoryNameSystemEnabled()) { @@ -40,29 +40,29 @@ namespace armarx::armem::mns::plugins } } - void ClientPlugin::preOnConnectComponent() + void MemoryNameSystemComponentPlugin::preOnConnectComponent() { if (isMemoryNameSystemEnabled()) { - parent<ClientPluginUser>().memoryNameSystem = mns::Client(getMemoryNameSystem(), &parent()); + parent<MemoryNameSystemComponentPluginUser>().memoryNameSystem = mns::Client(getMemoryNameSystem(), &parent()); } } - bool ClientPlugin::isMemoryNameSystemEnabled() + bool MemoryNameSystemComponentPlugin::isMemoryNameSystemEnabled() { return parentDerives<Component>() ? parent<Component>().getProperty<bool>(makePropertyName(PROPERTY_MNS_ENABLED_NAME)) : - parent<ClientPluginUser>().memoryNameSystemEnabled; + parent<MemoryNameSystemComponentPluginUser>().memoryNameSystemEnabled; } - std::string ClientPlugin::getMemoryNameSystemName() + std::string MemoryNameSystemComponentPlugin::getMemoryNameSystemName() { return parentDerives<Component>() ? parent<Component>().getProperty<std::string>(makePropertyName(PROPERTY_MNS_NAME_NAME)) : - std::string{parent<ClientPluginUser>().memoryNameSystemName}; + std::string{parent<MemoryNameSystemComponentPluginUser>().memoryNameSystemName}; } - mns::MemoryNameSystemInterfacePrx ClientPlugin::getMemoryNameSystem() + mns::MemoryNameSystemInterfacePrx MemoryNameSystemComponentPlugin::getMemoryNameSystem() { return isMemoryNameSystemEnabled() && parentDerives<Component>() ? parent<Component>().getProxy<MemoryNameSystemInterfacePrx>(getMemoryNameSystemName()) @@ -74,16 +74,16 @@ namespace armarx::armem::mns::plugins namespace armarx::armem::mns { - ClientPluginUser::ClientPluginUser() + MemoryNameSystemComponentPluginUser::MemoryNameSystemComponentPluginUser() { addPlugin(plugin); } - ClientPluginUser::~ClientPluginUser() + MemoryNameSystemComponentPluginUser::~MemoryNameSystemComponentPluginUser() { } - armem::data::WaitForMemoryResult ClientPluginUser::useMemoryServer(const MemoryID& id) + armem::data::WaitForMemoryResult MemoryNameSystemComponentPluginUser::useMemoryServer(const MemoryID& id) { armem::data::WaitForMemoryResult result; try @@ -100,12 +100,12 @@ namespace armarx::armem::mns return result; } - armem::data::WaitForMemoryResult ClientPluginUser::useMemoryServer(const std::string& memoryName) + armem::data::WaitForMemoryResult MemoryNameSystemComponentPluginUser::useMemoryServer(const std::string& memoryName) { return useMemoryServer(MemoryID().withMemoryName(memoryName)); } - armem::data::WaitForMemoryResult ClientPluginUser::waitForMemoryServer(const std::string& memoryName) + armem::data::WaitForMemoryResult MemoryNameSystemComponentPluginUser::waitForMemoryServer(const std::string& memoryName) { armem::data::WaitForMemoryResult result; try @@ -121,7 +121,7 @@ namespace armarx::armem::mns return result; } - armem::data::ResolveMemoryNameResult ClientPluginUser::resolveMemoryServer(const std::string& memoryName) + armem::data::ResolveMemoryNameResult MemoryNameSystemComponentPluginUser::resolveMemoryServer(const std::string& memoryName) { armem::data::ResolveMemoryNameResult result; try diff --git a/source/RobotAPI/libraries/armem/mns/ClientPlugin.h b/source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.h similarity index 76% rename from source/RobotAPI/libraries/armem/mns/ClientPlugin.h rename to source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.h index 66c74be16b7635d1d4d15be86cebc22e6b75b982..e5673ec143333b8c611a7fa0f453a3f90dca1e6f 100644 --- a/source/RobotAPI/libraries/armem/mns/ClientPlugin.h +++ b/source/RobotAPI/libraries/armem/client/MemoryNameSystemComponentPlugin.h @@ -4,27 +4,27 @@ #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> #include <RobotAPI/libraries/armem/core/MemoryID.h> -#include <RobotAPI/libraries/armem/mns/Client.h> +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> namespace armarx::armem::mns { - class ClientPluginUser; + class MemoryNameSystemComponentPluginUser; } -namespace armarx::armem::mns::plugins +namespace armarx::armem::client::plugins { /** * @brief A base plugin offering optional access and dependency * to the Memory Name System (MNS). */ - class ClientPlugin : public ComponentPlugin + class MemoryNameSystemComponentPlugin : public ComponentPlugin { public: using ComponentPlugin::ComponentPlugin; - virtual ~ClientPlugin() override; + virtual ~MemoryNameSystemComponentPlugin() override; void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override; @@ -54,20 +54,16 @@ namespace armarx::armem::mns::plugins } -namespace armarx::armem::mns +namespace armarx::armem::client { - /** - * @brief Base class for users of the `ClientPlugin`. - * This is itself not a usable plugin user (hence still in the plugins namespace). - */ - class ClientPluginUser : + class MemoryNameSystemComponentPluginUser : virtual public ManagedIceObject { protected: - ClientPluginUser(); - virtual ~ClientPluginUser(); + MemoryNameSystemComponentPluginUser(); + virtual ~MemoryNameSystemComponentPluginUser(); armem::data::WaitForMemoryResult waitForMemoryServer(const std::string& memoryName); armem::data::ResolveMemoryNameResult resolveMemoryServer(const std::string& memoryName); @@ -79,14 +75,15 @@ namespace armarx::armem::mns public: /// Only valid when enabled. - mns::Client memoryNameSystem; + MemoryNameSystem memoryNameSystem; bool memoryNameSystemEnabled = true; std::string memoryNameSystemName = "MemoryNameSystem"; + private: - ComponentPlugin* plugin = nullptr; + plugins::MemoryNameSystemComponentPlugin* plugin = nullptr; }; }