changeset 29:a0af5a8182a8

sync, removed old patch for Orthanc framework 1.5.6
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Aug 2020 14:26:01 +0200
parents b7e32fe4973b
children 3abebab5d004
files CMakeLists.txt Plugin/Plugin.cpp Resources/Orthanc/CMake/DownloadOrthancFramework.cmake Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Resources/Patches/orthanc-1.5.6.patch
diffstat 5 files changed, 77 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Tue Jul 07 20:42:52 2020 +0200
+++ b/CMakeLists.txt	Tue Aug 04 14:26:01 2020 +0200
@@ -20,15 +20,12 @@
 
 set(ORTHANC_PLUGIN_VERSION "mainline")
 
-if (ORTHANC_PLUGIN_VERSION STREQUAL "mainline")
+if (ORTHANC_PLUGIN_VERSION STREQUAL "mainlinea")
   set(ORTHANC_FRAMEWORK_VERSION "mainline")
   set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg")
 else()
-  set(ORTHANC_FRAMEWORK_VERSION "1.5.6")
+  set(ORTHANC_FRAMEWORK_VERSION "1.7.2")
   set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web")
-
-  # diff --new-file -urEb Orthanc-1.5.6.orig/ Orthanc-1.5.6 > orthanc-1.5.6.patch
-  set(ORTHANC_FRAMEWORK_PATCH "${CMAKE_SOURCE_DIR}/Resources/Patches/orthanc-1.5.6.patch")
 endif()
 
 
@@ -45,6 +42,8 @@
 # Download and setup the Orthanc framework
 include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake)
 
+include_directories(${ORTHANC_FRAMEWORK_ROOT})
+
 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "system")
   link_libraries(${ORTHANC_FRAMEWORK_LIBRARIES})
 
@@ -54,7 +53,7 @@
   include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/CMake/GoogleTestConfiguration.cmake)
 
 else()
