changeset 1407:d371a66972a4

OrthancPluginGetExpectedDatabaseVersion
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Jun 2015 10:19:13 +0200
parents d29e56f59dcf
children 29d3e64dd828 8146fcd7d8af
files CMakeLists.txt OrthancServer/DatabaseWrapper.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Include/OrthancCPlugin.h
diffstat 4 files changed, 56 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Jun 02 17:48:13 2015 +0200
+++ b/CMakeLists.txt	Wed Jun 03 10:19:13 2015 +0200
@@ -5,6 +5,14 @@
 # Version of the build, should always be "mainline" except in release branches
 set(ORTHANC_VERSION "mainline")
 
+# Version of the database schema. History:
+#   * Orthanc 0.1.0 -> Orthanc 0.3.0 = no versioning
+#   * Orthanc 0.3.1                  = version 2
+#   * Orthanc 0.4.0 -> Orthanc 0.7.2 = version 3
+#   * Orthanc 0.7.3 -> Orthanc 0.8.4 = version 4
+#   * Orthanc 0.8.5 -> mainline      = version 5
+set(ORTHANC_DATABASE_VERSION 5)
+
 
 #####################################################################
 ## CMake parameters tunable at the command line
@@ -308,6 +316,7 @@
 
 add_definitions(
   -DORTHANC_VERSION="${ORTHANC_VERSION}"
+  -DORTHANC_DATABASE_VERSION=${ORTHANC_DATABASE_VERSION}
   )
 
 list(LENGTH OPENSSL_SOURCES OPENSSL_SOURCES_LENGTH)
--- a/OrthancServer/DatabaseWrapper.cpp	Tue Jun 02 17:48:13 2015 +0200
+++ b/OrthancServer/DatabaseWrapper.cpp	Wed Jun 03 10:19:13 2015 +0200
@@ -796,15 +796,6 @@
       LOG(INFO) << "Version of the Orthanc database: " << version;
       unsigned int v = boost::lexical_cast<unsigned int>(version);
 
-      /**
-       * History of the database versions:
-       *  - Orthanc before Orthanc 0.3.0 (inclusive) had no version
-       *  - Version 2: only Orthanc 0.3.1
-       *  - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive)
-       *  - Version 4: from Orthanc 0.7.3 to Orthanc 0.8.4 (inclusive)
-       *  - Version 5: from Orthanc 0.8.5 (inclusive)
-       **/
-
       // This version of Orthanc is only compatible with versions 3, 4 and 5 of the DB schema
       ok = (v == 3 || v == 4 || v == 5);
 
@@ -821,6 +812,12 @@
         UpgradeDatabase(db_, EmbeddedResources::UPGRADE_DATABASE_4_TO_5);
         v = 5;
       }
+
+      // Sanity check
+      if (ORTHANC_DATABASE_VERSION != v)
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }
     }
     catch (boost::bad_lexical_cast&)
     {
--- a/Plugins/Engine/OrthancPlugins.cpp	Tue Jun 02 17:48:13 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Wed Jun 03 10:19:13 2015 +0200
@@ -1205,6 +1205,14 @@
         }
       }
 
+      case _OrthancPluginService_GetExpectedDatabaseVersion:
+      {
+        const _OrthancPluginReturnSingleValue& p =
+          *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(parameters);
+        *(p.resultUint32) = ORTHANC_DATABASE_VERSION;
+        return true;
+      }
+
       default:
         return false;
     }
--- a/Plugins/Include/OrthancCPlugin.h	Tue Jun 02 17:48:13 2015 +0200
+++ b/Plugins/Include/OrthancCPlugin.h	Wed Jun 03 10:19:13 2015 +0200
@@ -89,8 +89,8 @@
 #endif
 
 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER     0
-#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER     8
-#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER  6
+#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER     9
+#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER  0
 
 
 
@@ -255,6 +255,7 @@
     _OrthancPluginService_SetGlobalProperty = 9,
     _OrthancPluginService_GetCommandLineArgumentsCount = 10,
     _OrthancPluginService_GetCommandLineArgument = 11,
+    _OrthancPluginService_GetExpectedDatabaseVersion = 12,
 
     /* Registration of callbacks */
     _OrthancPluginService_RegisterRestCallback = 1000,
@@ -2085,6 +2086,36 @@
   }
 
 
+  /**
+   * @brief Get the expected version of the database schema.
+   *
+   * Retrieve the expected version of the database schema.
+   * 
+   * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
+   * @return The version.
+   **/
+  ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
+    OrthancPluginContext*  context)
+  {
+    uint32_t count = 0;
+
+    _OrthancPluginReturnSingleValue params;
+    memset(&params, 0, sizeof(params));
+    params.resultUint32 = &count;
+
+    if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params))
+    {
+      /* Error */
+      return 0;
+    }
+    else
+    {
+      return count;
+    }
+  }
+
+
+
 #ifdef  __cplusplus
 }
 #endif