# HG changeset patch # User Sebastien Jodogne # Date 1526326437 -7200 # Node ID ec09641d6f419094b18a8bc89a448673790cab58 # Parent 4c809711149e0c6f938f1355263b83f50489092c simplifications diff -r 4c809711149e -r ec09641d6f41 Core/JobsEngine/SetOfInstancesJob.cpp --- a/Core/JobsEngine/SetOfInstancesJob.cpp Mon May 14 21:24:51 2018 +0200 +++ b/Core/JobsEngine/SetOfInstancesJob.cpp Mon May 14 21:33:57 2018 +0200 @@ -113,44 +113,34 @@ } - void SetOfInstancesJob::Next() - { - if (IsDone()) - { - throw OrthancException(ErrorCode_BadSequenceOfCalls); - } - else - { - position_ += 1; - } - } - - - const std::string& SetOfInstancesJob::GetCurrentInstance() const - { - if (IsDone()) - { - throw OrthancException(ErrorCode_BadSequenceOfCalls); - } - else - { - return instances_[position_]; - } - } - - JobStepResult* SetOfInstancesJob::ExecuteStep() { - if (IsDone()) + if (!started_) + { + throw OrthancException(ErrorCode_InternalError); + } + + if (instances_.empty() && + position_ == 0) { + // No instance to handle, we're done + position_ = 1; + return new JobStepResult(JobStepCode_Success); + } + + if (position_ >= instances_.size()) + { + // Already done return new JobStepResult(JobStepCode_Failure); } + const std::string currentInstance = instances_[position_]; + bool ok; try { - ok = HandleInstance(GetCurrentInstance()); + ok = HandleInstance(currentInstance); if (!ok && !permissive_) { @@ -171,13 +161,14 @@ if (!ok) { - failedInstances_.insert(GetCurrentInstance()); + failedInstances_.insert(currentInstance); } - Next(); + position_ += 1; - if (IsDone()) + if (position_ == instances_.size()) { + // We're done return new JobStepResult(JobStepCode_Success); } else diff -r 4c809711149e -r ec09641d6f41 Core/JobsEngine/SetOfInstancesJob.h --- a/Core/JobsEngine/SetOfInstancesJob.h Mon May 14 21:24:51 2018 +0200 +++ b/Core/JobsEngine/SetOfInstancesJob.h Mon May 14 21:33:57 2018 +0200 @@ -48,13 +48,6 @@ size_t position_; std::set failedInstances_; - bool IsDone() const - { - return (position_ >= instances_.size()); - } - - void Next(); - protected: virtual bool HandleInstance(const std::string& instance) = 0; @@ -91,8 +84,6 @@ return started_; } - const std::string& GetCurrentInstance() const; - const std::vector& GetInstances() const { return instances_; diff -r 4c809711149e -r ec09641d6f41 OrthancServer/OrthancRestApi/OrthancRestModalities.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon May 14 21:24:51 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon May 14 21:33:57 2018 +0200 @@ -78,7 +78,7 @@ << remote_.GetApplicationEntityTitle() << "\""; std::string dicom; - context_.ReadDicom(dicom, GetCurrentInstance()); + context_.ReadDicom(dicom, instance); if (HasMoveOriginator()) { @@ -232,7 +232,7 @@ LOG(INFO) << "Sending instance " << instance << " to peer \"" << peer_.GetUrl() << "\""; - context_.ReadDicom(client_->GetBody(), GetCurrentInstance()); + context_.ReadDicom(client_->GetBody(), instance); std::string answer; if (client_->Apply(answer))