From cf37106587bfd4c77c710421ca78afc6046c7897 Mon Sep 17 00:00:00 2001
From: Joana <joana.plewnia@kit.edu>
Date: Mon, 29 Jul 2024 14:52:16 +0200
Subject: [PATCH] Loading LTM into current WM on startup of memory server. As
 the snapshots are the oldest though, they will be forgotten relatively fast
 if maxHistorySize for that CoreSegment is small. Currently import path is
 assumed to be the same as export path or empty. When empty, nothing is done,
 when non-empty export path and export name are used to import last snapshots
 for this memory.

---
 .../armem/server/ltm/detail/MemoryBase.h      | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h b/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
index 99df8e2e6..e085590fe 100644
--- a/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
+++ b/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
@@ -52,6 +52,8 @@ namespace armarx::armem::server::ltm::detail
         configure()
         {
             bool en = p.enabled_on_startup;
+            ARMARX_INFO << VAROUT(p.import_name);
+            ARMARX_INFO << VAROUT(p.import_path);
             ARMARX_INFO << VAROUT(p.configuration_on_startup);
             ARMARX_INFO << VAROUT(p.export_name);
             this->setExportName(p.export_name);
@@ -75,6 +77,12 @@ namespace armarx::armem::server::ltm::detail
             {
                 this->startRecording();
             }
+
+            std::string importPath = p.import_path;
+
+            if (importPath.length() > 0){
+                this->loadOnStartup();
+            }
         }
 
         /// enable this LTM
@@ -203,6 +211,8 @@ namespace armarx::armem::server::ltm::detail
             defs->optional(p.enabled_on_startup, prefix + "enabled");
             defs->optional(p.configuration_on_startup, prefix + "configuration");
             defs->optional(p.export_name, prefix + "exportName");
+            defs->optional(p.import_name, prefix + "importName");
+            defs->optional(p.import_path, prefix + "importPath");
         }
 
         /// enable/disable
@@ -270,6 +280,16 @@ namespace armarx::armem::server::ltm::detail
             return "LT-Memory";
         }
 
+        void loadOnStartup(){
+            ARMARX_INFO << "Loading on startup from " << p.import_path << "/" << p.import_name;
+            try{
+                this->loadAllAndResolve();
+            }
+            catch(...){
+                ARMARX_INFO << "Could not load memory " << this->name() << " on startup";
+            }
+        }
+
     protected:
         /// configuration
         virtual void
@@ -307,6 +327,8 @@ namespace armarx::armem::server::ltm::detail
                 "\"PngConverter\": {}, \"ExrConverter\": {}}"; //record with 20 fps as standard
             std::string export_name = "MemoryExport";
             std::string export_path = "/tmp/ltm";
+            std::string import_path = "/tmp/ltm";
+            std::string import_name = "MemoryExport";
         } p;
 
     protected:
-- 
GitLab