Mercurial > hg > orthanc-wsi
changeset 223:443f219a68fd
sync, compatibility with Orthanc framework 1.8.2
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 13 Jan 2021 09:23:22 +0100 |
parents | 68cc194e69e5 |
children | c6ef9ff37f69 |
files | Applications/CMakeLists.txt Applications/Dicomizer.cpp Framework/Inputs/DicomPyramidInstance.cpp Resources/CMake/Version.cmake Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h Resources/Orthanc/Stone/IOrthancConnection.cpp ViewerPlugin/CMakeLists.txt |
diffstat | 8 files changed, 99 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- 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(
--- 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 <Compatibility.h> // For std::unique_ptr #include <DicomParsing/FromDcmtkBridge.h> @@ -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); }
--- 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) ||
--- 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}" )
--- 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<const char*>(buffer), + reinterpret_cast<const char*>(buffer) + size, target, collectComments); +#else + Json::CharReaderBuilder builder; + builder.settings_["collectComments"] = collectComments; + + const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); + assert(reader.get() != NULL); + + JSONCPP_STRING err; + if (reader->parse(reinterpret_cast<const char*>(buffer), + reinterpret_cast<const char*>(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<const char*>(buffer), - reinterpret_cast<const char*>(buffer) + size, target); -#else - Json::CharReaderBuilder builder; - const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); - assert(reader.get() != NULL); - JSONCPP_STRING err; - if (reader->parse(reinterpret_cast<const char*>(buffer), - reinterpret_cast<const char*>(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) {
--- 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);
--- 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 <OrthancException.h> #include <Toolbox.h> +#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 <json/reader.h> +#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<const char*>(content), + reinterpret_cast<const char*>(content) + size, result); +#endif + + if (!ok) { throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); }
--- 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 )