changeset 1578:09715095fc53

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 15:33:36 +0200
parents 7aac0cddd42e
children b93c398f934d
files CMakeLists.txt Core/Enumerations.cpp Core/Enumerations.h Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h Resources/GenerateErrorCodes.py UnitTestsSources/PluginsTests.cpp
diffstat 7 files changed, 136 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Aug 25 15:10:45 2015 +0200
+++ b/CMakeLists.txt	Tue Aug 25 15:33:36 2015 +0200
@@ -134,9 +134,6 @@
   Core/Uuid.cpp
   Core/Lua/LuaContext.cpp
   Core/Lua/LuaFunctionCall.cpp
-
-  Plugins/Engine/SharedLibrary.cpp
-  Plugins/Engine/PluginsManager.cpp
   )
 
 
@@ -178,8 +175,6 @@
   OrthancServer/QueryRetrieveHandler.cpp
   OrthancServer/LuaScripting.cpp
   OrthancServer/OrthancHttpHandler.cpp
-  Plugins/Engine/OrthancPlugins.cpp
-  Plugins/Engine/OrthancPluginDatabase.cpp
 
   # From "lua-scripting" branch
   OrthancServer/DicomInstanceToStore.cpp
@@ -211,14 +206,26 @@
   UnitTestsSources/UnitTestsMain.cpp
   UnitTestsSources/ImageProcessingTests.cpp
   UnitTestsSources/JpegLosslessTests.cpp
-  UnitTestsSources/PluginsTests.cpp
   UnitTestsSources/StreamTests.cpp
   )
 
 
