# HG changeset patch # User Sebastien Jodogne # Date 1405593960 -7200 # Node ID 5a5a4890ffca867761f2099f1974fbd4969f997f # Parent a53dc58edc5a2fa71e3532b8494d91a1d473babe check version in plugins diff -r a53dc58edc5a -r 5a5a4890ffca Plugins/OrthancCPlugin/OrthancCPlugin.h --- a/Plugins/OrthancCPlugin/OrthancCPlugin.h Wed Jul 16 16:51:26 2014 +0200 +++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h Thu Jul 17 12:46:00 2014 +0200 @@ -81,6 +81,10 @@ #define ORTHANC_PLUGINS_API #endif +#define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0 +#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 8 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 1 + /******************************************************************** @@ -349,6 +353,79 @@ /** + * @brief Check the version of Orthanc. + * + * This function checks whether the version of this C header is + * compatible with the current version of Orthanc. The result of + * this function should always be checked in the + * OrthancPluginInitialize() entry point of the plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return 1 if and only if the versions are compatible. If the + * result is 0, the initialization of the plugin should fail. + **/ + ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( + OrthancPluginContext* context) + { + int major, minor, revision; + + /* Assume compatibility with the mainline */ + if (!strcmp(context->orthancVersion, "mainline")) + { + printf("mainline\n"); + return 1; + } + + /* Parse the version of the Orthanc core */ + if ( +#ifdef _MSC_VER + sscanf_s +#else + sscanf +#endif + (context->orthancVersion, "%d.%d.%d", &major, &minor, &revision) != 3) + { + return 0; + } + + /* Check the major number of the version */ + + if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) + { + return 1; + } + + if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) + { + return 0; + } + + /* Check the minor number of the version */ + + if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) + { + return 1; + } + + if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) + { + return 0; + } + + /* Check the revision number of the version */ + + if (revision >= ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) + { + return 1; + } + else + { + return 0; + } + } + + + /** * @brief Free a memory buffer. * * Free a memory buffer that was allocated by the core system of Orthanc. diff -r a53dc58edc5a -r 5a5a4890ffca Plugins/Samples/Basic/Plugin.c --- a/Plugins/Samples/Basic/Plugin.c Wed Jul 16 16:51:26 2014 +0200 +++ b/Plugins/Samples/Basic/Plugin.c Thu Jul 17 12:46:00 2014 +0200 @@ -134,6 +134,18 @@ char info[1024]; char *id, *eos; + char error[256]; + if (OrthancPluginCheckVersion(c) == 0) + { + sprintf(error, "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); + return -1; + } + context = c; OrthancPluginLogWarning(context, "Sample plugin is initializing");