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

SimpleReaderBase class

parent 8e3bf5b1
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,7 @@ set(LIB_FILES
client/Writer.cpp
client/WriterComponentPlugin.cpp
client/util/SimpleReaderBase.cpp
client/util/SimpleWriterBase.cpp
client/Query.cpp
......@@ -165,6 +166,7 @@ set(LIB_HEADERS
client/Writer.h
client/WriterComponentPlugin.h
client/util/SimpleReaderBase.h
client/util/SimpleWriterBase.h
......
#include "SimpleReaderBase.h"
#include "RobotAPI/libraries/armem/client/ComponentPlugin.h"
namespace armarx::armem::client::util
{
SimpleReaderBase::SimpleReaderBase(ComponentPluginUser& component) :
component(component)
{
}
void
SimpleReaderBase::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");
}
void SimpleReaderBase::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 << "SimpleReaderBase: Connected to memory '"
<< props.memoryName;
memoryReaderClient.setReadingMemory(result.proxy);
}
std::mutex& SimpleReaderBase::memoryReaderMutex()
{
return memoryMutex;
}
armem::client::Reader& SimpleReaderBase::memoryReader()
{
return memoryReaderClient;
}
const SimpleReaderBase::Properties& SimpleReaderBase::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"
namespace armarx::armem
{
class ClientComponentPluginUser;
}
namespace armarx::armem::client
{
class ComponentPluginUser;
}
namespace armarx::armem::client::util
{
class SimpleReaderBase
{
public:
SimpleReaderBase(ComponentPluginUser& memoryClient);
virtual ~SimpleReaderBase() = default;
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def);
void connect();
protected:
// Properties
struct Properties
{
std::string memoryName = "";
std::string coreSegmentName = "";
};
const Properties& properties() const;
virtual std::string propertyPrefix() const = 0;
virtual Properties defaultProperties() const = 0;
std::mutex& memoryReaderMutex();
armem::client::Reader& memoryReader();
private:
Properties props;
armem::client::Reader memoryReaderClient;
std::mutex memoryMutex;
ComponentPluginUser& component;
};
} // namespace armarx::armem::client::util
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