-  include(${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
+  include(${ORTHANC_FRAMEWORK_ROOT}/../Resources/CMake/OrthancFrameworkParameters.cmake)
 
   set(ENABLE_LOCALE OFF)         # Disable support for locales (notably in Boost)
   set(ENABLE_GOOGLE_TEST ON)
@@ -63,31 +62,13 @@
   set(ENABLE_MODULE_DICOM OFF)
   set(ENABLE_ZLIB ON)
 
-  include(${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake)
-  include_directories(
-    ${ORTHANC_FRAMEWORK_ROOT}/Sources
-    )
+  include(${ORTHANC_FRAMEWORK_ROOT}/../Resources/CMake/OrthancFrameworkConfiguration.cmake)
 endif()
 
 
 include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Plugins/OrthancPluginsExports.cmake)
 
 
-# Possibly patch the Orthanc framework
-if (DEFINED ORTHANC_FRAMEWORK_PATCH AND
-    NOT EXISTS "${ORTHANC_FRAMEWORK_ROOT}/patched")
-  execute_process(
-    COMMAND ${PATCH_EXECUTABLE} -p0 -N -i ${ORTHANC_FRAMEWORK_PATCH}
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-    RESULT_VARIABLE Failure
-    )
-
-  if (Failure)
-    message(FATAL_ERROR "Error while patching a file")
-  endif()
-endif()
-
-
 # Check that the Orthanc SDK headers are available
 if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK)
   if (ORTHANC_SDK_VERSION STREQUAL "1.4.2")
@@ -107,7 +88,7 @@
 if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
   execute_process(
     COMMAND 
-    ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/Resources/WindowsResources.py
+    ${PYTHON_EXECUTABLE} ${ORTHANC_FRAMEWORK_ROOT}/../Resources/WindowsResources.py
     ${ORTHANC_PLUGIN_VERSION} "TransfersAccelerator index plugin" OrthancTransfers.dll
     "TransfersAccelerator as a database back-end to Orthanc (index)"
     ERROR_VARIABLE Failure
--- a/Plugin/Plugin.cpp	Tue Jul 07 20:42:52 2020 +0200
+++ b/Plugin/Plugin.cpp	Tue Aug 04 14:26:01 2020 +0200
@@ -617,7 +617,7 @@
 {
   ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
   {
-#if defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE)  // This indicates Orthanc framework >= 1.7.2
+#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2)
     Orthanc::Logging::InitializePluginContext(context);
 #else
     Orthanc::Logging::Initialize(context);
--- a/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake	Tue Jul 07 20:42:52 2020 +0200
+++ b/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake	Tue Aug 04 14:26:01 2020 +0200
@@ -110,6 +110,8 @@
         set(ORTHANC_FRAMEWORK_MD5 "ce5f689e852b01d3672bd3d2f952a5ef")
       elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.7.1")
         set(ORTHANC_FRAMEWORK_MD5 "3c171217f930abe80246997bdbcaf7cc")
+      elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.7.2")
+        set(ORTHANC_FRAMEWORK_MD5 "328f94dcbd78c169655a13f7ad58a2c2")
 
       # Below this point are development snapshots that were used to
       # release some plugin, before an official release of the Orthanc
@@ -125,7 +127,7 @@
     endif()
   endif()
 
-elseif (NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "system")
+elseif (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")
   message("Using the Orthanc framework from a path of the filesystem. Assuming mainline version.")
   set(ORTHANC_FRAMEWORK_MAJOR 999)
   set(ORTHANC_FRAMEWORK_MINOR 999)
@@ -175,17 +177,14 @@
 ##
 
 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")
-  if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT)
+  if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT OR
+      ORTHANC_FRAMEWORK_ROOT STREQUAL "")
     message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ROOT must provide the path to the sources of Orthanc")
   endif()
   
   if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT})
     message(FATAL_ERROR "Non-existing directory: ${ORTHANC_FRAMEWORK_ROOT}")
   endif()
-  
-  if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
-    message(FATAL_ERROR "Directory not containing the source code of the Orthanc framework: ${ORTHANC_FRAMEWORK_ROOT}")
-  endif()
 endif()
 
 
@@ -232,16 +231,6 @@
   if (Failure)
     message(FATAL_ERROR "Error while running Mercurial")
   endif()
-
-  unset(ORTHANC_FRAMEWORK_ROOT CACHE)
-  set(ORTHANC_FRAMEWORK_ROOT "${ORTHANC_ROOT}/OrthancFramework" CACHE
-    STRING "Path to the Orthanc framework source directory")
-
-  if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
-    message(FATAL_ERROR "Directory not containing the source code of the Orthanc framework: ${ORTHANC_ROOT}")
-  endif()
-
-  unset(ORTHANC_ROOT)
 endif()
 
 
@@ -252,7 +241,8 @@
 ##
 
 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive")
-  if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE)
+  if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR
+      ORTHANC_FRAMEWORK_ARCHIVE STREQUAL "")
     message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc")
   endif()
 endif()
@@ -369,18 +359,45 @@
       message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.")
     endif()
   endif()
+endif()
+
+
+
+##
+## Determine the path to the sources of the Orthanc framework
+##
+
+if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
+    ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" OR
+    ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
+  if (NOT DEFINED ORTHANC_ROOT OR
+      NOT DEFINED ORTHANC_FRAMEWORK_MAJOR OR
+      NOT DEFINED ORTHANC_FRAMEWORK_MINOR OR
+      NOT DEFINED ORTHANC_FRAMEWORK_REVISION)
+    message(FATAL_ERROR "Internal error in the DownloadOrthancFramework.cmake file")
+  endif()
 
   unset(ORTHANC_FRAMEWORK_ROOT CACHE)
-  set(ORTHANC_FRAMEWORK_ROOT "${ORTHANC_ROOT}/OrthancFramework" CACHE
-    STRING "Path to the Orthanc framework source directory")
 
-  if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
-    message(FATAL_ERROR "Directory not containing the source code of the Orthanc framework: ${ORTHANC_ROOT}")
+  if ("${ORTHANC_FRAMEWORK_MAJOR}.${ORTHANC_FRAMEWORK_MINOR}.${ORTHANC_FRAMEWORK_REVISION}" VERSION_LESS "1.7.2")
+    set(ORTHANC_FRAMEWORK_ROOT "${ORTHANC_ROOT}/Core" CACHE
+      STRING "Path to the Orthanc framework source directory")
+    set(ENABLE_PLUGINS_VERSION_SCRIPT OFF)
+  else()
+    set(ORTHANC_FRAMEWORK_ROOT "${ORTHANC_ROOT}/OrthancFramework/Sources" CACHE
+      STRING "Path to the Orthanc framework source directory")
   endif()
 
   unset(ORTHANC_ROOT)
 endif()
 
