changeset 1065:9d42f89b8c3c broker

improved readability
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 Oct 2019 14:08:15 +0200
parents af4b9cba905f
children b537002f83a9
files Framework/Loaders/LoaderStateMachine.cpp Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Framework/Messages/IObservable.cpp Framework/Messages/IObservable.h Framework/Messages/ObserverBase.h Framework/Scene2DViewport/MeasureTool.cpp
diffstat 6 files changed, 28 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/LoaderStateMachine.cpp	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Loaders/LoaderStateMachine.cpp	Tue Oct 15 14:08:15 2019 +0200
@@ -165,17 +165,11 @@
   {
     LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::LoaderStateMachine()";
 
-    oracleObservable.RegisterObserver<LoaderStateMachine, OrthancRestApiCommand::SuccessMessage>
-      (*this, &LoaderStateMachine::HandleSuccessMessage);
-
-    oracleObservable.RegisterObserver<LoaderStateMachine, GetOrthancImageCommand::SuccessMessage>
-      (*this, &LoaderStateMachine::HandleSuccessMessage);
-
-    oracleObservable.RegisterObserver<LoaderStateMachine, GetOrthancWebViewerJpegCommand::SuccessMessage>
-      (*this, &LoaderStateMachine::HandleSuccessMessage);
-
-    oracleObservable.RegisterObserver<LoaderStateMachine, OracleCommandExceptionMessage>
-      (*this, &LoaderStateMachine::HandleExceptionMessage);
+    // TODO => Move this out of constructor
+    Register<OrthancRestApiCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage);
+    Register<GetOrthancImageCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage);
+    Register<GetOrthancWebViewerJpegCommand::SuccessMessage>(oracleObservable, &LoaderStateMachine::HandleSuccessMessage);
+    Register<OracleCommandExceptionMessage>(oracleObservable, &LoaderStateMachine::HandleExceptionMessage);
   }
 
   LoaderStateMachine::~LoaderStateMachine()
--- a/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Tue Oct 15 14:08:15 2019 +0200
@@ -428,14 +428,15 @@
     sorter_(new BasicFetchingItemsSorter::Factory),
     volumeImageReadyInHighQuality_(false)
   {
-    oracleObservable.RegisterObserver<OrthancSeriesVolumeProgressiveLoader, OrthancRestApiCommand::SuccessMessage>
-      (*this, &OrthancSeriesVolumeProgressiveLoader::LoadGeometry);
-  
-    oracleObservable.RegisterObserver<OrthancSeriesVolumeProgressiveLoader, GetOrthancImageCommand::SuccessMessage>
-      (*this, &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent);
-    
-    oracleObservable.RegisterObserver<OrthancSeriesVolumeProgressiveLoader, GetOrthancWebViewerJpegCommand::SuccessMessage>
-      (*this, &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent);
+    // TODO => Move this out of constructor
+    Register<OrthancRestApiCommand::SuccessMessage>
+      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadGeometry);
+
+    Register<GetOrthancImageCommand::SuccessMessage>
+      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent);
+
+    Register<GetOrthancWebViewerJpegCommand::SuccessMessage>
+      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent);
   }
 
   OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader()
--- a/Framework/Messages/IObservable.cpp	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Messages/IObservable.cpp	Tue Oct 15 14:08:15 2019 +0200
@@ -56,7 +56,7 @@
   }
   
 
-  void IObservable::RegisterObserverCallback(ICallable* callable)
+  void IObservable::RegisterCallable(ICallable* callable)
   {
     if (callable == NULL)
     {
--- a/Framework/Messages/IObservable.h	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Messages/IObservable.h	Tue Oct 15 14:08:15 2019 +0200
@@ -44,12 +44,12 @@
     void EmitMessageInternal(const IObserver* receiver,
                              const IMessage& message);
 
-    // Takes ownsership of the callable
-    void RegisterObserverCallback(ICallable* callable);
-
   public:
     virtual ~IObservable();
 
+    // Takes ownsership of the callable
+    void RegisterCallable(ICallable* callable);
+
     // TODO - Remove this?
     void Unregister(IObserver* observer);
 
@@ -60,13 +60,5 @@
 
     // Takes ownsership
     void RegisterForwarder(IMessageForwarder* forwarder);
-
-    template<typename TObserver,
-             typename TMessage>
-    void RegisterObserver(TObserver& observer,
-                          void (TObserver::* MemberMethod) (const TMessage&))
-    {
-      RegisterObserverCallback(new Callable<TObserver, TMessage>(observer.GetSharedObserver(), MemberMethod));
-    }
   };
 }
--- a/Framework/Messages/ObserverBase.h	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Messages/ObserverBase.h	Tue Oct 15 14:08:15 2019 +0200
@@ -23,6 +23,7 @@
 
 #include "ICallable.h"
 #include "IObserver.h"
+#include "IObservable.h"
 
 #include <Core/OrthancException.h>
 
@@ -54,5 +55,12 @@
     {
       return new Callable<TObserver, TMessage>(GetSharedObserver(), MemberMethod);
     }
+
+    template <typename TMessage>
+    void Register(IObservable& observable,
+                  void (TObserver::* MemberMethod) (const TMessage&))
+    {
+      observable.RegisterCallable(CreateCallable(MemberMethod));
+    }
   };
 }
--- a/Framework/Scene2DViewport/MeasureTool.cpp	Tue Oct 15 13:46:01 2019 +0200
+++ b/Framework/Scene2DViewport/MeasureTool.cpp	Tue Oct 15 14:08:15 2019 +0200
@@ -84,8 +84,8 @@
     : controllerW_(controllerW)
     , enabled_(true)
   {
-    GetController()->RegisterObserver<MeasureTool, ViewportController::SceneTransformChanged>
-      (*this, &MeasureTool::OnSceneTransformChanged);
+    // TODO => Move this out of constructor
+    Register<ViewportController::SceneTransformChanged>(*GetController(), &MeasureTool::OnSceneTransformChanged);
   }