Mercurial > hg > orthanc
changeset 5907:8329d28611ad get-scu
scu/move jobs: report progress between steps
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -401,7 +401,6 @@ DicomControlUserConnection::IProgressListener* listener = reinterpret_cast<DicomControlUserConnection::IProgressListener*>(callbackData); if (listener) { - LOG(INFO) << "---------" << response->NumberOfRemainingSubOperations << " " << response->NumberOfCompletedSubOperations; listener->OnProgressUpdated(response->NumberOfRemainingSubOperations, response->NumberOfCompletedSubOperations, response->NumberOfFailedSubOperations,
--- a/OrthancFramework/Sources/JobsEngine/IJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/IJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -49,13 +49,18 @@ // For pausing/canceling/ending jobs: This method must release allocated resources virtual void Stop(JobStopReason reason) = 0; - virtual float GetProgress() = 0; + virtual float GetProgress() const = 0; - virtual void GetJobType(std::string& target) = 0; + virtual bool NeedsProgressUpdateBetweenSteps() const // only for jobs whose progress is updated by outside events (like C-Move and C-Get) + { + return false; + } + + virtual void GetJobType(std::string& target) const = 0; - virtual void GetPublicContent(Json::Value& value) = 0; + virtual void GetPublicContent(Json::Value& value) const = 0; - virtual bool Serialize(Json::Value& value) = 0; + virtual bool Serialize(Json::Value& value) const = 0; // This function can only be called if the job has reached its // "success" state
--- a/OrthancFramework/Sources/JobsEngine/JobInfo.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobInfo.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -54,7 +54,8 @@ const JobStatus& status, const boost::posix_time::ptime& creationTime, const boost::posix_time::ptime& lastStateChangeTime, - const boost::posix_time::time_duration& runtime) : + const boost::posix_time::time_duration& runtime, + const IJob& job) : id_(id), priority_(priority), state_(state), @@ -68,11 +69,16 @@ if (state_ == JobState_Running) { float ms = static_cast<float>(runtime_.total_milliseconds()); + if (job.NeedsProgressUpdateBetweenSteps()) + { + status_.UpdateProgress(job); + } - if (status_.GetProgress() > 0.01f && + float progress = status_.GetProgress(); + + if (progress > 0.01f && ms > 0.01f) { - float progress = status_.GetProgress(); long long remaining = boost::math::llround(ms / progress * (1.0f - progress)); eta_ = timestamp_ + boost::posix_time::milliseconds(remaining); hasEta_ = true;
--- a/OrthancFramework/Sources/JobsEngine/JobInfo.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobInfo.h Fri Dec 06 15:55:12 2024 +0100 @@ -51,7 +51,8 @@ const JobStatus& status, const boost::posix_time::ptime& creationTime, const boost::posix_time::ptime& lastStateChangeTime, - const boost::posix_time::time_duration& runtime) ORTHANC_LOCAL; + const boost::posix_time::time_duration& runtime, + const IJob& job) ORTHANC_LOCAL; JobInfo();
--- a/OrthancFramework/Sources/JobsEngine/JobStatus.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobStatus.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -41,7 +41,7 @@ JobStatus::JobStatus(ErrorCode code, const std::string& details, - IJob& job) : + const IJob& job) : errorCode_(code), progress_(job.GetProgress()), publicContent_(Json::objectValue),
--- a/OrthancFramework/Sources/JobsEngine/JobStatus.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobStatus.h Fri Dec 06 15:55:12 2024 +0100 @@ -44,7 +44,7 @@ JobStatus(ErrorCode code, const std::string& details, - IJob& job); + const IJob& job); ErrorCode GetErrorCode() const { @@ -61,6 +61,11 @@ return progress_; } + void UpdateProgress(const IJob& job) + { + progress_ = job.GetProgress(); + } + const std::string& GetJobType() const { return jobType_;
--- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -223,8 +223,14 @@ lastStateChangeTime_ = time; } - const boost::posix_time::time_duration& GetRuntime() const + boost::posix_time::time_duration GetRuntime() const { + if (state_ == JobState_Running) + { + const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); + return now - lastStateChangeTime_; + } + return runtime_; } @@ -644,7 +650,8 @@ handler.GetLastStatus(), handler.GetCreationTime(), handler.GetLastStateChangeTime(), - handler.GetRuntime()); + handler.GetRuntime(), + handler.GetJob()); return true; } }
--- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -398,7 +398,7 @@ } - float SequenceOfOperationsJob::GetProgress() + float SequenceOfOperationsJob::GetProgress() const { boost::mutex::scoped_lock lock(mutex_); @@ -406,13 +406,13 @@ static_cast<float>(operations_.size() + 1)); } - void SequenceOfOperationsJob::GetJobType(std::string& target) + void SequenceOfOperationsJob::GetJobType(std::string& target) const { target = "SequenceOfOperations"; } - void SequenceOfOperationsJob::GetPublicContent(Json::Value& value) + void SequenceOfOperationsJob::GetPublicContent(Json::Value& value) const { boost::mutex::scoped_lock lock(mutex_); @@ -421,7 +421,7 @@ } - bool SequenceOfOperationsJob::Serialize(Json::Value& value) + bool SequenceOfOperationsJob::Serialize(Json::Value& value) const { boost::mutex::scoped_lock lock(mutex_);
--- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -54,7 +54,7 @@ std::string description_; bool done_; - boost::mutex mutex_; + mutable boost::mutex mutex_; std::vector<Operation*> operations_; size_t current_; boost::condition_variable operationAdded_; @@ -117,13 +117,13 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE; + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE; virtual bool GetOutput(std::string& output, MimeType& mime,
--- a/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -137,7 +137,7 @@ } - float SetOfCommandsJob::GetProgress() + float SetOfCommandsJob::GetProgress() const { if (commands_.empty()) { @@ -237,13 +237,13 @@ static const char* KEY_COMMANDS = "Commands"; - void SetOfCommandsJob::GetPublicContent(Json::Value& value) + void SetOfCommandsJob::GetPublicContent(Json::Value& value) const { value[KEY_DESCRIPTION] = GetDescription(); } - bool SetOfCommandsJob::Serialize(Json::Value& target) + bool SetOfCommandsJob::Serialize(Json::Value& target) const { target = Json::objectValue;
--- a/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -92,7 +92,7 @@ virtual void Start() ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; bool IsStarted() const; @@ -100,9 +100,9 @@ virtual JobStepResult Step(const std::string& jobId) ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; virtual bool GetOutput(std::string& output, MimeType& mime,
--- a/OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -209,7 +209,7 @@ static const char* KEY_FAILED_INSTANCES = "FailedInstances"; static const char* KEY_PARENT_RESOURCES = "ParentResources"; - void SetOfInstancesJob::GetPublicContent(Json::Value& target) + void SetOfInstancesJob::GetPublicContent(Json::Value& target) const { SetOfCommandsJob::GetPublicContent(target); target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount()); @@ -222,7 +222,7 @@ } - bool SetOfInstancesJob::Serialize(Json::Value& target) + bool SetOfInstancesJob::Serialize(Json::Value& target) const { if (SetOfCommandsJob::Serialize(target)) {
--- a/OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -77,8 +77,8 @@ virtual void Reset() ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value& target) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& target) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancFramework/UnitTestsSources/JobsTests.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancFramework/UnitTestsSources/JobsTests.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -103,24 +103,24 @@ { } - virtual float GetProgress() ORTHANC_OVERRIDE + virtual float GetProgress() const ORTHANC_OVERRIDE { return static_cast<float>(count_) / static_cast<float>(steps_ - 1); } - virtual void GetJobType(std::string& type) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& type) const ORTHANC_OVERRIDE { type = "DummyJob"; } - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE { value = Json::objectValue; value["Type"] = "DummyJob"; return true; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE { value["hello"] = "world"; } @@ -199,7 +199,7 @@ { } - virtual void GetJobType(std::string& s) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& s) const ORTHANC_OVERRIDE { s = "DummyInstancesJob"; }
--- a/OrthancServer/Plugins/Engine/PluginsJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Plugins/Engine/PluginsJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -147,7 +147,7 @@ } } - float PluginsJob::GetProgress() + float PluginsJob::GetProgress() const { return parameters_.getProgress(parameters_.job); } @@ -194,7 +194,7 @@ }; } - void PluginsJob::GetPublicContent(Json::Value& value) + void PluginsJob::GetPublicContent(Json::Value& value) const { if (parameters_.getContent != NULL) { @@ -232,7 +232,7 @@ } } - bool PluginsJob::Serialize(Json::Value& value) + bool PluginsJob::Serialize(Json::Value& value) const { if (parameters_.getSerialized != NULL) {
--- a/OrthancServer/Plugins/Engine/PluginsJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Plugins/Engine/PluginsJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -58,16 +58,16 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = type_; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE; virtual bool GetOutput(std::string& output, MimeType& mime,
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -1478,7 +1478,7 @@ } - float ArchiveJob::GetProgress() + float ArchiveJob::GetProgress() const { if (writer_.get() == NULL || writer_->GetStepsCount() == 0) @@ -1493,7 +1493,7 @@ } - void ArchiveJob::GetJobType(std::string& target) + void ArchiveJob::GetJobType(std::string& target) const { if (isMedia_) { @@ -1506,7 +1506,7 @@ } - void ArchiveJob::GetPublicContent(Json::Value& value) + void ArchiveJob::GetPublicContent(Json::Value& value) const { value = Json::objectValue; value[KEY_DESCRIPTION] = description_;
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -107,13 +107,13 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE; + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE { return false; // Cannot serialize this kind of job }
--- a/OrthancServer/Sources/ServerJobs/CleaningInstancesJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/CleaningInstancesJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -83,7 +83,7 @@ } - bool CleaningInstancesJob::Serialize(Json::Value& target) + bool CleaningInstancesJob::Serialize(Json::Value& target) const { if (!SetOfInstancesJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/CleaningInstancesJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/CleaningInstancesJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -62,7 +62,7 @@ void SetKeepSource(bool keep); - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; virtual void Start() ORTHANC_OVERRIDE; };
--- a/OrthancServer/Sources/ServerJobs/DicomGetScuJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomGetScuJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -51,7 +51,7 @@ void AddResourceToRetrieve(ResourceType level, const std::string& dicomId); - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "DicomGetScu"; }
--- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -242,7 +242,7 @@ } - void DicomModalityStoreJob::GetPublicContent(Json::Value& value) + void DicomModalityStoreJob::GetPublicContent(Json::Value& value) const { SetOfInstancesJob::GetPublicContent(value); @@ -281,7 +281,7 @@ } - bool DicomModalityStoreJob::Serialize(Json::Value& target) + bool DicomModalityStoreJob::Serialize(Json::Value& target) const { if (!SetOfInstancesJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -88,14 +88,14 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "DicomModalityStore"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; virtual void Reset() ORTHANC_OVERRIDE;
--- a/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -67,7 +67,7 @@ - void DicomMoveScuJob::GetPublicContent(Json::Value& value) + void DicomMoveScuJob::GetPublicContent(Json::Value& value) const { DicomRetrieveScuBaseJob::GetPublicContent(value); @@ -83,7 +83,7 @@ } - bool DicomMoveScuJob::Serialize(Json::Value& target) + bool DicomMoveScuJob::Serialize(Json::Value& target) const { if (!DicomRetrieveScuBaseJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomMoveScuJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -57,13 +57,13 @@ void SetTargetAet(const std::string& aet); - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "DicomMoveScu"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -28,6 +28,7 @@ #include "../ServerContext.h" #include <dcmtk/dcmnet/dimse.h> #include <algorithm> +#include "../../../OrthancFramework/Sources/Logging.h" static const char* const LOCAL_AET = "LocalAet"; static const char* const QUERY = "Query"; @@ -142,7 +143,7 @@ } - void DicomRetrieveScuBaseJob::GetPublicContent(Json::Value& value) + void DicomRetrieveScuBaseJob::GetPublicContent(Json::Value& value) const { SetOfCommandsJob::GetPublicContent(value); @@ -187,7 +188,7 @@ } - bool DicomRetrieveScuBaseJob::Serialize(Json::Value& target) + bool DicomRetrieveScuBaseJob::Serialize(Json::Value& target) const { if (!SetOfCommandsJob::Serialize(target)) { @@ -212,20 +213,26 @@ uint16_t nbFailedSubOperations, uint16_t nbWarningSubOperations) { + boost::mutex::scoped_lock lock(progressMutex_); + nbRemainingSubOperations_ = nbRemainingSubOperations; nbCompletedSubOperations_ = nbCompletedSubOperations; nbFailedSubOperations_ = nbFailedSubOperations; nbWarningSubOperations_ = nbWarningSubOperations; } - float DicomRetrieveScuBaseJob::GetProgress() + float DicomRetrieveScuBaseJob::GetProgress() const { + boost::mutex::scoped_lock lock(progressMutex_); + uint32_t totalOperations = nbRemainingSubOperations_ + nbCompletedSubOperations_ + nbFailedSubOperations_ + nbWarningSubOperations_; if (totalOperations == 0) { return 0.0f; } + LOG(INFO) << "---------" << nbRemainingSubOperations_ << " " << nbCompletedSubOperations_; + return float(nbCompletedSubOperations_ + nbFailedSubOperations_ + nbWarningSubOperations_) / float(totalOperations); } }
--- a/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -25,6 +25,7 @@ #include "../../../OrthancFramework/Sources/Compatibility.h" #include "../../../OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.h" #include "../../../OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h" +#include <boost/thread/mutex.hpp> #include "../QueryRetrieveHandler.h" @@ -87,6 +88,7 @@ std::unique_ptr<DicomControlUserConnection> connection_; + mutable boost::mutex progressMutex_; uint16_t nbRemainingSubOperations_; uint16_t nbCompletedSubOperations_; uint16_t nbFailedSubOperations_; @@ -132,15 +134,21 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value &value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value &value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value &target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value &target) const ORTHANC_OVERRIDE; virtual void OnProgressUpdated(uint16_t nbRemainingSubOperations, uint16_t nbCompletedSubOperations, uint16_t nbFailedSubOperations, uint16_t nbWarningSubOperations) ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; + + virtual bool NeedsProgressUpdateBetweenSteps() const ORTHANC_OVERRIDE + { + return true; + } + }; }
--- a/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/MergeStudyJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -353,7 +353,7 @@ } - void MergeStudyJob::GetPublicContent(Json::Value& value) + void MergeStudyJob::GetPublicContent(Json::Value& value) const { CleaningInstancesJob::GetPublicContent(value); value["TargetStudy"] = targetStudy_; @@ -386,7 +386,7 @@ } - bool MergeStudyJob::Serialize(Json::Value& target) + bool MergeStudyJob::Serialize(Json::Value& target) const { if (!CleaningInstancesJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/MergeStudyJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/MergeStudyJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -89,13 +89,13 @@ { } - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "MergeStudy"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -220,7 +220,7 @@ } - void OrthancPeerStoreJob::GetPublicContent(Json::Value& value) + void OrthancPeerStoreJob::GetPublicContent(Json::Value& value) const { SetOfInstancesJob::GetPublicContent(value); @@ -285,7 +285,7 @@ } - bool OrthancPeerStoreJob::Serialize(Json::Value& target) + bool OrthancPeerStoreJob::Serialize(Json::Value& target) const { if (!SetOfInstancesJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -92,13 +92,13 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; // For pausing jobs - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "OrthancPeerStore"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -542,7 +542,7 @@ } - void ResourceModificationJob::GetPublicContent(Json::Value& value) + void ResourceModificationJob::GetPublicContent(Json::Value& value) const { boost::recursive_mutex::scoped_lock lock(outputMutex_); @@ -636,7 +636,7 @@ } } - bool ResourceModificationJob::Serialize(Json::Value& value) + bool ResourceModificationJob::Serialize(Json::Value& value) const { if (modification_.get() == NULL) {
--- a/OrthancServer/Sources/ServerJobs/ResourceModificationJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ResourceModificationJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -116,14 +116,14 @@ // Only possible if "IsSingleResourceModification()" ResourceType GetOutputLevel() const; - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "ResourceModification"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE; virtual void Reset() ORTHANC_OVERRIDE;
--- a/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/SplitStudyJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -306,7 +306,7 @@ } - void SplitStudyJob::GetPublicContent(Json::Value& value) + void SplitStudyJob::GetPublicContent(Json::Value& value) const { CleaningInstancesJob::GetPublicContent(value); @@ -351,7 +351,7 @@ } - bool SplitStudyJob::Serialize(Json::Value& target) + bool SplitStudyJob::Serialize(Json::Value& target) const { if (!CleaningInstancesJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/SplitStudyJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/SplitStudyJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -113,13 +113,13 @@ { } - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "SplitStudy"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -404,7 +404,7 @@ } - void StorageCommitmentScpJob::GetPublicContent(Json::Value& value) + void StorageCommitmentScpJob::GetPublicContent(Json::Value& value) const { SetOfCommandsJob::GetPublicContent(value); @@ -434,7 +434,7 @@ } - bool StorageCommitmentScpJob::Serialize(Json::Value& target) + bool StorageCommitmentScpJob::Serialize(Json::Value& target) const { if (!SetOfCommandsJob::Serialize(target)) {
--- a/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/StorageCommitmentScpJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -89,13 +89,13 @@ { } - virtual void GetJobType(std::string& target) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& target) const ORTHANC_OVERRIDE { target = "StorageCommitmentScp"; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; }; }
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -376,7 +376,7 @@ static const char* KEY_WORKERS_COUNT = "WorkersCount"; - void ThreadedSetOfInstancesJob::GetPublicContent(Json::Value& target) + void ThreadedSetOfInstancesJob::GetPublicContent(Json::Value& target) const { boost::recursive_mutex::scoped_lock lock(mutex_); @@ -391,7 +391,7 @@ } - bool ThreadedSetOfInstancesJob::Serialize(Json::Value& target) + bool ThreadedSetOfInstancesJob::Serialize(Json::Value& target) const { boost::recursive_mutex::scoped_lock lock(mutex_); @@ -478,7 +478,7 @@ return keepSource_; } - float ThreadedSetOfInstancesJob::GetProgress() + float ThreadedSetOfInstancesJob::GetProgress() const { boost::recursive_mutex::scoped_lock lock(mutex_);
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Fri Dec 06 15:55:12 2024 +0100 @@ -140,15 +140,15 @@ virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE; - virtual float GetProgress() ORTHANC_OVERRIDE; + virtual float GetProgress() const ORTHANC_OVERRIDE; bool IsStarted() const; virtual JobStepResult Step(const std::string& jobId) ORTHANC_OVERRIDE; - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE; + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE; - virtual bool Serialize(Json::Value& target) ORTHANC_OVERRIDE; + virtual bool Serialize(Json::Value& target) const ORTHANC_OVERRIDE; virtual bool GetOutput(std::string& output, MimeType& mime,
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Fri Dec 06 12:17:47 2024 +0100 +++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Fri Dec 06 15:55:12 2024 +0100 @@ -106,24 +106,24 @@ { } - virtual float GetProgress() ORTHANC_OVERRIDE + virtual float GetProgress() const ORTHANC_OVERRIDE { return static_cast<float>(count_) / static_cast<float>(steps_ - 1); } - virtual void GetJobType(std::string& type) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& type) const ORTHANC_OVERRIDE { type = "DummyJob"; } - virtual bool Serialize(Json::Value& value) ORTHANC_OVERRIDE + virtual bool Serialize(Json::Value& value) const ORTHANC_OVERRIDE { value = Json::objectValue; value["Type"] = "DummyJob"; return true; } - virtual void GetPublicContent(Json::Value& value) ORTHANC_OVERRIDE + virtual void GetPublicContent(Json::Value& value) const ORTHANC_OVERRIDE { value["hello"] = "world"; } @@ -202,7 +202,7 @@ { } - virtual void GetJobType(std::string& s) ORTHANC_OVERRIDE + virtual void GetJobType(std::string& s) const ORTHANC_OVERRIDE { s = "DummyInstancesJob"; }