changeset 1075:81b29bc7c3d4 broker

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2019 14:39:51 +0200
parents 229ea1389845
children 008dbc4ceb62
files Framework/Loaders/LoaderStateMachine.cpp Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Framework/Messages/IMessageEmitter.h Framework/Messages/IObservable.cpp Framework/Messages/IObservable.h Framework/Messages/LockingEmitter.cpp Framework/Messages/LockingEmitter.h Framework/Oracle/GetOrthancImageCommand.cpp Framework/Oracle/GetOrthancImageCommand.h Framework/Oracle/GetOrthancWebViewerJpegCommand.cpp Framework/Oracle/GetOrthancWebViewerJpegCommand.h Framework/Oracle/IOracle.h Framework/Oracle/ThreadedOracle.cpp Framework/Oracle/ThreadedOracle.h
diffstat 14 files changed, 37 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/LoaderStateMachine.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Loaders/LoaderStateMachine.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -97,7 +97,8 @@
         ") < simultaneousDownloads_ (" << simultaneousDownloads_ << 
         ") --> will Schedule command addr " << std::hex << nextCommand << std::dec;
 
-      oracle_.Schedule(*this, nextCommand);
+      boost::shared_ptr<IObserver> observer(GetSharedObserver());
+      oracle_.Schedule(observer, nextCommand);
       pendingCommands_.pop_front();
 
       activeCommands_++;
--- a/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -292,7 +292,9 @@
       }
 
       command->SetPayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex));
-      oracle_.Schedule(*this, command.release());
+
+      boost::shared_ptr<IObserver> observer(GetSharedObserver());
+      oracle_.Schedule(observer, command.release());
     }
     else
     {
@@ -479,7 +481,8 @@
       command->SetUri("/series/" + seriesId + "/instances-tags");
 
 //      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries about to call oracle_.Schedule";
-      oracle_.Schedule(*this, command.release());
+      boost::shared_ptr<IObserver> observer(GetSharedObserver());
+      oracle_.Schedule(observer, command.release());
 //      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries called oracle_.Schedule";
     }
   }
--- a/Framework/Messages/IMessageEmitter.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Messages/IMessageEmitter.h	Thu Oct 17 14:39:51 2019 +0200
@@ -24,6 +24,8 @@
 #include "IObserver.h"
 #include "IMessage.h"
 
