Skip to content
Snippets Groups Projects
Commit 7442f6c5 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add ArMemExampleClient

parent 74fe251f
No related branches found
No related tags found
1 merge request!89Implement core data structure of ArMem Memories
/*
* 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()
{
}
}
/*
* 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;
};
}
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()
/*
* 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);
}
# Libs required for the tests
SET(LIBS ${LIBS} ArmarXCore ArMemExampleClient)
armarx_add_test(ArMemExampleClientTest ArMemExampleClientTest.cpp "${LIBS}")
......@@ -3,6 +3,7 @@ add_subdirectory(units)
add_subdirectory(ArViz)
add_subdirectory(ArMemExampleMemory)
add_subdirectory(ArMemExampleClient)
add_subdirectory(ArMemGlobalStorage)
add_subdirectory(ArMemLocalStorage)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment