Skip to content
Snippets Groups Projects
SpecializedSegment.cpp 2.45 KiB
Newer Older
#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;
    }

}