From dac499f5ad06a275605e278f71f2a84ddab097d2 Mon Sep 17 00:00:00 2001
From: albrecpe <albrecpe@gmail.com>
Date: Fri, 8 Mar 2024 17:00:51 +0100
Subject: [PATCH] Implement snapshot fetching

---
 .../skills_gui/memory/SkillManagerWrapper.cpp |  8 ++++-
 .../skills_gui/memory/SkillManagerWrapper.h   | 36 ++++++++++++-------
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp
index d8ff3fd78..bf3db4738 100644
--- a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp
+++ b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.cpp
@@ -10,7 +10,7 @@ namespace armarx::skills::gui
     using SkillMap =
         std::map<skills::ProviderID, std::map<skills::SkillID, skills::SkillDescription>>;
 
-    const StatusMap
+    StatusMap
     SkillManagerWrapper::fetchExecutions()
     {
         if (!memory)
@@ -197,6 +197,12 @@ namespace armarx::skills::gui
         }
     }
 
+    void SkillManagerWrapper::updateFromMemory()
+    {
+        snapshot.statuses = fetchExecutions();
+        snapshot.skills = fetchSkills();
+    }
+
     const std::optional<ProviderID>
     SkillManagerWrapper::findFirstProvider(SkillMap const& map, SkillID const& skillId)
     {
diff --git a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.h b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.h
index 5b81961b5..ea902a723 100644
--- a/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.h
+++ b/source/RobotAPI/libraries/skills_gui/memory/SkillManagerWrapper.h
@@ -52,18 +52,6 @@ namespace armarx::skills::gui
         void stopExecution(skills::SkillExecutionID const& executionId,
                            const unsigned int max_retries = 0);
 
-        /**
-         * @brief Fetches and returns the latest skills update from memory.
-         * @return The map representing all skills in memory. Empty, if error occurred.
-         */
-        const SkillMap fetchSkills();
-
-        /**
-         * @brief Fetches and returns the latest status update from memory.
-         * @return The map containing status updates for all execution ids. Empty, if error occurred.
-         */
-        const StatusMap fetchExecutions();
-
         static const std::optional<skills::ProviderID> findFirstProvider(SkillMap const& map,
                                                                          SkillID const& skillId);
 
@@ -87,6 +75,11 @@ namespace armarx::skills::gui
          */
         void stopAllExecutions();
 
+        /**
+         * @brief Requests this wrapper to overwrite its own state from memory.
+         */
+        void updateFromMemory();
+
     private:
         mutable std::mutex mutex_memory;
 
@@ -96,8 +89,27 @@ namespace armarx::skills::gui
         struct Snapshot {
             StatusMap statuses;
             SkillMap skills;
+
+            // default constructor (construct empty)
+            Snapshot() : statuses({}), skills({})
+            {
+            }
         };
 
+        Snapshot snapshot;
+
+        /**
+         * @brief Fetches and returns the latest skills update from memory.
+         * @return The map representing all skills in memory. Empty, if error occurred.
+         */
+        SkillMap fetchSkills();
+
+        /**
+         * @brief Fetches and returns the latest status update from memory.
+         * @return The map containing status updates for all execution ids. Empty, if error occurred.
+         */
+        StatusMap fetchExecutions();
+
         /**
          * @brief Modifies the given map to match the search.
          * @param update The map to modify.
-- 
GitLab