Mercurial > hg > orthanc-wsi
changeset 5:77b76c1a213f
check the version of the Orthanc core
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Oct 2016 13:34:49 +0200 |
parents | e49aaf9127ca |
children | d0108402e85c |
files | Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h ViewerPlugin/CMakeLists.txt ViewerPlugin/Plugin.cpp |
diffstat | 4 files changed, 104 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Oct 24 09:09:13 2016 +0200 +++ b/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Oct 26 13:34:49 2016 +0200 @@ -906,5 +906,97 @@ throw PluginException(error); } } + + + static void ReportIncompatibleVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision) + { + char buf[128]; + sprintf(buf, "Your version of the Orthanc core (%s) is too old to run this plugin (%d.%d.%d is required)", + context->orthancVersion, major, minor, revision); + OrthancPluginLogError(context, buf); + } + + + bool CheckMinimalOrthancVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision) + { + if (context == NULL) + { + OrthancPluginLogError(context, "Bad Orthanc context in the plugin"); + return false; + } + + if (!strcmp(context->orthancVersion, "mainline")) + { + // Assume compatibility with the mainline + return true; + } + + // Parse the version of the Orthanc core + int aa, bb, cc; + if ( +#ifdef _MSC_VER + sscanf_s +#else + sscanf +#endif + (context->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || + aa < 0 || + bb < 0 || + cc < 0) + { + throw false; + } + + unsigned int a = static_cast<unsigned int>(aa); + unsigned int b = static_cast<unsigned int>(bb); + unsigned int c = static_cast<unsigned int>(cc); + + // Check the major version number + + if (a > major) + { + return true; + } + + if (a < major) + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + + + // Check the minor version number + assert(a == major); + + if (b > minor) + { + return true; + } + + if (b < minor) + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + + // Check the patch level version number + assert(a == major && b == minor); + + if (c >= revision) + { + return true; + } + else + { + ReportIncompatibleVersion(context, major, minor, revision); + return false; + } + } }
--- a/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Oct 24 09:09:13 2016 +0200 +++ b/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Oct 26 13:34:49 2016 +0200 @@ -388,6 +388,11 @@ } } + bool CheckMinimalOrthancVersion(OrthancPluginContext* context, + unsigned int major, + unsigned int minor, + unsigned int revision); + namespace Internals {
--- a/ViewerPlugin/CMakeLists.txt Mon Oct 24 09:09:13 2016 +0200 +++ b/ViewerPlugin/CMakeLists.txt Wed Oct 26 13:34:49 2016 +0200 @@ -177,6 +177,7 @@ ${ORTHANC_ROOT}/Core/Logging.cpp ${ORTHANC_ROOT}/Core/MultiThreading/Semaphore.cpp ${ORTHANC_ROOT}/Core/Toolbox.cpp + ${ORTHANC_ROOT}/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp ${AUTOGENERATED_SOURCES}
--- a/ViewerPlugin/Plugin.cpp Mon Oct 24 09:09:13 2016 +0200 +++ b/ViewerPlugin/Plugin.cpp Wed Oct 26 13:34:49 2016 +0200 @@ -330,6 +330,12 @@ return -1; } + if (!OrthancPlugins::CheckMinimalOrthancVersion(context_, 1, 1, 0)) + { + // We need the "/instances/.../frames/.../raw" URI that was introduced in Orthanc 1.1.0 + return -1; + } + // Limit the number of PNG transcoders to the number of available // hardware threads (e.g. number of CPUs or cores or // hyperthreading units)