-set(SERVE_FOLDERS_SOURCES
-  Plugins/Samples/ServeFolders/Plugin.cpp
-  )
+if (ENABLE_PLUGINS)
+  list(APPEND ORTHANC_SERVER_SOURCES
+    Plugins/Engine/OrthancPluginDatabase.cpp
+    Plugins/Engine/OrthancPlugins.cpp
+    Plugins/Engine/PluginsManager.cpp
+    Plugins/Engine/SharedLibrary.cpp
+    )
+
+  list(APPEND ORTHANC_UNIT_TESTS_SOURCES
+    UnitTestsSources/PluginsTests.cpp
+    )
+
+  set(SERVE_FOLDERS_SOURCES
+    Plugins/Samples/ServeFolders/Plugin.cpp
+    )
+endif()
 
 
 set(ORTHANC_EMBEDDED_FILES
@@ -457,28 +464,29 @@
 ## Build the "ServeFolders" plugin
 #####################################################################
 
-add_definitions(-DSERVE_FOLDERS_VERSION="${ORTHANC_VERSION}")
+if (ENABLE_PLUGINS)
+  add_definitions(-DSERVE_FOLDERS_VERSION="${ORTHANC_VERSION}")
 
-include_directories(${CMAKE_SOURCE_DIR}/Plugins/Include)
+  include_directories(${CMAKE_SOURCE_DIR}/Plugins/Include)
 
-add_library(
-  ServeFolders SHARED 
-  ${SERVE_FOLDERS_SOURCES}
-  ${JSONCPP_SOURCES}
-  )
+  add_library(
+    ServeFolders SHARED 
+    ${SERVE_FOLDERS_SOURCES}
+    ${JSONCPP_SOURCES}
+    )
 
-set_target_properties(
-  ServeFolders PROPERTIES 
-  VERSION ${ORTHANC_VERSION} 
-  SOVERSION ${ORTHANC_VERSION}
-  )
+  set_target_properties(
+    ServeFolders PROPERTIES 
+    VERSION ${ORTHANC_VERSION} 
+    SOVERSION ${ORTHANC_VERSION}
+    )
 
-install(
-  TARGETS ServeFolders
-  RUNTIME DESTINATION lib    # Destination for Windows
-  LIBRARY DESTINATION share/orthanc/plugins    # Destination for Linux
-  )
-
+  install(
+    TARGETS ServeFolders
+    RUNTIME DESTINATION lib    # Destination for Windows
+    LIBRARY DESTINATION share/orthanc/plugins    # Destination for Linux
+    )
+endif()
 
 
 
@@ -524,13 +532,15 @@
 ## Install the plugin SDK
 #####################################################################
 
-install(
-  FILES
-  Plugins/Include/orthanc/OrthancCPlugin.h 
-  Plugins/Include/orthanc/OrthancCDatabasePlugin.h 
-  Plugins/Include/orthanc/OrthancCppDatabasePlugin.h 
-  DESTINATION include/orthanc
-  )
+if (ENABLE_PLUGINS)
+  install(
+    FILES
+    Plugins/Include/orthanc/OrthancCPlugin.h 
+    Plugins/Include/orthanc/OrthancCDatabasePlugin.h 
+    Plugins/Include/orthanc/OrthancCppDatabasePlugin.h 
+    DESTINATION include/orthanc
+    )
+endif()
 
 
 
--- a/Core/Enumerations.cpp	Tue Aug 25 15:10:45 2015 +0200
+++ b/Core/Enumerations.cpp	Tue Aug 25 15:33:36 2015 +0200
@@ -40,6 +40,8 @@
 
 namespace Orthanc
 {
+  // This function is autogenerated by the script
+  // "Resources/GenerateErrorCodes.py"
   const char* EnumerationToString(ErrorCode error)
   {
     switch (error)
@@ -921,6 +923,8 @@
   }
 
 
+  // This function is autogenerated by the script
+  // "Resources/GenerateErrorCodes.py"
   HttpStatus ConvertErrorCodeToHttpStatus(ErrorCode error)
   {
     switch (error)
--- a/Core/Enumerations.h	Tue Aug 25 15:10:45 2015 +0200
+++ b/Core/Enumerations.h	Tue Aug 25 15:33:36 2015 +0200
@@ -41,36 +41,38 @@
     Endianness_Little
   };
 
+  // This enumeration is autogenerated by the script
+  // "Resources/GenerateErrorCodes.py"
   enum ErrorCode
   {
-    ErrorCode_Custom = -1,
-    ErrorCode_Success = 0,
-    ErrorCode_InternalError = 1,
-    ErrorCode_NotImplemented = 2,
-    ErrorCode_ParameterOutOfRange = 3,
-    ErrorCode_NotEnoughMemory = 4,
-    ErrorCode_BadParameterType = 5,
-    ErrorCode_BadSequenceOfCalls = 6,
-    ErrorCode_InexistentItem = 7,
-    ErrorCode_BadRequest = 8,
-    ErrorCode_NetworkProtocol = 9,
-    ErrorCode_SystemCommand = 10,
-    ErrorCode_Database = 11,
-    ErrorCode_UriSyntax = 12,
-    ErrorCode_InexistentFile = 13,
-    ErrorCode_CannotWriteFile = 14,
-    ErrorCode_BadFileFormat = 15,
-    ErrorCode_Timeout = 16,
-    ErrorCode_UnknownResource = 17,
-    ErrorCode_IncompatibleDatabaseVersion = 18,
-    ErrorCode_FullStorage = 19,
-    ErrorCode_CorruptedFile = 20,
-    ErrorCode_InexistentTag = 21,
-    ErrorCode_ReadOnly = 22,
-    ErrorCode_IncompatibleImageFormat = 23,
-    ErrorCode_IncompatibleImageSize = 24,
-    ErrorCode_SharedLibrary = 25,
-    ErrorCode_Plugin = 26
+    ErrorCode_Custom = -1    /*!< Custom error, see the attached error message */,
+    ErrorCode_Success = 0    /*!< Success */,
+    ErrorCode_InternalError = 1    /*!< Internal error */,
+    ErrorCode_NotImplemented = 2    /*!< Not implemented yet */,
+    ErrorCode_ParameterOutOfRange = 3    /*!< Parameter out of range */,
+    ErrorCode_NotEnoughMemory = 4    /*!< Not enough memory */,
+    ErrorCode_BadParameterType = 5    /*!< Bad type for a parameter */,
+    ErrorCode_BadSequenceOfCalls = 6    /*!< Bad sequence of calls */,
+    ErrorCode_InexistentItem = 7    /*!< Accessing an inexistent item */,
+    ErrorCode_BadRequest = 8    /*!< Bad request */,
+    ErrorCode_NetworkProtocol = 9    /*!< Error in the network protocol */,
+    ErrorCode_SystemCommand = 10    /*!< Error while calling a system command */,
+    ErrorCode_Database = 11    /*!< Error with the database engine */,
+    ErrorCode_UriSyntax = 12    /*!< Badly formatted URI */,
+    ErrorCode_InexistentFile = 13    /*!< Inexistent file */,
+    ErrorCode_CannotWriteFile = 14    /*!< Cannot write to file */,
+    ErrorCode_BadFileFormat = 15    /*!< Bad file format */,
+    ErrorCode_Timeout = 16    /*!< Timeout */,
+    ErrorCode_UnknownResource = 17    /*!< Unknown resource */,
+    ErrorCode_IncompatibleDatabaseVersion = 18    /*!< Incompatible version of the database */,
+    ErrorCode_FullStorage = 19    /*!< The file storage is full */,
+    ErrorCode_CorruptedFile = 20    /*!< Corrupted file (inconsistent MD5 hash) */,
+    ErrorCode_InexistentTag = 21    /*!< Inexistent tag */,
+    ErrorCode_ReadOnly = 22    /*!< Cannot modify a read-only data structure */,
+    ErrorCode_IncompatibleImageFormat = 23    /*!< Incompatible format of the images */,
+    ErrorCode_IncompatibleImageSize = 24    /*!< Incompatible size of the images */,
+    ErrorCode_SharedLibrary = 25    /*!< Error while using a shared library (plugin) */,
+    ErrorCode_Plugin = 26    /*!< Error encountered inside a plugin */
   };
 
   enum LogLevel
--- a/Plugins/Engine/OrthancPlugins.cpp	Tue Aug 25 15:10:45 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Aug 25 15:33:36 2015 +0200
@@ -172,6 +172,12 @@
 
   OrthancPlugins::OrthancPlugins()
   {
+    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode))
+    {
+      /* Sanity check of the compiler */
+      throw OrthancException(ErrorCode_Plugin);
+    }
+
     pimpl_.reset(new PImpl());
     pimpl_->manager_.RegisterServiceProvider(*this);
   }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Aug 25 15:10:45 2015 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Tue Aug 25 15:33:36 2015 +0200
