diff Plugins/Engine/OrthancPlugins.cpp @ 1627:da7854deb662

Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Sep 2015 16:32:29 +0200
parents c17b1142caab
children 77c4cc4def0f
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Fri Sep 18 16:32:29 2015 +0200
@@ -370,8 +370,14 @@
            callback = pimpl_->onStoredCallbacks_.begin(); 
          callback != pimpl_->onStoredCallbacks_.end(); ++callback)
     {
-      (*callback) (reinterpret_cast<OrthancPluginDicomInstance*>(&instance),
-                   instanceId.c_str());
+      OrthancPluginErrorCode error = (*callback) 
+        (reinterpret_cast<OrthancPluginDicomInstance*>(&instance),
+         instanceId.c_str());
+
+      if (error != OrthancPluginErrorCode_Success)
+      {
+        throw OrthancException(Plugins::Convert(error));
+      }
     }
   }
 
@@ -379,24 +385,22 @@
 
   void OrthancPlugins::SignalChange(const ServerIndexChange& change)
   {
-    try
-    {
-      boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_);
+    boost::recursive_mutex::scoped_lock lock(pimpl_->changeCallbackMutex_);
 
-      for (std::list<OrthancPluginOnChangeCallback>::const_iterator 
-             callback = pimpl_->onChangeCallbacks_.begin(); 
-           callback != pimpl_->onChangeCallbacks_.end(); ++callback)
+    for (std::list<OrthancPluginOnChangeCallback>::const_iterator 
+           callback = pimpl_->onChangeCallbacks_.begin(); 
+         callback != pimpl_->onChangeCallbacks_.end(); ++callback)
+    {
+      OrthancPluginErrorCode error = (*callback)
+        (Plugins::Convert(change.GetChangeType()),
+         Plugins::Convert(change.GetResourceType()),
+         change.GetPublicId().c_str());
+
+      if (error != OrthancPluginErrorCode_Success)
       {
-        (*callback) (Plugins::Convert(change.GetChangeType()),
-                     Plugins::Convert(change.GetResourceType()),
-                     change.GetPublicId().c_str());
+        throw OrthancException(Plugins::Convert(error));
       }
     }
-    catch (OrthancException&)
-    {
-      // This change type or resource type is not supported by the plugin SDK
-      return;
-    }
   }
 
 
@@ -1577,17 +1581,22 @@
       {
       }
 
+
       virtual void Create(const std::string& uuid,
                           const void* content, 
                           size_t size,
                           FileContentType type)
       {
-        if (params_.create(uuid.c_str(), content, size, Plugins::Convert(type)) != 0)
+        OrthancPluginErrorCode error = params_.create
+          (uuid.c_str(), content, size, Plugins::Convert(type));
+
+        if (error != OrthancPluginErrorCode_Success)
         {
-          throw OrthancException(ErrorCode_Plugin);
+          throw OrthancException(Plugins::Convert(error));
         }
       }
 
+
       virtual void Read(std::string& content,
                         const std::string& uuid,
                         FileContentType type)
@@ -1595,16 +1604,19 @@
         void* buffer = NULL;
         int64_t size = 0;
 
-        if (params_.read(&buffer, &size, uuid.c_str(), Plugins::Convert(type)) != 0)
+        OrthancPluginErrorCode error = params_.read
+          (&buffer, &size, uuid.c_str(), Plugins::Convert(type));
+
+        if (error != OrthancPluginErrorCode_Success)
         {
-          throw OrthancException(ErrorCode_Plugin);
-        }        
+          throw OrthancException(Plugins::Convert(error));
+        }
 
         try
         {
           content.resize(static_cast<size_t>(size));
         }
-        catch (OrthancException&)
+        catch (...)
         {
           Free(buffer);
           throw;
@@ -1618,13 +1630,17 @@
         Free(buffer);
       }
 
+
       virtual void Remove(const std::string& uuid,
                           FileContentType type) 
       {
-        if (params_.remove(uuid.c_str(), Plugins::Convert(type)) != 0)
+        OrthancPluginErrorCode error = params_.remove
+          (uuid.c_str(), Plugins::Convert(type));
+
+        if (error != OrthancPluginErrorCode_Success)
         {
-          throw OrthancException(ErrorCode_Plugin);
-        }        
+          throw OrthancException(Plugins::Convert(error));
+        }
       }
     };
   }