Mercurial > hg > orthanc
changeset 2586:ec09641d6f41 jobs
simplifications
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 May 2018 21:33:57 +0200 |
parents | 4c809711149e |
children | bf14b037731f |
files | Core/JobsEngine/SetOfInstancesJob.cpp Core/JobsEngine/SetOfInstancesJob.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp |
diffstat | 3 files changed, 24 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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<std::string> 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<std::string>& GetInstances() const { return instances_;
--- 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))