@@ -156,6 +156,14 @@
 #endif
 
   /**
+   * The various error codes that can be returned by the Orthanc core.
+   **/
+  typedef enum
+  {
+  } OrthancPluginErrorCode;
+
+
+  /**
    * Forward declaration of one of the mandatory functions for Orthanc
    * plugins.
    **/
@@ -600,6 +608,12 @@
   {
     int major, minor, revision;
 
+    if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode))
+    {
+      /* Mismatch in the size of the enumerations */
+      return 0;
+    }
+
     /* Assume compatibility with the mainline */
     if (!strcmp(context->orthancVersion, "mainline"))
     {
--- a/Resources/GenerateErrorCodes.py	Tue Aug 25 15:10:45 2015 +0200
+++ b/Resources/GenerateErrorCodes.py	Tue Aug 25 15:33:36 2015 +0200
@@ -55,16 +55,33 @@
 
 
 ##
-## Generate the "ErrorCode" enumeration in "Core/Enumerations.h"
+## Generate the "ErrorCode" enumeration in "Enumerations.h"
 ##
 
-with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'r') as f:
+path = os.path.join(BASE, 'Core', 'Enumerations.h')
+with open(path, 'r') as f:
     a = f.read()
 
-s = ',\n'.join(map(lambda x: '    ErrorCode_%s = %d' % (x['Name'], int(x['Code'])), ERRORS))
+s = ',\n'.join(map(lambda x: '    ErrorCode_%s = %d    /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
 a = re.sub('(enum ErrorCode\s*{)[^}]*?(\s*};)', r'\1\n%s\2' % s, a, re.DOTALL)
 
-with open(os.path.join(BASE, 'Core', 'Enumerations.h'), 'w') as f:
+with open(path, 'w') as f:
+    f.write(a)
+
+
+
+##
+## Generate the "OrthancPluginErrorCode" enumeration in "OrthancCPlugin.h"
+##
+
+path = os.path.join(BASE, 'Plugins', 'Include', 'orthanc', 'OrthancCPlugin.h')
+with open(path, 'r') as f:
+    a = f.read()
+
+s = ',\n'.join(map(lambda x: '    OrthancPluginErrorCode_%s = %d    /*!< %s */' % (x['Name'], int(x['Code']), x['Description']), ERRORS))
+a = re.sub('(typedef enum\s*{)[^}]*?(\s*} OrthancPluginErrorCode;)', r'\1\n%s\2' % s, a, re.DOTALL)
+
+with open(path, 'w') as f:
     f.write(a)
 
 
@@ -72,10 +89,11 @@
 ##
 ## Generate the "EnumerationToString(ErrorCode)" and
 ## "ConvertErrorCodeToHttpStatus(ErrorCode)" functions in
-## "Core/Enumerations.cpp"
+## "Enumerations.cpp"
 ##
 
-with open(os.path.join(BASE, 'Core', 'Enumerations.cpp'), 'r') as f:
+path = os.path.join(BASE, 'Core', 'Enumerations.cpp')
+with open(path, 'r') as f:
     a = f.read()
 
 s = '\n\n'.join(map(lambda x: '      case ErrorCode_%s:\n        return "%s";' % (x['Name'], x['Description']), ERRORS))
@@ -90,5 +108,5 @@
 a = re.sub('(ConvertErrorCodeToHttpStatus\(ErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)',
            r'\1\n%s\2' % s, a, re.DOTALL)
 
-with open(os.path.join(BASE, 'Core', 'Enumerations.cpp'), 'w') as f:
+with open(path, 'w') as f:
     f.write(a)
--- a/UnitTestsSources/PluginsTests.cpp	Tue Aug 25 15:10:45 2015 +0200
+++ b/UnitTestsSources/PluginsTests.cpp	Tue Aug 25 15:33:36 2015 +0200
@@ -37,6 +37,17 @@
 
 using namespace Orthanc;
 
+
+#if ORTHANC_PLUGINS_ENABLED == 1
+
+TEST(SharedLibrary, Enumerations)
+{
+  // The plugin engine cannot work if the size of an enumeration does
+  // not correspond to the size of "int32_t"
+  ASSERT_EQ(sizeof(int32_t), sizeof(OrthancPluginErrorCode));
+}
+
+
 TEST(SharedLibrary, Basic)
 {
 #if defined(_WIN32)
@@ -74,3 +85,5 @@
 #error Support your platform here
 #endif
 }
+
+#endif