diff Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp @ 1310:9bea7e15b519 broker

- first pass at changes to cope with the refactoring of the loading system - global loader-related data accessible through ILoadersContext::ILock - many changes in legacy loaders (CT, RTSTRUCT, DOSE) + loader cache - NOT FINISHED! there are shared_from_this calls in ctors! this will crash!
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 09 Mar 2020 14:53:22 +0100
parents 257f2c9a02ac
children 9b126de2cde2
line wrap: on
line diff
--- a/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Wed Mar 04 13:20:12 2020 +0100
+++ b/Framework/Deprecated/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Mon Mar 09 14:53:22 2020 +0100
@@ -21,6 +21,7 @@
 
 #include "OrthancSeriesVolumeProgressiveLoader.h"
 
+#include "../../Loaders/ILoadersContext.h"
 #include "../../Loaders/BasicFetchingItemsSorter.h"
 #include "../../Loaders/BasicFetchingStrategy.h"
 #include "../../Toolbox/GeometryToolbox.h"
@@ -31,6 +32,8 @@
 
 namespace Deprecated
 {
+  using OrthancStone::ILoadersContext;
+
   class OrthancSeriesVolumeProgressiveLoader::ExtractedSlice : public OrthancStone::DicomVolumeImageMPRSlicer::Slice
   {
   private:
@@ -302,9 +305,12 @@
       }
 
       command->AcquirePayload(new Orthanc::SingleValueObject<unsigned int>(sliceIndex));
-
-      boost::shared_ptr<IObserver> observer(GetSharedObserver());
-      oracle_.Schedule(observer, command.release());
+      
+      {
+        std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock());
+        boost::shared_ptr<IObserver> observer(GetSharedObserver());
+        lock->Schedule(observer, 0, command.release()); // TODO: priority!
+      }
     }
     else
     {
@@ -430,25 +436,30 @@
   }
 
 
-  OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader(const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume,
-                                                                             OrthancStone::IOracle& oracle,
-                                                                             OrthancStone::IObservable& oracleObservable) :
-    oracle_(oracle),
-    active_(false),
-    simultaneousDownloads_(4),
-    volume_(volume),
-    sorter_(new OrthancStone::BasicFetchingItemsSorter::Factory),
-    volumeImageReadyInHighQuality_(false)
+  OrthancSeriesVolumeProgressiveLoader::OrthancSeriesVolumeProgressiveLoader(
+    OrthancStone::ILoadersContext& loadersContext,
+    const boost::shared_ptr<OrthancStone::DicomVolumeImage>& volume)
+    : loadersContext_(loadersContext)
+    , active_(false)
+    , simultaneousDownloads_(4)
+    , volume_(volume)
+    , sorter_(new OrthancStone::BasicFetchingItemsSorter::Factory)
+    , volumeImageReadyInHighQuality_(false)
   {
-    // TODO => Move this out of constructor
-    Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>
-      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadGeometry);
+    std::auto_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext.Lock());
+
+    // TODO => Move this out of constructor WHY?
+    Register<OrthancStone::OrthancRestApiCommand::SuccessMessage>(
+      lock->GetOracleObservable(), 
+      &OrthancSeriesVolumeProgressiveLoader::LoadGeometry);
 
-    Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>
-      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent);
+    Register<OrthancStone::GetOrthancImageCommand::SuccessMessage>(
+      lock->GetOracleObservable(),
+      &OrthancSeriesVolumeProgressiveLoader::LoadBestQualitySliceContent);
 
-    Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>
-      (oracleObservable, &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent);
+    Register<OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage>(
+      lock->GetOracleObservable(),
+      &OrthancSeriesVolumeProgressiveLoader::LoadJpegSliceContent);
   }
 
   OrthancSeriesVolumeProgressiveLoader::~OrthancSeriesVolumeProgressiveLoader()
@@ -489,11 +500,11 @@
 
       std::unique_ptr<OrthancStone::OrthancRestApiCommand> command(new OrthancStone::OrthancRestApiCommand);
       command->SetUri("/series/" + seriesId + "/instances-tags");
-
-//      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries about to call oracle_.Schedule";
-      boost::shared_ptr<IObserver> observer(GetSharedObserver());
-      oracle_.Schedule(observer, command.release());
-//      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries called oracle_.Schedule";
+      {
+        std::unique_ptr<OrthancStone::ILoadersContext::ILock> lock(loadersContext_.Lock());
+        boost::shared_ptr<IObserver> observer(GetSharedObserver());
+        lock->Schedule(observer, 0, command.release()); //TODO: priority!
+      }
     }
   }