changeset 393:e7a494bdd956

removed Messages/MessageType.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Nov 2018 18:30:30 +0100
parents d87fe075d31b
children 17d54c028805
files Applications/Samples/SimpleViewer/Messages.h Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp Applications/Samples/SimpleViewerApplicationSingleFile.h Applications/Samples/SingleFrameApplication.h Applications/Samples/SingleFrameEditorApplication.h Framework/Messages/IMessage.h Framework/Messages/IObservable.h Framework/Messages/IObserver.h Framework/Messages/MessageType.h Framework/SmartLoader.cpp Framework/StoneEnumerations.h Resources/CMake/OrthancStoneConfiguration.cmake UnitTestsSources/TestMessageBroker2.cpp
diffstat 13 files changed, 93 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Samples/SimpleViewer/Messages.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Applications/Samples/SimpleViewer/Messages.h	Fri Nov 09 18:30:30 2018 +0100
@@ -1,13 +1,10 @@
 #pragma once
 
-#include "Framework/Messages/MessageType.h"
-
 namespace SimpleViewer
 {
   enum SimpleViewerMessageType
   {
     SimpleViewerMessageType_First = OrthancStone::MessageType_CustomMessage,
     SimpleViewerMessageType_AppStatusUpdated
-
   };
 }
--- a/Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp	Fri Nov 09 17:59:35 2018 +0100
+++ b/Applications/Samples/SimpleViewer/SimpleViewerApplication.cpp	Fri Nov 09 18:30:30 2018 +0100
@@ -54,17 +54,17 @@
       thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
       thumbnailsLayout_->SetVertical();
 
-      mainWidget_ = new SliceViewerWidget(IObserver::broker_, "main-viewport");
+      mainWidget_ = new SliceViewerWidget(IObserver::GetBroker(), "main-viewport");
       //mainWidget_->RegisterObserver(*this);
 
       // hierarchy
       mainLayout_->AddWidget(thumbnailsLayout_);
       mainLayout_->AddWidget(mainWidget_);
 
-      orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
+      orthancApiClient_.reset(new OrthancApiClient(IObserver::GetBroker(), context_->GetWebService()));
 
       // sources
-      smartLoader_.reset(new SmartLoader(IObserver::broker_, *orthancApiClient_));
+      smartLoader_.reset(new SmartLoader(IObserver::GetBroker(), *orthancApiClient_));
       smartLoader_->SetImageQuality(SliceImageQuality_FullPam);
 
       mainLayout_->SetTransmitMouseOver(true);
