From fdf01373c6df4614821c30560245497ef3a76e6f Mon Sep 17 00:00:00 2001
From: Christoph Pohl <christoph.pohl@kit.edu>
Date: Sat, 25 Mar 2023 16:42:33 +0100
Subject: [PATCH] Improve memory reader interface

---
 .../armarx/manipulation/client/core/Reader.h  | 19 +++++++++++++------
 .../client/executable_action/Reader.cpp       |  6 ++----
 .../client/executable_action/Reader.h         |  4 +---
 .../client/executed_action/Reader.cpp         |  7 +++----
 .../client/executed_action/Reader.h           |  4 +---
 5 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/source/armarx/manipulation/client/core/Reader.h b/source/armarx/manipulation/client/core/Reader.h
index c15bfb72..dda03ffc 100644
--- a/source/armarx/manipulation/client/core/Reader.h
+++ b/source/armarx/manipulation/client/core/Reader.h
@@ -47,7 +47,7 @@ namespace armarx::manipulation::memory::client::core
         using armem::client::util::SimpleReaderBase::SimpleReaderBase;
 
         std::vector<BusinessObj>
-        query(const std::string& providerName,
+        query(const std::optional<std::string>& providerName = std::nullopt,
               const std::optional<std::string>& entityName = std::nullopt,
               const std::optional<armem::Time>& startTime = std::nullopt,
               const std::optional<armem::Time>& endTime = std::nullopt)
@@ -60,8 +60,15 @@ namespace armarx::manipulation::memory::client::core
 
             ps = std::experimental::make_observer(&qb.coreSegments()
                                                        .withName(properties().coreSegmentName)
-                                                       .providerSegments()
-                                                       .withName(providerName));
+                                                       .providerSegments());
+            if (providerName.has_value())
+            {
+                ps = std::experimental::make_observer(&ps->withName(providerName.value()));
+            }
+            else
+            {
+                ps = std::experimental::make_observer(&ps->all());
+            }
             if (entityName.has_value())
             {
                 es = std::experimental::make_observer(&ps->entities().withName(entityName.value()));
@@ -82,7 +89,7 @@ namespace armarx::manipulation::memory::client::core
             }
             (void*)ss.get();
             const auto query = qb.buildQueryInput();
-            return fromQuery(memoryReader().query(query), providerName);
+            return fromQuery(memoryReader().query(query));
         }
 
         std::string
@@ -100,9 +107,9 @@ namespace armarx::manipulation::memory::client::core
 
     private:
         std::vector<BusinessObj>
-        fromQuery(const armem::client::QueryResult& query, const std::string& providerName)
+        fromQuery(const armem::client::QueryResult& query)
         {
-            return ImplT::fromQuery(query, properties().coreSegmentName, providerName);
+            return ImplT::fromQuery(query, properties().coreSegmentName);
         }
     };
 } // namespace armarx::manipulation::memory::client::core
\ No newline at end of file
diff --git a/source/armarx/manipulation/client/executable_action/Reader.cpp b/source/armarx/manipulation/client/executable_action/Reader.cpp
index e651bda3..de8f78df 100644
--- a/source/armarx/manipulation/client/executable_action/Reader.cpp
+++ b/source/armarx/manipulation/client/executable_action/Reader.cpp
@@ -30,11 +30,9 @@ namespace armarx::manipulation::memory::client::core
     std::vector<manipulation::core::ExecutableAction>
     ReaderImplementation<armarx::manipulation::core::ExecutableAction>::fromQuery(
         const armem::client::QueryResult& query,
-        const std::string& coreSegment,
-        const std::string& providerSegment)
+        const std::string& coreSegment)
     {
-        const auto& segment =
-            query.memory.getCoreSegment(coreSegment).getProviderSegment(providerSegment);
+        const auto& segment = query.memory.getCoreSegment(coreSegment);
         std::vector<armarx::manipulation::core::ExecutableAction> actions;
         segment.forEachInstance(
             [&actions](const auto& instance)
diff --git a/source/armarx/manipulation/client/executable_action/Reader.h b/source/armarx/manipulation/client/executable_action/Reader.h
index b5deea26..18a8945d 100644
--- a/source/armarx/manipulation/client/executable_action/Reader.h
+++ b/source/armarx/manipulation/client/executable_action/Reader.h
@@ -37,9 +37,7 @@ namespace armarx::manipulation::memory::client
             static constexpr std::string_view providerName = "";
 
             static std::vector<manipulation::core::ExecutableAction>
-            fromQuery(const armem::client::QueryResult& query,
-                      const std::string& coreSegment,
-                      const std::string& providerSegment);
+            fromQuery(const armem::client::QueryResult& query, const std::string& coreSegment);
         };
 
 
diff --git a/source/armarx/manipulation/client/executed_action/Reader.cpp b/source/armarx/manipulation/client/executed_action/Reader.cpp
index 649ae25f..5f5cc43c 100644
--- a/source/armarx/manipulation/client/executed_action/Reader.cpp
+++ b/source/armarx/manipulation/client/executed_action/Reader.cpp
@@ -31,11 +31,10 @@ namespace armarx::manipulation::memory::client::core
     std::vector<manipulation::core::ExecutedAction>
     ReaderImplementation<armarx::manipulation::core::ExecutedAction>::fromQuery(
         const armem::client::QueryResult& query,
-        const std::string& coreSegment,
-        const std::string& providerSegment)
+        const std::string& coreSegment)
     {
-        const auto& segment =
-            query.memory.getCoreSegment(coreSegment).getProviderSegment(providerSegment);
+        const auto& segment = query.memory.getCoreSegment(coreSegment);
+
         std::vector<armarx::manipulation::core::ExecutedAction> actions;
         segment.forEachInstance(
             [&actions](const auto& instance)
diff --git a/source/armarx/manipulation/client/executed_action/Reader.h b/source/armarx/manipulation/client/executed_action/Reader.h
index 47177179..f58a1e27 100644
--- a/source/armarx/manipulation/client/executed_action/Reader.h
+++ b/source/armarx/manipulation/client/executed_action/Reader.h
@@ -37,9 +37,7 @@ namespace armarx::manipulation::memory::client
             static constexpr std::string_view providerName = "";
 
             static std::vector<manipulation::core::ExecutedAction>
-            fromQuery(const armem::client::QueryResult& query,
-                      const std::string& coreSegment,
-                      const std::string& providerSegment);
+            fromQuery(const armem::client::QueryResult& query, const std::string& coreSegment);
         };
 
 
-- 
GitLab