From 87474ee7a277d76ac93dccb70fe9f49aa67c81e2 Mon Sep 17 00:00:00 2001
From: uhfpm_plewnia <uhfpm@student.kit.edu>
Date: Tue, 22 Aug 2023 15:30:48 +0200
Subject: [PATCH] fixed issue with starting and stopping of recording several
 parallel LTMs at once

---
 .../armem/server/MemoryToIceAdapter.cpp       | 41 ++++++++++++-------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp
index 6a8c3a3a3..d9c6a40aa 100644
--- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp
+++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp
@@ -524,8 +524,30 @@ namespace armarx::armem::server
         ARMARX_TRACE;
         ARMARX_CHECK_NOT_NULL(longtermMemory);
         ARMARX_IMPORTANT << "Enabling the recording of memory " << longtermMemory->id().str();
-        longtermMemory->startRecording(); // TODO: config and execution time!
-        //other LTMs only start recording when defined from the beginning
+        std::vector<armarx::armem::server::ltm::Memory*> ltms;
+        ltms.push_back(longtermMemory);
+        ltms.push_back(secondLTM);
+        ltms.push_back(thirdLTM);
+        ltms.push_back(fourthLTM);
+        ltms.push_back(fiftLTM);
+        ltms.push_back(sixthLTM);
+        ltms.push_back(seventhLTM);
+        ltms.push_back(eightLTM);
+        ltms.push_back(ninthLTM);
+        ltms.push_back(tenthLTM);
+        ltms.push_back(eleventhLTM);
+        /*
+        ltms.push_back(twelvethLTM);
+        ltms.push_back(thirteenthLTM);
+        ltms.push_back(fourteenthLTM);
+        ltms.push_back(fifteenthLTM);
+        ltms.push_back(sixteenthLTM);
+        */
+        for(int i = 0; i < static_cast<int>(ltms.size()); i++){
+          ltms.at(i)->startRecording();
+        }
+        //longtermMemory->startRecording(); // TODO: config and execution time!
+
 
         dto::StartRecordResult ret;
         ret.success = true;
@@ -560,7 +582,7 @@ namespace armarx::armem::server
         ltms.push_back(sixteenthLTM);
         */
         std::vector<std::thread> threads;
-        for(int i = 0; i < 5; ++i){
+        for(int i = 0; i < static_cast<int>(ltms.size()); ++i){
             threads.push_back(std::thread([i, &ltms]{
                 ltms.at(i)->stopRecording();
             }));
@@ -570,17 +592,8 @@ namespace armarx::armem::server
             thread.join();
         }
 
-        ARMARX_INFO << "Stopped all LTM recordings";
-
-        /**
-        thirdLTM->stopRecording();
-        longtermMemory->stopRecording();
-        secondLTM->stopRecording();
-
-        fourthLTM->stopRecording();
-        fiftLTM->stopRecording();
-
-        */
+        ARMARX_INFO << "Stopped all LTM recordings, please wait with stopping the component until "
+                       "all files are written";
 
         dto::StopRecordResult ret;
         ret.success = true;
-- 
GitLab