+#include <boost/weak_ptr.hpp>
+
 namespace OrthancStone
 {
   /**
@@ -39,7 +41,7 @@
     {
     }
 
-    virtual void EmitMessage(const IObserver& observer,
+    virtual void EmitMessage(boost::weak_ptr<IObserver>& observer,
                              const IMessage& message) = 0;
   };
 }
--- a/Framework/Messages/IObservable.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Messages/IObservable.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -94,11 +94,16 @@
   }
 
   
-  void IObservable::EmitMessage(const IObserver& observer,
+  void IObservable::EmitMessage(boost::weak_ptr<IObserver>& observer,
                                 const IMessage& message)
   {
     LOG(TRACE) << "IObservable::EmitMessage observer = "
       << std::hex << &observer << std::dec;
-    EmitMessageInternal(&observer, message);
+
+    boost::shared_ptr<IObserver> lock(observer.lock());
+    if (lock)
+    {
+      EmitMessageInternal(lock.get(), message);
+    }
   }
 }
--- a/Framework/Messages/IObservable.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Messages/IObservable.h	Thu Oct 17 14:39:51 2019 +0200
@@ -48,7 +48,7 @@
 
     void BroadcastMessage(const IMessage& message);
 
-    void EmitMessage(const IObserver& observer,
+    void EmitMessage(boost::weak_ptr<IObserver>& observer,
                      const IMessage& message);
   };
 }
--- a/Framework/Messages/LockingEmitter.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Messages/LockingEmitter.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -24,7 +24,7 @@
 
 namespace OrthancStone
 {
-  void LockingEmitter::EmitMessage(IObserver& observer,
+  void LockingEmitter::EmitMessage(boost::weak_ptr<IObserver>& observer,
                                    const IMessage& message)
   {
     try
--- a/Framework/Messages/LockingEmitter.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Messages/LockingEmitter.h	Thu Oct 17 14:39:51 2019 +0200
@@ -45,7 +45,7 @@
     IObservable          oracleObservable_;
 
   public:
-    virtual void EmitMessage(IObserver& observer,
+    virtual void EmitMessage(boost::weak_ptr<IObserver>& observer,
                              const IMessage& message) ORTHANC_OVERRIDE;
 
 
--- a/Framework/Oracle/GetOrthancImageCommand.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/GetOrthancImageCommand.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -83,7 +83,7 @@
   }
 
   void GetOrthancImageCommand::ProcessHttpAnswer(IMessageEmitter& emitter,
-                                                 const IObserver& receiver,
+                                                 boost::weak_ptr<IObserver>& receiver,
                                                  const std::string& answer,
                                                  const HttpHeaders& answerHeaders) const
   {
--- a/Framework/Oracle/GetOrthancImageCommand.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/GetOrthancImageCommand.h	Thu Oct 17 14:39:51 2019 +0200
@@ -112,7 +112,7 @@
     }
 
     void ProcessHttpAnswer(IMessageEmitter& emitter,
-                           const IObserver& receiver,
+                           boost::weak_ptr<IObserver>& receiver,
                            const std::string& answer,
                            const HttpHeaders& answerHeaders) const;
   };
--- a/Framework/Oracle/GetOrthancWebViewerJpegCommand.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/GetOrthancWebViewerJpegCommand.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -77,7 +77,7 @@
 
 
   void GetOrthancWebViewerJpegCommand::ProcessHttpAnswer(IMessageEmitter& emitter,
-                                                         const IObserver& receiver,
+                                                         boost::weak_ptr<IObserver>& receiver,
                                                          const std::string& answer) const
   {
     // This code comes from older "OrthancSlicesLoader::ParseSliceImageJpeg()"
--- a/Framework/Oracle/GetOrthancWebViewerJpegCommand.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/GetOrthancWebViewerJpegCommand.h	Thu Oct 17 14:39:51 2019 +0200
@@ -129,7 +129,7 @@
     std::string GetUri() const;
 
     void ProcessHttpAnswer(IMessageEmitter& emitter,
-                           const IObserver& receiver,
+                           boost::weak_ptr<IObserver>& receiver,
                            const std::string& answer) const;
   };
 }
--- a/Framework/Oracle/IOracle.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/IOracle.h	Thu Oct 17 14:39:51 2019 +0200
@@ -33,7 +33,7 @@
     {
     }
 
-    virtual void Schedule(const IObserver& receiver,
+    virtual void Schedule(boost::shared_ptr<IObserver>& receiver,
                           IOracleCommand* command) = 0;  // Takes ownership
   };
 }
--- a/Framework/Oracle/ThreadedOracle.cpp	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/ThreadedOracle.cpp	Thu Oct 17 14:39:51 2019 +0200
@@ -39,11 +39,11 @@
   class ThreadedOracle::Item : public Orthanc::IDynamicObject
   {
   private:
-    const IObserver&                receiver_;
+    boost::weak_ptr<IObserver>      receiver_;
     std::auto_ptr<IOracleCommand>   command_;
 
   public:
-    Item(const IObserver& receiver,
+    Item(boost::weak_ptr<IObserver> receiver,
          IOracleCommand* command) :
       receiver_(receiver),
       command_(command)
@@ -54,7 +54,7 @@
       }
     }
 
-    const IObserver& GetReceiver() const
+    boost::weak_ptr<IObserver>& GetReceiver()
     {
       return receiver_;
     }
@@ -73,12 +73,12 @@
     class Item
     {
     private:
-      const IObserver&                   receiver_;
+      boost::weak_ptr<IObserver>         receiver_;
       std::auto_ptr<SleepOracleCommand>  command_;
       boost::posix_time::ptime           expiration_;
 
     public:
-      Item(const IObserver& receiver,
+      Item(boost::weak_ptr<IObserver>& receiver,
            SleepOracleCommand* command) :
         receiver_(receiver),
         command_(command)
@@ -123,7 +123,7 @@
       }
     }
 
-    void Add(const IObserver& receiver,
+    void Add(boost::weak_ptr<IObserver>& receiver,
              SleepOracleCommand* command)   // Takes ownership
     {
       boost::mutex::scoped_lock lock(mutex_);
@@ -213,7 +213,7 @@
 
 
   static void Execute(IMessageEmitter& emitter,
-                      const IObserver& receiver,
+                      boost::weak_ptr<IObserver>& receiver,
                       const HttpCommand& command)
   {
     Orthanc::HttpClient client;
@@ -242,7 +242,7 @@
 
   static void Execute(IMessageEmitter& emitter,
                       const Orthanc::WebServiceParameters& orthanc,
-                      const IObserver& receiver,
+                      boost::weak_ptr<IObserver>& receiver,
                       const OrthancRestApiCommand& command)
   {
     Orthanc::HttpClient client(orthanc, command.GetUri());
@@ -270,7 +270,7 @@
 
   static void Execute(IMessageEmitter& emitter,
                       const Orthanc::WebServiceParameters& orthanc,
-                      const IObserver& receiver,
+                      boost::weak_ptr<IObserver>& receiver,
                       const GetOrthancImageCommand& command)
   {
     Orthanc::HttpClient client(orthanc, command.GetUri());
@@ -290,7 +290,7 @@
 
   static void Execute(IMessageEmitter& emitter,
                       const Orthanc::WebServiceParameters& orthanc,
-                      const IObserver& receiver,
+                      boost::weak_ptr<IObserver>& receiver,
                       const GetOrthancWebViewerJpegCommand& command)
   {
     Orthanc::HttpClient client(orthanc, command.GetUri());
@@ -563,7 +563,7 @@
   }
 
 
-  void ThreadedOracle::Schedule(const IObserver& receiver,
+  void ThreadedOracle::Schedule(boost::shared_ptr<IObserver>& receiver,
                                 IOracleCommand* command)
   {
     queue_.Enqueue(new Item(receiver, command));
--- a/Framework/Oracle/ThreadedOracle.h	Thu Oct 17 13:48:52 2019 +0200
+++ b/Framework/Oracle/ThreadedOracle.h	Thu Oct 17 14:39:51 2019 +0200
@@ -88,7 +88,7 @@
       StopInternal();
     }
 
-    virtual void Schedule(const IObserver& receiver,
+    virtual void Schedule(boost::shared_ptr<IObserver>& receiver,
                           IOracleCommand* command);
   };
 }