From 0f9cced42bbe0c5ec4bac1025c12bd9fc412c632 Mon Sep 17 00:00:00 2001
From: Jens Georg <mail@jensge.org>
Date: Wed, 8 Apr 2020 15:02:27 +0200
Subject: [PATCH] Remove writeAfterOpen

Fixes #144
---
 include/DeviceModule.h            | 4 ----
 src/Application.cc                | 2 +-
 src/DeviceModule.cc               | 7 +++++--
 src/ExceptionHandlingDecorator.cc | 3 ---
 4 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/include/DeviceModule.h b/include/DeviceModule.h
index e53ecf75..44717ff2 100644
--- a/include/DeviceModule.h
+++ b/include/DeviceModule.h
@@ -257,10 +257,6 @@ namespace ChimeraTK {
      *  The function is running an endless loop inside its own thread (moduleThread). */
     void handleException();
 
-    /** List of TransferElements to be written after the device has been opened. This is used to write constant feeders
-     *  to the device. */
-    std::list<boost::shared_ptr<TransferElement>> writeAfterOpen;
-
     /** List of TransferElements to be written after the device has been recovered.
      *  See function addRecoveryAccessor() for details.*/
     std::list<boost::shared_ptr<TransferElement>> writeRecoveryOpen;
diff --git a/src/Application.cc b/src/Application.cc
index f4432022..9ed358a0 100644
--- a/src/Application.cc
+++ b/src/Application.cc
@@ -1019,7 +1019,7 @@ void Application::typedMakeConnection(VariableNetwork& network) {
           }
           assert(devmod != nullptr);
           // register feeder to be written after the device has been opened
-          devmod->writeAfterOpen.push_back(impl);
+          devmod->writeRecoveryOpen.push_back(impl);
         }
         else if(consumer.getType() == NodeType::TriggerReceiver) {
           throw ChimeraTK::logic_error("Using constants as triggers is not supported!");
diff --git a/src/DeviceModule.cc b/src/DeviceModule.cc
index ae76d4cd..64029da7 100644
--- a/src/DeviceModule.cc
+++ b/src/DeviceModule.cc
@@ -294,13 +294,16 @@ namespace ChimeraTK {
           }
         }
       }
+
       // The device was successfully opened, try to initialise it
       try {
         for(auto& initHandler : initialisationHandlers) {
           initHandler(this);
         }
-        for(auto& te : writeAfterOpen) {
-          te->write();
+        for(auto& te : writeRecoveryOpen) {
+          if(te->getVersionNumber() != VersionNumber{nullptr}) {
+            te->write();
+          }
         }
       }
       catch(ChimeraTK::runtime_error& e) {
diff --git a/src/ExceptionHandlingDecorator.cc b/src/ExceptionHandlingDecorator.cc
index 2eae375e..caa98bfa 100644
--- a/src/ExceptionHandlingDecorator.cc
+++ b/src/ExceptionHandlingDecorator.cc
@@ -52,9 +52,6 @@ namespace ChimeraTK {
             // If the application has not yet fully started, we cannot wait for the device to open. Instead register
             // the variable in the DeviceMoule, so the transfer will be performed after the device is opened.
             assert(_recoveryAccessor != nullptr); // should always be true for writeable registers with this decorator
-            // Note: it's ok to use the recoveryAccessor here as well, since device opening and recovery happens in the
-            // same thread in the DeviceModule.
-            deviceModule.writeAfterOpen.push_back(this->_recoveryAccessor);
             return false;
           }
           // We artificially increase the testabel mode counter so the test does not slip out of testable mode here in case
-- 
GitLab