changeset 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 8dc468f44661
children 77c4cc4def0f
files NEWS Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Samples/Basic/Plugin.c Plugins/Samples/GdcmDecoding/CMakeLists.txt Plugins/Samples/GdcmDecoding/OrthancContext.h Plugins/Samples/GdcmDecoding/Plugin.cpp Plugins/Samples/ServeFolders/CMakeLists.txt Plugins/Samples/StorageArea/Plugin.cpp
diffstat 9 files changed, 95 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Sep 18 14:28:47 2015 +0200
+++ b/NEWS	Fri Sep 18 16:32:29 2015 +0200
@@ -3,6 +3,11 @@
 
 * Add ".dcm" suffix to files in ZIP archives (cf. URI ".../archive")
 
+Maintenance
+-----------
+
+* Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
+
 
 Version 0.9.4 (2015/09/16)
 ==========================
--- 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));
+        }
       }
     };
   }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Sep 18 16:32:29 2015 +0200
@@ -663,7 +663,7 @@
    * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance.
    * @ingroup Callbacks
    **/
-  typedef int32_t (*OrthancPluginOnStoredInstanceCallback) (
+  typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) (
     OrthancPluginDicomInstance* instance,
     const char* instanceId);
 
@@ -673,7 +673,7 @@
    * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
    * @ingroup Callbacks
    **/
-  typedef int32_t (*OrthancPluginOnChangeCallback) (
+  typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) (
     OrthancPluginChangeType changeType,
     OrthancPluginResourceType resourceType,
     const char* resourceId);
@@ -699,7 +699,7 @@
    * @return 0 if success, other value if error.
    * @ingroup Callbacks
    **/
-  typedef int32_t (*OrthancPluginStorageCreate) (
+  typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) (
     const char* uuid,
     const void* content,
     int64_t size,
@@ -719,7 +719,7 @@
    * @return 0 if success, other value if error.
    * @ingroup Callbacks
    **/
-  typedef int32_t (*OrthancPluginStorageRead) (
+  typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) (
     void** content,
     int64_t* size,
     const char* uuid,
@@ -737,7 +737,7 @@
    * @return 0 if success, other value if error.
    * @ingroup Callbacks
    **/
-  typedef int32_t (*OrthancPluginStorageRemove) (
+  typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) (
     const char* uuid,
     OrthancPluginContentType type);
 
--- a/Plugins/Samples/Basic/Plugin.c	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/Basic/Plugin.c	Fri Sep 18 16:32:29 2015 +0200
@@ -210,9 +210,9 @@
 }
 
 
-ORTHANC_PLUGINS_API int32_t CallbackCreateDicom(OrthancPluginRestOutput* output,
-                                                const char* url,
-                                                const OrthancPluginHttpRequest* request)
+ORTHANC_PLUGINS_API OrthancPluginErrorCode CallbackCreateDicom(OrthancPluginRestOutput* output,
+                                                               const char* url,
+                                                               const OrthancPluginHttpRequest* request)
 {
   const char* pathLocator = "\"Path\" : \"";
   char info[1024];
@@ -250,12 +250,12 @@
     OrthancPluginAnswerBuffer(context, output, "OK\n", 3, "text/plain");
   }
 
-  return 0;
+  return OrthancPluginErrorCode_Success;
 }
 
 
-ORTHANC_PLUGINS_API int32_t OnStoredCallback(OrthancPluginDicomInstance* instance,
-                                             const char* instanceId)
+ORTHANC_PLUGINS_API OrthancPluginErrorCode OnStoredCallback(OrthancPluginDicomInstance* instance,
+                                                            const char* instanceId)
 {
   char buffer[256];
   FILE* fp;
@@ -291,13 +291,13 @@
     OrthancPluginLogError(context, "Instance has no reception date, should never happen!");
   }
 
-  return 0;
+  return OrthancPluginErrorCode_Success;
 }
 
 
-ORTHANC_PLUGINS_API int32_t OnChangeCallback(OrthancPluginChangeType changeType,
-                                             OrthancPluginResourceType resourceType,
-                                             const char* resourceId)
+ORTHANC_PLUGINS_API OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
+                                                            OrthancPluginResourceType resourceType,
+                                                            const char* resourceId)
 {
   char info[1024];
   OrthancPluginMemoryBuffer tmp;
@@ -317,7 +317,7 @@
     }
   }
 
-  return 0;
+  return OrthancPluginErrorCode_Success;
 }
 
 
--- a/Plugins/Samples/GdcmDecoding/CMakeLists.txt	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/GdcmDecoding/CMakeLists.txt	Fri Sep 18 16:32:29 2015 +0200
@@ -33,10 +33,9 @@
   ${GOOGLE_LOG_SOURCES}
   ${ORTHANC_ROOT}/Core/ChunkedBuffer.cpp
   ${ORTHANC_ROOT}/Core/Enumerations.cpp
