changeset 1097:4383382db01d broker

deprecating LockingEmitter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Oct 2019 22:31:18 +0200
parents 97cbb2c31a65
children 17660df24c36
files Applications/Generic/GuiAdapter.cpp Applications/Generic/GuiAdapter.h Framework/Loaders/LoaderCache.cpp Framework/Loaders/LoaderCache.h Framework/Messages/LockingEmitter.cpp Framework/Messages/LockingEmitter.h Framework/Oracle/OrthancRestApiCommand.cpp Framework/Oracle/OrthancRestApiCommand.h Framework/Oracle/ThreadedOracle.cpp
diffstat 9 files changed, 93 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Generic/GuiAdapter.cpp	Thu Oct 24 09:38:17 2019 +0200
+++ b/Applications/Generic/GuiAdapter.cpp	Thu Oct 24 22:31:18 2019 +0200
@@ -792,7 +792,7 @@
     while (!stop)
     {
       {
-        LockingEmitter::WriterLock lock(lockingEmitter_);
+        Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
         if(func != NULL)
           (*func)(cookie);
         OnAnimationFrame(); // in SDL we must call it
@@ -802,7 +802,7 @@
 
       while (!stop && SDL_PollEvent(&event))
       {
-        LockingEmitter::WriterLock lock(lockingEmitter_);
+        Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
 
         if (event.type == SDL_QUIT)
         {
--- a/Applications/Generic/GuiAdapter.h	Thu Oct 24 09:38:17 2019 +0200
+++ b/Applications/Generic/GuiAdapter.h	Thu Oct 24 22:31:18 2019 +0200
@@ -95,7 +95,10 @@
   struct GuiAdapterWheelEvent;
   struct GuiAdapterKeyboardEvent;
 
-  class LockingEmitter;
+  namespace Deprecated
+  {
+    class LockingEmitter;
+  }
     
 #if 1
   typedef bool (*OnMouseEventFunc)(std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData);
@@ -225,7 +228,7 @@
   {
   public:
 #if ORTHANC_ENABLE_THREADS == 1
-    GuiAdapter(LockingEmitter& lockingEmitter) : lockingEmitter_(lockingEmitter)
+    GuiAdapter(Deprecated::LockingEmitter& lockingEmitter) : lockingEmitter_(lockingEmitter)
 #else
     GuiAdapter()
 #endif
@@ -301,7 +304,7 @@
     This object is used by the multithreaded Oracle to serialize access to
     shared data. We need to use it as soon as we access the state.
     */
-    LockingEmitter& lockingEmitter_;
+    Deprecated::LockingEmitter& lockingEmitter_;
 #endif
 
     /**
--- a/Framework/Loaders/LoaderCache.cpp	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Loaders/LoaderCache.cpp	Thu Oct 24 22:31:18 2019 +0200
@@ -65,7 +65,7 @@
 
   }
 #else
-  LoaderCache::LoaderCache(ThreadedOracle& oracle, LockingEmitter& lockingEmitter)
+  LoaderCache::LoaderCache(ThreadedOracle& oracle, Deprecated::LockingEmitter& lockingEmitter)
     : oracle_(oracle)
     , lockingEmitter_(lockingEmitter)
   {
@@ -98,7 +98,7 @@
 #if ORTHANC_ENABLE_WASM == 1
           loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, oracle_));
 #else
-          LockingEmitter::WriterLock lock(lockingEmitter_);
+          Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
           loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, lock.GetOracleObservable()));
 #endif
 //          LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : loader = " << loader.get();
@@ -167,7 +167,7 @@
 #if ORTHANC_ENABLE_WASM == 1
           loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, oracle_));
 #else
-          LockingEmitter::WriterLock lock(lockingEmitter_);
+          Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
           loader.reset(new OrthancMultiframeVolumeLoader(volumeImage, oracle_, lock.GetOracleObservable()));
 #endif
           loader->LoadInstance(instanceUuid);
@@ -268,7 +268,7 @@
 #if ORTHANC_ENABLE_WASM == 1
           loader.reset(new DicomStructureSetLoader(oracle_, oracle_));
 #else
-          LockingEmitter::WriterLock lock(lockingEmitter_);
+          Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
           loader.reset(new DicomStructureSetLoader(oracle_, lock.GetOracleObservable()));
 #endif
           loader->LoadInstance(inInstanceUuid, initiallyVisibleStructures);
@@ -364,7 +364,7 @@
   void LoaderCache::ClearCache()
   {
 #if ORTHANC_ENABLE_WASM != 1
-    LockingEmitter::WriterLock lock(lockingEmitter_);
+    Deprecated::LockingEmitter::WriterLock lock(lockingEmitter_);
 #endif
     
 //#ifndef NDEBUG
--- a/Framework/Loaders/LoaderCache.h	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Loaders/LoaderCache.h	Thu Oct 24 22:31:18 2019 +0200
@@ -43,7 +43,10 @@
   class WebAssemblyOracle;
 #else
   class ThreadedOracle;
-  class LockingEmitter;
+  namespace Deprecated
+  {
+    class LockingEmitter;
+  }
 #endif
 
   class LoaderCache
@@ -52,7 +55,7 @@
 #if ORTHANC_ENABLE_WASM == 1
     LoaderCache(WebAssemblyOracle& oracle);
 #else
-    LoaderCache(ThreadedOracle& oracle, LockingEmitter& lockingEmitter);
+    LoaderCache(ThreadedOracle& oracle, Deprecated::LockingEmitter& lockingEmitter);
 #endif
 
     boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader>
@@ -87,7 +90,7 @@
     WebAssemblyOracle& oracle_;
 #else
     ThreadedOracle& oracle_;
-    LockingEmitter& lockingEmitter_;
+    Deprecated::LockingEmitter& lockingEmitter_;
 #endif
 
     std::map<std::string, boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> >
--- a/Framework/Messages/LockingEmitter.cpp	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Messages/LockingEmitter.cpp	Thu Oct 24 22:31:18 2019 +0200
@@ -24,17 +24,20 @@
 
 namespace OrthancStone
 {
-  void LockingEmitter::EmitMessage(boost::weak_ptr<IObserver>& observer,
-                                   const IMessage& message)
+  namespace Deprecated
   {
-    try
+    void LockingEmitter::EmitMessage(boost::weak_ptr<IObserver>& observer,
+                                     const IMessage& message)
     {
-      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();
+      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 24 09:38:17 2019 +0200
+++ b/Framework/Messages/LockingEmitter.h	Thu Oct 24 22:31:18 2019 +0200
@@ -32,58 +32,61 @@
 
 namespace OrthancStone
 {
-  /**
-   * This class is used when using the ThreadedOracle : since messages
-   * can be sent from multiple Oracle threads, this IMessageEmitter
-   * implementation serializes the callbacks.
-   * 
-   * The internal mutex used in Oracle messaging can also be used to 
-   * protect the application data. Thus, this class can be used as a single
-   * application-wide mutex.
-   */
-  class LockingEmitter : public IMessageEmitter
+  namespace Deprecated
   {
-  private:
-    boost::shared_mutex  mutex_;
-    IObservable          oracleObservable_;
-
-  public:
-    virtual void EmitMessage(boost::weak_ptr<IObserver>& observer,
-                             const IMessage& message) ORTHANC_OVERRIDE;
-
-
-    class ReaderLock : public boost::noncopyable
+    /**
+     * This class is used when using the ThreadedOracle : since messages
+     * can be sent from multiple Oracle threads, this IMessageEmitter
+     * implementation serializes the callbacks.
+     * 
+     * The internal mutex used in Oracle messaging can also be used to 
+     * protect the application data. Thus, this class can be used as a single
+     * application-wide mutex.
+     */
+    class LockingEmitter : public IMessageEmitter
     {
     private:
-      LockingEmitter& that_;
-      boost::shared_lock<boost::shared_mutex>  lock_;
+      boost::shared_mutex  mutex_;
+      IObservable          oracleObservable_;
 
     public:
-      ReaderLock(LockingEmitter& that) :
-      that_(that),
-      lock_(that.mutex_)
+      virtual void EmitMessage(boost::weak_ptr<IObserver>& observer,
+                               const IMessage& message) ORTHANC_OVERRIDE;
+
+
+      class ReaderLock : public boost::noncopyable
       {
-      }
-    };
+      private:
+        LockingEmitter& that_;
+        boost::shared_lock<boost::shared_mutex>  lock_;
+
+      public:
+        ReaderLock(LockingEmitter& that) :
+        that_(that),
+        lock_(that.mutex_)
+        {
+        }
+      };
 
 
-    class WriterLock : public boost::noncopyable
-    {
-    private:
-      LockingEmitter& that_;
-      boost::unique_lock<boost::shared_mutex>  lock_;
+      class WriterLock : public boost::noncopyable
+      {
+      private:
+        LockingEmitter& that_;
+        boost::unique_lock<boost::shared_mutex>  lock_;
 
-    public:
-      WriterLock(LockingEmitter& that) :
-      that_(that),
-      lock_(that.mutex_)
-      {
-      }
+      public:
+        WriterLock(LockingEmitter& that) :
+        that_(that),
+        lock_(that.mutex_)
+        {
+        }
 
-      IObservable& GetOracleObservable()
-      {
-        return that_.oracleObservable_;
-      }
+        IObservable& GetOracleObservable()
+        {
+          return that_.oracleObservable_;
+        }
+      };
     };
-  };
+  }
 }
--- a/Framework/Oracle/OrthancRestApiCommand.cpp	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Oracle/OrthancRestApiCommand.cpp	Thu Oct 24 22:31:18 2019 +0200
@@ -51,7 +51,8 @@
   OrthancRestApiCommand::OrthancRestApiCommand() :
     method_(Orthanc::HttpMethod_Get),
     uri_("/"),
-    timeout_(600)
+    timeout_(600),
+    applyPlugins_(false)
   {
   }
 
--- a/Framework/Oracle/OrthancRestApiCommand.h	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Oracle/OrthancRestApiCommand.h	Thu Oct 24 22:31:18 2019 +0200
@@ -69,6 +69,7 @@
     std::string          body_;
     HttpHeaders          headers_;
     unsigned int         timeout_;
+    bool                 applyPlugins_;  // Only makes sense for Stone as an Orthanc plugin
 
   public:
     OrthancRestApiCommand();
@@ -137,5 +138,15 @@
     {
       return timeout_;
     }
+
+    void SetApplyPlugins(bool applyPlugins)
+    {
+      applyPlugins_ = applyPlugins;
+    }
+
+    bool IsApplyPlugins() const
+    {
+      return applyPlugins_;
+    }
   };
 }
--- a/Framework/Oracle/ThreadedOracle.cpp	Thu Oct 24 09:38:17 2019 +0200
+++ b/Framework/Oracle/ThreadedOracle.cpp	Thu Oct 24 22:31:18 2019 +0200
@@ -255,6 +255,8 @@
         delete workers_[i];
       }
     } 
+
+    queue_.Clear();
   }
 
 
@@ -287,7 +289,7 @@
     catch (...)
     {
       LOG(ERROR) << "Native exception while stopping the threaded oracle";
-    }           
+    }
   }