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

Update SimpleReaderBase and SimpleWriterBase to use MNS client

parent 125f8f5e
No related branches found
No related tags found
No related merge requests found
#include "SimpleReaderBase.h"
#include "RobotAPI/libraries/armem/client/ComponentPlugin.h"
#include <RobotAPI/libraries/armem/core/error.h>
#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h>
namespace armarx::armem::client::util
{
SimpleReaderBase::SimpleReaderBase(ComponentPluginUser& memoryClient) :
component(memoryClient)
SimpleReaderBase::SimpleReaderBase(MemoryNameSystem& memoryNameSystem) :
memoryNameSystem(memoryNameSystem)
{
}
void SimpleReaderBase::registerPropertyDefinitions(
armarx::PropertyDefinitionsPtr& def)
{
......@@ -20,36 +24,40 @@ namespace armarx::armem::client::util
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
ARMARX_IMPORTANT << "SimpleReaderBase: Waiting for memory '" << props.memoryName
<< "' ...";
auto result = component.useMemory(props.memoryName);
if (not result.success)
try
{
memoryReaderClient = memoryNameSystem.useReader(MemoryID().withMemoryName(props.memoryName));
ARMARX_IMPORTANT << "SimpleReaderBase: Connected to memory '" << props.memoryName << "'";
}
catch (const armem::error::CouldNotResolveMemoryServer& e)
{
ARMARX_ERROR << result.errorMessage;
ARMARX_ERROR << e.what();
return;
}
ARMARX_IMPORTANT << "SimpleReaderBase: Connected to memory '"
<< props.memoryName;
memoryReaderClient.setReadingMemory(result.proxy);
}
std::mutex& SimpleReaderBase::memoryReaderMutex()
{
return memoryMutex;
}
const armem::client::Reader& SimpleReaderBase::memoryReader() const
{
return memoryReaderClient;
}
const SimpleReaderBase::Properties& SimpleReaderBase::properties() const
{
return props;
}
} // namespace armarx::armem::client::util
\ No newline at end of file
} // namespace armarx::armem::client::util
......@@ -23,14 +23,14 @@
#include <mutex>
#include "ArmarXCore/core/application/properties/PropertyDefinitionContainer.h"
#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h>
#include "RobotAPI/libraries/armem/client/Reader.h"
#include <RobotAPI/libraries/armem/client/Reader.h>
namespace armarx::armem::client
{
class ComponentPluginUser;
class MemoryNameSystem;
}
namespace armarx::armem::client::util
......@@ -39,13 +39,16 @@ namespace armarx::armem::client::util
class SimpleReaderBase
{
public:
SimpleReaderBase(ComponentPluginUser& memoryClient);
SimpleReaderBase(MemoryNameSystem& memoryNameSystem);
virtual ~SimpleReaderBase() = default;
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def);
void connect();
protected:
// Properties
struct Properties
{
......@@ -61,13 +64,15 @@ namespace armarx::armem::client::util
std::mutex& memoryReaderMutex();
const armem::client::Reader& memoryReader() const;
private:
Properties props;
armem::client::Reader memoryReaderClient;
std::mutex memoryMutex;
ComponentPluginUser& component;
MemoryNameSystem& memoryNameSystem;
};
} // namespace armarx::armem::client::util
#include "SimpleWriterBase.h"
#include "RobotAPI/libraries/armem/client/ComponentPlugin.h"
#include <RobotAPI/libraries/armem/core/error.h>
#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h>
namespace armarx::armem::client::util
{
SimpleWriterBase::SimpleWriterBase(ComponentPluginUser& component) :
component(component)
SimpleWriterBase::SimpleWriterBase(MemoryNameSystem& memoryNameSystem) :
memoryNameSystem(memoryNameSystem)
{
}
void
SimpleWriterBase::registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def)
{
......@@ -26,36 +29,40 @@ namespace armarx::armem::client::util
"Name of this provider");
}
void SimpleWriterBase::connect()
{
// Wait for the memory to become available and add it as dependency.
ARMARX_IMPORTANT << "SimpleWriterBase: Waiting for memory '"
<< props.memoryName << "' ...";
auto result = component.useMemory(props.memoryName);
if (not result.success)
try
{
ARMARX_ERROR << result.errorMessage;
memoryWriterClient = memoryNameSystem.useWriter(MemoryID().withMemoryName(props.memoryName));
ARMARX_IMPORTANT << "SimpleWriterBase: Connected to memory '" << props.memoryName << "'";
}
catch (const armem::error::CouldNotResolveMemoryServer& e)
{
ARMARX_ERROR << e.what();
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
} // namespace armarx::armem::client::util
......@@ -23,15 +23,14 @@
#include <mutex>
#include "ArmarXCore/core/application/properties/PropertyDefinitionContainer.h"
#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h>
// #include "RobotAPI/libraries/armem/client/Reader.h"
#include "RobotAPI/libraries/armem/client/Writer.h"
#include <RobotAPI/libraries/armem/client/Writer.h>
namespace armarx::armem::client
{
class ComponentPluginUser;
class MemoryNameSystem;
}
namespace armarx::armem::client::util
......@@ -40,15 +39,15 @@ namespace armarx::armem::client::util
class SimpleWriterBase
{
public:
SimpleWriterBase(ComponentPluginUser& component);
SimpleWriterBase(MemoryNameSystem& memoryNameSystem);
virtual ~SimpleWriterBase() = default;
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def);
void connect();
protected:
std::mutex& memoryWriterMutex();
armem::client::Writer& memoryWriter();
struct Properties
{
......@@ -62,16 +61,19 @@ namespace armarx::armem::client::util
virtual std::string propertyPrefix() const = 0;
virtual Properties defaultProperties() const = 0;
std::mutex& memoryWriterMutex();
armem::client::Writer& memoryWriter();
private:
Properties props;
armem::client::Writer memoryWriterClient;
std::mutex memoryMutex;
// armem::client::Reader memoryReader;
// std::mutex memoryReaderMutex;
MemoryNameSystem& memoryNameSystem;
ComponentPluginUser& component;
};
} // namespace armarx::armem::client::util
\ No newline at end of file
} // 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