@@ -153,7 +153,7 @@
   {
     LOG(INFO) << "Loading thumbnail for series " << seriesId;
     SliceViewerWidget* thumbnailWidget = 
-      new SliceViewerWidget(IObserver::broker_, "thumbnail-series-" + seriesId);
+      new SliceViewerWidget(IObserver::GetBroker(), "thumbnail-series-" + seriesId);
     thumbnails_.push_back(thumbnailWidget);
     thumbnailsLayout_->AddWidget(thumbnailWidget);
     thumbnailWidget->RegisterObserverCallback(
--- a/Applications/Samples/SimpleViewerApplicationSingleFile.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Applications/Samples/SimpleViewerApplicationSingleFile.h	Fri Nov 09 18:30:30 2018 +0100
@@ -298,17 +298,17 @@
           thumbnailsLayout_->SetBackgroundColor(50, 50, 50);
           thumbnailsLayout_->SetVertical();
 
-          mainWidget_ = new SliceViewerWidget(broker_, "main-viewport");
+          mainWidget_ = new SliceViewerWidget(GetBroker(), "main-viewport");
           //mainWidget_->RegisterObserver(*this);
 
           // hierarchy
           mainLayout_->AddWidget(thumbnailsLayout_);
           mainLayout_->AddWidget(mainWidget_);
 
-          orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
+          orthancApiClient_.reset(new OrthancApiClient(GetBroker(), context_->GetWebService()));
 
           // sources
-          smartLoader_.reset(new SmartLoader(IObserver::broker_, *orthancApiClient_));
+          smartLoader_.reset(new SmartLoader(GetBroker(), *orthancApiClient_));
           smartLoader_->SetImageQuality(SliceImageQuality_FullPam);
 
           mainLayout_->SetTransmitMouseOver(true);
@@ -393,7 +393,7 @@
       void LoadThumbnailForSeries(const std::string& seriesId, const std::string& instanceId)
       {
         LOG(INFO) << "Loading thumbnail for series " << seriesId;
-        SliceViewerWidget* thumbnailWidget = new SliceViewerWidget(IObserver::broker_, "thumbnail-series-" + seriesId);
+        SliceViewerWidget* thumbnailWidget = new SliceViewerWidget(GetBroker(), "thumbnail-series-" + seriesId);
         thumbnails_.push_back(thumbnailWidget);
         thumbnailsLayout_->AddWidget(thumbnailWidget);
         thumbnailWidget->RegisterObserverCallback(new Callable<SimpleViewerApplication, SliceViewerWidget::GeometryChangedMessage>(*this, &SimpleViewerApplication::OnWidgetGeometryChanged));
--- a/Applications/Samples/SingleFrameApplication.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Applications/Samples/SingleFrameApplication.h	Fri Nov 09 18:30:30 2018 +0100
@@ -242,10 +242,10 @@
         std::string instance = parameters["instance"].as<std::string>();
         int frame = parameters["frame"].as<unsigned int>();
 
-        orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
-        mainWidget_ = new SliceViewerWidget(broker_, "main-widget");
+        orthancApiClient_.reset(new OrthancApiClient(GetBroker(), context_->GetWebService()));
+        mainWidget_ = new SliceViewerWidget(GetBroker(), "main-widget");
 
-        std::auto_ptr<OrthancFrameLayerSource> layer(new OrthancFrameLayerSource(broker_, *orthancApiClient_));
+        std::auto_ptr<OrthancFrameLayerSource> layer(new OrthancFrameLayerSource(GetBroker(), *orthancApiClient_));
         source_ = layer.get();
         layer->LoadFrame(instance, frame);
         layer->RegisterObserverCallback(new Callable<SingleFrameApplication, ILayerSource::GeometryReadyMessage>(*this, &SingleFrameApplication::OnMainWidgetGeometryReady));
--- a/Applications/Samples/SingleFrameEditorApplication.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Applications/Samples/SingleFrameEditorApplication.h	Fri Nov 09 18:30:30 2018 +0100
@@ -2890,12 +2890,12 @@
         std::string instance = parameters["instance"].as<std::string>();
         int frame = parameters["frame"].as<unsigned int>();
 
-        orthancApiClient_.reset(new OrthancApiClient(IObserver::broker_, context_->GetWebService()));
+        orthancApiClient_.reset(new OrthancApiClient(GetBroker(), context_->GetWebService()));
 
         Orthanc::FontRegistry fonts;
         fonts.AddFromResource(Orthanc::EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
         
-        stack_.reset(new BitmapStack(IObserver::broker_, *orthancApiClient_));
+        stack_.reset(new BitmapStack(GetBroker(), *orthancApiClient_));
         stack_->LoadFrame(instance, frame, false); //.SetPan(200, 0);
         //stack_->LoadFrame("61f3143e-96f34791-ad6bbb8d-62559e75-45943e1b", 0, false);
 
@@ -2913,7 +2913,7 @@
         }
         
         
-        mainWidget_ = new BitmapStackWidget(IObserver::broker_, *stack_, "main-widget");
+        mainWidget_ = new BitmapStackWidget(GetBroker(), *stack_, "main-widget");
         mainWidget_->SetTransmitMouseOver(true);
         mainWidget_->SetInteractor(interactor_);
 
--- a/Framework/Messages/IMessage.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Framework/Messages/IMessage.h	Fri Nov 09 18:30:30 2018 +0100
@@ -21,13 +21,12 @@
 
 #pragma once
 
-#include "MessageType.h"
+#include "../StoneEnumerations.h"
 
 #include <boost/noncopyable.hpp>
 
-namespace OrthancStone {
-
-
+namespace OrthancStone 
+{
   // base message that are exchanged between IObservable and IObserver
   class IMessage : public boost::noncopyable
   {
--- a/Framework/Messages/IObservable.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Framework/Messages/IObservable.h	Fri Nov 09 18:30:30 2018 +0100
@@ -21,39 +21,33 @@
 
 #pragma once
 
-#include <set>
-#include <assert.h>
-#include <algorithm>
-#include <iostream>
-#include <map>
-
-
-#include "MessageBroker.h"
-#include "MessageType.h"
+#include "../StoneEnumerations.h"
 #include "ICallable.h"
 #include "IObserver.h"
+#include "MessageBroker.h"
 #include "MessageForwarder.h"
 
-namespace OrthancStone {
+#include <set>
+#include <map>
 
-
+namespace OrthancStone 
+{
   class IObservable : public boost::noncopyable
   {
-  protected:
-    MessageBroker&                     broker_;
+  private:
+    typedef std::map<int, std::set<ICallable*> >  Callables;
+    typedef std::set<IMessageForwarder*>          Forwarders;
 
-    typedef std::map<int, std::set<ICallable*> >   Callables;
-    Callables                         callables_;
-
-    typedef std::set<IMessageForwarder*>      Forwarders;
-    Forwarders                        forwarders_;
+    MessageBroker&  broker_;
+    Callables       callables_;
+    Forwarders      forwarders_;
 
   public:
-
-    IObservable(MessageBroker& broker)
-      : broker_(broker)
+    IObservable(MessageBroker& broker) :
+      broker_(broker)
     {
     }
+
     virtual ~IObservable()
     {
       // delete all callables (this will also unregister them from the broker)
@@ -105,6 +99,9 @@
       forwarders_.insert(forwarder);
     }
 
+    MessageBroker& GetBroker() const
+    {
+      return broker_;
+    }
   };
-
 }
--- a/Framework/Messages/IObserver.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Framework/Messages/IObserver.h	Fri Nov 09 18:30:30 2018 +0100
@@ -23,21 +23,17 @@
 
 #include "MessageBroker.h"
 #include "IMessage.h"
-#include <set>
-#include <assert.h>
 
-namespace OrthancStone {
-
-  class IObservable;
-
+namespace OrthancStone 
+{
   class IObserver : public boost::noncopyable
   {
-  protected:
-    MessageBroker&                    broker_;
+  private:
+    MessageBroker&  broker_;
 
   public:
-    IObserver(MessageBroker& broker)
-      : broker_(broker)
+    IObserver(MessageBroker& broker) :
+      broker_(broker)
     {
       broker_.Register(*this);
     }
@@ -46,6 +42,10 @@
     {
       broker_.Unregister(*this);
     }
+
+    MessageBroker& GetBroker() const
+    {
+      return broker_;
+    }
   };
-
 }
--- a/Framework/Messages/MessageType.h	Fri Nov 09 17:59:35 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/**
- * Stone of Orthanc
- * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
- * Department, University Hospital of Liege, Belgium
- * Copyright (C) 2017-2018 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/>.
- **/
-
-#pragma once
-
-namespace OrthancStone {
-
-  enum MessageType
-  {
-    MessageType_Widget_GeometryChanged,
-    MessageType_Widget_ContentChanged,
-
-    MessageType_LayerSource_GeometryReady,   // instance tags have been loaded
-    MessageType_LayerSource_GeometryError,
-    MessageType_LayerSource_ContentChanged,
-    MessageType_LayerSource_SliceChanged,
-    MessageType_LayerSource_ImageReady,      // instance pixels data have been loaded
-    MessageType_LayerSource_LayerReady,      // layer is ready to be rendered
-    MessageType_LayerSource_LayerError,
-
-    MessageType_SliceLoader_GeometryReady,
-    MessageType_SliceLoader_GeometryError,
-    MessageType_SliceLoader_ImageReady,
-    MessageType_SliceLoader_ImageError,
-
-    MessageType_HttpRequestSuccess,
-    MessageType_HttpRequestError,
-
-    MessageType_OrthancApi_InternalGetJsonResponseReady,
-    MessageType_OrthancApi_InternalGetJsonResponseError,
-
-    MessageType_OrthancApi_GenericGetJson_Ready,
-    MessageType_OrthancApi_GenericGetBinary_Ready,
-    MessageType_OrthancApi_GenericHttpError_Ready,
-    MessageType_OrthancApi_GenericEmptyResponse_Ready,
-
-    MessageType_ViewportChanged,
-
-    // used in unit tests only
-    MessageType_Test1,
-    MessageType_Test2,
-
-    MessageType_CustomMessage // Custom messages ids ust be greater than this (this one must remain in last position)
-  };
-}
--- a/Framework/SmartLoader.cpp	Fri Nov 09 17:59:35 2018 +0100
+++ b/Framework/SmartLoader.cpp	Fri Nov 09 18:30:30 2018 +0100
@@ -105,7 +105,7 @@
 
     CachedSlice* Clone() const
     {
-      CachedSlice* output = new CachedSlice(broker_);
+      CachedSlice* output = new CachedSlice(GetBroker());
       output->sliceIndex_ = sliceIndex_;
       output->slice_.reset(slice_->Clone());
       output->image_ = image_;
@@ -150,7 +150,7 @@
     }
     else
     {
-      layerSource.reset(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_));
+      layerSource.reset(new OrthancFrameLayerSource(IObserver::GetBroker(), orthancApiClient_));
       dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_);
       layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady));
       layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::ImageReadyMessage>(*this, &SmartLoader::OnImageReady));
@@ -189,7 +189,7 @@
 
 
     // create the slice in the cache with "empty" data
-    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
+    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker()));
     cachedSlice->slice_.reset(new Slice(instanceId, frame));
     cachedSlice->status_ = CachedSliceStatus_ScheduledToLoad;
     std::string sliceKeyId = instanceId + ":" + boost::lexical_cast<std::string>(frame);
@@ -198,7 +198,7 @@
 
     cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice);
 
-    std::auto_ptr<ILayerSource> layerSource(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_));
+    std::auto_ptr<ILayerSource> layerSource(new OrthancFrameLayerSource(IObserver::GetBroker(), orthancApiClient_));
 
     dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_);
     layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady));
