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

Add SpecializedSegment to reduce duplicated code

parent ad73a369
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,7 @@ set(LIB_FILES
server/MemoryRemoteGui.cpp
server/RemoteGuiAronDataVisitor.cpp
server/segment/SpecializedSegment.cpp
server/query_proc/base/BaseQueryProcessorBase.cpp
server/query_proc/base/EntityQueryProcessorBase.cpp
server/query_proc/base/ProviderSegmentQueryProcessorBase.cpp
......@@ -225,6 +226,7 @@ set(LIB_HEADERS
server/MemoryRemoteGui.h
server/RemoteGuiAronDataVisitor.h
server/segment/SpecializedSegment.h
server/query_proc.h
server/query_proc/base/BaseQueryProcessorBase.h
server/query_proc/base/EntityQueryProcessorBase.h
......
#include "SpecializedSegment.h"
#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h>
#include <ArmarXCore/core/application/properties/PluginAll.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h>
#include <RobotAPI/libraries/armem/server/MemoryToIceAdapter.h>
namespace armarx::armem::server::segment
{
SpecializedSegment::SpecializedSegment(
server::MemoryToIceAdapter& iceMemory,
aron::typenavigator::ObjectNavigatorPtr aronType,
const std::string& defaultCoreSegmentName,
int64_t defaultMaxHistorySize
) :
iceMemory(iceMemory), aronType(aronType)
{
setDefaultCoreSegmentName(defaultCoreSegmentName);
setDefaultMaxHistorySize(defaultMaxHistorySize);
}
SpecializedSegment::~SpecializedSegment()
{
}
void SpecializedSegment::defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix)
{
defs->optional(properties.coreSegmentName,
prefix + "seg.CoreSegmentName",
"Name of the " + properties.coreSegmentName + " core segment.");
defs->optional(properties.maxHistorySize,
prefix + "seg.MaxHistorySize",
"Maximal size of the " + properties.coreSegmentName + " entity histories (-1 for infinite).");
}
void SpecializedSegment::init()
{
ARMARX_CHECK_NOT_NULL(iceMemory.workingMemory);
Logging::setTag(properties.coreSegmentName + " Core Segment");
ARMARX_INFO << "Adding core segment '" << properties.coreSegmentName << "'";
coreSegment = &iceMemory.workingMemory->addCoreSegment(properties.coreSegmentName, aronType);
coreSegment->setMaxHistorySize(properties.maxHistorySize);
}
std::mutex& SpecializedSegment::mutex() const
{
ARMARX_CHECK_NOT_NULL(coreSegment);
return coreSegment->mutex();
}
void SpecializedSegment::setDefaultCoreSegmentName(const std::string& coreSegmentName)
{
this->properties.coreSegmentName = coreSegmentName;
}
void SpecializedSegment::setDefaultMaxHistorySize(int64_t maxHistorySize)
{
this->properties.maxHistorySize = maxHistorySize;
}
void SpecializedSegment::setAronType(aron::typenavigator::ObjectNavigatorPtr aronType)
{
this->aronType = aronType;
}
}
#pragma once
#include <mutex>
#include <string>
#include <ArmarXCore/core/application/properties/forward_declarations.h>
#include <ArmarXCore/core/logging/Logging.h>
namespace armarx::aron::typenavigator
{
using ObjectNavigatorPtr = std::shared_ptr<class ObjectNavigator>;
}
namespace armarx::armem
{
namespace server
{
class MemoryToIceAdapter;
}
namespace wm
{
class CoreSegment;
}
}
namespace armarx::armem::server::segment
{
/**
* @brief Specialized management of a core segment.
*/
class SpecializedSegment :
public armarx::Logging
{
public:
SpecializedSegment(
server::MemoryToIceAdapter& iceMemory,
aron::typenavigator::ObjectNavigatorPtr aronType = nullptr,
const std::string& defaultCoreSegmentName = "",
int64_t defaultMaxHistorySize = -1);
virtual ~SpecializedSegment();
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string& prefix = "");
virtual void init();
// void connect();
std::mutex& mutex() const;
protected:
void setDefaultCoreSegmentName(const std::string& coreSegmentName);
void setDefaultMaxHistorySize(int64_t maxHistorySize);
void setAronType(aron::typenavigator::ObjectNavigatorPtr aronType);
protected:
server::MemoryToIceAdapter& iceMemory;
wm::CoreSegment* coreSegment = nullptr;
aron::typenavigator::ObjectNavigatorPtr aronType;
struct Properties
{
std::string coreSegmentName = "";
int64_t maxHistorySize = -1;
};
Properties properties;
};
}
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