From 38fd10f950cd1c1bc14cde5c70e901bda78bc8d4 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Mon, 20 Jan 2020 20:07:08 +0100
Subject: [PATCH] some code cleanup and comments

---
 src/DeviceModule.cc                            |  8 +++-----
 src/ExceptionHandlingDecorator.cc              | 17 +++++++++--------
 .../testProcessVariableRecovery.cc             | 18 ++++++++----------
 3 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/DeviceModule.cc b/src/DeviceModule.cc
index 34b5a7d8..3fa2ca8f 100644
--- a/src/DeviceModule.cc
+++ b/src/DeviceModule.cc
@@ -294,8 +294,6 @@ namespace ChimeraTK {
         }
         for(auto& te : writeAfterOpen) {
           te->write();
-//          addRecoveryAccessor(te);
-
         }
       }
       catch(ChimeraTK::runtime_error& e) {
@@ -372,12 +370,12 @@ namespace ChimeraTK {
           for(auto& te : writeAfterOpen) {
             te->write();
           }
-          {
-            boost::unique_lock<boost::shared_mutex> uniiqueLock(recoverySharedMutex);
+          { // scope for the lock guard
+            boost::unique_lock<boost::shared_mutex> uniqueLock(recoverySharedMutex);
             for(auto& te : writeRecoveryOpen) {
               te->write();
             }
-          }
+          } // end of scope for the lock guard
         }
         catch(ChimeraTK::runtime_error& e) {
           // Report the error. This puts the exception to the queue and we can continue with waiting for the queue.
diff --git a/src/ExceptionHandlingDecorator.cc b/src/ExceptionHandlingDecorator.cc
index cc09ec7a..6ef4d3c8 100644
--- a/src/ExceptionHandlingDecorator.cc
+++ b/src/ExceptionHandlingDecorator.cc
@@ -16,10 +16,9 @@ namespace ChimeraTK {
   ExceptionHandlingDecorator<UserType>::ExceptionHandlingDecorator(
       boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> accessor, DeviceModule& devMod,
       boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> recoveryAccessor)
-    : ExceptionHandlingDecorator<UserType>(accessor, devMod) {
-
+  : ExceptionHandlingDecorator<UserType>(accessor, devMod) {
     // Register recoveryAccessor at the DeviceModule
-    if(recoveryAccessor != nullptr){
+    if(recoveryAccessor != nullptr) {
       _recoveryAccessor = recoveryAccessor;
       dm.addRecoveryAccessor(_recoveryAccessor);
     }
@@ -111,16 +110,18 @@ namespace ChimeraTK {
     {
       auto lock{dm.getRecoverySharedLock()};
 
-      if(_recoveryAccessor != nullptr){
+      if(_recoveryAccessor != nullptr) {
         // Access to _recoveryAccessor is only possible channel-wise
-        for(unsigned int ch=0; ch<_recoveryAccessor->getNumberOfChannels(); ++ch){
+        for(unsigned int ch = 0; ch < _recoveryAccessor->getNumberOfChannels(); ++ch) {
           _recoveryAccessor->accessChannel(ch) = buffer_2D[ch];
         }
       }
-      else{
-        throw ChimeraTK::logic_error("ChimeraTK::ExceptionhandlingDecorator: Calling write() on a non-writeable accessor is not supported ");
+      else {
+        throw ChimeraTK::logic_error(
+            "ChimeraTK::ExceptionhandlingDecorator: Calling write() on a non-writeable accessor is not supported ");
       }
-    }
+    } // lock guard goes out of scope
+
     // Now delegate call to the generic decorator, which swaps the buffer
     genericTransfer([this]() { return ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPreWrite(), true; });
   }
diff --git a/tests/executables_src/testProcessVariableRecovery.cc b/tests/executables_src/testProcessVariableRecovery.cc
index 1b5c5612..666cdf9e 100644
--- a/tests/executables_src/testProcessVariableRecovery.cc
+++ b/tests/executables_src/testProcessVariableRecovery.cc
@@ -62,7 +62,7 @@ struct TestApplication : public ctk::Application {
  */
 struct ReadOnlyTestApplication : public ctk::Application {
   ReadOnlyTestApplication() : Application("ReadOnlytestApp") {}
-  ~ReadOnlyTestApplication(){ shutdown(); }
+  ~ReadOnlyTestApplication() { shutdown(); }
 
   void defineConnections() {
     dev["TEST"]("FROM_DEV_SCALAR2") >> module("FROM_DEV_SCALAR2");
@@ -75,24 +75,23 @@ struct ReadOnlyTestApplication : public ctk::Application {
   struct TestModule : public ctk::ApplicationModule {
     using ctk::ApplicationModule::ApplicationModule;
 
-    ctk::ScalarPushInput<int>     start{this, "startTest", "", "This has to be written once, before writing to the device", {"CS"}};
+    ctk::ScalarPushInput<int> start{
+        this, "startTest", "", "This has to be written once, before writing to the device", {"CS"}};
     ctk::ScalarPollInput<int32_t> scalarROInput{this, "FROM_DEV_SCALAR2", "", "Here I read from a scalar RO-register"};
 
     void mainLoop() override {
-
       // Just to have a blocking read, gives the test
       // time to dumpConnections and explicitly trigger
       // before terminating.
       start.read();
 
       scalarROInput = 42;
-      try{
+      try {
         scalarROInput.write();
-        BOOST_CHECK_MESSAGE(false,
-          "ReadOnlyTestApplication: Calling write() on input to read-only device register did not throw.");
+        BOOST_CHECK_MESSAGE(
+            false, "ReadOnlyTestApplication: Calling write() on input to read-only device register did not throw.");
       }
-      catch(ChimeraTK::logic_error &e){
-
+      catch(ChimeraTK::logic_error& e) {
         const std::string exMsg{e.what()};
         std::regex exceptionHandlingRegex{"^ChimeraTK::ExceptionhandlingDecorator:*"};
         std::smatch exMatch;
@@ -106,7 +105,7 @@ struct ReadOnlyTestApplication : public ctk::Application {
 
 /*********************************************************************************************************************/
 
-BOOST_AUTO_TEST_CASE(testWriteToReadOnly){
+BOOST_AUTO_TEST_CASE(testWriteToReadOnly) {
   std::cout << "testWriteToReadOnly" << std::endl;
 
   ReadOnlyTestApplication app;
@@ -123,7 +122,6 @@ BOOST_AUTO_TEST_CASE(testWriteToReadOnly){
   test.writeScalar("/READ_ONLY_TEST/startTest", 1);
 }
 
-
 BOOST_AUTO_TEST_CASE(testProcessVariableRecovery) {
   std::cout << "testProcessVariableRecovery" << std::endl;
   TestApplication app;
-- 
GitLab