+if (NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "system")
+  if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/OrthancException.h OR
+      NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/../Resources/CMake/OrthancFrameworkParameters.cmake)
+    message(FATAL_ERROR "Directory not containing the source code of the Orthanc framework: ${ORTHANC_FRAMEWORK_ROOT}")
+  endif()
+endif()
+
 
 
 ##
@@ -425,6 +442,35 @@
       message(FATAL_ERROR "Please install the libjsoncpp-dev package")
     endif()
 
+    # Switch to the C++11 standard if the version of JsonCpp is 1.y.z
+    # (same as variable JSONCPP_CXX11 in the source code of Orthanc)
+    if (EXISTS ${JSONCPP_INCLUDE_DIR}/json/version.h)
+      file(STRINGS
+        "${JSONCPP_INCLUDE_DIR}/json/version.h" 
+        JSONCPP_VERSION_MAJOR1 REGEX
+        ".*define JSONCPP_VERSION_MAJOR.*")
+
+      if (NOT JSONCPP_VERSION_MAJOR1)
+        message(FATAL_ERROR "Unable to extract the major version of JsonCpp")
+      endif()
+      
+      string(REGEX REPLACE
+        ".*JSONCPP_VERSION_MAJOR.*([0-9]+)$" "\\1" 
+        JSONCPP_VERSION_MAJOR ${JSONCPP_VERSION_MAJOR1})
+      message("JsonCpp major version: ${JSONCPP_VERSION_MAJOR}")
+
+      if (JSONCPP_VERSION_MAJOR GREATER 0)
+        message("Switching to C++11 standard, as version of JsonCpp is >= 1.0.0")
+        if (CMAKE_COMPILER_IS_GNUCXX)
+          set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
+        elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+          set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+        endif()
+      endif()
+    else()
+      message("Unable to detect the major version of JsonCpp, assuming < 1.0.0")
+    endif()
+
     # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake)
     include(FindBoost)
     find_package(Boost COMPONENTS filesystem thread system date_time regex ${ORTHANC_BOOST_COMPONENTS})
@@ -517,8 +563,4 @@
 
   unset(CMAKE_REQUIRED_INCLUDES)
   unset(CMAKE_REQUIRED_LIBRARIES)
-  
-  if (NOT "${ORTHANC_FRAMEWORK_ROOT}" STREQUAL "")
-    include_directories(${ORTHANC_FRAMEWORK_ROOT})
-  endif()
 endif()
--- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h	Tue Jul 07 20:42:52 2020 +0200
+++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h	Tue Aug 04 14:26:01 2020 +0200
@@ -1158,9 +1158,9 @@
     
   public:
 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1)    
-    DicomInstance(const OrthancPluginDicomInstance* instance);
+    explicit DicomInstance(const OrthancPluginDicomInstance* instance);
 #else
-    DicomInstance(OrthancPluginDicomInstance* instance);
+    explicit DicomInstance(OrthancPluginDicomInstance* instance);
 #endif
 
 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0)
