# HG changeset patch # User Alain Mazy # Date 1591696498 -7200 # Node ID cbdf62468d7793451d1cb520eb1c01fd1672a305 # Parent a2e4edc7b9aa58b6bd382d7b99c671795fa0d099# Parent ceba3213cb9ecd266ac3ef9f1a5d67fdfd95c134 merge diff -r ceba3213cb9e -r cbdf62468d77 Core/JobsEngine/JobsRegistry.cpp --- a/Core/JobsEngine/JobsRegistry.cpp Tue Jun 09 11:37:52 2020 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Tue Jun 09 11:54:58 2020 +0200 @@ -495,15 +495,20 @@ job.SetLastErrorCode(ErrorCode_CanceledJob); } - if (observer_ != NULL) { - if (reason == CompletedReason_Success) + boost::shared_lock lock(observersMutex_); + + for (Observers::iterator it = observers_.begin(); it != observers_.end(); ++it) { - observer_->SignalJobSuccess(job.GetId()); - } - else - { - observer_->SignalJobFailure(job.GetId()); + if (reason == CompletedReason_Success) + { + (*it)->SignalJobSuccess(job.GetId()); + } + else + { + (*it)->SignalJobFailure(job.GetId()); + } + } } @@ -711,9 +716,13 @@ LOG(INFO) << "New job submitted with priority " << priority << ": " << id; - if (observer_ != NULL) { - observer_->SignalJobSubmitted(id); + boost::shared_lock lock(observersMutex_); + + for (Observers::iterator it = observers_.begin(); it != observers_.end(); ++it) + { + (*it)->SignalJobSubmitted(id); + } } // WARNING: The following call might make "handler" invalid if @@ -1100,17 +1109,21 @@ } - void JobsRegistry::SetObserver(JobsRegistry::IObserver& observer) + void JobsRegistry::AddObserver(JobsRegistry::IObserver& observer) { - boost::mutex::scoped_lock lock(mutex_); - observer_ = &observer; + boost::unique_lock lock(observersMutex_); + observers_.insert(&observer); } - void JobsRegistry::ResetObserver() + void JobsRegistry::ResetObserver(JobsRegistry::IObserver& observer) { - boost::mutex::scoped_lock lock(mutex_); - observer_ = NULL; + boost::unique_lock lock(observersMutex_); + Observers::iterator it = observers_.find(&observer); + if (it != observers_.end()) + { + observers_.erase(it); + } } @@ -1381,8 +1394,7 @@ JobsRegistry::JobsRegistry(IJobUnserializer& unserializer, const Json::Value& s, size_t maxCompletedJobs) : - maxCompletedJobs_(maxCompletedJobs), - observer_(NULL) + maxCompletedJobs_(maxCompletedJobs) { if (SerializationToolbox::ReadString(s, TYPE) != JOBS_REGISTRY || !s.isMember(JOBS) || diff -r ceba3213cb9e -r cbdf62468d77 Core/JobsEngine/JobsRegistry.h --- a/Core/JobsEngine/JobsRegistry.h Tue Jun 09 11:37:52 2020 +0200 +++ b/Core/JobsEngine/JobsRegistry.h Tue Jun 09 11:54:58 2020 +0200 @@ -86,6 +86,7 @@ JobHandler*& b) const; }; + typedef std::set Observers; typedef std::map JobsIndex; typedef std::list CompletedJobs; typedef std::set RetryJobs; @@ -103,7 +104,8 @@ boost::condition_variable someJobComplete_; size_t maxCompletedJobs_; - IObserver* observer_; + boost::shared_mutex observersMutex_; + Observers observers_; #ifndef NDEBUG @@ -141,8 +143,7 @@ public: JobsRegistry(size_t maxCompletedJobs) : - maxCompletedJobs_(maxCompletedJobs), - observer_(NULL) + maxCompletedJobs_(maxCompletedJobs) { } @@ -195,9 +196,9 @@ bool GetState(JobState& state, const std::string& id); - void SetObserver(IObserver& observer); + void AddObserver(IObserver& observer); - void ResetObserver(); + void ResetObserver(IObserver& observer); void GetStatistics(unsigned int& pending, unsigned int& running, diff -r ceba3213cb9e -r cbdf62468d77 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Tue Jun 09 11:37:52 2020 +0200 +++ b/OrthancServer/ServerContext.cpp Tue Jun 09 11:54:58 2020 +0200 @@ -190,7 +190,7 @@ LOG(INFO) << "Not reloading the jobs from the last execution of Orthanc"; } - jobsEngine_.GetRegistry().SetObserver(*this); + jobsEngine_.GetRegistry().AddObserver(*this); jobsEngine_.Start(); isJobsEngineUnserialized_ = true; @@ -347,7 +347,7 @@ saveJobsThread_.join(); } - jobsEngine_.GetRegistry().ResetObserver(); + jobsEngine_.GetRegistry().ResetObserver(*this); if (isJobsEngineUnserialized_) { diff -r ceba3213cb9e -r cbdf62468d77 Plugins/Engine/PluginsEnumerations.cpp --- a/Plugins/Engine/PluginsEnumerations.cpp Tue Jun 09 11:37:52 2020 +0200 +++ b/Plugins/Engine/PluginsEnumerations.cpp Tue Jun 09 11:54:58 2020 +0200 @@ -92,7 +92,7 @@ namespace Plugins { - OrthancPluginChangeType Convert(ChangeType type) + OrthancPluginChangeType Convert55(ChangeType type) { switch (type) { diff -r ceba3213cb9e -r cbdf62468d77 Plugins/Engine/PluginsEnumerations.h --- a/Plugins/Engine/PluginsEnumerations.h Tue Jun 09 11:37:52 2020 +0200 +++ b/Plugins/Engine/PluginsEnumerations.h Tue Jun 09 11:54:58 2020 +0200 @@ -56,7 +56,7 @@ namespace Plugins { - OrthancPluginChangeType Convert(ChangeType type); + OrthancPluginChangeType Convert55(ChangeType type); OrthancPluginPixelFormat Convert(PixelFormat format);