changeset 4023:cbdf62468d77 more-changes

merge
author Alain Mazy <alain@mazy.be>
date Tue, 09 Jun 2020 11:54:58 +0200
parents a2e4edc7b9aa (diff) ceba3213cb9e (current diff)
children 1d2b31fc782f
files
diffstat 5 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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<boost::shared_mutex> 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<boost::shared_mutex> 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<boost::shared_mutex> 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<boost::shared_mutex> 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) ||
--- 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<IObserver*>                            Observers;
     typedef std::map<std::string, JobHandler*>              JobsIndex;
     typedef std::list<JobHandler*>                          CompletedJobs;
     typedef std::set<JobHandler*>                           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,
--- 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_)
       {
--- 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)
       {
--- 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);