changeset 1074:229ea1389845 broker

LockingEmitter.cpp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2019 13:48:52 +0200
parents 8d3936f06541
children 81b29bc7c3d4
files Framework/Messages/LockingEmitter.cpp Framework/Messages/LockingEmitter.h Resources/CMake/OrthancStoneConfiguration.cmake
diffstat 3 files changed, 50 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Framework/Messages/LockingEmitter.cpp	Thu Oct 17 13:48:52 2019 +0200
@@ -0,0 +1,40 @@
+/**
+ * Stone of Orthanc
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017-2019 Osimis S.A., Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "LockingEmitter.h"
+
+#include <Core/OrthancException.h>
+
+namespace OrthancStone
+{
+  void LockingEmitter::EmitMessage(IObserver& observer,
+                                   const IMessage& message)
+  {
+    try
+    {
+      boost::unique_lock<boost::shared_mutex>  lock(mutex_);
+      oracleObservable_.EmitMessage(observer, message);
+    }
+    catch (Orthanc::OrthancException& e)
+    {
+      LOG(ERROR) << "Exception while emitting a message: " << e.What();
+    }
+  }
+}
--- a/Framework/Messages/LockingEmitter.h	Thu Oct 17 11:27:51 2019 +0200
+++ b/Framework/Messages/LockingEmitter.h	Thu Oct 17 13:48:52 2019 +0200
@@ -23,7 +23,9 @@
 #include "IMessageEmitter.h"
 #include "IObservable.h"
 
-#include <boost/thread.hpp>
+#include <Core/Enumerations.h>  // For ORTHANC_OVERRIDE
+
+#include <boost/thread/shared_mutex.hpp>
 
 namespace OrthancStone
 {
@@ -43,19 +45,8 @@
     IObservable          oracleObservable_;
 
   public:
-    virtual void EmitMessage(const IObserver& observer,
-      const IMessage& message) ORTHANC_OVERRIDE
-    {
-      try
-      {
-        boost::unique_lock<boost::shared_mutex>  lock(mutex_);
-        oracleObservable_.EmitMessage(observer, message);
-      }
-      catch (Orthanc::OrthancException& e)
-      {
-        LOG(ERROR) << "Exception while emitting a message: " << e.What();
-      }
-    }
+    virtual void EmitMessage(IObserver& observer,
+                             const IMessage& message) ORTHANC_OVERRIDE;
 
 
     class ReaderLock : public boost::noncopyable
@@ -66,8 +57,8 @@
 
     public:
       ReaderLock(LockingEmitter& that) :
-        that_(that),
-        lock_(that.mutex_)
+      that_(that),
+      lock_(that.mutex_)
       {
       }
     };
@@ -81,8 +72,8 @@
 
     public:
       WriterLock(LockingEmitter& that) :
-        that_(that),
-        lock_(that.mutex_)
+      that_(that),
+      lock_(that.mutex_)
       {
       }
 
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Thu Oct 17 11:27:51 2019 +0200
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Thu Oct 17 13:48:52 2019 +0200
@@ -401,6 +401,7 @@
 
 if (ENABLE_THREADS)
   list(APPEND ORTHANC_STONE_SOURCES
+    ${ORTHANC_STONE_ROOT}/Framework/Messages/LockingEmitter.cpp
     ${ORTHANC_STONE_ROOT}/Framework/Messages/LockingEmitter.h
     ${ORTHANC_STONE_ROOT}/Framework/Oracle/ThreadedOracle.cpp
     )