diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 0f702af4fcd0dcfd31e727a87f881c8d0e5ad6a7..f4f2f66c9d32c3404ef2dd08d17ca3422023cfa0 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -107,23 +107,9 @@ set(LIB_FILES server/query_proc/base/CoreSegmentQueryProcessorBase.cpp server/query_proc/base/MemoryQueryProcessorBase.cpp - server/query_proc/workingmemory/BaseQueryProcessor.cpp - server/query_proc/workingmemory/EntityQueryProcessor.cpp - server/query_proc/workingmemory/ProviderSegmentQueryProcessor.cpp - server/query_proc/workingmemory/CoreSegmentQueryProcessor.cpp - server/query_proc/workingmemory/MemoryQueryProcessor.cpp - - server/query_proc/longtermmemory/BaseQueryProcessor.cpp - server/query_proc/longtermmemory/EntityQueryProcessor.cpp - server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.cpp - server/query_proc/longtermmemory/CoreSegmentQueryProcessor.cpp - server/query_proc/longtermmemory/MemoryQueryProcessor.cpp - - server/query_proc/diskmemory/BaseQueryProcessor.cpp - server/query_proc/diskmemory/EntityQueryProcessor.cpp - server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp - server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp - server/query_proc/diskmemory/MemoryQueryProcessor.cpp + server/query_proc/diskmemory.cpp + server/query_proc/ltm.cpp + server/query_proc/wm.cpp mns/MemoryNameSystem.cpp mns/ComponentPlugin.cpp @@ -227,29 +213,17 @@ set(LIB_HEADERS server/segment/SpecializedSegment.h server/query_proc.h + + server/query_proc/base.h server/query_proc/base/BaseQueryProcessorBase.h server/query_proc/base/EntityQueryProcessorBase.h server/query_proc/base/ProviderSegmentQueryProcessorBase.h server/query_proc/base/CoreSegmentQueryProcessorBase.h server/query_proc/base/MemoryQueryProcessorBase.h - server/query_proc/workingmemory/BaseQueryProcessor.h - server/query_proc/workingmemory/EntityQueryProcessor.h - server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h - server/query_proc/workingmemory/CoreSegmentQueryProcessor.h - server/query_proc/workingmemory/MemoryQueryProcessor.h - - server/query_proc/longtermmemory/BaseQueryProcessor.h - server/query_proc/longtermmemory/EntityQueryProcessor.h - server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h - server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h - server/query_proc/longtermmemory/MemoryQueryProcessor.h - - server/query_proc/diskmemory/BaseQueryProcessor.h - server/query_proc/diskmemory/EntityQueryProcessor.h - server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h - server/query_proc/diskmemory/CoreSegmentQueryProcessor.h - server/query_proc/diskmemory/MemoryQueryProcessor.h + server/query_proc/diskmemory.h + server/query_proc/ltm.h + server/query_proc/wm.h mns.h mns/MemoryNameSystem.h diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp index 8c814a160b49b0367cece67d407b986ac4d372e5..ae847a803dc64e68b53c432b222cb6ddbe2fcd86 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp @@ -1,13 +1,11 @@ #include "ComponentPlugin.h" -#include <ArmarXCore/core/Component.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include "MemoryToIceAdapter.h" #include <RobotAPI/libraries/armem/core/error.h> -#include "MemoryToIceAdapter.h" - -//#include <RobotAPI/libraries/armem/core/io/diskWriter/NlohmannJSON/NlohmannJSONDiskWriter.h> +#include <ArmarXCore/core/Component.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> namespace armarx::armem::server::plugins diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h index 50951ab829b11971420a47d680b07e5ce7e4e115..0b2b872c1ff4686eecefd8ae8508bcfc45600d5f 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h @@ -98,7 +98,7 @@ namespace armarx::armem::server public: /// The actual memory. - wm::Memory workingMemory; + server::wm::Memory workingMemory; // [[deprecated ("The global working memory mutex is deprecated. Use the core segment mutexes instead.")]] // std::mutex workingMemoryMutex; diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp index 2207233b2abb5f1a73595bc32f5d60d86fd06a6d..6f6abbb037eb91dbb0374ffece9921fb12c48f06 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp @@ -1,19 +1,21 @@ #include "MemoryRemoteGui.h" -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include "RemoteGuiAronDataVisitor.h" #include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> #include <RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + #include <SimoxUtility/meta/type_name.h> -#include "RemoteGuiAronDataVisitor.h" +#include <mutex> namespace armarx::armem::server { - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::Memory& memory) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::Memory& memory) const { GroupBox group; group.setLabel(makeGroupLabel("Memory", memory.name(), memory.size())); @@ -22,7 +24,7 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("core segments"))); } - memory.forEachCoreSegment([this, &group](const wm::CoreSegment & coreSegment) + memory.forEachCoreSegment([this, &group](const armem::wm::CoreSegment & coreSegment) { group.addChild(makeGroupBox(coreSegment)); return true; @@ -31,10 +33,8 @@ namespace armarx::armem::server } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::CoreSegment& coreSegment) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::CoreSegment& coreSegment) const { - std::scoped_lock lock(coreSegment.mutex()); - GroupBox group; group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.size())); @@ -42,7 +42,7 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("provider segments"))); } - coreSegment.forEachProviderSegment([this, &group](const wm::ProviderSegment & providerSegment) + coreSegment.forEachProviderSegment([this, &group](const armem::wm::ProviderSegment & providerSegment) { group.addChild(makeGroupBox(providerSegment)); return true; @@ -51,7 +51,7 @@ namespace armarx::armem::server } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::ProviderSegment& providerSegment) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::ProviderSegment& providerSegment) const { GroupBox group; group.setLabel(makeGroupLabel("Provider Segment", providerSegment.name(), providerSegment.size())); @@ -60,7 +60,7 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("entities"))); } - providerSegment.forEachEntity([this, &group](const wm::Entity & entity) + providerSegment.forEachEntity([this, &group](const armem::wm::Entity & entity) { group.addChild(makeGroupBox(entity)); return true; @@ -69,7 +69,7 @@ namespace armarx::armem::server } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::Entity& entity) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::Entity& entity) const { GroupBox group; group.setLabel(makeGroupLabel("Entity", entity.name(), entity.size())); @@ -79,7 +79,7 @@ namespace armarx::armem::server group.addChild(Label(makeNoItemsMessage("snapshots"))); } - auto addChild = [this, &group](const wm::EntitySnapshot & snapshot) + auto addChild = [this, &group](const armem::wm::EntitySnapshot & snapshot) { group.addChild(makeGroupBox(snapshot)); return true; @@ -101,7 +101,7 @@ namespace armarx::armem::server } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::EntitySnapshot& snapshot) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::EntitySnapshot& snapshot) const { GroupBox group; group.setLabel(makeGroupLabel("t", armem::toDateTimeMilliSeconds(snapshot.time()), @@ -111,7 +111,7 @@ namespace armarx::armem::server { group.addChild(Label(makeNoItemsMessage("instances"))); } - snapshot.forEachInstance([this, &group](const wm::EntityInstance & instance) + snapshot.forEachInstance([this, &group](const armem::wm::EntityInstance & instance) { group.addChild(makeGroupBox(instance)); return true; @@ -122,7 +122,7 @@ namespace armarx::armem::server } - MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const wm::EntityInstance& instance) const + MemoryRemoteGui::GroupBox MemoryRemoteGui::makeGroupBox(const armem::wm::EntityInstance& instance) const { GroupBox group; diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h index 0c363e0758ca5caf75fa04d45ca35c879bbabe55..35e82d48a4d084c73f6c0bd870488fe8201c56c7 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.h @@ -2,7 +2,7 @@ #include <ArmarXGui/libraries/RemoteGui/Client/Widgets.h> -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> +#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h> namespace armarx::armem::server @@ -17,12 +17,12 @@ namespace armarx::armem::server using GroupBox = armarx::RemoteGui::Client::GroupBox; using Label = armarx::RemoteGui::Client::Label; - GroupBox makeGroupBox(const wm::Memory& memory) const; - GroupBox makeGroupBox(const wm::CoreSegment& coreSegment) const; - GroupBox makeGroupBox(const wm::ProviderSegment& providerSegment) const; - GroupBox makeGroupBox(const wm::Entity& entity) const; - GroupBox makeGroupBox(const wm::EntitySnapshot& entitySnapshot) const; - GroupBox makeGroupBox(const wm::EntityInstance& instance) const; + GroupBox makeGroupBox(const armem::wm::Memory& memory) const; + GroupBox makeGroupBox(const armem::wm::CoreSegment& coreSegment) const; + GroupBox makeGroupBox(const armem::wm::ProviderSegment& providerSegment) const; + GroupBox makeGroupBox(const armem::wm::Entity& entity) const; + GroupBox makeGroupBox(const armem::wm::EntitySnapshot& entitySnapshot) const; + GroupBox makeGroupBox(const armem::wm::EntityInstance& instance) const; std::string makeGroupLabel(const std::string& term, const std::string& name, size_t size, diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index 9fd9d5ccf68640468ea18235ce2a7afe316d7d3d..52fb496592390a1f7df893d0709c73937da55ae5 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -1,11 +1,13 @@ #include "MemoryToIceAdapter.h" +#include "query_proc/wm.h" +#include "query_proc/ltm.h" -#include "query_proc/workingmemory/MemoryQueryProcessor.h" -#include "query_proc/longtermmemory/MemoryQueryProcessor.h" +#include <RobotAPI/libraries/armem/server/wm/ice_conversions.h> #include <RobotAPI/libraries/armem/core/error.h> #include <RobotAPI/libraries/armem/core/wm/ice_conversions.h> + #include <RobotAPI/libraries/aron/core/Exception.h> #include <ArmarXCore/core/logging/Logging.h> @@ -36,7 +38,7 @@ namespace armarx::armem::server data::AddSegmentResult output; - armem::wm::CoreSegment* coreSegment = nullptr; + server::wm::CoreSegment* coreSegment = nullptr; try { coreSegment = &workingMemory->getCoreSegment(input.coreSegmentName); @@ -68,7 +70,7 @@ namespace armarx::armem::server // This is ok. if (input.clearWhenExists) { - wm::ProviderSegment& provider = coreSegment->getProviderSegment(input.providerSegmentName); + server::wm::ProviderSegment& provider = coreSegment->getProviderSegment(input.providerSegmentName); provider.clear(); } } @@ -227,11 +229,11 @@ namespace armarx::armem::server ARMARX_CHECK_NOT_NULL(workingMemory); // Core segment processors will aquire the core segment locks. - armem::wm::query_proc::MemoryQueryProcessor wmProcessor( + query_proc::wm_server::MemoryQueryProcessor wmServerProcessor( input.withData ? armem::DataMode::WithData : armem::DataMode::NoData); - wm::Memory wmResult = wmProcessor.process(input, *workingMemory); + armem::wm::Memory wmResult = wmServerProcessor.process(input.memoryQueries, *workingMemory); - armem::ltm::query_proc::MemoryQueryProcessor ltmProcessor; + query_proc::ltm::MemoryQueryProcessor ltmProcessor; ltm::Memory ltmResult = ltmProcessor.process(input, *longtermMemory); armem::query::data::Result result; @@ -244,7 +246,7 @@ namespace armarx::armem::server // This may also affect the data returned by the current query. // However, this is expected behavior, since we copy the data in the processor (copyEmpty) we can safely return the copy and // remove the original memory reference from WM here. - wm::Memory ltmConverted = ltmResult.convert(); + armem::wm::Memory ltmConverted = ltmResult.convert(); if (ltmConverted.empty()) { ARMARX_ERROR << "A converted memory contains no data although the original memory contained data. This indicates that something is wrong."; @@ -260,7 +262,9 @@ namespace armarx::armem::server auto queryInput = armem::client::QueryInput::fromIce(input); queryInput.replaceQueryTarget(query::data::QueryTarget::LTM, query::data::QueryTarget::WM); - wm::Memory merged_result = wmProcessor.process(queryInput.toIce(), wmResult); + query_proc::wm::MemoryQueryProcessor wm2wmProcessor( + input.withData ? armem::DataMode::WithData : armem::DataMode::NoData); + armem::wm::Memory merged_result = wm2wmProcessor.process(queryInput.toIce(), wmResult); if (merged_result.empty()) { ARMARX_ERROR << "A merged and postprocessed Memory has no data although at least the LTM result contains data. This indicates that something is wrong."; @@ -326,7 +330,7 @@ namespace armarx::armem::server if (queryResult.success) { - wm::Memory m; + armem::wm::Memory m; fromIce(queryResult.memory, m); longtermMemory->append(m); } diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h index cc665745970fad337c3e7af8adcdd1b9f713abc8..6aa68b5714ad369e3b2bbad08d7c1ca06ab04bb8 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.h @@ -6,12 +6,12 @@ #include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> #include <RobotAPI/libraries/armem/core/longtermmemory/Memory.h> #include <RobotAPI/libraries/armem/client/Query.h> +#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h> namespace armarx::armem::server { - /** * @brief Helps connecting a Memory server to the Ice interface. * @@ -23,7 +23,8 @@ namespace armarx::armem::server public: /// Construct an MemoryToIceAdapter from an existing Memory. - MemoryToIceAdapter(wm::Memory* workingMemory = nullptr, ltm::Memory* longtermMemory = nullptr); + MemoryToIceAdapter(server::wm::Memory* workingMemory = nullptr, + ltm::Memory* longtermMemory = nullptr); void setMemoryListener(client::MemoryListenerInterfacePrx memoryListenerTopic); @@ -54,7 +55,7 @@ namespace armarx::armem::server public: - wm::Memory* workingMemory; + server::wm::Memory* workingMemory; ltm::Memory* longtermMemory; client::MemoryListenerInterfacePrx memoryListenerTopic; diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base.h b/source/RobotAPI/libraries/armem/server/query_proc/base.h new file mode 100644 index 0000000000000000000000000000000000000000..1d826798cecac7371882ce0783ddc05414a4f237 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/base.h @@ -0,0 +1,12 @@ +#pragma once + +#include <RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h> +#include <RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h> +#include <RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h> +#include <RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h> + + +namespace armarx::armem::server::query_proc::base +{ + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.cpp b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.cpp index 34e2abd99c889d65723065c8b4726b2ea0aa9bd1..a3dfb4eb4102e21ee0cc97d7a9919b55c7c83f35 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.cpp @@ -1,2 +1,21 @@ #include "BaseQueryProcessorBase.h" +#include <ArmarXCore/core/logging/Logging.h> + + +namespace armarx::armem::server::query_proc::base +{ + + std::set<query::data::QueryTarget> + detail::getTargets(const std::vector<query::data::QueryTarget>& _targets) + { + std::set<query::data::QueryTarget> targets(_targets.begin(), _targets.end()); + if (targets.empty()) + { + ARMARX_DEBUG << "Query has no targets - using WM as default."; + targets.insert(query::data::QueryTarget::WM); + } + return targets; + } + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h index 5e2ba4235154d81950f73fc218b302c41c382ffa..73c662e04ebd734cbe79c3b19f676f684223a88c 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h @@ -1,88 +1,91 @@ #pragma once -#include <ArmarXCore/core/logging/Logging.h> #include <RobotAPI/interface/armem/query.h> +#include <Ice/Handle.h> -namespace armarx::armem::base::query_proc +#include <set> +#include <vector> + + +namespace armarx::armem::server::query_proc::base::detail { + // If empty, e.g. when receiving queries from python, we use WM as default. + // We do it here as (Sl)ice does not support default values for vectors. + std::set<query::data::QueryTarget> getTargets(const std::vector<query::data::QueryTarget>& _targets); +} +namespace armarx::armem::server::query_proc::base +{ + + using QueryTarget = query::data::QueryTarget; + /** * @brief Base class for memory query processors. */ - template <class DataT, class QueryT> + template <QueryTarget queryTarget, class DataT, class ResultT, class QueryT> class BaseQueryProcessorBase { public: + using QueryPtrT = ::IceInternal::Handle<QueryT>; using QuerySeqT = std::vector<QueryPtrT>; + public: virtual ~BaseQueryProcessorBase() = default; - DataT process(const QueryT& query, const DataT& data) const + ResultT process(const QueryT& query, const DataT& data) const { - DataT result { data.id() }; - if (getTargets(query.targets).count(getTargetType())) + ResultT result { data.id() }; + if (detail::getTargets(query.targets).count(queryTarget)) { this->process(result, query, data); } return result; } - DataT process(const QueryPtrT& query, const DataT& data) const + ResultT process(const QueryPtrT& query, const DataT& data) const { return this->process(*query, *data); } - DataT process(const QuerySeqT& queries, const DataT& data) const + ResultT process(const QuerySeqT& queries, const DataT& data) const { - DataT result { data.id() }; + ResultT result { data.id() }; this->process(result, queries, data); return result; } - void process(DataT& result, const QuerySeqT& queries, const DataT& data) const + void process(ResultT& result, const QuerySeqT& queries, const DataT& data) const { if (queries.empty()) { - ARMARX_DEBUG << "There are no queries to process."; return; } for (const auto& query : queries) { - if (getTargets(query->targets).count(getTargetType())) + if (detail::getTargets(query->targets).count(queryTarget)) { this->process(result, *query, data); } } } - virtual void process(DataT& result, const QueryT& query, const DataT& data) const = 0; - - protected: + /** + * @brief Process the query and populate `result`. + * + * @param result The result container. + * @param query The query. + * @param data The source container. + */ + virtual void process(ResultT& result, const QueryT& query, const DataT& data) const = 0; - virtual query::data::QueryTarget getTargetType() const = 0; - - - private: + }; - /// If empty, e.g. when receiving queries from python, we use WM as default. - /// We do it here as (Sl)ice does not support default values for vectors. - static std::set<query::data::QueryTarget> getTargets(const std::vector<query::data::QueryTarget>& _targets) - { - std::set<query::data::QueryTarget> targets(_targets.begin(), _targets.end()); - if (targets.empty()) - { - ARMARX_DEBUG << "Query has no targets - using WM as default."; - targets.insert(query::data::QueryTarget::WM); - } - return targets; - } - }; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h index bb0c5072ebab28eb03cdb15fa3eab9ef315b783c..3050e6e4e91a90bfbfa97feff7f3afc6cb804f41 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h @@ -9,31 +9,46 @@ #include <RobotAPI/libraries/armem/core/error.h> #include "BaseQueryProcessorBase.h" -#include "ProviderSegmentQueryProcessorBase.h" -namespace armarx::armem::base::query_proc +namespace armarx::armem::server::query_proc::base { /** * @brief Handles memory queries. */ - template <class _CoreSegmentT> + template <QueryTarget queryTarget, class _CoreSegmentT, class _ResultCoreSegmentT, class _ChildProcessorT> class CoreSegmentQueryProcessorBase : - virtual public BaseQueryProcessorBase<_CoreSegmentT, armem::query::data::CoreSegmentQuery> + public BaseQueryProcessorBase<queryTarget, _CoreSegmentT, _ResultCoreSegmentT, armem::query::data::CoreSegmentQuery> { - using Base = BaseQueryProcessorBase<_CoreSegmentT, armem::query::data::CoreSegmentQuery>; + using Base = BaseQueryProcessorBase<queryTarget, _CoreSegmentT, _ResultCoreSegmentT, armem::query::data::CoreSegmentQuery>; public: + using CoreSegmentT = _CoreSegmentT; - using ProviderSegmentT = typename _CoreSegmentT::ProviderSegmentT; - using EntityT = typename ProviderSegmentT::EntityT; - using EntitySnapshotT = typename EntityT::EntitySnapshotT; + using ProviderSegmentT = typename CoreSegmentT::ProviderSegmentT; + + using ResultCoreSegmentT = _ResultCoreSegmentT; + using ResultProviderSegmentT = typename ResultCoreSegmentT::ProviderSegmentT; + + using ChildProcessorT = _ChildProcessorT; + + + public: + + CoreSegmentQueryProcessorBase() + { + } + CoreSegmentQueryProcessorBase(ChildProcessorT&& childProcessor) : + childProcessor(childProcessor) + { + } + using Base::process; - virtual void process(_CoreSegmentT& result, + virtual void process(ResultCoreSegmentT& result, const armem::query::data::CoreSegmentQuery& query, - const _CoreSegmentT& coreSegment) const override + const CoreSegmentT& coreSegment) const override { if (auto q = dynamic_cast<const armem::query::data::core::All*>(&query)) { @@ -53,25 +68,24 @@ namespace armarx::armem::base::query_proc } } - void process(_CoreSegmentT& result, + void process(ResultCoreSegmentT& result, const armem::query::data::core::All& query, - const _CoreSegmentT& coreSegment) const + const CoreSegmentT& coreSegment) const { coreSegment.forEachProviderSegment([this, &query, &result](const ProviderSegmentT & providerSegment) { - result.addProviderSegment(providerSegmentProcessorProcess(query.providerSegmentQueries, providerSegment)); - return true; + childProcessor.process(result.addProviderSegment(providerSegment.name()), query.providerSegmentQueries, providerSegment); }); } - void process(_CoreSegmentT& result, + void process(ResultCoreSegmentT& result, const armem::query::data::core::Single& query, - const _CoreSegmentT& coreSegment) const + const CoreSegmentT& coreSegment) const { try { const ProviderSegmentT& providerSegment = coreSegment.getProviderSegment(query.providerSegmentName); - result.addProviderSegment(providerSegmentProcessorProcess(query.providerSegmentQueries, providerSegment)); + childProcessor.process(result.addProviderSegment(providerSegment.name()), query.providerSegmentQueries, providerSegment); } catch (const error::MissingEntry&) { @@ -79,9 +93,9 @@ namespace armarx::armem::base::query_proc } } - void process(_CoreSegmentT& result, + void process(ResultCoreSegmentT& result, const armem::query::data::core::Regex& query, - const _CoreSegmentT& coreSegment) const + const CoreSegmentT& coreSegment) const { std::regex regex(query.providerSegmentNameRegex); coreSegment.forEachProviderSegment( @@ -89,13 +103,15 @@ namespace armarx::armem::base::query_proc { if (std::regex_search(providerSegment.name(), regex)) { - result.addProviderSegment(providerSegmentProcessorProcess(query.providerSegmentQueries, providerSegment)); + childProcessor.process(result.addProviderSegment(providerSegment.name()), query.providerSegmentQueries, providerSegment); } - return true; }); } + protected: - virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& a, const ProviderSegmentT& o) const = 0; + + ChildProcessorT childProcessor; + }; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h index 6713a3e69a62cca8d9c083513b520c951c005984..0c4a842fa2772ae18b475b9e28ad3b13077bb49d 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h @@ -1,41 +1,42 @@ #pragma once -#include <cstdint> -#include <iterator> +#include "BaseQueryProcessorBase.h" + +#include <RobotAPI/libraries/armem/core/Time.h> +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/core/ice_conversions.h> #include <RobotAPI/interface/armem/query.h> -#include <ArmarXCore/core/exceptions/LocalException.h> -#include <ArmarXCore/core/logging/Logging.h> #include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/logging/Logging.h> -#include <RobotAPI/libraries/armem/core/error.h> -#include <RobotAPI/libraries/armem/core/ice_conversions.h> - -#include "BaseQueryProcessorBase.h" -#include "RobotAPI/libraries/armem/core/Time.h" +#include <cstdint> +#include <iterator> -namespace armarx::armem::base::query_proc +namespace armarx::armem::server::query_proc::base { - /** - * @brief Handles memory queries. - */ - template <class _EntityT> + template <QueryTarget queryTarget, class _EntityT, class _ResultEntityT> class EntityQueryProcessorBase : - virtual public BaseQueryProcessorBase<_EntityT, armem::query::data::EntityQuery> + public BaseQueryProcessorBase<queryTarget, _EntityT, _ResultEntityT, armem::query::data::EntityQuery> { - using Base = BaseQueryProcessorBase<_EntityT, armem::query::data::EntityQuery>; + using Base = BaseQueryProcessorBase<queryTarget, _EntityT, _ResultEntityT, armem::query::data::EntityQuery>; public: + using EntityT = _EntityT; using EntitySnapshotT = typename EntityT::EntitySnapshotT; + using ResultEntityT = _ResultEntityT; + using ResultSnapshotT = typename ResultEntityT::EntitySnapshotT; + + using Base::process; - void process(_EntityT& result, - const armem::query::data::EntityQuery& query, - const _EntityT& entity) const override + virtual void process(ResultEntityT& result, + const armem::query::data::EntityQuery& query, + const EntityT& entity) const override { if (auto q = dynamic_cast<const armem::query::data::entity::All*>(&query)) { @@ -71,9 +72,10 @@ namespace armarx::armem::base::query_proc } } - void process(_EntityT& result, + + void process(ResultEntityT& result, const armem::query::data::entity::All& query, - const _EntityT& entity) const + const EntityT& entity) const { (void) query; // Copy this entitiy and its contents. @@ -81,13 +83,13 @@ namespace armarx::armem::base::query_proc entity.forEachSnapshot([this, &result](const EntitySnapshotT & snapshot) { addResultSnapshot(result, snapshot); - return true; }); } - void process(_EntityT& result, + + void process(ResultEntityT& result, const armem::query::data::entity::Single& query, - const _EntityT& entity) const + const EntityT& entity) const { if (query.timestamp < 0) { @@ -132,9 +134,10 @@ namespace armarx::armem::base::query_proc } } - void process(_EntityT& result, + + void process(ResultEntityT& result, const armem::query::data::entity::TimeRange& query, - const _EntityT& entity) const + const EntityT& entity) const { if (query.minTimestamp <= query.maxTimestamp || query.minTimestamp < 0 || query.maxTimestamp < 0) { @@ -144,9 +147,10 @@ namespace armarx::armem::base::query_proc } } - void process(_EntityT& result, + + void process(ResultEntityT& result, const armem::query::data::entity::IndexRange& query, - const _EntityT& entity) const + const EntityT& entity) const { entity.forEachSnapshotInIndexRange( query.first, query.last, @@ -156,10 +160,11 @@ namespace armarx::armem::base::query_proc }); } - void process(_EntityT& result, + + void process(ResultEntityT& result, const Time& min, const Time& max, - const _EntityT& entity, + const EntityT& entity, const armem::query::data::EntityQuery& query) const { (void) query; @@ -172,9 +177,9 @@ namespace armarx::armem::base::query_proc } - void process(_EntityT& result, + void process(ResultEntityT& result, const armem::query::data::entity::BeforeOrAtTime& query, - const _EntityT& entity) const + const EntityT& entity) const { const auto referenceTimestamp = fromIce<Time>(query.timestamp); ARMARX_CHECK(referenceTimestamp.toMicroSeconds() >= 0) << "Reference timestamp is negative!"; @@ -191,51 +196,40 @@ namespace armarx::armem::base::query_proc } - void process(_EntityT& result, + void process(ResultEntityT& result, const armem::query::data::entity::BeforeTime& query, - const _EntityT& entity) const + const EntityT& entity) const { const armem::Time referenceTimestamp = fromIce<Time>(query.timestamp); ARMARX_CHECK(referenceTimestamp.toMicroSeconds() >= 0) << "Reference timestamp must be non-negative."; -#if 0 - try + std::vector<const EntitySnapshotT*> befores; + entity.forEachSnapshotBefore(referenceTimestamp, [&befores](const EntitySnapshotT & s) { -#endif - std::vector<const EntitySnapshotT*> befores; - entity.forEachSnapshotBefore(referenceTimestamp, [&befores](const EntitySnapshotT & s) - { - befores.push_back(&s); - return true; - }); - - size_t num = 0; - if (query.maxEntries < 0) - { - num = befores.size(); - } - else - { - num = std::min(befores.size(), static_cast<size_t>(query.maxEntries)); - } + befores.push_back(&s); + }); - for (size_t r = 0; r < num; ++r) - { - size_t i = befores.size() - 1 - r; - addResultSnapshot(result, *befores[i]); - } -#if 0 + size_t num = 0; + if (query.maxEntries < 0) + { + num = befores.size(); } - catch (const error::MissingEntry&) + else { - // Leave empty. + num = std::min(befores.size(), static_cast<size_t>(query.maxEntries)); + } + + for (size_t r = 0; r < num; ++r) + { + size_t i = befores.size() - 1 - r; + addResultSnapshot(result, *befores[i]); } -#endif } - void process(_EntityT& result, + + void process(ResultEntityT& result, const armem::query::data::entity::TimeApprox& query, - const _EntityT& entity) const + const EntityT& entity) const { const auto referenceTimestamp = fromIce<Time>(query.timestamp); ARMARX_CHECK(referenceTimestamp.toMicroSeconds() >= 0) << "Reference timestamp is negative!"; @@ -281,14 +275,16 @@ namespace armarx::armem::base::query_proc } catch (const armem::error::MissingEntry&) { - } } protected: - virtual void addResultSnapshot(_EntityT& result, typename _EntityT::ContainerT::const_iterator it) const = 0; - virtual void addResultSnapshot(_EntityT& result, const typename _EntityT::EntitySnapshotT& snapshot) const = 0; + + void addResultSnapshot(ResultEntityT& result, const EntitySnapshotT& snapshot) const + { + result.addSnapshot(snapshot); + } }; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h index 66c2a8042b740ec72c6be3ca653f6ed72fc8c35b..df71683c29f2cb17db976e8be971725934b03348 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h @@ -1,47 +1,56 @@ #pragma once -#include <regex> - -#include <RobotAPI/interface/armem/query.h> - #include "BaseQueryProcessorBase.h" -#include "CoreSegmentQueryProcessorBase.h" +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/interface/armem/query.h> #include <ArmarXCore/core/logging/Logging.h> #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <RobotAPI/libraries/armem/core/error.h> +#include <regex> -namespace armarx::armem::base::query_proc +namespace armarx::armem::server::query_proc::base { - /** - * @brief Handles memory queries. - */ - template <class _MemoryT> + + template <QueryTarget queryTarget, class _MemoryT, class _ResultMemoryT, class _ChildProcessorT> class MemoryQueryProcessorBase : - virtual public BaseQueryProcessorBase<_MemoryT, armem::query::data::MemoryQuery> + public BaseQueryProcessorBase<queryTarget, _MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery> { - using Base = BaseQueryProcessorBase<_MemoryT, armem::query::data::MemoryQuery>; + using Base = BaseQueryProcessorBase<queryTarget, _MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery>; public: + using MemoryT = _MemoryT; using CoreSegmentT = typename MemoryT::CoreSegmentT; - using ProviderSegmentT = typename CoreSegmentT::ProviderSegmentT; - using EntityT = typename ProviderSegmentT::EntityT; - using EntitySnapshotT = typename EntityT::EntitySnapshotT; + + using ResultMemoryT = _ResultMemoryT; + using ResultCoreSegmentT = typename ResultMemoryT::CoreSegmentT; + + using ChildProcessorT = _ChildProcessorT; + + + public: + + MemoryQueryProcessorBase() + { + } + MemoryQueryProcessorBase(ChildProcessorT&& childProcessor) : + childProcessor(childProcessor) + { + } using Base::process; - _MemoryT 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); } - void process(_MemoryT& result, - const armem::query::data::MemoryQuery& query, - const _MemoryT& memory) const override + virtual void process(ResultMemoryT& result, + const armem::query::data::MemoryQuery& query, + const MemoryT& memory) const override { if (auto q = dynamic_cast<const armem::query::data::memory::All*>(&query)) { @@ -57,51 +66,52 @@ namespace armarx::armem::base::query_proc } else { - throw armem::error::UnknownQueryType("memory segment", query); + throw armem::error::UnknownQueryType(MemoryT::getLevelName(), query); } } - void process(_MemoryT& result, + void process(ResultMemoryT& result, const armem::query::data::memory::All& query, - const _MemoryT& memory) const + const MemoryT& memory) const { memory.forEachCoreSegment([this, &result, &query](const CoreSegmentT & coreSegment) { - result.addCoreSegment(coreSegmentProcessorProcess(query.coreSegmentQueries, coreSegment)); - return true; + childProcessor.process(result.addCoreSegment(coreSegment.name()), query.coreSegmentQueries, coreSegment); }); } - void process(_MemoryT& result, + void process(ResultMemoryT& result, const armem::query::data::memory::Single& query, - const _MemoryT& memory) const + const MemoryT& memory) const { try { const CoreSegmentT& coreSegment = memory.getCoreSegment(query.coreSegmentName); - result.addCoreSegment(coreSegmentProcessorProcess(query.coreSegmentQueries, coreSegment)); + childProcessor.process(result.addCoreSegment(coreSegment.name()), query.coreSegmentQueries, coreSegment); } catch (const error::MissingEntry&) { } } - void process(_MemoryT& result, + void process(ResultMemoryT& result, const armem::query::data::memory::Regex& query, - const _MemoryT& memory) const + const MemoryT& memory) const { const std::regex regex(query.coreSegmentNameRegex); memory.forEachCoreSegment([this, &result, &query, ®ex](const CoreSegmentT & coreSegment) { if (std::regex_search(coreSegment.name(), regex)) { - result.addCoreSegment(coreSegmentProcessorProcess(query.coreSegmentQueries, coreSegment)); + childProcessor.process(result.addCoreSegment(coreSegment.name()), query.coreSegmentQueries, coreSegment); } - return true; }); } + protected: - virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& a, const CoreSegmentT& o) const = 0; + + ChildProcessorT childProcessor; + }; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h index cb191d02edeaaa471290d5bf67475a5950572213..5102a12829c106e58159e7dcc35a7df0890f93d5 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h @@ -1,39 +1,50 @@ #pragma once -#include <RobotAPI/interface/armem/query.h> - #include "BaseQueryProcessorBase.h" -#include "EntityQueryProcessorBase.h" -#include <regex> +#include <RobotAPI/libraries/armem/core/error.h> -#include <ArmarXCore/core/logging/Logging.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/error.h> +#include <regex> -namespace armarx::armem::base::query_proc +namespace armarx::armem::server::query_proc::base { - /** - * @brief Handles memory queries. - */ - template <class _ProviderSegmentT> + template <QueryTarget queryTarget, class _ProviderSegmentT, class _ResultProviderSegmentT, class _ChildProcessorT> class ProviderSegmentQueryProcessorBase : - virtual public BaseQueryProcessorBase<_ProviderSegmentT, armem::query::data::ProviderSegmentQuery> + public BaseQueryProcessorBase<queryTarget, _ProviderSegmentT, _ResultProviderSegmentT, armem::query::data::ProviderSegmentQuery> { - using Base = BaseQueryProcessorBase<_ProviderSegmentT, armem::query::data::ProviderSegmentQuery>; + using Base = BaseQueryProcessorBase<queryTarget, _ProviderSegmentT, _ResultProviderSegmentT, armem::query::data::ProviderSegmentQuery>; + public: + using ProviderSegmentT = _ProviderSegmentT; using EntityT = typename ProviderSegmentT::EntityT; - using EntitySnapshotT = typename EntityT::EntitySnapshotT; + + using ResultProviderSegmentT = _ResultProviderSegmentT; + using ResultEntityT = typename ResultProviderSegmentT::EntityT; + + using ChildProcessorT = _ChildProcessorT; + + + public: + + ProviderSegmentQueryProcessorBase() + { + } + ProviderSegmentQueryProcessorBase(ChildProcessorT&& childProcessor) : + childProcessor(childProcessor) + { + } + using Base::process; - void process(_ProviderSegmentT& result, - const armem::query::data::ProviderSegmentQuery& query, - const _ProviderSegmentT& providerSegment) const override + virtual void process(ResultProviderSegmentT& result, + const armem::query::data::ProviderSegmentQuery& query, + const ProviderSegmentT& providerSegment) const override { if (auto q = dynamic_cast<const armem::query::data::provider::All*>(&query)) { @@ -49,29 +60,28 @@ namespace armarx::armem::base::query_proc } else { - throw armem::error::UnknownQueryType("provider segment", query); + throw armem::error::UnknownQueryType(ProviderSegmentT::getLevelName(), query); } } - void process(_ProviderSegmentT& result, + void process(ResultProviderSegmentT& result, const armem::query::data::provider::All& query, - const _ProviderSegmentT& providerSegment) const + const ProviderSegmentT& providerSegment) const { providerSegment.forEachEntity([this, &result, &query](const EntityT & entity) { - result.addEntity(entityProcessorProcess(query.entityQueries, entity)); - return true; + childProcessor.process(result.addEntity(entity.name()), query.entityQueries, entity); }); } - void process(_ProviderSegmentT& result, + void process(ResultProviderSegmentT& result, const armem::query::data::provider::Single& query, - const _ProviderSegmentT& providerSegment) const + const ProviderSegmentT& providerSegment) const { try { const EntityT& entity = providerSegment.getEntity(query.entityName); - result.addEntity(entityProcessorProcess(query.entityQueries, entity)); + childProcessor.process(result.addEntity(entity.name()), query.entityQueries, entity); } catch (const error::MissingEntry&) { @@ -79,22 +89,25 @@ namespace armarx::armem::base::query_proc } } - void process(_ProviderSegmentT& result, + void process(ResultProviderSegmentT& result, const armem::query::data::provider::Regex& query, - const _ProviderSegmentT& providerSegment) const + const ProviderSegmentT& providerSegment) const { const std::regex regex(query.entityNameRegex); providerSegment.forEachEntity([this, &result, &query, ®ex](const EntityT & entity) { if (std::regex_search(entity.name(), regex)) { - result.addEntity(entityProcessorProcess(query.entityQueries, entity)); + childProcessor.process(result.addEntity(entity.name()), query.entityQueries, entity); } return true; }); } + protected: - virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& a, const EntityT& o) const = 0; + + ChildProcessorT childProcessor; + }; } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a695cf43d51dcbbc2329fa1c48fbe8e63565c24f --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.cpp @@ -0,0 +1,7 @@ +#include "diskmemory.h" + + +namespace armarx::armem::server::query_proc::d_ltm +{ +} + diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.h new file mode 100644 index 0000000000000000000000000000000000000000..0f2ffe791d192b9bc2b5f2a2be311735808427a4 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory.h @@ -0,0 +1,32 @@ +#pragma once + +#include <RobotAPI/libraries/armem/core/diskmemory/Memory.h> +#include <RobotAPI/libraries/armem/server/query_proc/base.h> + + +namespace armarx::armem::server::query_proc::d_ltm +{ + static const base::QueryTarget queryTarget = query::data::QueryTarget::LTM; + + + class EntityQueryProcessor : + public base::EntityQueryProcessorBase<queryTarget, armem::d_ltm::Entity, armem::d_ltm::Entity> + { + }; + + class ProviderSegmentQueryProcessor : + public base::ProviderSegmentQueryProcessorBase <queryTarget, armem::d_ltm::ProviderSegment, armem::d_ltm::ProviderSegment, EntityQueryProcessor > + { + }; + + class CoreSegmentQueryProcessor : + public base::CoreSegmentQueryProcessorBase<queryTarget, armem::d_ltm::CoreSegment, armem::d_ltm::CoreSegment, ProviderSegmentQueryProcessor> + { + }; + + class MemoryQueryProcessor : + public base::MemoryQueryProcessorBase <queryTarget, armem::d_ltm::Memory, armem::d_ltm::Memory, CoreSegmentQueryProcessor > + { + }; + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp deleted file mode 100644 index 68821bcd95cdf2aaccf7126d4055495d39d0393d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BaseQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h deleted file mode 100644 index 0e3ddac45c6a8eee377f468767a3bc39a580c554..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/DataMode.h> - -#include "../base/BaseQueryProcessorBase.h" - - -namespace armarx::armem::d_ltm::query_proc -{ - /** - * @brief Base class for memory query processors. - */ - template <class DataT, class QueryT> - class BaseQueryProcessor : - virtual public base::query_proc::BaseQueryProcessorBase<DataT, QueryT> - { - using Base = base::query_proc::BaseQueryProcessorBase<DataT, QueryT>; - - public: - BaseQueryProcessor() - {} - - protected: - - query::data::QueryTarget getTargetType() const override - { - return query::data::QueryTarget::LTM; - } - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp deleted file mode 100644 index afbe35ad15eea0342b0b0d4df0200aaf0d32aa2a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CoreSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h deleted file mode 100644 index 5c043a2d1dbe2218078591adc3fc0ebac0bfe932..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/CoreSegmentQueryProcessorBase.h" - -#include "../../../core/diskmemory/CoreSegment.h" - -#include "ProviderSegmentQueryProcessor.h" - - -namespace armarx::armem::d_ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class CoreSegmentQueryProcessor : - virtual public BaseQueryProcessor<d_ltm::CoreSegment, armem::query::data::CoreSegmentQuery>, - virtual public base::query_proc::CoreSegmentQueryProcessorBase<d_ltm::CoreSegment> - { - using Base = BaseQueryProcessor<d_ltm::CoreSegment, armem::query::data::CoreSegmentQuery>; - - public: - CoreSegmentQueryProcessor() : - Base() - {} - - protected: - virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override - { - return providerSegmentProcessor.process(q, s); - } - - private: - ProviderSegmentQueryProcessor providerSegmentProcessor; - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp deleted file mode 100644 index c1c321b026b173c6552758fb9d8b9fdf722ea5a4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "EntityQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h deleted file mode 100644 index 712345e2a3d650f43974af3190225daa51deb13a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/EntityQueryProcessorBase.h" - -#include "../../../core/diskmemory/Entity.h" - -#include "EntityQueryProcessor.h" - -namespace armarx::armem::d_ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class EntityQueryProcessor : - virtual public BaseQueryProcessor<d_ltm::Entity, armem::query::data::EntityQuery>, - virtual public base::query_proc::EntityQueryProcessorBase<d_ltm::Entity> - { - using Base = BaseQueryProcessor<d_ltm::Entity, armem::query::data::EntityQuery>; - - public: - - EntityQueryProcessor() : - Base() - {} - - - private: - - void addResultSnapshot(d_ltm::Entity& result, d_ltm::Entity::ContainerT::const_iterator it) const override - { - addResultSnapshot(result, it->second); - } - - void addResultSnapshot(d_ltm::Entity& result, const d_ltm::EntitySnapshot& snapshot) const override - { - result.addSnapshot(d_ltm::EntitySnapshot(snapshot)); - } - - }; - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp deleted file mode 100644 index 69b04de6c9e623286a5bda836dddfdc8b551b64a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MemoryQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h deleted file mode 100644 index 038523950bfe399c2ef7a65b79fde43376651617..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/MemoryQueryProcessorBase.h" - -#include "../../../core/diskmemory/Memory.h" - -#include "CoreSegmentQueryProcessor.h" - -namespace armarx::armem::d_ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class MemoryQueryProcessor : - virtual public BaseQueryProcessor<d_ltm::Memory, armem::query::data::MemoryQuery>, - virtual public base::query_proc::MemoryQueryProcessorBase<d_ltm::Memory> - { - using Base = BaseQueryProcessor<d_ltm::Memory, armem::query::data::MemoryQuery>; - - public: - MemoryQueryProcessor() : - Base() - {} - - protected: - virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegmentT& s) const override - { - return coreSegmentProcessor.process(q, s); - } - - private: - CoreSegmentQueryProcessor coreSegmentProcessor; - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp deleted file mode 100644 index 9a2a4405001f0904b74fc6afcf96813eef0879cd..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "ProviderSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h deleted file mode 100644 index 2043273ec7c5f3fee2d02410a145ef436c47459c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/ProviderSegmentQueryProcessorBase.h" - -#include "../../../core/diskmemory/ProviderSegment.h" - -#include "EntityQueryProcessor.h" - -namespace armarx::armem::d_ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class ProviderSegmentQueryProcessor : - virtual public BaseQueryProcessor<d_ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>, - virtual public base::query_proc::ProviderSegmentQueryProcessorBase<d_ltm::ProviderSegment> - { - using Base = BaseQueryProcessor<d_ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>; - - public: - ProviderSegmentQueryProcessor() : - Base() - {} - - protected: - virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const EntityT& s) const override - { - return entityProcessor.process(q, s); - } - - private: - EntityQueryProcessor entityProcessor; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.cpp deleted file mode 100644 index 68821bcd95cdf2aaccf7126d4055495d39d0393d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BaseQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.h deleted file mode 100644 index 64f560afff93e5d0cfff4b036f68f0fb4e8cdaba..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/BaseQueryProcessor.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/DataMode.h> - -#include "../base/BaseQueryProcessorBase.h" - - -namespace armarx::armem::ltm::query_proc -{ - /** - * @brief Base class for memory query processors. - */ - template <class DataT, class QueryT> - class BaseQueryProcessor : - virtual public base::query_proc::BaseQueryProcessorBase<DataT, QueryT> - { - using Base = base::query_proc::BaseQueryProcessorBase<DataT, QueryT>; - - public: - BaseQueryProcessor() - {} - - protected: - - query::data::QueryTarget getTargetType() const override - { - return query::data::QueryTarget::LTM; - } - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.cpp deleted file mode 100644 index afbe35ad15eea0342b0b0d4df0200aaf0d32aa2a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "CoreSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h deleted file mode 100644 index dc379f1d88fa82bbe886e412e0341079fa43fce9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/CoreSegmentQueryProcessorBase.h" - -#include "../../../core/longtermmemory/CoreSegment.h" - -#include "ProviderSegmentQueryProcessor.h" - - -namespace armarx::armem::ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class CoreSegmentQueryProcessor : - virtual public BaseQueryProcessor<ltm::CoreSegment, armem::query::data::CoreSegmentQuery>, - virtual public base::query_proc::CoreSegmentQueryProcessorBase<ltm::CoreSegment> - { - using Base = BaseQueryProcessor<ltm::CoreSegment, armem::query::data::CoreSegmentQuery>; - - public: - CoreSegmentQueryProcessor() : - Base() - {} - - protected: - virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override - { - return providerSegmentProcessor.process(q, s); - } - - private: - ProviderSegmentQueryProcessor providerSegmentProcessor; - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.cpp deleted file mode 100644 index c1c321b026b173c6552758fb9d8b9fdf722ea5a4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "EntityQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h deleted file mode 100644 index c7f793705e9143bb7b2f947f2750498ee26b8411..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/EntityQueryProcessorBase.h" - -#include "../../../core/longtermmemory/Entity.h" - -#include "EntityQueryProcessor.h" - -namespace armarx::armem::ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class EntityQueryProcessor : - virtual public BaseQueryProcessor<ltm::Entity, armem::query::data::EntityQuery>, - virtual public base::query_proc::EntityQueryProcessorBase<ltm::Entity> - { - using Base = BaseQueryProcessor<ltm::Entity, armem::query::data::EntityQuery>; - - public: - EntityQueryProcessor() : - Base() - {} - - private: - void addResultSnapshot(ltm::Entity& result, ltm::Entity::ContainerT::const_iterator it) const override - { - addResultSnapshot(result, it->second); - } - - void addResultSnapshot(ltm::Entity& result, const ltm::EntitySnapshot& snapshot) const override - { - result.addSnapshot(ltm::EntitySnapshot{snapshot}); - } - - }; - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.cpp deleted file mode 100644 index 69b04de6c9e623286a5bda836dddfdc8b551b64a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MemoryQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h deleted file mode 100644 index a5129417262515975efa247398602272865ee5ec..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/MemoryQueryProcessorBase.h" - -#include "../../../core/longtermmemory/Memory.h" - -#include "CoreSegmentQueryProcessor.h" - -namespace armarx::armem::ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class MemoryQueryProcessor : - virtual public BaseQueryProcessor<ltm::Memory, armem::query::data::MemoryQuery>, - virtual public base::query_proc::MemoryQueryProcessorBase<ltm::Memory> - { - using Base = BaseQueryProcessor<ltm::Memory, armem::query::data::MemoryQuery>; - - public: - MemoryQueryProcessor() : - Base() - {} - - protected: - virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegmentT& s) const override - { - return coreSegmentProcessor.process(q, s); - } - - private: - CoreSegmentQueryProcessor coreSegmentProcessor; - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.cpp deleted file mode 100644 index 9a2a4405001f0904b74fc6afcf96813eef0879cd..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "ProviderSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h deleted file mode 100644 index e0c6db9e3ef06e6241e9af8c572bb7fc78eec452..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "BaseQueryProcessor.h" -#include "../base/ProviderSegmentQueryProcessorBase.h" - -#include "../../../core/longtermmemory/ProviderSegment.h" - -#include "EntityQueryProcessor.h" - -namespace armarx::armem::ltm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class ProviderSegmentQueryProcessor : - virtual public BaseQueryProcessor<ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>, - virtual public base::query_proc::ProviderSegmentQueryProcessorBase<ltm::ProviderSegment> - { - using Base = BaseQueryProcessor<ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>; - - public: - ProviderSegmentQueryProcessor() : - Base() - {} - - protected: - virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const EntityT& s) const override - { - return entityProcessor.process(q, s); - } - - private: - EntityQueryProcessor entityProcessor; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ltm.cpp b/source/RobotAPI/libraries/armem/server/query_proc/ltm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..238cc4b8d1601bf1ffae131caabbf8ca8435899a --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/ltm.cpp @@ -0,0 +1,7 @@ +#include "ltm.h" + + +namespace armarx::armem::server::query_proc::ltm +{ +} + diff --git a/source/RobotAPI/libraries/armem/server/query_proc/ltm.h b/source/RobotAPI/libraries/armem/server/query_proc/ltm.h new file mode 100644 index 0000000000000000000000000000000000000000..ae0dc778c821ae138c98b8554a22237bf26e5989 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/ltm.h @@ -0,0 +1,32 @@ +#pragma once + +#include <RobotAPI/libraries/armem/core/longtermmemory/Memory.h> +#include <RobotAPI/libraries/armem/server/query_proc/base.h> + + +namespace armarx::armem::server::query_proc::ltm +{ + static const base::QueryTarget queryTarget = query::data::QueryTarget::LTM; + + + class EntityQueryProcessor : + public base::EntityQueryProcessorBase<queryTarget, armem::ltm::Entity, armem::ltm::Entity> + { + }; + + class ProviderSegmentQueryProcessor : + public base::ProviderSegmentQueryProcessorBase <queryTarget, armem::ltm::ProviderSegment, armem::ltm::ProviderSegment, EntityQueryProcessor > + { + }; + + class CoreSegmentQueryProcessor : + public base::CoreSegmentQueryProcessorBase <queryTarget, armem::ltm::CoreSegment, armem::ltm::CoreSegment, ProviderSegmentQueryProcessor> + { + }; + + class MemoryQueryProcessor : + public base::MemoryQueryProcessorBase <queryTarget, armem::ltm::Memory, armem::ltm::Memory, CoreSegmentQueryProcessor > + { + }; + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/wm.cpp b/source/RobotAPI/libraries/armem/server/query_proc/wm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e968623d63aa57213507879608c81823d31c7d6 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/wm.cpp @@ -0,0 +1,70 @@ +#include "wm.h" + + + +namespace armarx::armem::server::query_proc::wm::detail +{ + + HasDataMode::HasDataMode(armem::DataMode dataMode) : dataMode(dataMode) + { + } + +} + + +namespace armarx::armem::server::query_proc::wm +{ + + ProviderSegmentQueryProcessor::ProviderSegmentQueryProcessor(DataMode dataMode) : + ProviderSegmentQueryProcessorBase(dataMode), HasDataMode(dataMode) + { + } + + + CoreSegmentQueryProcessor::CoreSegmentQueryProcessor(DataMode dataMode) : + CoreSegmentQueryProcessorBase(dataMode), HasDataMode(dataMode) + { + } + + + MemoryQueryProcessor::MemoryQueryProcessor(DataMode dataMode) : + MemoryQueryProcessorBase(dataMode), HasDataMode(dataMode) + { + } + +} + + +namespace armarx::armem::server::query_proc::wm_server +{ + ProviderSegmentQueryProcessor::ProviderSegmentQueryProcessor(DataMode dataMode) : + ProviderSegmentQueryProcessorBase(dataMode), HasDataMode(dataMode) + { + } + + + CoreSegmentQueryProcessor::CoreSegmentQueryProcessor(DataMode dataMode) : + CoreSegmentQueryProcessorBase(dataMode), + HasDataMode(dataMode) + { + } + + + void CoreSegmentQueryProcessor::process( + armem::wm::CoreSegment& result, + const armem::query::data::CoreSegmentQuery& query, + const CoreSegment& coreSegment) const + { + std::scoped_lock lock(coreSegment.mutex()); + CoreSegmentQueryProcessorBase::process(result, query, coreSegment); + } + + + MemoryQueryProcessor::MemoryQueryProcessor(DataMode dataMode) : + MemoryQueryProcessorBase(dataMode), + HasDataMode(dataMode) + { + } + + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/wm.h b/source/RobotAPI/libraries/armem/server/query_proc/wm.h new file mode 100644 index 0000000000000000000000000000000000000000..aa52b4ab22fe1c6ef194ef37d4e38f5c7720d6c5 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/wm.h @@ -0,0 +1,164 @@ +#pragma once + +#include <RobotAPI/libraries/armem/core/DataMode.h> +#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> +#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h> +#include <RobotAPI/libraries/armem/server/query_proc/base.h> + + +namespace armarx::armem::server::query_proc::wm +{ + static const base::QueryTarget queryTarget = query::data::QueryTarget::WM; +} +namespace armarx::armem::server::query_proc::wm::detail +{ + + class HasDataMode + { + public: + + HasDataMode(armem::DataMode dataMode); + + + protected: + + armem::DataMode dataMode; + + }; + + + + template <class SourceEntityT> + class EntityQueryProcessor : + public base::EntityQueryProcessorBase<queryTarget, SourceEntityT, armem::wm::Entity>, + public HasDataMode + { + public: + + EntityQueryProcessor(DataMode dataMode = DataMode::WithData) : + HasDataMode(dataMode) + {} + + + protected: + + void addResultSnapshot(armem::wm::Entity& result, const typename SourceEntityT::EntitySnapshotT& snapshot) const + { + bool withData = (dataMode == DataMode::WithData); + if (withData) + { + result.addSnapshot(server::wm::EntitySnapshot{ snapshot }); + } + else + { + server::wm::EntitySnapshot copy = snapshot; + copy.forEachInstance([](server::wm::EntityInstance & i) + { + i.data() = nullptr; + return true; + }); + result.addSnapshot(std::move(copy)); + } + } + + }; +} + + +namespace armarx::armem::server::query_proc::wm +{ + + using EntityQueryProcessor = detail::EntityQueryProcessor<armem::wm::Entity>; + + + class ProviderSegmentQueryProcessor : + public base::ProviderSegmentQueryProcessorBase<queryTarget, armem::wm::ProviderSegment, armem::wm::ProviderSegment, EntityQueryProcessor >, + public detail::HasDataMode + { + public: + + ProviderSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); + + }; + + + class CoreSegmentQueryProcessor : + public base::CoreSegmentQueryProcessorBase <queryTarget, armem::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor >, + public detail::HasDataMode + { + using Base = base::CoreSegmentQueryProcessorBase<queryTarget, armem::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor>; + using CoreSegment = armem::wm::CoreSegment; + using ProviderSegment = armem::wm::ProviderSegment; + + public: + + CoreSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); + + }; + + + class MemoryQueryProcessor : + public base::MemoryQueryProcessorBase<queryTarget, armem::wm::Memory, armem::wm::Memory, CoreSegmentQueryProcessor>, + public detail::HasDataMode + { + public: + + MemoryQueryProcessor(DataMode dataMode = DataMode::WithData); + + }; + +} + + +namespace armarx::armem::server::query_proc::wm_server +{ + + using EntityQueryProcessor = wm::detail::EntityQueryProcessor<server::wm::Entity>; + + + class ProviderSegmentQueryProcessor : + public base::ProviderSegmentQueryProcessorBase<wm::queryTarget, server::wm::ProviderSegment, armem::wm::ProviderSegment, EntityQueryProcessor >, + public wm::detail::HasDataMode + { + public: + + ProviderSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); + + }; + + + class CoreSegmentQueryProcessor : + public base::CoreSegmentQueryProcessorBase <wm::queryTarget, server::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor >, + public wm::detail::HasDataMode + { + using Base = base::CoreSegmentQueryProcessorBase<wm::queryTarget, server::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor>; + using CoreSegment = server::wm::CoreSegment; + using ProviderSegment = server::wm::ProviderSegment; + + public: + + CoreSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); + + + using Base::process; + + /// Locks the core segment, then delegates back to `CoreSegmentQueryProcessorBase`. + void process( + armem::wm::CoreSegment& result, + const armem::query::data::CoreSegmentQuery& query, + const CoreSegment& coreSegment) const override; + + }; + + + class MemoryQueryProcessor : + public base::MemoryQueryProcessorBase<wm::queryTarget, server::wm::Memory, armem::wm::Memory, CoreSegmentQueryProcessor>, + public wm::detail::HasDataMode + { + public: + + MemoryQueryProcessor(DataMode dataMode = DataMode::WithData); + + }; + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.cpp deleted file mode 100644 index 68821bcd95cdf2aaccf7126d4055495d39d0393d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BaseQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.h deleted file mode 100644 index d4875053c93dc2278cdb9f327fc0739370811fe7..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/BaseQueryProcessor.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include <RobotAPI/interface/armem/query.h> -#include <RobotAPI/libraries/armem/core/DataMode.h> - -#include <RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h> - - -namespace armarx::armem::wm::query_proc -{ - /** - * @brief Base class for memory query processors. - */ - template <class DataT, class QueryT> - class BaseQueryProcessor : - virtual public base::query_proc::BaseQueryProcessorBase<DataT, QueryT> - { - using Base = base::query_proc::BaseQueryProcessorBase<DataT, QueryT>; - - public: - - BaseQueryProcessor(DataMode dataMode = DataMode::WithData) : - dataMode(dataMode) - {} - - - protected: - - query::data::QueryTarget getTargetType() const override - { - return query::data::QueryTarget::WM; - } - - DataMode dataMode; - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.cpp deleted file mode 100644 index deb66ad71924022ba5a4ebcf2aa582265023dcf5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "CoreSegmentQueryProcessor.h" - -#include <RobotAPI/libraries/armem/core/wm/ice_conversions.h> - - -namespace armarx::armem::wm::query_proc -{ - - CoreSegmentQueryProcessor::CoreSegmentQueryProcessor(DataMode dataMode) : - Base(dataMode), providerSegmentProcessor(dataMode) - {} - - - CoreSegmentQueryProcessor::~CoreSegmentQueryProcessor() = default; - - - void CoreSegmentQueryProcessor::process( - CoreSegment& result, const armem::query::data::CoreSegmentQuery& query, const CoreSegment& coreSegment) const - { - std::scoped_lock lock(coreSegment.mutex()); - CoreSegmentQueryProcessorBase::process(result, query, coreSegment); - } - - - data::CoreSegment CoreSegmentQueryProcessor::processToIce(const armem::query::data::CoreSegmentQuery& query, const wm::CoreSegment& coreSegment) const - { - data::CoreSegment data; - toIce(data, process(query, coreSegment)); - return data; - } - - - ProviderSegment CoreSegmentQueryProcessor::providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegment& s) const - { - return providerSegmentProcessor.process(q, s); - } - - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h deleted file mode 100644 index a09f5c8cef96350398e35d0448f9a3aee1f27a53..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include <mutex> - -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <RobotAPI/libraries/armem/server/query_proc/base/CoreSegmentQueryProcessorBase.h> - -#include "BaseQueryProcessor.h" -#include "ProviderSegmentQueryProcessor.h" - - -namespace armarx::armem::wm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class CoreSegmentQueryProcessor : - virtual public BaseQueryProcessor<wm::CoreSegment, armem::query::data::CoreSegmentQuery>, - virtual public base::query_proc::CoreSegmentQueryProcessorBase<wm::CoreSegment> - { - using Base = BaseQueryProcessor<wm::CoreSegment, armem::query::data::CoreSegmentQuery>; - - public: - - CoreSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); - virtual ~CoreSegmentQueryProcessor() override; - - using Base::process; - - /// Locks the core segment, then delegates back to `CoreSegmentQueryProcessorBase`. - void process(CoreSegment& result, - const armem::query::data::CoreSegmentQuery& query, - const CoreSegment& coreSegment) const override; - - data::CoreSegment processToIce(const armem::query::data::CoreSegmentQuery& query, const wm::CoreSegment& coreSegment) const; - - - protected: - - virtual ProviderSegment providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override; - - - private: - - ProviderSegmentQueryProcessor providerSegmentProcessor; - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp deleted file mode 100644 index ec1c7640c229c551d0b8b6b1a8f2df7b771139ef..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "EntityQueryProcessor.h" - -#include <RobotAPI/libraries/armem/core/wm/ice_conversions.h> - - -namespace armarx::armem::wm::query_proc -{ - EntityQueryProcessor::EntityQueryProcessor(DataMode dataMode) : - BaseQueryProcessor<wm::Entity, armem::query::data::EntityQuery>(dataMode) - {} - - - EntityQueryProcessor::~EntityQueryProcessor() = default; - - - void EntityQueryProcessor::addResultSnapshot(wm::Entity& result, const wm::EntitySnapshot& snapshot) const - { - bool withData = (dataMode == DataMode::WithData); - if (withData) - { - result.addSnapshot(wm::EntitySnapshot{ snapshot }); - } - else - { - wm::EntitySnapshot copy = snapshot; - copy.forEachInstance([](EntityInstance & i) - { - i.data() = nullptr; - return true; - }); - result.addSnapshot(std::move(copy)); - } - } - - - data::Entity EntityQueryProcessor::processToIce(const armem::query::data::EntityQuery& query, const wm::Entity& entity) const - { - data::Entity data; - toIce(data, process(query, entity)); - return data; - } - - - void EntityQueryProcessor::addResultSnapshot(wm::Entity& result, wm::Entity::ContainerT::const_iterator it) const - { - addResultSnapshot(result, it->second); - } - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.h deleted file mode 100644 index 4d0a2e02ad44a3364ee4cfd6a4e7db3b0c5fb993..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h> - -#include "BaseQueryProcessor.h" - - -namespace armarx::armem::wm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class EntityQueryProcessor : - virtual public BaseQueryProcessor<wm::Entity, armem::query::data::EntityQuery>, - virtual public base::query_proc::EntityQueryProcessorBase<wm::Entity> - { - using Base = BaseQueryProcessor<wm::Entity, armem::query::data::EntityQuery>; - - public: - - EntityQueryProcessor(DataMode dataMode = DataMode::WithData); - virtual ~EntityQueryProcessor() override; - - data::Entity processToIce(const armem::query::data::EntityQuery& query, const wm::Entity& entity) const; - - - private: - - void addResultSnapshot(wm::Entity& result, wm::Entity::ContainerT::const_iterator it) const override; - void addResultSnapshot(wm::Entity& result, const wm::EntitySnapshot& snapshot) const override; - - }; - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.cpp deleted file mode 100644 index 7aa868af13bc525b42d93f230a8398c27531525d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "MemoryQueryProcessor.h" - - -namespace armarx::armem::wm::query_proc -{ - - MemoryQueryProcessor::MemoryQueryProcessor(DataMode dataMode) : - Base(dataMode), coreSegmentProcessor(dataMode) - {} - - - MemoryQueryProcessor::~MemoryQueryProcessor() - { - } - - - CoreSegment MemoryQueryProcessor::coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegment& s) const - { - return coreSegmentProcessor.process(q, s); - } - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h deleted file mode 100644 index a442baaf38b297ab3659228e21e0a158cd00a4bb..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h> - -#include "BaseQueryProcessor.h" - -#include "CoreSegmentQueryProcessor.h" - - -namespace armarx::armem::wm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class MemoryQueryProcessor : - virtual public BaseQueryProcessor<wm::Memory, armem::query::data::MemoryQuery>, - virtual public base::query_proc::MemoryQueryProcessorBase<wm::Memory> - { - using Base = BaseQueryProcessor<wm::Memory, armem::query::data::MemoryQuery>; - - public: - - MemoryQueryProcessor(DataMode dataMode = DataMode::WithData); - virtual ~MemoryQueryProcessor() override; - - - protected: - - virtual CoreSegment coreSegmentProcessorProcess( - const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegment& s) const override; - - - private: - - CoreSegmentQueryProcessor coreSegmentProcessor; - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.cpp deleted file mode 100644 index d50d252aacbd6460bcaa668b2e983c445b018f17..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "ProviderSegmentQueryProcessor.h" - -#include <RobotAPI/libraries/armem/core/wm/ice_conversions.h> - - -namespace armarx::armem::wm::query_proc -{ - - ProviderSegmentQueryProcessor::ProviderSegmentQueryProcessor(DataMode dataMode) : - Base(dataMode), entityProcessor(dataMode) - {} - - - ProviderSegmentQueryProcessor::~ProviderSegmentQueryProcessor() = default; - - - data::ProviderSegment ProviderSegmentQueryProcessor::processToIce(const armem::query::data::ProviderSegmentQuery& query, const wm::ProviderSegment& providerSegment) const - { - data::ProviderSegment data; - toIce(data, process(query, providerSegment)); - return data; - } - - - Entity ProviderSegmentQueryProcessor::entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const Entity& s) const - { - return entityProcessor.process(q, s); - } - -} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h deleted file mode 100644 index ee878428d4e52d237bb0fe9c9050fa071c38953a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <RobotAPI/libraries/armem/server/query_proc/base/ProviderSegmentQueryProcessorBase.h> - -#include "BaseQueryProcessor.h" -#include "EntityQueryProcessor.h" - - -namespace armarx::armem::wm::query_proc -{ - /** - * @brief Handles memory queries. - */ - class ProviderSegmentQueryProcessor : - virtual public BaseQueryProcessor<wm::ProviderSegment, armem::query::data::ProviderSegmentQuery>, - virtual public base::query_proc::ProviderSegmentQueryProcessorBase<wm::ProviderSegment> - { - using Base = BaseQueryProcessor<wm::ProviderSegment, armem::query::data::ProviderSegmentQuery>; - - public: - - ProviderSegmentQueryProcessor(DataMode dataMode = DataMode::WithData); - virtual ~ProviderSegmentQueryProcessor() override; - - - using Base::process; - data::ProviderSegment processToIce(const armem::query::data::ProviderSegmentQuery& query, const wm::ProviderSegment& providerSegment) const; - - - protected: - - virtual Entity entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const Entity& s) const override; - - private: - - EntityQueryProcessor entityProcessor; - - }; -} diff --git a/source/RobotAPI/libraries/armem/server/segment/Segment.h b/source/RobotAPI/libraries/armem/server/segment/Segment.h index 52d12980eaf68a022ae595e7da41f3b2c03fd5a4..7808e99d31f4df3543bfbd5b882a408dda143ed5 100644 --- a/source/RobotAPI/libraries/armem/server/segment/Segment.h +++ b/source/RobotAPI/libraries/armem/server/segment/Segment.h @@ -16,11 +16,12 @@ namespace armarx::armem namespace server { class MemoryToIceAdapter; - } - namespace wm - { - class CoreSegment; - class ProviderSegment; + + namespace wm + { + class CoreSegment; + class ProviderSegment; + } } } namespace armarx::armem::server::segment @@ -67,9 +68,9 @@ namespace armarx::armem::server::segment /** * @brief A base class for core segments */ - class CoreSegmentBase : public detail::SegmentBase<armarx::armem::wm::CoreSegment> + class CoreSegmentBase : public detail::SegmentBase<server::wm::CoreSegment> { - using Base = detail::SegmentBase<armarx::armem::wm::CoreSegment>; + using Base = detail::SegmentBase<server::wm::CoreSegment>; public: @@ -107,9 +108,9 @@ namespace armarx::armem::server::segment /** * @brief A base class for provider segments */ - class ProviderSegmentBase : public detail::SegmentBase<armarx::armem::wm::ProviderSegment> + class ProviderSegmentBase : public detail::SegmentBase<server::wm::ProviderSegment> { - using Base = detail::SegmentBase<armarx::armem::wm::ProviderSegment>; + using Base = detail::SegmentBase<server::wm::ProviderSegment>; public: @@ -142,7 +143,7 @@ namespace armarx::armem::server::segment aron::typenavigator::ObjectNavigatorPtr coreSegmentAronType; aron::typenavigator::ObjectNavigatorPtr providerSegmentAronType; - armarx::armem::wm::CoreSegment* coreSegment; + server::wm::CoreSegment* coreSegment; }; diff --git a/source/RobotAPI/libraries/armem/server/segment/SpecializedSegment.h b/source/RobotAPI/libraries/armem/server/segment/SpecializedSegment.h index d6601c39b8076a140070db86859b38d575e52dc7..460fbf3f0f0cd4ea6c2835d499071f2e43bf2a7d 100644 --- a/source/RobotAPI/libraries/armem/server/segment/SpecializedSegment.h +++ b/source/RobotAPI/libraries/armem/server/segment/SpecializedSegment.h @@ -14,11 +14,11 @@ namespace armarx::armem namespace server { class MemoryToIceAdapter; - } - namespace wm - { - class CoreSegment; + namespace wm + { + class CoreSegment; + } } } @@ -59,7 +59,7 @@ namespace armarx::armem::server::segment protected: server::MemoryToIceAdapter& iceMemory; - wm::CoreSegment* coreSegment = nullptr; + server::wm::CoreSegment* coreSegment = nullptr; aron::typenavigator::ObjectNavigatorPtr aronType; struct Properties diff --git a/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.cpp b/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d90756691871b6ad444a67fa76a733d0086b5b29 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.cpp @@ -0,0 +1,15 @@ +#include "MaxHistorySize.h" + + +namespace armarx::armem::server::detail +{ + void MaxHistorySize::setMaxHistorySize(long maxSize) + { + this->_maxHistorySize = maxSize; + } + + long MaxHistorySize::getMaxHistorySize() const + { + return _maxHistorySize; + } +} diff --git a/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.h b/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.h new file mode 100644 index 0000000000000000000000000000000000000000..e2f2d498c2945f4456c281abafe0f1ad66074e72 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/detail/MaxHistorySize.h @@ -0,0 +1,58 @@ +#pragma once + + +namespace armarx::armem::server::detail +{ + // TODO: Replace by ConstrainedHistorySize (not only max entries, e.g. delete oldest / delete least accessed / ...) + + class MaxHistorySize + { + public: + + /** + * @brief Set the maximum number of snapshots to be contained in an entity. + * Affected entities are to be update right away. + */ + void setMaxHistorySize(long maxSize); + + long getMaxHistorySize() const; + + + protected: + + /** + * @brief Maximum size of entity histories. + * + * If negative, the size of `history` is not limited. + * + * @see Entity::maxHstorySize + */ + long _maxHistorySize = -1; + + }; + + + + template <class DerivedT> + class MaxHistorySizeParent : public MaxHistorySize + { + public: + + /** + * @brief Sets the maximum history size of entities in this container. + * This affects all current entities as well as new ones. + * + * @see MaxHistorySize::setMaxHistorySize() + */ + void setMaxHistorySize(long maxSize) + { + MaxHistorySize::setMaxHistorySize(maxSize); + static_cast<DerivedT&>(*this).forEachChild([maxSize](auto & child) + { + child.setMaxHistorySize(maxSize); + return true; + }); + } + + }; +} diff --git a/source/RobotAPI/libraries/armem/server/wm/ice_conversions.cpp b/source/RobotAPI/libraries/armem/server/wm/ice_conversions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ba3352d6e8bb443693ebfa5752a46cad9c24267 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/ice_conversions.cpp @@ -0,0 +1,64 @@ +#include "ice_conversions.h" + +#include <RobotAPI/libraries/armem/core/base/ice_conversions.h> + + +namespace armarx::armem::server +{ + + void wm::toIce(data::EntityInstance& ice, const EntityInstance& data) + { + base::toIce(ice, data); + } + void wm::fromIce(const data::EntityInstance& ice, EntityInstance& data) + { + base::fromIce(ice, data); + } + + + void wm::toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot) + { + base::toIce(ice, snapshot); + } + void wm::fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot) + { + base::fromIce(ice, snapshot); + } + + void wm::toIce(data::Entity& ice, const Entity& entity) + { + base::toIce(ice, entity); + } + void wm::fromIce(const data::Entity& ice, Entity& entity) + { + base::fromIce(ice, entity); + } + + void wm::toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment) + { + base::toIce(ice, providerSegment); + } + void wm::fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment) + { + base::fromIce(ice, providerSegment); + } + + void wm::toIce(data::CoreSegment& ice, const CoreSegment& coreSegment) + { + base::toIce(ice, coreSegment); + } + void wm::fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment) + { + base::fromIce(ice, coreSegment); + } + + void wm::toIce(data::Memory& ice, const Memory& memory) + { + base::toIce(ice, memory); + } + void wm::fromIce(const data::Memory& ice, Memory& memory) + { + base::fromIce(ice, memory); + } + +} diff --git a/source/RobotAPI/libraries/armem/server/wm/ice_conversions.h b/source/RobotAPI/libraries/armem/server/wm/ice_conversions.h new file mode 100644 index 0000000000000000000000000000000000000000..c25b16775bc577c61d0c804cf4525b23ecd5e5d1 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/ice_conversions.h @@ -0,0 +1,30 @@ +#pragma once + +#include <RobotAPI/interface/armem/memory.h> + +#include "memory_definitions.h" + + +namespace armarx::armem::server::wm +{ + + void toIce(data::EntityInstance& ice, const EntityInstance& data); + void fromIce(const data::EntityInstance& ice, EntityInstance& data); + + + void toIce(data::EntitySnapshot& ice, const EntitySnapshot& snapshot); + void fromIce(const data::EntitySnapshot& ice, EntitySnapshot& snapshot); + + void toIce(data::Entity& ice, const Entity& entity); + void fromIce(const data::Entity& ice, Entity& entity); + + + void toIce(data::ProviderSegment& ice, const ProviderSegment& providerSegment); + void fromIce(const data::ProviderSegment& ice, ProviderSegment& providerSegment); + + void toIce(data::CoreSegment& ice, const CoreSegment& coreSegment); + void fromIce(const data::CoreSegment& ice, CoreSegment& coreSegment); + + void toIce(data::Memory& ice, const Memory& memory); + void fromIce(const data::Memory& ice, Memory& memory); +} diff --git a/source/RobotAPI/libraries/armem/server/wm/memory_definitions.cpp b/source/RobotAPI/libraries/armem/server/wm/memory_definitions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..58be8027db2561979d3510b7d481715678b61eae --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/memory_definitions.cpp @@ -0,0 +1,202 @@ +#include "memory_definitions.h" + +#include "error.h" + +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <map> +#include <vector> + + +namespace armarx::armem::server::wm +{ + + void Entity::setMaxHistorySize(long maxSize) + { + MaxHistorySize::setMaxHistorySize(maxSize); + truncate(); + } + + + auto Entity::update(const EntityUpdate& update) -> UpdateResult + { + UpdateResult result = EntityBase::update(update); + result.removedSnapshots = this->truncate(); + return result; + } + + + std::vector<EntitySnapshot> Entity::truncate() + { + std::vector<EntitySnapshot> removedElements; + if (_maxHistorySize >= 0) + { + while (this->_container.size() > size_t(_maxHistorySize)) + { + removedElements.push_back(std::move(this->_container.begin()->second)); + this->_container.erase(this->_container.begin()); + } + ARMARX_CHECK_LESS_EQUAL(this->_container.size(), _maxHistorySize); + } + return removedElements; + } + + + + Entity& ProviderSegment::addEntity(Entity&& entity) + { + Entity& added = ProviderSegmentBase::addEntity(std::move(entity)); + added.setMaxHistorySize(this->getMaxHistorySize()); + return added; + } + + + + std::mutex& CoreSegment::mutex() const + { + return _mutex; + } + + + std::optional<wm::EntitySnapshot> CoreSegment::getLatestEntitySnapshot(const MemoryID& entityID) const + { + const wm::Entity& entity = this->getEntity(entityID); + if (entity.empty()) + { + return std::nullopt; + } + else + { + return entity.getLatestSnapshot(); + } + } + + + std::optional<wm::EntityInstance> CoreSegment::getLatestEntityInstance( + const MemoryID& entityID, int instanceIndex) const + { + auto snapshot = getLatestEntitySnapshot(entityID); + if (snapshot.has_value() + and instanceIndex >= 0 + and static_cast<size_t>(instanceIndex) < snapshot->size()) + { + return snapshot->getInstance(instanceIndex); + } + else + { + return std::nullopt; + } + } + + + armarx::aron::datanavigator::DictNavigatorPtr + CoreSegment::getLatestEntityInstanceData(const MemoryID& entityID, int instanceIndex) const + { + auto instance = getLatestEntityInstance(entityID, instanceIndex); + if (instance.has_value()) + { + return instance->data(); + } + else + { + return nullptr; + } + } + + + ProviderSegment& CoreSegment::addProviderSegment(ProviderSegment&& providerSegment) + { + ProviderSegmentT& added = CoreSegmentBase::addProviderSegment(std::move(providerSegment)); + added.setMaxHistorySize(this->getMaxHistorySize()); + return added; + } + + + std::optional<wm::EntitySnapshot> + CoreSegment::getLatestEntitySnapshotLocking(const MemoryID& entityID) const + { + std::scoped_lock lock(_mutex); + return getLatestEntitySnapshot(entityID); + } + + std::optional<wm::EntityInstance> + CoreSegment::getLatestEntityInstanceLocking(const MemoryID& entityID, int instanceIndex) const + { + std::scoped_lock lock(_mutex); + return getLatestEntityInstance(entityID, instanceIndex); + } + + armarx::aron::datanavigator::DictNavigatorPtr + CoreSegment::getLatestEntityInstanceDataLocking(const MemoryID& entityID, int instanceIndex) const + { + std::scoped_lock lock(_mutex); + return getLatestEntityInstanceData(entityID, instanceIndex); + } + + + // TODO: add core segment if param is set + std::vector<Memory::Base::UpdateResult> + Memory::updateLocking(const Commit& commit) + { + // Group updates by core segment, then update each core segment in a batch to only lock it once. + std::map<std::string, std::vector<const EntityUpdate*>> updatesPerCoreSegment; + for (const EntityUpdate& update : commit.updates) + { + updatesPerCoreSegment[update.entityID.coreSegmentName].push_back(&update); + } + + std::vector<Memory::Base::UpdateResult> result; + // To throw an exception after the commit if a core segment is missing and the memory should not create new ones + std::vector<std::string> missingCoreSegmentNames; + for (const auto& [coreSegmentName, updates] : updatesPerCoreSegment) + { + auto it = this->_container.find(coreSegmentName); + if (it != this->_container.end()) + { + CoreSegment& coreSegment = it->second; + + // Lock the core segment for the whole batch. + std::scoped_lock lock(coreSegment.mutex()); + + for (const EntityUpdate* update : updates) + { + auto r = coreSegment.update(*update); + Base::UpdateResult ret { r }; + ret.memoryUpdateType = UpdateType::UpdatedExisting; + result.push_back(ret); + } + } + else + { + // Perform the other updates first, then throw afterwards. + missingCoreSegmentNames.push_back(coreSegmentName); + } + } + // Throw an exception if something went wrong. + if (not missingCoreSegmentNames.empty()) + { + // Just throw an exception for the first entry. We can extend this exception in the future. + throw armem::error::MissingEntry::create<CoreSegment>(missingCoreSegmentNames.front(), *this); + } + return result; + } + + + // TODO: Add core segment if param is set + Memory::Base::UpdateResult + Memory::updateLocking(const EntityUpdate& update) + { + this->_checkContainerName(update.entityID.memoryName, this->name()); + + CoreSegment& segment = getCoreSegment(update.entityID.coreSegmentName); + Base::UpdateResult result; + { + std::scoped_lock lock(segment.mutex()); + result = segment.update(update); + } + result.memoryUpdateType = UpdateType::UpdatedExisting; + return result; + } + +} diff --git a/source/RobotAPI/libraries/armem/server/wm/memory_definitions.h b/source/RobotAPI/libraries/armem/server/wm/memory_definitions.h new file mode 100644 index 0000000000000000000000000000000000000000..cf54d95fe54913685c2bcb4d260d894898d52a34 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/wm/memory_definitions.h @@ -0,0 +1,190 @@ +#pragma once + +#include "detail/MaxHistorySize.h" + +#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> +#include <RobotAPI/libraries/armem/core/base/EntityInstanceBase.h> +#include <RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h> +#include <RobotAPI/libraries/armem/core/base/EntityBase.h> +#include <RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h> +#include <RobotAPI/libraries/armem/core/base/CoreSegmentBase.h> +#include <RobotAPI/libraries/armem/core/base/MemoryBase.h> + +#include <mutex> +#include <optional> + + +namespace armarx::armem::server::wm +{ + + using EntityInstanceMetadata = base::EntityInstanceMetadata; + using EntityInstanceData = armarx::aron::datanavigator::DictNavigator; + using EntityInstanceDataPtr = armarx::aron::datanavigator::DictNavigatorPtr; + + using EntityInstance = armem::wm::EntityInstance; + using EntitySnapshot = armem::wm::EntitySnapshot; + + + /// @see base::EntityBase + class Entity : + public base::EntityBase<EntitySnapshot, Entity>, + public detail::MaxHistorySize + { + public: + + using base::EntityBase<EntitySnapshot, Entity>::EntityBase; + + + /** + * @brief Sets the maximum history size. + * + * The current history is truncated if necessary. + */ + void setMaxHistorySize(long maxSize); + + UpdateResult update(const EntityUpdate& update); + + + protected: + + /// If maximum size is set, ensure `history`'s is not higher. + std::vector<EntitySnapshotT> truncate(); + + }; + + + + /// @see base::ProviderSegmentBase + class ProviderSegment : + public base::ProviderSegmentBase<Entity, ProviderSegment>, + public detail::MaxHistorySizeParent<ProviderSegment> + { + public: + + using base::ProviderSegmentBase<Entity, ProviderSegment>::ProviderSegmentBase; + + + using ProviderSegmentBase::addEntity; + EntityT& addEntity(EntityT&& entity); + + }; + + + + /// @brief base::CoreSegmentBase + class CoreSegment : + public base::CoreSegmentBase<ProviderSegment, CoreSegment>, + public detail::MaxHistorySizeParent<CoreSegment> + { + using Base = base::CoreSegmentBase<ProviderSegment, CoreSegment>; + + public: + + using Base::CoreSegmentBase; + + // ToDo: Replace by runLocked() + std::mutex& mutex() const; + + + // Non-locking interface + + std::optional<wm::EntitySnapshot> getLatestEntitySnapshot( + const MemoryID& entityID) const; + std::optional<wm::EntityInstance> getLatestEntityInstance( + const MemoryID& entityID, int instanceIndex = 0) const; + armarx::aron::datanavigator::DictNavigatorPtr getLatestEntityInstanceData( + const MemoryID& entityID, int instanceIndex = 0) const; + + + template <class AronDtoT> + std::optional<AronDtoT> getLatestEntityInstanceDataAs( + const MemoryID& entityID, int instanceIndex = 0) const + { + wm::EntityInstanceDataPtr data = getLatestEntityInstanceData(entityID, instanceIndex); + if (data) + { + AronDtoT aron; + aron.fromAron(data); + return aron; + } + else + { + return std::nullopt; + } + } + + + /// @see base::CoreSegmentBase::addProviderSegment() + using CoreSegmentBase::addProviderSegment; + ProviderSegment& addProviderSegment(ProviderSegment&& providerSegment); + + + // Locking interface + + std::optional<wm::EntitySnapshot> getLatestEntitySnapshotLocking( + const MemoryID& entityID) const; + std::optional<wm::EntityInstance> getLatestEntityInstanceLocking( + const MemoryID& entityID, int instanceIndex = 0) const; + armarx::aron::datanavigator::DictNavigatorPtr getLatestEntityInstanceDataLocking( + const MemoryID& entityID, int instanceIndex = 0) const; + + + template <class AronDtoT> + std::optional<AronDtoT> getLatestEntityInstanceDataLockingAs( + const MemoryID& entityID, int instanceIndex = 0) const + { + // Keep lock to a minimum. + wm::EntityInstanceDataPtr data = nullptr; + { + std::scoped_lock lock(_mutex); + data = getLatestEntityInstanceData(entityID, instanceIndex); + } + if (data) + { + AronDtoT aron; + aron.fromAron(data); + return aron; + } + else + { + return std::nullopt; + } + } + + + protected: + + mutable std::mutex _mutex; + + }; + + + + /// @see base::MemoryBase + class Memory : + public base::MemoryBase<CoreSegment, Memory> + { + using Base = base::MemoryBase<CoreSegment, Memory>; + + public: + + using Base::MemoryBase; + + + /** + * @brief Perform the commit, locking the core segments. + * + * Groups the commits by core segment, and updates each core segment + * in a batch, locking the core segment. + */ + std::vector<Base::UpdateResult> updateLocking(const Commit& commit); + + /** + * @brief Update the memory, locking the updated core segment. + */ + Base::UpdateResult updateLocking(const EntityUpdate& update); + + }; + +} +