changeset 74:ab5218c18b7a

compatibility with forthcoming sdk 0.9.5
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Sep 2015 17:52:52 +0200
parents 465bed3c5c81
children e15a59a4b4d4
files NEWS Plugin/Plugin.cpp
diffstat 2 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Fri Aug 28 13:51:55 2015 +0200
+++ b/NEWS	Fri Sep 18 17:52:52 2015 +0200
@@ -1,12 +1,16 @@
 Pending changes in the mainline
 ===============================
 
+=> Minimum SDK version: 0.9.4 <=
+
 * Fix for old versions of jQuery
 
 
 Version 1.2 (2015-08-02)
 ========================
 
+=> Minimum SDK version: 0.9.1 <=
+
 * Update to Boost 1.58.0 for static and Windows builds
 * Inject version information into Windows binaries
 * Support of OS X
--- a/Plugin/Plugin.cpp	Fri Aug 28 13:51:55 2015 +0200
+++ b/Plugin/Plugin.cpp	Fri Sep 18 17:52:52 2015 +0200
@@ -31,6 +31,16 @@
 #include "SeriesInformationAdapter.h"
 
 
+#if (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER >= 9 && ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= 5)
+#  define RETURN_TYPE     OrthancPluginErrorCode
+#  define RETURN_SUCCESS  OrthancPluginErrorCode_Success
+#  define RETURN_FAILURE  OrthancPluginErrorCode_Plugin
+#else
+#  define RETURN_TYPE     int32_t
+#  define RETURN_SUCCESS  0
+#  define RETURN_FAILURE  -1
+#endif
+
 
 class CacheContext
 {
@@ -71,9 +81,9 @@
 
 
 
-static int32_t OnChangeCallback(OrthancPluginChangeType changeType,
-                                OrthancPluginResourceType resourceType,
-                                const char* resourceId)
+static RETURN_TYPE OnChangeCallback(OrthancPluginChangeType changeType,
+                                    OrthancPluginResourceType resourceType,
+                                    const char* resourceId)
 {
   try
   {
@@ -93,28 +103,28 @@
       }
     }
 
-    return 0;
+    return RETURN_SUCCESS;
   }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
-    return 0;  // Ignore error
+    return RETURN_SUCCESS;  // Ignore error
   }
 }
 
 
 
 template <enum OrthancPlugins::CacheBundle bundle>
-int32_t ServeCache(OrthancPluginRestOutput* output,
-                   const char* url,
-                   const OrthancPluginHttpRequest* request)
+static RETURN_TYPE ServeCache(OrthancPluginRestOutput* output,
+                              const char* url,
+                              const OrthancPluginHttpRequest* request)
 {
   try
   {
     if (request->method != OrthancPluginHttpMethod_Get)
     {
       OrthancPluginSendMethodNotAllowed(context_, output, "GET");
-      return 0;
+      return RETURN_SUCCESS;
     }
 
     const std::string id = request->groups[0];
@@ -129,22 +139,22 @@
       OrthancPluginSendHttpStatusCode(context_, output, 404);
     }
 
-    return 0;
+    return RETURN_SUCCESS;
   }
   catch (Orthanc::OrthancException& e)
   {
     OrthancPluginLogError(context_, e.What());
-    return -1;
+    return RETURN_FAILURE;
   }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
-    return -1;
+    return RETURN_FAILURE;
   }
   catch (boost::bad_lexical_cast&)
   {
     OrthancPluginLogError(context_, "Bad lexical cast");
-    return -1;
+    return RETURN_FAILURE;
   }
 }
 
@@ -185,14 +195,14 @@
 
 
 template <enum Orthanc::EmbeddedResources::DirectoryResourceId folder>
-static int32_t ServeEmbeddedFolder(OrthancPluginRestOutput* output,
-                                   const char* url,
-                                   const OrthancPluginHttpRequest* request)
+static RETURN_TYPE ServeEmbeddedFolder(OrthancPluginRestOutput* output,
+                                       const char* url,
+                                       const OrthancPluginHttpRequest* request)
 {
   if (request->method != OrthancPluginHttpMethod_Get)
   {
     OrthancPluginSendMethodNotAllowed(context_, output, "GET");
-    return 0;
+    return RETURN_SUCCESS;
   }
 
   std::string path = "/" + std::string(request->groups[0]);
@@ -206,29 +216,29 @@
     const char* resource = s.size() ? s.c_str() : NULL;
     OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime);
 
-    return 0;
+    return RETURN_SUCCESS;
   }
   catch (std::runtime_error&)
   {
     std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]);
     OrthancPluginLogError(context_, s.c_str());
     OrthancPluginSendHttpStatusCode(context_, output, 404);
-    return 0;
+    return RETURN_SUCCESS;
   }
 }
 
 
 
-static int32_t IsStableSeries(OrthancPluginRestOutput* output,
-                              const char* url,
-                              const OrthancPluginHttpRequest* request)
+static RETURN_TYPE IsStableSeries(OrthancPluginRestOutput* output,
+                                  const char* url,
+                                  const OrthancPluginHttpRequest* request)
 {
  try
   {
     if (request->method != OrthancPluginHttpMethod_Get)
     {
       OrthancPluginSendMethodNotAllowed(context_, output, "GET");
-      return 0;
+      return RETURN_SUCCESS;
     }
 
     const std::string id = request->groups[0];
@@ -247,22 +257,22 @@
       OrthancPluginSendHttpStatusCode(context_, output, 404);
     }
 
-    return 0;
+    return RETURN_SUCCESS;
   }
   catch (Orthanc::OrthancException& e)
   {
     OrthancPluginLogError(context_, e.What());
-    return -1;
+    return RETURN_FAILURE;
   }
   catch (std::runtime_error& e)
   {
     OrthancPluginLogError(context_, e.what());
-    return -1;
+    return RETURN_FAILURE;
   }
   catch (boost::bad_lexical_cast&)
   {
     OrthancPluginLogError(context_, "Bad lexical cast");
-    return -1;
+    return RETURN_FAILURE;
   }
 }