Skip to content
Snippets Groups Projects
Commit 515753f9 authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

Allow the query processor to lock the core segment when querying data from the memory

parent f22e2bff
No related branches found
No related tags found
No related merge requests found
#pragma once #pragma once
#include "BaseQueryProcessorBase.h" #include <regex>
#include <RobotAPI/libraries/armem/core/error.h>
#include <RobotAPI/interface/armem/query.h> #include <RobotAPI/interface/armem/query.h>
#include <RobotAPI/libraries/armem/core/error.h>
#include <regex> #include "BaseQueryProcessorBase.h"
namespace armarx::armem::server::query_proc::base namespace armarx::armem::server::query_proc::base
{ {
...@@ -16,11 +15,10 @@ namespace armarx::armem::server::query_proc::base ...@@ -16,11 +15,10 @@ namespace armarx::armem::server::query_proc::base
public BaseQueryProcessorBase<_MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery> public BaseQueryProcessorBase<_MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery>
{ {
protected: protected:
using Base =
using Base = BaseQueryProcessorBase<_MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery>; BaseQueryProcessorBase<_MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery>;
public: public:
using MemoryT = _MemoryT; using MemoryT = _MemoryT;
using CoreSegmentT = typename MemoryT::CoreSegmentT; using CoreSegmentT = typename MemoryT::CoreSegmentT;
...@@ -31,25 +29,26 @@ namespace armarx::armem::server::query_proc::base ...@@ -31,25 +29,26 @@ namespace armarx::armem::server::query_proc::base
public: public:
MemoryQueryProcessorBase() MemoryQueryProcessorBase()
{ {
} }
MemoryQueryProcessorBase(ChildProcessorT&& childProcessor) :
childProcessor(childProcessor) MemoryQueryProcessorBase(ChildProcessorT&& childProcessor) : childProcessor(childProcessor)
{ {
} }
using Base::process; using Base::process;
ResultMemoryT process(const armem::query::data::Input& input, const MemoryT& memory) const
ResultMemoryT
process(const armem::query::data::Input& input, const MemoryT& memory) const
{ {
return this->process(input.memoryQueries, memory); return this->process(input.memoryQueries, memory);
} }
virtual void process(ResultMemoryT& result, virtual void
const armem::query::data::MemoryQuery& query, process(ResultMemoryT& result,
const MemoryT& memory) const override const armem::query::data::MemoryQuery& query,
const MemoryT& memory) const override
{ {
if (auto q = dynamic_cast<const armem::query::data::memory::All*>(&query)) if (auto q = dynamic_cast<const armem::query::data::memory::All*>(&query))
{ {
...@@ -69,19 +68,19 @@ namespace armarx::armem::server::query_proc::base ...@@ -69,19 +68,19 @@ namespace armarx::armem::server::query_proc::base
} }
} }
virtual void process(ResultMemoryT& result, virtual void
const armem::query::data::memory::All& query, process(ResultMemoryT& result,
const MemoryT& memory) const const armem::query::data::memory::All& query,
const MemoryT& memory) const
{ {
memory.forEachCoreSegment([this, &result, &query](const CoreSegmentT& coreSegment) memory.forEachCoreSegment([this, &result, &query](const CoreSegmentT& coreSegment)
{ { this->_processResult(result, coreSegment, query); });
this->_processResult(result, coreSegment, query);
});
} }
virtual void process(ResultMemoryT& result, virtual void
const armem::query::data::memory::Single& query, process(ResultMemoryT& result,
const MemoryT& memory) const const armem::query::data::memory::Single& query,
const MemoryT& memory) const
{ {
if (auto coreSegment = memory.findCoreSegment(query.coreSegmentName)) if (auto coreSegment = memory.findCoreSegment(query.coreSegmentName))
{ {
...@@ -89,32 +88,35 @@ namespace armarx::armem::server::query_proc::base ...@@ -89,32 +88,35 @@ namespace armarx::armem::server::query_proc::base
} }
} }
virtual void process(ResultMemoryT& result, virtual void
const armem::query::data::memory::Regex& query, process(ResultMemoryT& result,
const MemoryT& memory) const const armem::query::data::memory::Regex& query,
const MemoryT& memory) const
{ {
const std::regex regex(query.coreSegmentNameRegex); const std::regex regex(query.coreSegmentNameRegex);
memory.forEachCoreSegment([this, &result, &query, &regex](const CoreSegmentT& coreSegment) memory.forEachCoreSegment(
{ [this, &result, &query, &regex](const CoreSegmentT& coreSegment)
if (std::regex_search(coreSegment.name(), regex))
{ {
this->_processResult(result, coreSegment, query); if (std::regex_search(coreSegment.name(), regex))
} {
}); this->_processResult(result, coreSegment, query);
}
});
} }
protected: protected:
virtual bool
virtual bool _processAllowed(const armem::query::data::MemoryQuery& query) const _processAllowed(const armem::query::data::MemoryQuery& query) const
{ {
// always execute query. Override if you want to execute the quey only if a special condition is fulfilled (e.g. querytargets) // always execute query. Override if you want to execute the quey only if a special condition is fulfilled (e.g. querytargets)
return true; return true;
} }
void _processResult(ResultMemoryT& result, virtual void
const CoreSegmentT& coreSegment, _processResult(ResultMemoryT& result,
const armem::query::data::MemoryQuery& query) const const CoreSegmentT& coreSegment,
const armem::query::data::MemoryQuery& query) const
{ {
ResultCoreSegmentT* child = result.findCoreSegment(coreSegment.name()); ResultCoreSegmentT* child = result.findCoreSegment(coreSegment.name());
if (child == nullptr) if (child == nullptr)
...@@ -126,8 +128,6 @@ namespace armarx::armem::server::query_proc::base ...@@ -126,8 +128,6 @@ namespace armarx::armem::server::query_proc::base
protected: protected:
ChildProcessorT childProcessor; ChildProcessorT childProcessor;
}; };
} } // namespace armarx::armem::server::query_proc::base
...@@ -208,6 +208,16 @@ namespace armarx::armem::server::query_proc::wm_server ...@@ -208,6 +208,16 @@ namespace armarx::armem::server::query_proc::wm_server
using Base::process; using Base::process;
void
_processResult(ResultMemoryT& result,
const CoreSegmentT& coreSegment,
const armem::query::data::MemoryQuery& query) const final
{
coreSegment.doLocked([&](){
Base::_processResult(result, coreSegment, query);
});
}
}; };
} }
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