changeset 1825:f0f8a94c0858

only one modality worklist handler at once
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2015 14:24:26 +0100
parents b530c3dfe2a6
children ac5b0b4e2434
files Plugins/Engine/OrthancPlugins.cpp
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Wed Nov 25 14:14:32 2015 +0100
+++ b/Plugins/Engine/OrthancPlugins.cpp	Wed Nov 25 14:24:26 2015 +0100
@@ -278,7 +278,6 @@
     typedef std::list<RestCallback*>  RestCallbacks;
     typedef std::list<OrthancPluginOnStoredInstanceCallback>  OnStoredCallbacks;
     typedef std::list<OrthancPluginOnChangeCallback>  OnChangeCallbacks;
-    typedef std::list<OrthancPluginWorklistCallback>  WorklistCallbacks;
     typedef std::map<Property, std::string>  Properties;
 
     PluginsManager manager_;
@@ -286,12 +285,12 @@
     RestCallbacks restCallbacks_;
     OnStoredCallbacks  onStoredCallbacks_;
     OnChangeCallbacks  onChangeCallbacks_;
-    WorklistCallbacks  worklistCallbacks_;
+    OrthancPluginWorklistCallback  worklistCallback_;
     std::auto_ptr<StorageAreaFactory>  storageArea_;
     boost::recursive_mutex restCallbackMutex_;
     boost::recursive_mutex storedCallbackMutex_;
     boost::recursive_mutex changeCallbackMutex_;
-    boost::recursive_mutex worklistCallbackMutex_;
+    boost::mutex worklistCallbackMutex_;
     boost::recursive_mutex invokeServiceMutex_;
     Properties properties_;
     int argc_;
@@ -301,6 +300,7 @@
 
     PImpl() : 
       context_(NULL), 
+      worklistCallback_(NULL),
       argc_(1),
       argv_(NULL)
     {
@@ -339,13 +339,11 @@
       currentQuery_ = &query;
 
       {
-        boost::recursive_mutex::scoped_lock lock(that_.pimpl_->worklistCallbackMutex_);
+        boost::mutex::scoped_lock lock(that_.pimpl_->worklistCallbackMutex_);
 
-        for (PImpl::WorklistCallbacks::const_iterator
-               callback = that_.pimpl_->worklistCallbacks_.begin(); 
-             callback != that_.pimpl_->worklistCallbacks_.end(); ++callback)
+        if (that_.pimpl_->worklistCallback_)
         {
-          OrthancPluginErrorCode error = (*callback) 
+          OrthancPluginErrorCode error = that_.pimpl_->worklistCallback_
             (reinterpret_cast<OrthancPluginWorklistAnswers*>(&answers),
              reinterpret_cast<const OrthancPluginWorklistQuery*>(this),
              remoteAet.c_str(),
@@ -718,8 +716,18 @@
     const _OrthancPluginWorklistCallback& p = 
       *reinterpret_cast<const _OrthancPluginWorklistCallback*>(parameters);
 
-    LOG(INFO) << "Plugin has registered an modality worklist callback";
-    pimpl_->worklistCallbacks_.push_back(p.callback);
+    boost::mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
+
+    if (pimpl_->worklistCallback_ != NULL)
+    {
+      LOG(ERROR) << "Can only register one plugin to handle modality worklists";
+      throw OrthancException(ErrorCode_Plugin);
+    }
+    else
+    {
+      LOG(INFO) << "Plugin has registered an modality worklist callback";
+      pimpl_->worklistCallback_ = p.callback;
+    }
   }
 
 
@@ -2137,8 +2145,8 @@
 
   bool OrthancPlugins::HasWorklistHandler()
   {
-    boost::recursive_mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
-    return !pimpl_->worklistCallbacks_.empty();
+    boost::mutex::scoped_lock lock(pimpl_->worklistCallbackMutex_);
+    return pimpl_->worklistCallback_ != NULL;
   }
 
 }