# HG changeset patch # User Sebastien Jodogne # Date 1578399163 -3600 # Node ID af35ec39ebec8086c958806b3f4e7550d579e353 # Parent 3fe803f65c4759447957df25530dd9bad526ca01 refactoring ILoadersContext diff -r 3fe803f65c47 -r af35ec39ebec Framework/Loaders/GenericLoadersContext.cpp --- 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); - } - } } diff -r 3fe803f65c47 -r af35ec39ebec Framework/Loaders/GenericLoadersContext.h --- 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); diff -r 3fe803f65c47 -r af35ec39ebec Framework/Loaders/ILoadersContext.h --- 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 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; }; }