-  ${ORTHANC_ROOT}/Core/ImageFormats/ImageAccessor.cpp
-  ${ORTHANC_ROOT}/Core/ImageFormats/ImageBuffer.cpp
-  ${ORTHANC_ROOT}/Core/ImageFormats/ImageProcessing.cpp
-  ${ORTHANC_ROOT}/Core/OrthancException.cpp
+  ${ORTHANC_ROOT}/Core/Images/ImageAccessor.cpp
+  ${ORTHANC_ROOT}/Core/Images/ImageBuffer.cpp
+  ${ORTHANC_ROOT}/Core/Images/ImageProcessing.cpp
   ${ORTHANC_ROOT}/Core/Toolbox.cpp
   ${ORTHANC_ROOT}/Resources/ThirdParty/base64/base64.cpp
   ${ORTHANC_ROOT}/Resources/ThirdParty/md5/md5.c
--- a/Plugins/Samples/GdcmDecoding/OrthancContext.h	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/GdcmDecoding/OrthancContext.h	Fri Sep 18 16:32:29 2015 +0200
@@ -22,7 +22,7 @@
 
 #include <orthanc/OrthancCPlugin.h>
 
-#include "../../../Core/ImageFormats/ImageBuffer.h"
+#include "../../../Core/Images/ImageBuffer.h"
 
 #include <map>
 #include <string>
--- a/Plugins/Samples/GdcmDecoding/Plugin.cpp	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/GdcmDecoding/Plugin.cpp	Fri Sep 18 16:32:29 2015 +0200
@@ -25,7 +25,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include "OrthancContext.h"
-#include "../../../Core/ImageFormats/ImageProcessing.h"
+#include "../../../Core/Images/ImageProcessing.h"
 
 #include <gdcmReader.h>
 #include <gdcmImageReader.h>
--- a/Plugins/Samples/ServeFolders/CMakeLists.txt	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/ServeFolders/CMakeLists.txt	Fri Sep 18 16:32:29 2015 +0200
@@ -6,6 +6,7 @@
 SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)")
 SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages")
 SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp")
+SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of boost")
 
 set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/../../../)
 set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..)
@@ -15,10 +16,12 @@
 include(${CMAKE_SOURCE_DIR}/../Common/OrthancPlugins.cmake)
 include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
 include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake)
+include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake)
 
 add_library(ServeFolders SHARED 
   Plugin.cpp
   ${JSONCPP_SOURCES}
+  ${BOOST_SOURCES}
   )
 
 
--- a/Plugins/Samples/StorageArea/Plugin.cpp	Fri Sep 18 14:28:47 2015 +0200
+++ b/Plugins/Samples/StorageArea/Plugin.cpp	Fri Sep 18 16:32:29 2015 +0200
@@ -33,43 +33,43 @@
 }
 
 
-static int32_t StorageCreate(const char* uuid,
-                             const void* content,
-                             int64_t size,
-                             OrthancPluginContentType type)
+static OrthancPluginErrorCode StorageCreate(const char* uuid,
+                                            const void* content,
+                                            int64_t size,
+                                            OrthancPluginContentType type)
 {
   std::string path = GetPath(uuid);
 
   FILE* fp = fopen(path.c_str(), "wb");
   if (!fp)
   {
-    return -1;
+    return OrthancPluginErrorCode_Plugin;
   }
 
   bool ok = fwrite(content, size, 1, fp) == 1;
   fclose(fp);
 
-  return ok ? 0 : -1;
+  return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin;
 }
 
 
-static int32_t StorageRead(void** content,
-                           int64_t* size,
-                           const char* uuid,
-                           OrthancPluginContentType type)
+static OrthancPluginErrorCode StorageRead(void** content,
+                                          int64_t* size,
+                                          const char* uuid,
+                                          OrthancPluginContentType type)
 {
   std::string path = GetPath(uuid);
 
   FILE* fp = fopen(path.c_str(), "rb");
   if (!fp)
   {
-    return -1;
+    return OrthancPluginErrorCode_Plugin;
   }
 
   if (fseek(fp, 0, SEEK_END) < 0)
   {
     fclose(fp);
-    return -1;
+    return OrthancPluginErrorCode_Plugin;
   }
 
   *size = ftell(fp);
@@ -77,7 +77,7 @@
   if (fseek(fp, 0, SEEK_SET) < 0)
   {
     fclose(fp);
-    return -1;
+    return OrthancPluginErrorCode_Plugin;
   }
 
   bool ok = true;
@@ -98,15 +98,23 @@
 
   fclose(fp);
 
-  return ok ? 0 : -1;  
+  return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin;
 }
 
 
-static int32_t StorageRemove(const char* uuid,
-                             OrthancPluginContentType type)
+static OrthancPluginErrorCode StorageRemove(const char* uuid,
+                                            OrthancPluginContentType type)
 {
   std::string path = GetPath(uuid);
-  return remove(path.c_str());
+
+  if (remove(path.c_str()) == 0)
+  {
+    return OrthancPluginErrorCode_Success;
+  }
+  else
+  {
+    return OrthancPluginErrorCode_Plugin;
+  }
 }