--- a/Resources/Patches/orthanc-1.5.6.patch	Tue Jul 07 20:42:52 2020 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-diff --new-file -urEb Orthanc-1.5.6.orig/patched Orthanc-1.5.6/patched
---- Orthanc-1.5.6.orig/patched	1970-01-01 01:00:00.000000000 +0100
-+++ Orthanc-1.5.6/patched	2019-03-04 16:41:37.532734849 +0100
-@@ -0,0 +1 @@
-+patched
-diff --new-file -urEb Orthanc-1.5.6.orig/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Orthanc-1.5.6/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
---- Orthanc-1.5.6.orig/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	2019-03-04 16:19:10.126165813 +0100
-+++ Orthanc-1.5.6/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	2019-03-04 16:19:39.330128951 +0100
-@@ -145,6 +145,13 @@
-   }
- 
- 
-+  void MemoryBuffer::Swap(MemoryBuffer& other)
-+  {
-+    std::swap(buffer_.data, other.buffer_.data);
-+    std::swap(buffer_.size, other.buffer_.size);
-+  }
-+
-+
-   OrthancPluginMemoryBuffer MemoryBuffer::Release()
-   {
-     OrthancPluginMemoryBuffer result = buffer_;
-@@ -1024,11 +1031,11 @@
-   {
-     CheckImageAvailable();
- 
--    OrthancPluginMemoryBuffer tmp;
--    OrthancPluginCompressPngImage(GetGlobalContext(), &tmp, GetPixelFormat(),
-+    OrthancPlugins::MemoryBuffer answer;
-+    OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(),
-                                   GetWidth(), GetHeight(), GetPitch(), GetBuffer());
- 
--    target.Assign(tmp);
-+    target.Swap(answer);
-   }
- 
- 
-@@ -1037,11 +1044,11 @@
-   {
-     CheckImageAvailable();
- 
--    OrthancPluginMemoryBuffer tmp;
--    OrthancPluginCompressJpegImage(GetGlobalContext(), &tmp, GetPixelFormat(),
-+    OrthancPlugins::MemoryBuffer answer;
-+    OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(),
-                                    GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
- 
--    target.Assign(tmp);
-+    target.Swap(answer);
-   }
- 
- 
-@@ -1580,16 +1587,16 @@
-       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
-     }
- 
--    OrthancPluginMemoryBuffer answer;
-+    OrthancPlugins::MemoryBuffer answer;
-     uint16_t status;
-     OrthancPluginErrorCode code = OrthancPluginCallPeerApi
--        (GetGlobalContext(), &answer, NULL, &status, peers_,
-+        (GetGlobalContext(), *answer, NULL, &status, peers_,
-          static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(),
-          0, NULL, NULL, NULL, 0, timeout_);
- 
-     if (code == OrthancPluginErrorCode_Success)
-     {
--      target.Assign(answer);
-+      target.Swap(answer);
-       return (status == 200);
-     }
-     else
-@@ -1704,16 +1711,16 @@
-       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
-     }
- 
--    OrthancPluginMemoryBuffer answer;
-+    OrthancPlugins::MemoryBuffer answer;
-     uint16_t status;
-     OrthancPluginErrorCode code = OrthancPluginCallPeerApi
--        (GetGlobalContext(), &answer, NULL, &status, peers_,
-+        (GetGlobalContext(), *answer, NULL, &status, peers_,
-          static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(),
-          0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
- 
-     if (code == OrthancPluginErrorCode_Success)
-     {
--      target.Assign(answer);
-+      target.Swap(answer);
-       return (status == 200);
-     }
-     else
-@@ -1732,16 +1739,15 @@
-       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
-     }
- 
--    OrthancPluginMemoryBuffer answer;
-+    OrthancPlugins::MemoryBuffer answer;
-     uint16_t status;
-     OrthancPluginErrorCode code = OrthancPluginCallPeerApi
--        (GetGlobalContext(), &answer, NULL, &status, peers_,
-+        (GetGlobalContext(), *answer, NULL, &status, peers_,
-          static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
-          0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_);
- 
-     if (code == OrthancPluginErrorCode_Success)
-     {
--      OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer);
-       return (status == 200);
-     }
-     else
-@@ -1769,16 +1775,15 @@
-       ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
-     }
- 
--    OrthancPluginMemoryBuffer answer;
-+    OrthancPlugins::MemoryBuffer answer;
-     uint16_t status;
-     OrthancPluginErrorCode code = OrthancPluginCallPeerApi
--        (GetGlobalContext(), &answer, NULL, &status, peers_,
--         static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(),
-+      (GetGlobalContext(), *answer, NULL, &status, peers_,
-+       static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(),
-          0, NULL, NULL, NULL, 0, timeout_);
- 
-     if (code == OrthancPluginErrorCode_Success)
-     {
--      OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &answer);
-       return (status == 200);
-     }
-     else
-diff --new-file -urEb Orthanc-1.5.6.orig/Plugins/Samples/Common/OrthancPluginCppWrapper.h Orthanc-1.5.6/Plugins/Samples/Common/OrthancPluginCppWrapper.h
---- Orthanc-1.5.6.orig/Plugins/Samples/Common/OrthancPluginCppWrapper.h	2019-03-04 16:19:10.126165813 +0100
-+++ Orthanc-1.5.6/Plugins/Samples/Common/OrthancPluginCppWrapper.h	2019-03-04 16:19:42.018125583 +0100
-@@ -129,6 +129,8 @@
-     // This transfers ownership from "other" to "this"
-     void Assign(OrthancPluginMemoryBuffer& other);
- 
-+    void Swap(MemoryBuffer& other);
-+
-     OrthancPluginMemoryBuffer Release();
- 
-     const char* GetData() const