changeset 1040:d06186cdc502

check plugin version in samples
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Jul 2014 13:04:02 +0200
parents 5a5a4890ffca
children 2c49b7dffcec
files Plugins/OrthancCPlugin/OrthancCPlugin.h Plugins/Samples/Basic/Plugin.c Plugins/Samples/GdcmDecoding/OrthancContext.cpp Plugins/Samples/GdcmDecoding/OrthancContext.h Plugins/Samples/GdcmDecoding/Plugin.cpp
diffstat 5 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/OrthancCPlugin/OrthancCPlugin.h	Thu Jul 17 12:46:00 2014 +0200
+++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h	Thu Jul 17 13:04:02 2014 +0200
@@ -372,7 +372,6 @@
     /* Assume compatibility with the mainline */
     if (!strcmp(context->orthancVersion, "mainline"))
     {
-      printf("mainline\n");
       return 1;
     }
 
@@ -414,7 +413,7 @@
 
     /* Check the revision number of the version */
 
-    if (revision >= ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER)
+    if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER)
     {
       return 1;
     }
--- a/Plugins/Samples/Basic/Plugin.c	Thu Jul 17 12:46:00 2014 +0200
+++ b/Plugins/Samples/Basic/Plugin.c	Thu Jul 17 13:04:02 2014 +0200
@@ -134,21 +134,21 @@
   char info[1024];
   char *id, *eos;
 
-  char error[256];
+  context = c;
+  OrthancPluginLogWarning(context, "Sample plugin is initializing");
+
+  /* Check the version of the Orthanc core */
   if (OrthancPluginCheckVersion(c) == 0)
   {
-    sprintf(error, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
+    sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
             c->orthancVersion,
             ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
             ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
             ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
-    OrthancPluginLogError(context, error);
+    OrthancPluginLogError(context, info);
     return -1;
   }
 
-  context = c;
-  OrthancPluginLogWarning(context, "Sample plugin is initializing");
-
   sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion);
   OrthancPluginLogInfo(context, info);
 
--- a/Plugins/Samples/GdcmDecoding/OrthancContext.cpp	Thu Jul 17 12:46:00 2014 +0200
+++ b/Plugins/Samples/GdcmDecoding/OrthancContext.cpp	Thu Jul 17 13:04:02 2014 +0200
@@ -46,15 +46,6 @@
 }
 
 
-OrthancContext::~OrthancContext()
-{
-  if (context_ != NULL)
-  {
-    throw std::runtime_error("The Orthanc plugin was not properly finalized");
-  }
-}
-
-
 void OrthancContext::ExtractGetArguments(Arguments& arguments,
                                          const OrthancPluginHttpRequest& request)
 {
--- a/Plugins/Samples/GdcmDecoding/OrthancContext.h	Thu Jul 17 12:46:00 2014 +0200
+++ b/Plugins/Samples/GdcmDecoding/OrthancContext.h	Thu Jul 17 13:04:02 2014 +0200
@@ -52,8 +52,6 @@
 
   static OrthancContext& GetInstance();
 
-  ~OrthancContext();
-
   void Initialize(OrthancPluginContext* context)
   {
     context_ = context;
--- a/Plugins/Samples/GdcmDecoding/Plugin.cpp	Thu Jul 17 12:46:00 2014 +0200
+++ b/Plugins/Samples/GdcmDecoding/Plugin.cpp	Thu Jul 17 13:04:02 2014 +0200
@@ -29,6 +29,7 @@
 #include <string>
 #include <stdexcept>
 #include <sstream>
+#include <boost/lexical_cast.hpp>
 
 #include "OrthancContext.h"
 #include "../../../Core/ImageFormats/ImageProcessing.h"
@@ -235,6 +236,19 @@
   {
     OrthancContext::GetInstance().Initialize(context);
     OrthancContext::GetInstance().LogWarning("Initializing GDCM decoding");
+
+    // Check the version of the Orthanc core
+    if (OrthancPluginCheckVersion(context) == 0)
+    {
+      OrthancContext::GetInstance().LogError(
+        "Your version of Orthanc (" + std::string(context->orthancVersion) +
+        ") must be above " + boost::lexical_cast<std::string>(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) +
+        "." + boost::lexical_cast<std::string>(ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) +
+        "." + boost::lexical_cast<std::string>(ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER) +
+        " to run this plugin");
+      return -1;
+    }
+
     OrthancContext::GetInstance().Register("/instances/([^/]+)/(preview|image-uint8|image-uint16|image-int16)", DecodeImage);
     return 0;
   }