Skip to content
Snippets Groups Projects
Commit b1c7ff63 authored by Fabian Reister's avatar Fabian Reister
Browse files

simple writer base class

parent e4948084
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,8 @@ set(LIB_FILES
client/Writer.cpp
client/WriterComponentPlugin.cpp
client/util/SimpleWriterBase.cpp
client/Query.cpp
client/query/Builder.cpp
client/query/selectors.cpp
......@@ -163,6 +165,9 @@ set(LIB_HEADERS
client/Writer.h
client/WriterComponentPlugin.h
client/util/SimpleWriterBase.h
client/Query.h
client/query/Builder.h
client/query/query_fns.h
......
#include "SimpleWriterBase.h"
#include "RobotAPI/libraries/armem/client/ComponentPlugin.h"
namespace armarx::armem::client::util
{
SimpleWriterBase::SimpleWriterBase(ComponentPluginUser& component) :
component(component)
{
}
void
SimpleWriterBase::registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def)
{
ARMARX_DEBUG << "Writer: registerPropertyDefinitions";
const std::string prefix = propertyPrefix();
def->optional(props.memoryName, prefix + "Memory");
def->optional(props.coreSegmentName, prefix + "CoreSegment");
def->required(props.providerName,
prefix + "Provider",
"Name of this provider");
}
void SimpleWriterBase::connect()
{
// Wait for the memory to become available and add it as dependency.
ARMARX_IMPORTANT << "Writer: Waiting for memory '"
<< props.memoryName << "' ...";
auto result = component.useMemory(props.memoryName);
if (not result.success)
{
ARMARX_ERROR << result.errorMessage;
return;
}
ARMARX_IMPORTANT << "SimpleWriterBase: Connected to memory '"
<< props.memoryName;
memoryWriterClient.setWritingMemory(result.proxy);
// memoryReader.setReadingMemory(result.proxy);
}
std::mutex& SimpleWriterBase::memoryWriterMutex()
{
return memoryMutex;
}
armem::client::Writer& SimpleWriterBase::memoryWriter()
{
return memoryWriterClient;
}
const SimpleWriterBase::Properties& SimpleWriterBase::properties() const
{
return props;
}
} // namespace armarx::armem::client::util
\ No newline at end of file
/*
* 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/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <mutex>
#include "ArmarXCore/core/application/properties/PropertyDefinitionContainer.h"
// #include "RobotAPI/libraries/armem/client/Reader.h"
#include "RobotAPI/libraries/armem/client/Writer.h"
namespace armarx::armem
{
class ClientComponentPluginUser;
}
namespace armarx::armem::client
{
class ComponentPluginUser;
}
namespace armarx::armem::client::util
{
class SimpleWriterBase
{
public:
SimpleWriterBase(ComponentPluginUser& component);
virtual ~SimpleWriterBase() = default;
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def);
void connect();
protected:
std::mutex& memoryWriterMutex();
armem::client::Writer& memoryWriter();
struct Properties
{
std::string memoryName = "";
std::string coreSegmentName = "";
std::string providerName = ""; // required property
};
const Properties& properties() const;
virtual std::string propertyPrefix() const = 0;
virtual Properties defaultProperties() const = 0;
private:
Properties props;
armem::client::Writer memoryWriterClient;
std::mutex memoryMutex;
// armem::client::Reader memoryReader;
// std::mutex memoryReaderMutex;
ComponentPluginUser& component;
};
} // namespace armarx::armem::client::util
\ No newline at end of file
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