@@ -233,7 +233,7 @@
 
     LOG(WARNING) << "Geometry ready: " << sliceKeyId;
 
-    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
+    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker()));
     cachedSlice->slice_.reset(slice.Clone());
     cachedSlice->effectiveQuality_ = source.GetImageQuality();
     cachedSlice->status_ = CachedSliceStatus_GeometryLoaded;
@@ -256,7 +256,7 @@
 
     LOG(WARNING) << "Image ready: " << sliceKeyId;
 
-    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_));
+    boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker()));
     cachedSlice->image_.reset(Orthanc::Image::Clone(message.GetImage()));
     cachedSlice->effectiveQuality_ = message.GetImageQuality();
     cachedSlice->slice_.reset(message.GetSlice().Clone());
--- a/Framework/StoneEnumerations.h	Fri Nov 09 17:59:35 2018 +0100
+++ b/Framework/StoneEnumerations.h	Fri Nov 09 18:30:30 2018 +0100
@@ -115,6 +115,45 @@
     BitmapAnchor_TopRight
   };
 
+  enum MessageType
+  {
+    MessageType_Widget_GeometryChanged,
+    MessageType_Widget_ContentChanged,
+
+    MessageType_LayerSource_GeometryReady,   // instance tags have been loaded
+    MessageType_LayerSource_GeometryError,
+    MessageType_LayerSource_ContentChanged,
+    MessageType_LayerSource_SliceChanged,
+    MessageType_LayerSource_ImageReady,      // instance pixels data have been loaded
+    MessageType_LayerSource_LayerReady,      // layer is ready to be rendered
+    MessageType_LayerSource_LayerError,
+
+    MessageType_SliceLoader_GeometryReady,
+    MessageType_SliceLoader_GeometryError,
+    MessageType_SliceLoader_ImageReady,
+    MessageType_SliceLoader_ImageError,
+
+    MessageType_HttpRequestSuccess,
+    MessageType_HttpRequestError,
+
+    MessageType_OrthancApi_InternalGetJsonResponseReady,
+    MessageType_OrthancApi_InternalGetJsonResponseError,
+
+    MessageType_OrthancApi_GenericGetJson_Ready,
+    MessageType_OrthancApi_GenericGetBinary_Ready,
+    MessageType_OrthancApi_GenericHttpError_Ready,
+    MessageType_OrthancApi_GenericEmptyResponse_Ready,
+
+    MessageType_ViewportChanged,
+
+    // used in unit tests only
+    MessageType_Test1,
+    MessageType_Test2,
+
+    MessageType_CustomMessage // Custom messages ids ust be greater than this (this one must remain in last position)
+  };
+
+
   bool StringToSopClassUid(SopClassUid& result,
                            const std::string& source);
 
--- a/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Nov 09 17:59:35 2018 +0100
+++ b/Resources/CMake/OrthancStoneConfiguration.cmake	Fri Nov 09 18:30:30 2018 +0100
@@ -302,7 +302,6 @@
   ${ORTHANC_STONE_ROOT}/Framework/Messages/IObserver.h
   ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageBroker.h
   ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageForwarder.cpp
-  ${ORTHANC_STONE_ROOT}/Framework/Messages/MessageType.h
   ${ORTHANC_STONE_ROOT}/Framework/Messages/Promise.h
 
   ${ORTHANC_ROOT}/Plugins/Samples/Common/DicomDatasetReader.cpp
--- a/UnitTestsSources/TestMessageBroker2.cpp	Fri Nov 09 17:59:35 2018 +0100
+++ b/UnitTestsSources/TestMessageBroker2.cpp	Fri Nov 09 18:30:30 2018 +0100
@@ -112,7 +112,7 @@
 
     Promise& StartSomethingAsync()
     {
-      currentPromise_ = new Promise(broker_);
+      currentPromise_ = new Promise(GetBroker());
       return *currentPromise_;
     }