From ee9af09334b8f3781c0dfb70604d29b797695737 Mon Sep 17 00:00:00 2001
From: Fabian Paus <fabian.paus@kit.edu>
Date: Thu, 30 Dec 2021 16:00:41 +0100
Subject: [PATCH] ArViz: Create new function to send back interactions during a
 pullUpdates call

---
 source/RobotAPI/components/ArViz/ArVizStorage.cpp    |  8 ++++++++
 source/RobotAPI/components/ArViz/ArVizStorage.h      |  4 ++++
 source/RobotAPI/components/ArViz/Coin/Visualizer.cpp | 12 +++++-------
 source/RobotAPI/components/ArViz/Coin/Visualizer.h   |  2 +-
 source/RobotAPI/interface/ArViz/Component.ice        |  3 +++
 source/RobotAPI/interface/ArViz/Elements.ice         |  2 ++
 6 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/source/RobotAPI/components/ArViz/ArVizStorage.cpp b/source/RobotAPI/components/ArViz/ArVizStorage.cpp
index 1fbb408cc..3891d216e 100644
--- a/source/RobotAPI/components/ArViz/ArVizStorage.cpp
+++ b/source/RobotAPI/components/ArViz/ArVizStorage.cpp
@@ -205,6 +205,14 @@ namespace armarx
         return result;
     }
 
+    viz::data::LayerUpdates ArVizStorage::pullUpdatesSinceAndSendInteractions(
+            Ice::Long revision, viz::data::InteractionFeedbackSeq const& interactions, const Ice::Current& c)
+    {
+        // TODO: Implement storing the interactions somewhere
+
+        return pullUpdatesSince(revision, c);
+    }
+
     void ArVizStorage::record()
     {
         while (!recordingTask->isStopped())
diff --git a/source/RobotAPI/components/ArViz/ArVizStorage.h b/source/RobotAPI/components/ArViz/ArVizStorage.h
index 02ebc9815..69299fb6e 100644
--- a/source/RobotAPI/components/ArViz/ArVizStorage.h
+++ b/source/RobotAPI/components/ArViz/ArVizStorage.h
@@ -86,6 +86,10 @@ namespace armarx
 
         // StorageInterface interface
         viz::data::LayerUpdates pullUpdatesSince(Ice::Long revision, const Ice::Current&) override;
+        viz::data::LayerUpdates pullUpdatesSinceAndSendInteractions(
+                Ice::Long revision,
+                viz::data::InteractionFeedbackSeq const& interactions,
+                const Ice::Current&) override;
         std::string startRecording(std::string const& prefix, const Ice::Current&) override;
         void stopRecording(const Ice::Current&) override;
         viz::data::RecordingSeq getAllRecordings(const Ice::Current&) override;
diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
index 2c5ab83a7..f1675bdd2 100644
--- a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
+++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp
@@ -95,7 +95,7 @@ namespace armarx::viz
 
         callbackData = new CoinVisualizerWrapper;
         callbackData->this_ = this;
-        callback = newCallback_StorageInterface_pullUpdatesSince(callbackData,
+        callback = newCallback_StorageInterface_pullUpdatesSinceAndSendInteractions(callbackData,
                    &CoinVisualizerWrapper::onUpdateSuccess,
                    &CoinVisualizerWrapper::onUpdateFailure);
 
@@ -385,8 +385,8 @@ namespace armarx::viz
                 storage = stateStorage;
                 root->removeAllChildren();
                 layers.data.clear();
-                edUpdates.revision = 0;
-                edUpdates.updates.clear();
+                pulledUpdates.revision = 0;
+                pulledUpdates.updates.clear();
                 updateResult = CoinVisualizerUpdateResult::SUCCESS;
                 state = CoinVisualizerState::RUNNING;
             }
@@ -417,10 +417,8 @@ namespace armarx::viz
                 data::LayerUpdates currentUpdates = pulledUpdates;
                 updateResult = CoinVisualizerUpdateResult::WAITING;
                 timing.waitStart = time_start;
-                storage->begin_pullUpdatesSince(currentUpdates.revision, callback);
-
-                // TODO: Also send the interaction feedback to the storage
-                //       Would be best to do it in a single network call
+                storage->begin_pullUpdatesSinceAndSendInteractions(
+                            currentUpdates.revision, interactionFeedbackBuffer, callback);
 
                 // Clear interaction feedback buffer after it has been sent
                 interactionFeedbackBuffer.clear();
diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.h b/source/RobotAPI/components/ArViz/Coin/Visualizer.h
index 0581a3869..cffa7eb0c 100644
--- a/source/RobotAPI/components/ArViz/Coin/Visualizer.h
+++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.h
@@ -247,7 +247,7 @@ namespace armarx::viz
         void onUpdateSuccess(data::LayerUpdates const& updates);
         void onUpdateFailure(Ice::Exception const& ex);
         IceUtil::Handle<CoinVisualizerWrapper> callbackData;
-        armarx::viz::Callback_StorageInterface_pullUpdatesSincePtr callback;
+        armarx::viz::Callback_StorageInterface_pullUpdatesSinceAndSendInteractionsPtr callback;
 
         std::mutex storageMutex;
         viz::StorageInterfacePrx storage;
diff --git a/source/RobotAPI/interface/ArViz/Component.ice b/source/RobotAPI/interface/ArViz/Component.ice
index 6a855c934..8972819ea 100644
--- a/source/RobotAPI/interface/ArViz/Component.ice
+++ b/source/RobotAPI/interface/ArViz/Component.ice
@@ -90,6 +90,9 @@ interface StorageInterface
 {
     data::LayerUpdates pullUpdatesSince(long revision);
 
+    data::LayerUpdates pullUpdatesSinceAndSendInteractions(
+                long revision, data::InteractionFeedbackSeq interactions);
+
     string startRecording(string prefix);
 
     void stopRecording();
diff --git a/source/RobotAPI/interface/ArViz/Elements.ice b/source/RobotAPI/interface/ArViz/Elements.ice
index 8b7aa4db0..550f75bbf 100644
--- a/source/RobotAPI/interface/ArViz/Elements.ice
+++ b/source/RobotAPI/interface/ArViz/Elements.ice
@@ -99,6 +99,8 @@ module data
         GlobalPose chosenPose;
     };
 
+    sequence<InteractionFeedback> InteractionFeedbackSeq;
+
     module ElementFlags
     {
         const int NONE = 0;
-- 
GitLab