diff --git a/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.cpp b/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75928719dc2441212bc15be52f1a364a7484fd8d --- /dev/null +++ b/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.cpp @@ -0,0 +1,136 @@ +/* + * 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::ArMemExampleClient + * @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 "ArMemExampleClient.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <RobotAPI/interface/aron.h> + +#include <RobotAPI/libraries/armem/core/ice_conversions.h> + + +namespace armarx +{ + ArMemExampleClientPropertyDefinitions::ArMemExampleClientPropertyDefinitions(std::string prefix) : + armarx::ComponentPropertyDefinitions(prefix) + { + } + + armarx::PropertyDefinitionsPtr ArMemExampleClient::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ArMemExampleClientPropertyDefinitions(getConfigIdentifier()); + + defs->topic(debugObserver); + + defs->component(memory, "ArMemExampleMemory"); + + return defs; + } + + + std::string ArMemExampleClient::getDefaultName() const + { + return "ArMemExampleClient"; + } + + + void ArMemExampleClient::onInitComponent() + { + } + + + void ArMemExampleClient::onConnectComponent() + { + ARMARX_CHECK_NOT_NULL(memory); + + armem::MemoryID providerID; + if (true) + { + armem::data::AddSegmentInput input; + input.coreSegmentName = "ExampleCoreSegment"; + input.providerSegmentName = "ExampleProvider"; + + ARMARX_INFO << "Adding segment:" + << "\n- core segment: \t'" << input.coreSegmentName << "'" + << "\n- provider segment: \t'" << input.providerSegmentName << "'" + ; + + armem::data::AddSegmentOutput output = memory->addSegment(input); + + ARMARX_INFO << "Output: " + << "\n- success: \t" << output.success + << "\n- segmentID: \t" << output.segmentID + << "\n- errorMessage: \t" << output.errorMessage + ; + + providerID = armem::MemoryID::fromString(output.segmentID); + } + + if (true) + { + armem::Commit commit; + armem::EntityUpdate& update = commit.updates.emplace_back(); + + update.entityID = providerID; + update.entityID.entityName = "example_entity"; + update.timeCreated = armem::Time::now(); + update.instancesData = { new aron::AronData(), new aron::AronData() }; + + ARMARX_INFO << "Committing:" + << "\n- entityID: \t'" << update.entityID.str() << "'" + ; + + // Sending + update.timeSent = armem::Time::now(); + + armem::data::Commit commitIce; + armem::toIce(commitIce, commit); + armem::data::CommitResult commitResult = memory->commit(commitIce); + + ARMARX_CHECK_EQUAL(commitResult.results.size(), 1); + armem::data::EntityUpdateResult& result = commitResult.results.at(0); + + ARMARX_INFO << "Result: " + << "\n- snapshotID: \t" << result.snapshotID + << "\n- time arrived (us): \t" << result.timeArrivedMicroSeconds + ; + } + } + + + void ArMemExampleClient::onDisconnectComponent() + { + } + + + void ArMemExampleClient::onExitComponent() + { + } + + + void ArMemExampleClient::RemoteGui_update() + { + + } + +} diff --git a/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.h b/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.h new file mode 100644 index 0000000000000000000000000000000000000000..a1c3189478b27582b45cc550351a0612449c8dfc --- /dev/null +++ b/source/RobotAPI/components/ArMemExampleClient/ArMemExampleClient.h @@ -0,0 +1,104 @@ +/* + * 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::ArMemExampleClient + * @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/interface/armem/MemoryInterface.h> + + +namespace armarx +{ + /** + * @class ArMemExampleClientPropertyDefinitions + * @brief Property definitions of `ArMemExampleClient`. + */ + class ArMemExampleClientPropertyDefinitions : + public armarx::ComponentPropertyDefinitions + { + public: + ArMemExampleClientPropertyDefinitions(std::string prefix); + }; + + + + /** + * @defgroup Component-ArMemExampleClient ArMemExampleClient + * @ingroup RobotAPI-Components + * A description of the component ArMemExampleClient. + * + * @class ArMemExampleClient + * @ingroup Component-ArMemExampleClient + * @brief Brief description of class ArMemExampleClient. + * + * Detailed description of class ArMemExampleClient. + */ + class ArMemExampleClient : + virtual public armarx::Component + , virtual public LightweightRemoteGuiComponentPluginUser + //, virtual public armarx::ArVizComponentPluginUser + { + public: + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + + // LightweightRemoteGuiComponentPluginUser interface + public: + 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: + + armarx::DebugObserverInterfacePrx debugObserver; + + armem::MemoryInterfacePrx memory; + + }; +} diff --git a/source/RobotAPI/components/ArMemExampleClient/CMakeLists.txt b/source/RobotAPI/components/ArMemExampleClient/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bfa917947ced2e4d9a240de0952b08d93e1dce7c --- /dev/null +++ b/source/RobotAPI/components/ArMemExampleClient/CMakeLists.txt @@ -0,0 +1,26 @@ +armarx_component_set_name("ArMemExampleClient") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem + # RobotAPIComponentPlugins # for ArViz and other plugins +) + +set(SOURCES + ArMemExampleClient.cpp +) +set(HEADERS + ArMemExampleClient.h +) + + +armarx_add_component("${SOURCES}" "${HEADERS}") + + +# add unit tests +# add_subdirectory(test) + +#generate the application +armarx_generate_and_add_component_executable() diff --git a/source/RobotAPI/components/ArMemExampleClient/test/ArMemExampleClientTest.cpp b/source/RobotAPI/components/ArMemExampleClient/test/ArMemExampleClientTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67269fecc99271fcc1f88ffb7eed89e07ae2b7a8 --- /dev/null +++ b/source/RobotAPI/components/ArMemExampleClient/test/ArMemExampleClientTest.cpp @@ -0,0 +1,37 @@ +/* + * 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::ArMemExampleClient + * @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 + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ArMemExampleClient + +#define ARMARX_BOOST_TEST + +#include <RobotAPI/Test.h> +#include "../ArMemExampleClient.h" + +#include <iostream> + +BOOST_AUTO_TEST_CASE(testExample) +{ + armarx::ArMemExampleClient instance; + + BOOST_CHECK_EQUAL(true, true); +} diff --git a/source/RobotAPI/components/ArMemExampleClient/test/CMakeLists.txt b/source/RobotAPI/components/ArMemExampleClient/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..775fb5e2e01b19ab9996a6be1b7575fb53caade6 --- /dev/null +++ b/source/RobotAPI/components/ArMemExampleClient/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore ArMemExampleClient) + +armarx_add_test(ArMemExampleClientTest ArMemExampleClientTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/CMakeLists.txt b/source/RobotAPI/components/CMakeLists.txt index 524786f8810fcb31748cddb9728f1d8ca790b404..e7b83b1aa328589897294150faf376ff8ca0d3f6 100644 --- a/source/RobotAPI/components/CMakeLists.txt +++ b/source/RobotAPI/components/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(units) add_subdirectory(ArViz) add_subdirectory(ArMemExampleMemory) +add_subdirectory(ArMemExampleClient) add_subdirectory(ArMemGlobalStorage) add_subdirectory(ArMemLocalStorage)