changeset 1247:af35ec39ebec broker

refactoring ILoadersContext
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jan 2020 13:12:43 +0100
parents 3fe803f65c47
children 2a8359503f3b
files Framework/Loaders/GenericLoadersContext.cpp Framework/Loaders/GenericLoadersContext.h Framework/Loaders/ILoadersContext.h
diffstat 3 files changed, 26 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/GenericLoadersContext.cpp	Tue Jan 07 12:56:40 2020 +0100
+++ b/Framework/Loaders/GenericLoadersContext.cpp	Tue Jan 07 13:12:43 2020 +0100
@@ -34,6 +34,10 @@
       that_(that),
       lock_(that.mutex_)
     {
+      if (!that_.scheduler_)
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+      }
     }
       
     virtual ILoadersContext& GetContext() const ORTHANC_OVERRIDE
@@ -67,6 +71,13 @@
     {
       that_.scheduler_->CancelAllRequests();
     }
+
+    virtual void GetStatistics(uint64_t& scheduledCommands,
+                               uint64_t& processedCommands)
+    {
+      scheduledCommands = that_.scheduler_->GetTotalScheduled();
+      processedCommands = that_.scheduler_->GetTotalProcessed();
+    }
   };
 
 
@@ -87,6 +98,11 @@
     oracle_.reset(new ThreadedOracle(*this));
     scheduler_ = OracleScheduler::Create(*oracle_, oracleObservable_, *this,
                                          maxHighPriority, maxStandardPriority, maxLowPriority);
+
+    if (!scheduler_)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
   }
 
 
@@ -160,26 +176,8 @@
     }
   }
    
-
   ILoadersContext::ILock* GenericLoadersContext::Lock()
   {
     return new Locker(*this);
   }
-
-  
-  void GenericLoadersContext::GetStatistics(uint64_t& scheduledCommands,
-                                            uint64_t& processedCommands)
-  {
-    boost::recursive_mutex::scoped_lock lock(mutex_);
-
-    if (scheduler_)
-    {
-      scheduledCommands = scheduler_->GetTotalScheduled();
-      processedCommands = scheduler_->GetTotalProcessed();
-    }
-    else
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    }
-  }
 }
--- a/Framework/Loaders/GenericLoadersContext.h	Tue Jan 07 12:56:40 2020 +0100
+++ b/Framework/Loaders/GenericLoadersContext.h	Tue Jan 07 13:12:43 2020 +0100
@@ -67,9 +67,6 @@
    
     virtual ILock* Lock() ORTHANC_OVERRIDE;
 
-    virtual void GetStatistics(uint64_t& scheduledCommands,
-                               uint64_t& processedCommands) ORTHANC_OVERRIDE;
-
     void SetOrthancParameters(const Orthanc::WebServiceParameters& parameters);
 
     void SetRootDirectory(const std::string& root);
--- a/Framework/Loaders/ILoadersContext.h	Tue Jan 07 12:56:40 2020 +0100
+++ b/Framework/Loaders/ILoadersContext.h	Tue Jan 07 13:12:43 2020 +0100
@@ -99,6 +99,16 @@
        * variable is left.
        **/
       virtual void AddLoader(boost::shared_ptr<IObserver> loader) = 0;
+
+      /**
+       * Returns the number of commands that were scheduled and
+       * processed using the "Schedule()" method. By "processed"
+       * commands, we refer to the number of commands that were either
+       * executed by the oracle, or canceled by the user. So the
+       * counting sequences are monotonically increasing over time.
+       **/
+      virtual void GetStatistics(uint64_t& scheduledCommands,
+                                 uint64_t& processedCommands) = 0;
     };
 
     virtual ~ILoadersContext()
@@ -112,15 +122,5 @@
      * mutex is locked.
      **/
     virtual ILock* Lock() = 0;
-
-    /**
-     * Returns the number of commands that were scheduled and
-     * processed using the "ILock::Schedule()" method. By "processed"
-     * commands, we refer to the number of commands that were either
-     * executed by the oracle, or canceled by the user. So the
-     * counting sequences are monotonically increasing over time.
-     **/
-    virtual void GetStatistics(uint64_t& scheduledCommands,
-                               uint64_t& processedCommands) = 0;
   };
 }