# HG changeset patch # User Sebastien Jodogne # Date 1610526202 -3600 # Node ID 443f219a68fda96af0d02a6746b06729418c9e41 # Parent 68cc194e69e557235e086ea60f53f7cdf2544c31 sync, compatibility with Orthanc framework 1.8.2 diff -r 68cc194e69e5 -r 443f219a68fd Applications/CMakeLists.txt --- a/Applications/CMakeLists.txt Tue Jan 12 18:52:59 2021 +0100 +++ b/Applications/CMakeLists.txt Wed Jan 13 09:23:22 2021 +0100 @@ -104,6 +104,11 @@ ${ORTHANC_WSI_DIR}/Framework/Outputs/TruncatedPyramidWriter.cpp ${ORTHANC_WSI_DIR}/Framework/Targets/FolderTarget.cpp ${ORTHANC_WSI_DIR}/Framework/Targets/OrthancTarget.cpp + + # To access compatibility functions + # "OrthancPlugins::WriteFastJson()" and "OrthancPlugins::ReadJson()" + # if Orthanc framework <= 1.8.2 + ${ORTHANC_WSI_DIR}/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp ) EmbedResources( diff -r 68cc194e69e5 -r 443f219a68fd Applications/Dicomizer.cpp --- a/Applications/Dicomizer.cpp Tue Jan 12 18:52:59 2021 +0100 +++ b/Applications/Dicomizer.cpp Wed Jan 13 09:23:22 2021 +0100 @@ -33,6 +33,7 @@ #include "../Framework/MultiThreading/BagOfTasksProcessor.h" #include "../Framework/Outputs/DicomPyramidWriter.h" #include "../Framework/Outputs/TruncatedPyramidWriter.h" +#include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" #include // For std::unique_ptr #include @@ -297,7 +298,7 @@ std::string content; Orthanc::SystemToolbox::ReadFile(content, path); - if (!Orthanc::Toolbox::ReadJsonWithoutComments(json, content)) + if (!OrthancPlugins::ReadJsonWithoutComments(json, content)) { LOG(ERROR) << "Cannot parse the JSON file in: " << path; throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); @@ -471,7 +472,7 @@ Orthanc::EmbeddedResources::GetFileResource(brightfield, Orthanc::EmbeddedResources::BRIGHTFIELD_OPTICAL_PATH); Json::Value json; - if (!Orthanc::Toolbox::ReadJsonWithoutComments(json, brightfield)) + if (!OrthancPlugins::ReadJsonWithoutComments(json, brightfield)) { throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } diff -r 68cc194e69e5 -r 443f219a68fd Framework/Inputs/DicomPyramidInstance.cpp --- a/Framework/Inputs/DicomPyramidInstance.cpp Tue Jan 12 18:52:59 2021 +0100 +++ b/Framework/Inputs/DicomPyramidInstance.cpp Wed Jan 13 09:23:22 2021 +0100 @@ -23,6 +23,7 @@ #include "DicomPyramidInstance.h" #include "../DicomToolbox.h" +#include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" #include "../../Resources/Orthanc/Stone/DicomDatasetReader.h" #include "../../Resources/Orthanc/Stone/FullOrthancDataset.h" @@ -349,14 +350,14 @@ content[PHOTOMETRIC_INTERPRETATION] = Orthanc::EnumerationToString(photometric_); content[IMAGE_TYPE] = imageType_; - Orthanc::Toolbox::WriteFastJson(result, content); + OrthancPlugins::WriteFastJson(result, content); } void DicomPyramidInstance::Deserialize(const std::string& s) { Json::Value content; - Orthanc::Toolbox::ReadJson(content, s); + OrthancPlugins::ReadJson(content, s); if (content.type() != Json::objectValue || !content.isMember(FRAMES) || diff -r 68cc194e69e5 -r 443f219a68fd Resources/CMake/Version.cmake --- a/Resources/CMake/Version.cmake Tue Jan 12 18:52:59 2021 +0100 +++ b/Resources/CMake/Version.cmake Wed Jan 13 09:23:22 2021 +0100 @@ -4,11 +4,12 @@ set(ORTHANC_FRAMEWORK_VERSION "mainline") set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "hg") else() - set(ORTHANC_FRAMEWORK_VERSION "1.7.0") + set(ORTHANC_FRAMEWORK_VERSION "1.8.2") set(ORTHANC_FRAMEWORK_DEFAULT_SOURCE "web") endif() add_definitions( + -DHAS_ORTHANC_EXCEPTION=1 -DORTHANC_WSI_VERSION="${ORTHANC_WSI_VERSION}" ) diff -r 68cc194e69e5 -r 443f219a68fd Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp --- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Tue Jan 12 18:52:59 2021 +0100 +++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Wed Jan 13 09:23:22 2021 +0100 @@ -313,6 +313,37 @@ } + static bool ReadJsonInternal(Json::Value& target, + const void* buffer, + size_t size, + bool collectComments) + { +#if JSONCPP_USE_DEPRECATED == 1 + Json::Reader reader; + return reader.parse(reinterpret_cast(buffer), + reinterpret_cast(buffer) + size, target, collectComments); +#else + Json::CharReaderBuilder builder; + builder.settings_["collectComments"] = collectComments; + + const std::unique_ptr reader(builder.newCharReader()); + assert(reader.get() != NULL); + + JSONCPP_STRING err; + if (reader->parse(reinterpret_cast(buffer), + reinterpret_cast(buffer) + size, &target, &err)) + { + return true; + } + else + { + LOG(ERROR) << "Cannot parse JSON: " << err; + return false; + } +#endif + } + + bool ReadJson(Json::Value& target, const std::string& source) { @@ -324,29 +355,25 @@ const void* buffer, size_t size) { -#if JSONCPP_USE_DEPRECATED == 1 - Json::Reader reader; - return reader.parse(reinterpret_cast(buffer), - reinterpret_cast(buffer) + size, target); -#else - Json::CharReaderBuilder builder; - const std::unique_ptr reader(builder.newCharReader()); - assert(reader.get() != NULL); - JSONCPP_STRING err; - if (reader->parse(reinterpret_cast(buffer), - reinterpret_cast(buffer) + size, &target, &err)) - { - return true; - } - else - { - LogError("Cannot parse JSON: " + err); - return false; - } -#endif + return ReadJsonInternal(target, buffer, size, true); } + bool ReadJsonWithoutComments(Json::Value& target, + const std::string& source) + { + return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size()); + } + + + bool ReadJsonWithoutComments(Json::Value& target, + const void* buffer, + size_t size) + { + return ReadJsonInternal(target, buffer, size, false); + } + + void WriteFastJson(std::string& target, const Json::Value& source) { diff -r 68cc194e69e5 -r 443f219a68fd Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h --- a/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Tue Jan 12 18:52:59 2021 +0100 +++ b/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Wed Jan 13 09:23:22 2021 +0100 @@ -483,6 +483,13 @@ const void* buffer, size_t size); + bool ReadJsonWithoutComments(Json::Value& target, + const std::string& source); + + bool ReadJsonWithoutComments(Json::Value& target, + const void* buffer, + size_t size); + void WriteFastJson(std::string& target, const Json::Value& source); diff -r 68cc194e69e5 -r 443f219a68fd Resources/Orthanc/Stone/IOrthancConnection.cpp --- a/Resources/Orthanc/Stone/IOrthancConnection.cpp Tue Jan 12 18:52:59 2021 +0100 +++ b/Resources/Orthanc/Stone/IOrthancConnection.cpp Wed Jan 13 09:23:22 2021 +0100 @@ -25,12 +25,31 @@ #include #include +#if !defined(ORTHANC_FRAMEWORK_VERSION_IS_ABOVE) +# error You are using a version of the Orthanc framework that is too old +#endif + +#if !ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) +# include +#endif + + namespace OrthancStone { void IOrthancConnection::ParseJson(Json::Value& result, const std::string& content) { - if (!Orthanc::Toolbox::ReadJson(result, content)) + bool ok; + +#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) + ok = Orthanc::Toolbox::ReadJson(result, content); +#else + // Backward compatibility (for use in orthanc-wsi 1.0) + Json::Reader reader; + ok = reader.parse(content, result); +#endif + + if (!ok) { throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); } @@ -41,7 +60,18 @@ const void* content, size_t size) { - if (!Orthanc::Toolbox::ReadJson(result, content, size)) + bool ok; + +#if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0) + ok = Orthanc::Toolbox::ReadJson(result, content, size); +#else + // Backward compatibility (for use in orthanc-wsi 1.0) + Json::Reader reader; + ok = reader.parse(reinterpret_cast(content), + reinterpret_cast(content) + size, result); +#endif + + if (!ok) { throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); } diff -r 68cc194e69e5 -r 443f219a68fd ViewerPlugin/CMakeLists.txt --- a/ViewerPlugin/CMakeLists.txt Tue Jan 12 18:52:59 2021 +0100 +++ b/ViewerPlugin/CMakeLists.txt Wed Jan 13 09:23:22 2021 +0100 @@ -77,7 +77,6 @@ ##################################################################### add_definitions( - -DHAS_ORTHANC_EXCEPTION=1 -DORTHANC_ENABLE_LOGGING_PLUGIN=1 -DORTHANC_FRAMEWORK_BUILDING_PLUGIN=1 )