Mercurial > hg > orthanc-postgresql
changeset 170:a574a82f3175
using Orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Apr 2018 17:19:57 +0200 (2018-04-16) |
parents | 62fcde4eb3db |
children | 01c650c5aa18 |
files | CMakeLists.txt Core/PostgreSQLResult.cpp Core/PostgreSQLStatement.cpp Orthanc/Core/Endianness.h Orthanc/NEWS Orthanc/Plugins/Samples/Common/ExportedSymbols.list Orthanc/Plugins/Samples/Common/VersionScript.map Orthanc/README.txt Orthanc/Resources/CMake/AutoGeneratedCode.cmake Orthanc/Resources/CMake/BoostConfiguration.cmake Orthanc/Resources/CMake/Compiler.cmake Orthanc/Resources/CMake/DownloadPackage.cmake Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Orthanc/Resources/CMake/JsonCppConfiguration.cmake Orthanc/Resources/CMake/UuidConfiguration.cmake Orthanc/Resources/EmbedResources.py Orthanc/Resources/LinuxStandardBaseToolchain.cmake Orthanc/Resources/MinGW-W64-Toolchain32.cmake Orthanc/Resources/MinGW-W64-Toolchain64.cmake Orthanc/Resources/MinGWToolchain.cmake Orthanc/Resources/Patches/boost-1.66.0-linux-standard-base.patch Orthanc/Resources/ThirdParty/VisualStudio/stdint.h Orthanc/Resources/WindowsResources.py Orthanc/Resources/WindowsResources.rc Orthanc/Sdk-0.9.5/orthanc/OrthancCDatabasePlugin.h Orthanc/Sdk-0.9.5/orthanc/OrthancCPlugin.h Orthanc/Sdk-0.9.5/orthanc/OrthancCppDatabasePlugin.h Resources/CMake/LinuxStandardBaseToolchain.cmake Resources/Orthanc/DownloadOrthancFramework.cmake Resources/Orthanc/LinuxStandardBaseToolchain.cmake Resources/Orthanc/MinGW-W64-Toolchain32.cmake Resources/Orthanc/MinGW-W64-Toolchain64.cmake Resources/Orthanc/MinGWToolchain.cmake Resources/Orthanc/README.txt Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCDatabasePlugin.h Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCPlugin.h Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCppDatabasePlugin.h Resources/SyncOrthancFolder.py |
diffstat | 38 files changed, 7857 insertions(+), 10646 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Wed Apr 11 16:24:01 2018 +0200 +++ b/CMakeLists.txt Mon Apr 16 17:19:57 2018 +0200 @@ -30,49 +30,39 @@ set(BUILD_UNIT_TESTS ON CACHE BOOL "Build UnitTests") # Advanced parameters to fine-tune linking against system libraries -set(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") -set(USE_SYSTEM_GOOGLE_TEST ON CACHE BOOL "Use the system version of Google Test") -set(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") set(USE_SYSTEM_LIBPQ ON CACHE BOOL "Use the system version of the PostgreSQL client library") set(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK") -set(USE_SYSTEM_UUID ON CACHE BOOL "Use the system version of the uuid library from e2fsprogs") -# Distribution-specific settings -set(USE_GOOGLE_TEST_DEBIAN_PACKAGE OFF CACHE BOOL "Use the sources of Google Test shipped with libgtest-dev (Debian only)") -mark_as_advanced(USE_GOOGLE_TEST_DEBIAN_PACKAGE) - -set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/Orthanc) -set(ENABLE_LOCALE OFF) # Disable support for locales (notably in Boost) - -if (NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") - # The "patch" command-line tool is only needed for Boost and LSB - set(ORTHANC_DISABLE_PATCH ON) +# Download the Orthanc framework +if (ORTHANC_POSTGRESQL_VERSION STREQUAL "mainline") + set(ORTHANC_FRAMEWORK_SOURCE "hg") + set(ORTHANC_FRAMEWORK_VERSION "mainline") +else() + set(ORTHANC_FRAMEWORK_SOURCE "web") + set(ORTHANC_FRAMEWORK_VERSION "1.3.1") endif() -include(CheckIncludeFiles) -include(CheckIncludeFileCXX) -include(CheckLibraryExists) -include(FindPythonInterp) -include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/AutoGeneratedCode.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) +include(${CMAKE_SOURCE_DIR}/Resources/Orthanc/DownloadOrthancFramework.cmake) + + +# Initialize the Orthanc framework +include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake) + +set(ENABLE_LOCALE OFF) # Disable support for locales (notably in Boost) +set(ENABLE_GOOGLE_TEST ON) + +include(${ORTHANC_ROOT}/Resources/CMake/OrthancFrameworkConfiguration.cmake) +include_directories(${ORTHANC_ROOT}) + # The CMake script in "Graveyard" was used up to release 2.0. The new # script makes auto-configuration of the variables. include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake) #include(${CMAKE_SOURCE_DIR}/Resources/Graveyard/PostgreSQLConfiguration.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/UuidConfiguration.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) - -if (BUILD_UNIT_TESTS) - include(${ORTHANC_ROOT}/Resources/CMake/GoogleTestConfiguration.cmake) -endif() - if (STATIC_BUILD OR NOT USE_SYSTEM_ORTHANC_SDK) - include_directories(${ORTHANC_ROOT}/Sdk-0.9.5) + include_directories(${CMAKE_SOURCE_DIR}/Resources/Orthanc/Sdk-0.9.5) else () CHECK_INCLUDE_FILE_CXX(orthanc/OrthancCppDatabasePlugin.h HAVE_ORTHANC_H) if (NOT HAVE_ORTHANC_H) @@ -81,7 +71,6 @@ endif() - if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") link_libraries(secur32) @@ -134,11 +123,10 @@ ${CMAKE_SOURCE_DIR}/Core/PostgreSQLTransaction.cpp ${CMAKE_SOURCE_DIR}/Core/Configuration.cpp ${CMAKE_SOURCE_DIR}/Core/GlobalProperties.cpp + ${AUTOGENERATED_DIR}/EmbeddedResources.cpp + ${ORTHANC_CORE_SOURCES} ${LIBPQ_SOURCES} - ${BOOST_SOURCES} - ${JSONCPP_SOURCES} - ${UUID_SOURCES} ) add_library(OrthancPostgreSQLStorage @@ -152,7 +140,6 @@ add_library(OrthancPostgreSQLIndex SHARED ${CORE_SOURCES} - ${AUTOGENERATED_SOURCES} ${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp ${CMAKE_SOURCE_DIR}/IndexPlugin/Plugin.cpp ${INDEX_RESOURCES} @@ -182,13 +169,12 @@ if (BUILD_UNIT_TESTS) add_executable(UnitTests ${CORE_SOURCES} - ${GOOGLE_TEST_SOURCES} - ${AUTOGENERATED_SOURCES} ${CMAKE_SOURCE_DIR}/IndexPlugin/PostgreSQLWrapper.cpp ${CMAKE_SOURCE_DIR}/StoragePlugin/PostgreSQLStorageArea.cpp ${CMAKE_SOURCE_DIR}/UnitTestsSources/UnitTestsMain.cpp ${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLTests.cpp ${CMAKE_SOURCE_DIR}/UnitTestsSources/PostgreSQLWrapperTests.cpp + ${GOOGLE_TEST_SOURCES} ) target_link_libraries(UnitTests ${GOOGLE_TEST_LIBRARIES})
--- a/Core/PostgreSQLResult.cpp Wed Apr 11 16:24:01 2018 +0200 +++ b/Core/PostgreSQLResult.cpp Mon Apr 16 17:19:57 2018 +0200 @@ -31,7 +31,7 @@ #include <c.h> #include <catalog/pg_type.h> -#include "../Orthanc/Core/Endianness.h" +#include <Core/Endianness.h> namespace OrthancPlugins
--- a/Core/PostgreSQLStatement.cpp Wed Apr 11 16:24:01 2018 +0200 +++ b/Core/PostgreSQLStatement.cpp Mon Apr 16 17:19:57 2018 +0200 @@ -31,7 +31,7 @@ #include <c.h> #include <catalog/pg_type.h> -#include "../Orthanc/Core/Endianness.h" +#include <Core/Endianness.h> namespace OrthancPlugins
--- a/Orthanc/Core/Endianness.h Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * Copyright (C) 2017-2018 Osimis S.A., Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - -#pragma once - - -/******************************************************************** - ** LINUX-LIKE ARCHITECTURES - ********************************************************************/ - -#if defined(__LSB_VERSION__) -// Linux Standard Base (LSB) does not come with be16toh, be32toh, and -// be64toh -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0 -# include <endian.h> -#elif defined(__linux__) || defined(__EMSCRIPTEN__) -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# include <endian.h> -#endif - - -/******************************************************************** - ** WINDOWS ARCHITECTURES - ** - ** On Windows x86, "host" will always be little-endian ("le"). - ********************************************************************/ - -#if defined(_WIN32) -# if defined(_MSC_VER) -// Visual Studio - http://msdn.microsoft.com/en-us/library/a3140177.aspx -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# define be16toh(x) _byteswap_ushort(x) -# define be32toh(x) _byteswap_ulong(x) -# define be64toh(x) _byteswap_uint64(x) -# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) -// MinGW >= 4.3 - Use builtin intrinsic for byte swapping -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# define be16toh(x) __builtin_bswap16(x) -# define be32toh(x) __builtin_bswap32(x) -# define be64toh(x) __builtin_bswap64(x) -# else -// MinGW <= 4.2, we must manually implement the byte swapping -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0 -# define be16toh(x) __orthanc_bswap16(x) -# define be32toh(x) __orthanc_bswap32(x) -# define be64toh(x) __orthanc_bswap64(x) -# endif - -# define htobe16(x) be16toh(x) -# define htobe32(x) be32toh(x) -# define htobe64(x) be64toh(x) - -# define htole16(x) x -# define htole32(x) x -# define htole64(x) x - -# define le16toh(x) x -# define le32toh(x) x -# define le64toh(x) x -#endif - - -/******************************************************************** - ** FREEBSD ARCHITECTURES - ********************************************************************/ - -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# include <arpa/inet.h> -#endif - - -/******************************************************************** - ** OPENBSD ARCHITECTURES - ********************************************************************/ - -#if defined(__OpenBSD__) -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# include <endian.h> -#endif - - -/******************************************************************** - ** APPLE ARCHITECTURES (including OS X) - ********************************************************************/ - -#if defined(__APPLE__) -# define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1 -# include <libkern/OSByteOrder.h> -# define be16toh(x) OSSwapBigToHostInt16(x) -# define be32toh(x) OSSwapBigToHostInt32(x) -# define be64toh(x) OSSwapBigToHostInt64(x) - -# define htobe16(x) OSSwapHostToBigInt16(x) -# define htobe32(x) OSSwapHostToBigInt32(x) -# define htobe64(x) OSSwapHostToBigInt64(x) - -# define htole16(x) OSSwapHostToLittleInt16(x) -# define htole32(x) OSSwapHostToLittleInt32(x) -# define htole64(x) OSSwapHostToLittleInt64(x) - -# define le16toh(x) OSSwapLittleToHostInt16(x) -# define le32toh(x) OSSwapLittleToHostInt32(x) -# define le64toh(x) OSSwapLittleToHostInt64(x) -#endif - - -/******************************************************************** - ** PORTABLE (BUT SLOW) IMPLEMENTATION OF BYTE-SWAPPING - ********************************************************************/ - -#if ORTHANC_HAS_BUILTIN_BYTE_SWAP != 1 - -#include <stdint.h> - -static inline uint16_t __orthanc_bswap16(uint16_t a) -{ - return (a << 8) | (a >> 8); -} - -static inline uint32_t __orthanc_bswap32(uint32_t a) -{ - const uint8_t* p = reinterpret_cast<const uint8_t*>(&a); - return (static_cast<uint32_t>(p[0]) << 24 | - static_cast<uint32_t>(p[1]) << 16 | - static_cast<uint32_t>(p[2]) << 8 | - static_cast<uint32_t>(p[3])); -} - -static inline uint64_t __orthanc_bswap64(uint64_t a) -{ - const uint8_t* p = reinterpret_cast<const uint8_t*>(&a); - return (static_cast<uint64_t>(p[0]) << 56 | - static_cast<uint64_t>(p[1]) << 48 | - static_cast<uint64_t>(p[2]) << 40 | - static_cast<uint64_t>(p[3]) << 32 | - static_cast<uint64_t>(p[4]) << 24 | - static_cast<uint64_t>(p[5]) << 16 | - static_cast<uint64_t>(p[6]) << 8 | - static_cast<uint64_t>(p[7])); -} - -#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) -# if __BYTE_ORDER == __LITTLE_ENDIAN -# define be16toh(x) __orthanc_bswap16(x) -# define be32toh(x) __orthanc_bswap32(x) -# define be64toh(x) __orthanc_bswap64(x) -# define htobe16(x) __orthanc_bswap16(x) -# define htobe32(x) __orthanc_bswap32(x) -# define htobe64(x) __orthanc_bswap64(x) -# define htole16(x) x -# define htole32(x) x -# define htole64(x) x -# define le16toh(x) x -# define le32toh(x) x -# define le64toh(x) x -# elif __BYTE_ORDER == __BIG_ENDIAN -# define be16toh(x) x -# define be32toh(x) x -# define be64toh(x) x -# define htobe16(x) x -# define htobe32(x) x -# define htobe64(x) x -# define htole16(x) __orthanc_bswap16(x) -# define htole32(x) __orthanc_bswap32(x) -# define htole64(x) __orthanc_bswap64(x) -# define le16toh(x) __orthanc_bswap16(x) -# define le32toh(x) __orthanc_bswap32(x) -# define le64toh(x) __orthanc_bswap64(x) -# else -# error Please support your platform here -# endif -#else -# error Please support your platform here -#endif - -#endif
--- a/Orthanc/NEWS Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,946 +0,0 @@ -Pending changes in the mainline -=============================== - -REST API --------- - -* "/system" URI returns the version of the Orthanc REST API -* "/tools/now" returns the current UTC (universal) time -* "/tools/now-local" returns the curent local time. - This was the behavior of "/tools/now" until release 1.3.1. -* Added "?expand" GET argument to "/peers" and "/modalities" routes -* New URI: "/tools/create-media-extended" to generate a DICOMDIR - archive from several resources, including additional type-3 tags -* Preservation of UID relationships while anonymizing - -Lua ---- - -* New CMake option: "-DENABLE_LUA_MODULES=ON" to enable support for - loading external Lua modules if the Lua engine is statically linked - -Plugins -------- - -* New error code: DatabaseUnavailable - -Maintenance ------------ - -* Orthanc now uses UTC (universal time) instead of local time in its database -* Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005) -* Support of Linux Standard Base -* Static linking against libuuid (from e2fsprogs) -* Fix static build on CentOS 6 -* Possibility of using JsonCpp 0.10.6 if the compiler does not support C++11 - with the "-DUSE_LEGACY_JSONCPP=ON" CMake option -* Upgraded dependencies for static and Windows builds: - - boost 1.66.0 - - curl 7.57.0 - - jsoncpp 1.8.4 - - zlib 1.2.11 - - -Version 1.3.1 (2017-11-29) -========================== - -General -------- - -* Built-in decoding of palette images - -REST API --------- - -* New URI: "/instances/.../frames/.../raw.gz" to compress raw frames using gzip -* New argument "ignore-length" to force the inclusion of too long tags in JSON -* New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR - -Plugins -------- - -* New pixel formats exposed in SDK: BGRA32, Float32, Grayscale32, RGB48 - -Maintenance ------------ - -* Creation of ./Resources/CMake/OrthancFramework*.cmake to reuse the Orthanc - C++ framework in other projects -* New security-related options: "DicomAlwaysAllowEcho" -* Use "GBK" (frequently used in China) as an alias for "GB18030" -* Experimental support of actively maintained Civetweb to replace Mongoose 3.8 -* Fix issue 31 for good (create new modality types for Philips ADW, GE Xeleris, GE AWServer) -* Fix issue 64 (OpenBSD support) -* Fix static compilation of DCMTK 3.6.2 on Fedora -* Upgrade to Boost 1.65.1 in static builds -* Upgrade to SQLite amalgamation 3.21.0 in static builds - - -Version 1.3.0 (2017-07-19) -========================== - -General -------- - -* Orthanc now anonymizes according to Basic Profile of PS 3.15-2017c Table E.1-1 -* In the "DicomModalities" configuration: - - Manufacturer type MedInria is now obsolete - - Manufacturer types AgfaImpax and SyngoVia are obsolete too - (use GenericNoWildcardInDates instead) - - Obsolete manufacturers are still accepted but might disappear in the future - - Added new manufacturer: GenericNoUniversalWildcard to replace all '*' by '' in - outgoing C-Find requests -* New security-related options: "DicomAlwaysAllowStore" and "DicomCheckModalityHost" - -REST API --------- - -* Argument "Since" in URI "/tools/find" (related to issue 53) -* Argument "DicomVersion" in URIs "/{...}/{...}/anonymization" - -Plugins -------- - -* New function: "OrthancPluginRegisterIncomingHttpRequestFilter2()" - -Lua ---- - -* Added HTTP headers support for Lua HttpPost/HttpGet/HttpPut/HttpDelete - -Orthanc Explorer ----------------- - -* Query/retrieve: Added button for "DR" modality - -Maintenance ------------ - -* Ability to retrieve raw frames encoded as unsigned 32-bits integers -* Fix issue 29 (more consistent handling of the "--upgrade" argument) -* Fix issue 31 (create new modality types for Philips ADW, GE Xeleris, GE AWServer) -* Fix issue 35 (AET name is not transferred to Orthanc using DCMTK 3.6.0) -* Fix issue 44 (bad interpretation of photometric interpretation MONOCHROME1) -* Fix issue 45 (crash when providing a folder to "--config" command-line option) -* Fix issue 46 (PHI remaining after anonymization) -* Fix issue 49 (worklists: accentuated characters are removed from C-Find responses) -* Fix issue 52 (DICOM level security association problems) -* Fix issue 55 (modification/anonymization of tags that might break the database - model now requires the "Force" parameter to be set to "true" in the query) -* Fix issue 56 (case-insensitive matching over accents) -* Fix Debian #865606 (orthanc FTBFS with libdcmtk-dev 3.6.1~20170228-2) -* Fix XSS inside DICOM in Orthanc Explorer (as reported by Victor Pasnkel, Morphus Labs) -* Upgrade to DCMTK 3.6.2 in static builds (released on 2017-07-17) -* Upgrade to Boost 1.64.0 in static builds -* New advanced "Locale" configuration option -* Removed configuration option "USE_DCMTK_361_PRIVATE_DIC" - - -Version 1.2.0 (2016/12/13) -========================== - -General -------- - -* Handling of private tags/creators in the "Dictionary" configuration option -* New configuration options: "LoadPrivateDictionary", "DicomScuTimeout" and "DicomScpTimeout" -* New metadata automatically computed at the instance level: "TransferSyntax" and "SopClassUid" - -REST API --------- - -* "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files - (useful if private tags are registered, or if changing the default encoding) -* "Permissive" flag for URI "/modalities/{...}/store" to ignore C-STORE transfer errors -* "Asynchronous" flag for URIs "/modalities/{...}/store" and "/peers/{...}/store" - to avoid waiting for the completion of image transfers -* Possibility to DELETE "dicom-as-json" attachments to reconstruct the JSON summaries - (useful if "Dictionary" has changed) -* "Keep" option for modifications to keep original DICOM identifiers (advanced feature) -* "/tools/default-encoding" to get or temporarily change the default encoding -* "/{resource}/{id}/reconstruct" to reconstruct the main DICOM tags, the JSON summary and - the metadata of a resource (useful to compute new metadata, or if using "Keep" above) - -Plugins -------- - -* New function: "OrthancPluginRegisterPrivateDictionaryTag()" to register private tags -* More control over client cache in the ServeFolders plugin -* New C++ help wrappers in "Plugins/Samples/Common/" to read DICOM datasets from REST API -* New data structure: "OrthancPluginFindMatcher" to match DICOM against C-FIND queries - -Maintenance ------------ - -* Fix handling of encodings in C-FIND requests (including for worklists) -* Use of DCMTK 3.6.1 dictionary of private tags in standalone builds -* Avoid hard crash if not enough memory (handling of std::bad_alloc) -* Improved robustness of Orthanc Explorer wrt. query/retrieve (maybe fix issue 24) -* Fix serious performance issue with C-FIND -* Fix extraction of the symbolic name of the private tags -* Performance warning if runtime debug assertions are turned on -* Improved robustness against files with no PatientID -* Upgrade to curl 7.50.3 for static and Windows builds -* Content-Type for JSON documents is now "application/json; charset=utf-8" -* Ignore "Group Length" tags in C-FIND queries -* Fix handling of worklist SCP with ReferencedStudySequence and ReferencedPatientSequence -* Fix handling of Move Originator AET and ID in C-MOVE SCP -* Fix vulnerability ZSL-2016-5379 "Unquoted Service Path Privilege Escalation" in the - Windows service -* Fix vulnerability ZSL-2016-5380 "Remote Memory Corruption Vulnerability" in DCMTK 3.6.0 - - -Version 1.1.0 (2016/06/27) -========================== - -General -------- - -* HTTPS client certificates can be associated with Orthanc peers to enhance security over Internet -* Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers -* New command-line option "--logfile" to output the Orthanc log to the given file -* Support of SIGHUP signal (restart Orthanc only if the configuration files have changed) - -REST API --------- - -* New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding) -* New URI "/modalities/.../move" to issue C-MOVE SCU requests -* "MoveOriginatorID" can be specified for "/modalities/.../store" - -Dicom protocol --------------- - -* Support of optional tags for counting resources in C-FIND: - 0008-0061, 0008-0062, 0020-1200, 0020-1202, 0020-1204, 0020-1206, 0020-1208, 0020-1209 -* Support of Move Originator Message ID (0000,1031) in C-STORE responses driven by C-MOVE - -Plugins -------- - -* Speedup in plugins by removing unnecessary locks -* New callback to filter incoming HTTP requests: OrthancPluginRegisterIncomingHttpRequestFilter() -* New callback to handle non-worklists C-FIND requests: OrthancPluginRegisterFindCallback() -* New callback to handle C-MOVE requests: OrthancPluginRegisterMoveCallback() -* New function: "OrthancPluginHttpClient()" to do HTTP requests with full control -* New function: "OrthancPluginGenerateUuid()" to generate a UUID -* More than one custom image decoder can be installed (e.g. to handle different transfer syntaxes) - -Lua ---- - -* Possibility to dynamically fix outgoing C-FIND requests using "OutgoingFindRequestFilter()" -* Access to the HTTP headers in the "IncomingHttpRequestFilter()" callback - -Image decoding --------------- - -* Huge speedup if decoding the family of JPEG transfer syntaxes -* Refactoring leading to speedups with custom image decoders (including Web viewer plugin) -* Support decoding of RLE Lossless transfer syntax -* Support of signed 16bpp images in ParsedDicomFile - -Maintenance ------------ - -* New logo of Orthanc -* Fix issue 11 (is_regular_file() fails for FILE_ATTRIBUTE_REPARSE_POINT) -* Fix issue 16 ("Limit" parameter error in REST API /tools/find method) -* Fix of Debian bug #818512 ("FTBFS: Please install libdcmtk*-dev") -* Fix of Debian bug #823139 ("orthanc: Please provide RecoverCompressedFile.cpp") -* Replaced "localhost" by "127.0.0.1", as it might impact performance on Windows -* Compatibility with CMake >= 3.5.0 -* Possibility to use forthcoming DCMTK 3.6.1 in static builds (instead of 3.6.0) -* Upgrade to Boost 1.60.0 for static builds -* Use of HTTP status 403 Forbidden (instead of 401) if access to a REST resource is disallowed -* Option "HttpsVerifyPeers" can be used to connect against self-signed HTTPS certificates -* New configuration option "AllowFindSopClassesInStudy" -* Macro "__linux" (now obsolete) replaced by macro "__linux__" (maybe solves Debian bug #821011) -* Modification of instances can now replace PixelData (resp. EncapsulatedDocument) with - provided a PNG/JPEG image (resp. PDF file) if it is encoded using Data URI Scheme -* Dropped support of Google Log - - -Version 1.0.0 (2015/12/15) -========================== - -* Lua: "IncomingFindRequestFilter()" to apply filters to incoming C-FIND requests -* New function in plugin SDK: "OrthancPluginSendMultipartItem2()" -* Fix of DICOMDIR generation with DCMTK 3.6.1, support of encodings -* Fix range search if the lower or upper limit is absent -* Fix modality worklists lookups if tags with UN (unknown) VR are present -* Warn about badly formatted modality/peer definitions in configuration file at startup - - -Version 0.9.6 (2015/12/08) -========================== - -* Promiscuous mode (accept unknown SOP class UID) is now turned off by default -* Fix serialization of DICOM buffers that might contain garbage trailing -* Fix modality worklists server if some fields are null -* More tolerant "/series/.../ordered-slices" with broken series -* Improved logging information if upgrade fails -* Fix formatting of multipart HTTP answers (bis) - - -Version 0.9.5 (2015/12/02) -========================== - -Major ------ - -* Experimental support of DICOM C-FIND SCP for modality worklists through plugins -* Support of DICOM C-FIND SCU for modality worklists ("/modalities/{dicom}/find-worklist") - -REST API --------- - -* New URIs: - - "/series/.../ordered-slices" to order the slices of a 2D+t or 3D series - - "/tools/shutdown" to stop Orthanc from the REST API - - ".../compress", ".../uncompress" and ".../is-compressed" for attachments - - "/tools/create-archive" to create ZIP from a set of resources - - "/tools/create-media" to create ZIP+DICOMDIR from a set of resources - - "/instances/.../header" to get the meta information (header) of the DICOM instance -* "/tools/create-dicom": - - Support of binary tags encoded using data URI scheme - - Support of hierarchical structures (creation of sequences) - - Create tags with unknown VR -* "/modify" can insert/modify sequences -* ".../preview" and ".../image-uint8" can return JPEG images if the HTTP Accept Header asks so -* "Origin" metadata for the instances - -Minor ------ - -* New configuration options: - - "UnknownSopClassAccepted" to disable promiscuous mode (accept unknown SOP class UID) - - New configuration option: "Dictionary" to declare custom DICOM tags -* Add ".dcm" suffix to files in ZIP archives (cf. URI ".../archive") -* MIME content type can be associated to custom attachments (cf. "UserContentType") - -Plugins -------- - -* New functions: - - "OrthancPluginRegisterDecodeImageCallback()" to replace the built-in image decoder - - "OrthancPluginDicomInstanceToJson()" to convert DICOM to JSON - - "OrthancPluginDicomBufferToJson()" to convert DICOM to JSON - - "OrthancPluginRegisterErrorCode()" to declare custom error codes - - "OrthancPluginRegisterDictionaryTag()" to declare custom DICOM tags - - "OrthancPluginLookupDictionary()" to get information about some DICOM tag - - "OrthancPluginRestApiGet2()" to provide HTTP headers when calling Orthanc API - - "OrthancPluginGetInstanceOrigin()" to know through which mechanism an instance was received - - "OrthancPluginCreateImage()" and "OrthancPluginCreateImageAccessor()" to create images - - "OrthancPluginDecodeDicomImage()" to decode DICOM images - - "OrthancPluginComputeMd5()" and "OrthancPluginComputeSha1()" to compute MD5/SHA-1 hash -* New events in change callbacks: - - "OrthancStarted" - - "OrthancStopped" - - "UpdatedAttachment" - - "UpdatedMetadata" -* "/system" URI gives information about the plugins used for storage area and DB back-end -* Plugin callbacks must now return explicit "OrthancPluginErrorCode" (instead of integers) - -Lua ---- - -* Optional argument "keepStrings" in "DumpJson()" - -Maintenance ------------ - -* Full indexation of the patient/study tags to speed up searches and C-FIND -* Many refactorings, notably of the searching features and of the image decoding -* C-MOVE SCP for studies using AccessionNumber tag -* Fix issue 4 (C-STORE Association not renegotiated on Specific-to-specific transfer syntax change) -* Fix formatting of multipart HTTP answers -* "--logdir" flag creates a single log file instead of 3 separate files for errors/warnings/infos -* "--errors" flag lists the error codes that could be returned by Orthanc -* Under Windows, the exit status of Orthanc corresponds to the encountered error code -* New "AgfaImpax", "EFilm2" and "Vitrea" modality manufacturers -* C-FIND SCP will return tags with sequence value representation -* Upgrade to Boost 1.59.0 for static builds - - -Version 0.9.4 (2015/09/16) -========================== - -* Preview of PDF files encapsulated in DICOM from Orthanc Explorer -* Creation of DICOM files with encapsulated PDF through "/tools/create-dicom" -* "limit" and "since" arguments while retrieving DICOM resources in the REST API -* Support of "deflate" and "gzip" content-types in HTTP requests -* Options to validate peers against CA certificates in HTTPS requests -* New configuration option: "HttpTimeout" to set the default timeout for HTTP requests - -Lua ---- - -* More information about the origin request in the "OnStoredInstance()" and - "ReceivedInstanceFilter()" callbacks. WARNING: This can result in - incompatibilities wrt. previous versions of Orthanc. -* New function "GetOrthancConfiguration()" to get the Orthanc configuration - -Plugins -------- - -* New functions to compress/uncompress images using PNG and JPEG -* New functions to issue HTTP requests from plugins -* New function "OrthancPluginBufferCompression()" to (un)compress memory buffers -* New function "OrthancPluginReadFile()" to read files from the filesystem -* New function "OrthancPluginWriteFile()" to write files to the filesystem -* New function "OrthancPluginGetErrorDescription()" to convert error codes to strings -* New function "OrthancPluginSendHttpStatus()" to send HTTP status with a body -* New function "OrthancPluginRegisterRestCallbackNoLock()" for high-performance plugins -* Plugins have access to explicit error codes -* Improvements to the sample "ServeFolders" plugin -* Primitives to upgrade the database version in plugins - -Maintenance ------------ - -* Many code refactorings -* Improved error codes (no more custom descriptions in exceptions) -* If error while calling the REST API, the answer body contains description of the error - (this feature can be disabled with the "HttpDescribeErrors" option) -* Upgrade to curl 7.44.0 for static and Windows builds -* Upgrade to libcurl 1.0.2d for static and Windows builds -* Depends on libjpeg 9a -* Bypass zlib uncompression if "StorageCompression" is enabled and HTTP client supports deflate - - -Version 0.9.3 (2015/08/07) -========================== - -* C-Echo testing can be triggered from Orthanc Explorer (in the query/retrieve page) -* Removal of the dependency upon Google Log, Orthanc now uses its internal logger - (use -DENABLE_GOOGLE_LOG=ON to re-enable Google Log) -* Upgrade to JsonCpp 0.10.5 for static and Windows builds - - -Version 0.9.2 (2015/08/02) -========================== - -* Upgrade to Boost 1.58.0 for static and Windows builds -* Source code repository moved from Google Code to BitBucket -* Inject version information into Windows binaries -* Fix access to binary data in HTTP/REST requests by Lua scripts -* Fix potential deadlock in the callbacks of plugins - - -Version 0.9.1 (2015/07/02) -========================== - -General -------- - -* The configuration can be splitted into several files stored inside the same folder -* Custom setting of the local AET during C-STORE SCU (both in Lua and in the REST API) -* Many code refactorings - -Lua ---- - -* Access to the REST API of Orthanc (RestApiGet, RestApiPost, RestApiPut, RestApiDelete) -* Functions to convert between Lua values and JSON strings: "ParseJson" and "DumpJson" -* New events: "OnStablePatient", "OnStableStudy", "OnStableSeries", "Initialize", "Finalize" - -Plugins -------- - -* Plugins can retrieve the configuration file directly as a JSON string -* Plugins can send answers as multipart messages - -Fixes ------ - -* Fix compatibility issues for C-FIND SCU to Siemens Syngo.Via modalities SCP -* Fix issue 15 (Lua scripts making HTTP requests) -* Fix issue 35 (Characters in PatientID string are not protected for C-FIND) -* Fix issue 37 (Hyphens trigger range query even if datatype does not support ranges) - - -Version 0.9.0 (2015/06/03) -========================== - -Major ------ - -* DICOM Query/Retrieve available from Orthanc Explorer -* C-MOVE SCU and C-FIND SCU are accessible through the REST API -* "?expand" flag for URIs "/patients", "/studies" and "/series" -* "/tools/find" URI to search for DICOM resources from REST -* Support of FreeBSD -* The "Orthanc Client" SDK is now a separate project - -Minor ------ - -* Speed-up in Orthanc Explorer for large amount of images -* Speed-up of the C-FIND SCP server of Orthanc -* Allow replacing PatientID/StudyInstanceUID/SeriesInstanceUID from Lua scripts -* Option "CaseSensitivePN" to enable case-insensitive C-FIND SCP - -Fixes ------ - -* Prevent freeze on C-FIND if no DICOM tag is to be returned -* Fix slow C-STORE SCP on recent versions of GNU/Linux, if - USE_SYSTEM_DCMTK is set to OFF (http://forum.dcmtk.org/viewtopic.php?f=1&t=4009) -* Fix issue 30 (QR response missing "Query/Retrieve Level" (008,0052)) -* Fix issue 32 (Cyrillic symbols): Introduction of the "Windows1251" encoding -* Plugins now receive duplicated GET arguments in their REST callbacks - - -Version 0.8.6 (2015/02/12) -========================== - -Major ------ - -* URIs to get all the parents of a given resource in a single REST call -* Instances without PatientID are now allowed -* Support of HTTP proxy to access Orthanc peers - -Minor ------ - -* Support of Tudor DICOM in Query/Retrieve -* More flexible "/modify" and "/anonymize" for single instance -* Access to called AET and remote AET from Lua scripts ("OnStoredInstance") -* Option "DicomAssociationCloseDelay" to set delay before closing DICOM association -* ZIP archives now display the accession number of the studies - -Plugins -------- - -* Introspection of plugins (cf. the "/plugins" URI) -* Plugins can access the command-line arguments used to launch Orthanc -* Plugins can extend Orthanc Explorer with custom JavaScript -* Plugins can get/set global properties to save their configuration -* Plugins can do REST calls to other plugins (cf. "xxxAfterPlugins()") -* Scan of folders for plugins - -Fixes ------ - -* Code refactorings -* Fix issue 25 (AET with underscore not allowed) -* Fix replacement and insertion of private DICOM tags -* Fix anonymization generating non-portable DICOM files - - -Version 0.8.5 (2014/11/04) -========================== - -General -------- - -* Major speed-up thanks to a new database schema -* Plugins can monitor changes through callbacks -* Download ZIP + DICOMDIR from Orthanc Explorer -* Sample plugin framework to serve static resources (./Plugins/Samples/WebSkeleton/) - -Fixes ------ - -* Fix issue 19 (YBR_FULL are decoded incorrectly) -* Fix issue 21 (Microsoft Visual Studio precompiled headers) -* Fix issue 22 (Error decoding multi-frame instances) -* Fix issue 24 (Build fails on OSX when directory has .DS_Store files) -* Fix crash when bad HTTP credentials are provided - - -Version 0.8.4 (2014/09/19) -========================== - -* "/instances-tags" to get the tags of all the child instances of a - patient/study/series with a single REST call (bulk tags retrieval) -* Configuration/Lua to select the accepted C-STORE SCP transfer syntaxes -* Fix reporting of errors in Orthanc Explorer when sending images to peers/modalities -* Installation of plugin SDK in CMake - - -Version 0.8.3 (2014/09/11) -========================== - -Major ------ - -* Creation of ZIP archives for media storage, with DICOMDIR -* URIs to get all the children of a given resource in a single REST call -* "/tools/lookup" URI to map DICOM UIDs to Orthanc identifiers -* Support of index-only mode (using the "StoreDicom" option) -* Plugins can implement a custom storage area - -Minor ------ - -* Configuration option to enable HTTP Keep-Alive -* Configuration option to disable the logging of exported resources in "/exports" -* Plugins can retrieve the path to Orthanc and to its configuration file -* "/tools/create-dicom" now accepts the "PatientID" DICOM tag (+ updated sample) -* Possibility to set HTTP headers from plugins -* "LastUpdate" metadata is now always returned for patients, studies and series - -Maintenance ------------ - -* Refactoring of HttpOutput ("Content-Length" header is now always sent) -* Upgrade to Mongoose 3.8 -* Fixes for Visual Studio 2013 and Windows 64bit -* Fix issue 16: Handling of "AT" value representations in JSON -* Fix issue 17 - - -Version 0.8.2 (2014/08/07) -========================== - -* Support of the standard text encodings -* Hot restart of Orthanc by posting to "/tools/reset" -* More fault-tolerant commands in Lua scripts -* Parameter to set the default encoding for DICOM files without SpecificCharacterSet -* Fix of issue #14 (support of XCode 5.1) -* Upgrade to Google Test 1.7.0 - - -Version 0.8.1 (2014/07/29) -========================== - -General -------- - -* Access patient module at the study level to cope with PatientID collisions -* On-the-fly conversion of JSON to XML according to the HTTP Accept header -* C-Echo SCU in the REST API -* DICOM conformance statement available at URI "/tools/dicom-conformance" - -Lua scripts ------------ - -* Lua scripts can do HTTP requests, and thus can call Web services -* Lua scripts can invoke system commands, with CallSystem() - -Plugins -------- - -* Lookup for DICOM UIDs in the plugin SDK -* Plugins have access to the HTTP headers and can answer with HTTP status codes -* Callback to react to the incoming of DICOM instances - -Fixes ------ - -* Fix build of Google Log with Visual Studio >= 11.0 -* Fix automated generation of the list of resource children in the REST API - - -Version 0.8.0 (2014/07/10) -========================== - -Major changes -------------- - -* Routing images with Lua scripts -* Introduction of the Orthanc Plugin SDK -* Official support of OS X (Darwin) 10.8 - -Minor changes -------------- - -* Extraction of tags for the patient/study/series/instance DICOM modules -* Extraction of the tags shared by all the instances of a patient/study/series -* Options to limit the number of results for an incoming C-FIND query -* Support of kFreeBSD -* Several code refactorings -* Fix OrthancCppClient::GetVoxelSizeZ() - - -Version 0.7.6 (2014/06/11) -========================== - -* Support of JPEG and JPEG-LS decompression -* Download DICOM images as Matlab/Octave arrays -* Precompiled headers for Microsoft Visual Studio - - -Version 0.7.5 (2014/05/08) -========================== - -* Dynamic negotiation of SOP classes for C-STORE SCU -* Creation of DICOM instances using the REST API -* Embedding of images within DICOM instances -* Adding/removal/modification of remote modalities/peers through REST -* Reuse of the previous SCU connection to avoid unnecessary handshakes -* Fix problems with anonymization and modification -* Fix missing licensing terms about reuse of some code from DCMTK -* Various code refactorings - - -Version 0.7.4 (2014/04/16) -========================== - -* Switch to openssl-1.0.1g in static builds (cf. Heartbleed exploit) -* Switch to boost 1.55.0 in static builds (to solve compiling errors) -* Better logging about nonexistent tags -* Dcm4Chee manufacturer -* Automatic discovering of the path to the DICOM dictionaries -* In the "DicomModalities" config, the port number can be a string - - -Version 0.7.3 (2014/02/14) -========================== - -Major changes -------------- - -* Fixes in the implementation of the C-FIND handler for Query/Retrieve -* Custom attachment of files to patients, studies, series or instances -* Access to lowlevel info about the attached files through the REST API -* Recover pixel data for more transfer syntaxes (notably JPEG) - -Minor changes -------------- - -* AET comparison is now case-insensitive by default -* Possibility to disable the HTTP server or the DICOM server -* Automatic computation of MD5 hashes for the stored DICOM files -* Maintenance tool to recover DICOM files compressed by Orthanc -* The newline characters in the configuration file are fixed for GNU/Linux -* Capture of the SIGTERM signal in GNU/Linux - - -Version 0.7.2 (2013/11/08) -========================== - -* Support of Query/Retrieve from medInria -* Accept more transfer syntaxes for C-STORE SCP and SCU (notably JPEG) -* Create the meta-header when receiving files through C-STORE SCP -* Fixes and improvements thanks to the static analyzer cppcheck - - -Version 0.7.1 (2013/10/30) -========================== - -* Use ZIP64 only when required to improve compatibility (cf. issue #7) -* Refactoring of the CMake options -* Fix for big-endian architectures (RedHat bug #985748) -* Use filenames with 8 characters in ZIP files for maximum compatibility -* Possibility to build Orthanc inplace (in the source directory) - - -Version 0.7.0 (2013/10/25) -========================== - -Major changes -------------- - -* DICOM Query/Retrieve is supported - -Minor changes -------------- - -* Possibility to keep the PatientID during an anonymization -* Check whether "unzip", "tar" and/or "7-zip" are installed from CMake - - -Version 0.6.2 (2013/10/04) -========================== - -* Build of the C++ client as a shared library -* Improvements and documentation of the C++ client API -* Fix of Debian bug #724947 (licensing issue with the SHA-1 library) -* Switch to Boost 1.54.0 (cf. issue #9) -* "make uninstall" is now possible - - -Version 0.6.1 (2013/09/16) -========================== - -* Detection of stable patients/studies/series -* C-FIND SCU at the instance level -* Link from modified to original resource in Orthanc Explorer -* Fix of issue #8 -* Anonymization of the medical alerts tag (0010,2000) - - -Version 0.6.0 (2013/07/16) -========================== - -Major changes -------------- - -* Introduction of the C++ client -* Send DICOM resources to other Orthanc instances through HTTP -* Access to signed images (instances/.../image-int16) - (Closes: Debian #716958) - -Minor changes -------------- - -* Export of DICOM files to the host filesystem (instances/.../export) -* Statistics about patients, studies, series and instances -* Link from anonymized to original resource in Orthanc Explorer -* Fixes for Red Hat and Debian packaging -* Fixes for history in Orthanc Explorer -* Fixes for boost::thread, as reported by Cyril Paulus -* Fix licensing (Closes: Debian #712038) - -Metadata --------- - -* Access to the metadata through the REST API (.../metadata) -* Support of user-defined metadata -* "LastUpdate" metadata for patients, studies and series -* "/tools/now" to be used in combination with "LastUpdate" -* Improved support of series with temporal positions - - -Version 0.5.2 (2013/05/07) -========================== - -* "Bulk" Store-SCU (send several DICOM instances with the same - DICOM connection) -* Store-SCU for patients and studies in Orthanc Explorer -* Filtering of incoming DICOM instances (through Lua scripting) -* Filtering of incoming HTTP requests (through Lua scripting) -* Clearing of "/exports" and "/changes" -* Check MD5 of third party downloads -* Faking of the HTTP methods PUT and DELETE - - -Version 0.5.1 (2013/04/17) -========================== - -* Support of RGB images -* Fix of store SCU in release builds -* Possibility to store the SQLite index at another place than the - DICOM instances (for performance) - - -Version 0.5.0 (2013/01/31) -========================== - -Major changes -------------- - -* Download of modified or anonymized DICOM instances -* Inplace modification and anonymization of DICOM series, studies and patients - -Minor changes -------------- - -* Support of private tags -* Implementation of the PMSCT_RLE1 image decoding for Philips modalities -* Generation of random DICOM UID through the REST API (/tools/generate-uid) - - -Version 0.4.0 (2012/12/14) -========================== - -Major changes -------------- - -* Recycling of disk space -* Raw access to the value of the DICOM tags in the REST API - -Minor changes -------------- - -* Protection of patients against recycling (also in Orthanc Explorer) -* The DICOM dictionaries are embedded in Windows builds - - -Version 0.3.1 (2012/12/05) -========================== - -* Download archives of patients, studies and series as ZIP files -* Orthanc now checks the version of its database schema before starting - - -Version 0.3.0 (2012/11/30) -========================== - -Major changes -------------- - -* Transparent compression of the DICOM instances on the disk -* The patient/study/series/instances are now indexed by SHA-1 digests - of their DICOM Instance IDs (and not by UUIDs anymore): The same - DICOM objects are thus always identified by the same Orthanc IDs -* Log of exported instances through DICOM C-STORE SCU ("/exported" URI) -* Full refactoring of the DB schema and of the REST API -* Introduction of generic classes for REST APIs (in Core/RestApi) - -Minor changes -------------- - -* "/statistics" URI -* "last" flag to retrieve the last change from the "/changes" URI -* Generate a sample configuration file from command line -* "CompletedSeries" event in the changes API -* Thread to continuously flush DB to disk (SQLite checkpoints for - improved robustness) - - -Version 0.2.3 (2012/10/26) -========================== - -* Use HTTP Content-Disposition to set a filename when downloading JSON/DCM -* URI "/system" for general information about Orthanc -* Versioning info and help on the command line -* Improved logging -* Possibility of dynamic linking against jsoncpp, sqlite, boost and dmctk - for Debian packaging -* Fix some bugs -* Switch to default 8042 port for HTTP - - -Version 0.2.2 (2012/10/04) -========================== - -* Switch to Google Log -* Fixes to Debian packaging - - -Version 0.2.1 (2012/09/28) -========================== - -* Status of series -* Continuous Integration Server is up and running -* Ready for Debian packaging - - -Version 0.2.0 (2012/09/16) -========================== - -Major changes -------------- - -* Renaming to "Orthanc" -* Focus on security: Support of SSL, HTTP Basic Authentication and - interdiction of remote access -* Access to multi-frame images (for nuclear medicine) -* Access to the raw PNG images (in 8bpp and 16bpp) - -Minor changes -------------- - -* Change of the licensing of the "Core/SQLite" folder to BSD (to - reflect the original licensing terms of Chromium, from which the - code derives) -* Standalone build for cross-compilation - - -Version 0.1.1 (2012/07/20) -========================== - -* Fix Windows version -* Native Windows build with Microsoft Visual Studio 2005 -* Add path to storage in Configuration.json - - -Version 0.1.0 (2012/07/19) -========================== - -* Initial release
--- a/Orthanc/Plugins/Samples/Common/ExportedSymbols.list Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -# This is the list of the symbols that must be exported by Orthanc -# plugins, if targeting OS X - -_OrthancPluginInitialize -_OrthancPluginFinalize -_OrthancPluginGetName -_OrthancPluginGetVersion
--- a/Orthanc/Plugins/Samples/Common/VersionScript.map Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -# This is a version-script for Orthanc plugins - -{ -global: - OrthancPluginInitialize; - OrthancPluginFinalize; - OrthancPluginGetName; - OrthancPluginGetVersion; - -local: - *; -};
--- a/Orthanc/README.txt Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -This folder contains an excerpt of the source code of Orthanc. It is -automatically generated using the "../Resources/SyncOrthancFolder.py" -script.
--- a/Orthanc/Resources/CMake/AutoGeneratedCode.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED") -set(AUTOGENERATED_SOURCES) - -file(MAKE_DIRECTORY ${AUTOGENERATED_DIR}) -include_directories(${AUTOGENERATED_DIR}) - -macro(EmbedResources) - # Convert a semicolon separated list to a whitespace separated string - set(SCRIPT_OPTIONS) - set(SCRIPT_ARGUMENTS) - set(DEPENDENCIES) - set(IS_PATH_NAME false) - - # Loop over the arguments of the function - foreach(arg ${ARGN}) - # Extract the first character of the argument - string(SUBSTRING "${arg}" 0 1 FIRST_CHAR) - if (${FIRST_CHAR} STREQUAL "-") - # If the argument starts with a dash "-", this is an option to - # EmbedResources.py - list(APPEND SCRIPT_OPTIONS ${arg}) - else() - if (${IS_PATH_NAME}) - list(APPEND SCRIPT_ARGUMENTS "${arg}") - list(APPEND DEPENDENCIES "${arg}") - set(IS_PATH_NAME false) - else() - list(APPEND SCRIPT_ARGUMENTS "${arg}") - set(IS_PATH_NAME true) - endif() - endif() - endforeach() - - set(TARGET_BASE "${AUTOGENERATED_DIR}/EmbeddedResources") - add_custom_command( - OUTPUT - "${TARGET_BASE}.h" - "${TARGET_BASE}.cpp" - COMMAND - ${PYTHON_EXECUTABLE} - "${ORTHANC_ROOT}/Resources/EmbedResources.py" - ${SCRIPT_OPTIONS} - "${AUTOGENERATED_DIR}/EmbeddedResources" - ${SCRIPT_ARGUMENTS} - DEPENDS - "${ORTHANC_ROOT}/Resources/EmbedResources.py" - ${DEPENDENCIES} - ) - - list(APPEND AUTOGENERATED_SOURCES - "${AUTOGENERATED_DIR}/EmbeddedResources.cpp" - ) -endmacro()
--- a/Orthanc/Resources/CMake/BoostConfiguration.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -if (STATIC_BUILD OR NOT USE_SYSTEM_BOOST) - set(BOOST_STATIC 1) -else() - include(FindBoost) - - set(BOOST_STATIC 0) - #set(Boost_DEBUG 1) - #set(Boost_USE_STATIC_LIBS ON) - - if (ENABLE_LOCALE) - list(APPEND ORTHANC_BOOST_COMPONENTS locale) - endif() - - list(APPEND ORTHANC_BOOST_COMPONENTS filesystem thread system date_time regex) - find_package(Boost COMPONENTS "${ORTHANC_BOOST_COMPONENTS}") - - if (NOT Boost_FOUND) - foreach (item ${ORTHANC_BOOST_COMPONENTS}) - string(TOUPPER ${item} tmp) - - if (Boost_${tmp}_FOUND) - set(tmp2 "found") - else() - set(tmp2 "missing") - endif() - - message("Boost component ${item} - ${tmp2}") - endforeach() - - message(FATAL_ERROR "Unable to locate Boost on this system") - endif() - - # Boost releases 1.44 through 1.47 supply both V2 and V3 filesystem - # http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/index.htm - if (${Boost_VERSION} LESS 104400) - add_definitions( - -DBOOST_HAS_FILESYSTEM_V3=0 - ) - else() - add_definitions( - -DBOOST_HAS_FILESYSTEM_V3=1 - -DBOOST_FILESYSTEM_VERSION=3 - ) - endif() - - include_directories(${Boost_INCLUDE_DIRS}) - link_libraries(${Boost_LIBRARIES}) -endif() - - -if (BOOST_STATIC) - ## - ## Parameters for static compilation of Boost - ## - - set(BOOST_NAME boost_1_66_0) - set(BOOST_BCP_SUFFIX bcpdigest-1.3.2) - set(BOOST_MD5 "e509e66140e8f2fd4d326b0052825f52") - set(BOOST_URL "http://www.orthanc-server.com/downloads/third-party/${BOOST_NAME}_${BOOST_BCP_SUFFIX}.tar.gz") - set(BOOST_SOURCES_DIR ${CMAKE_BINARY_DIR}/${BOOST_NAME}) - - if (IS_DIRECTORY "${BOOST_SOURCES_DIR}") - set(FirstRun OFF) - else() - set(FirstRun ON) - endif() - - DownloadPackage(${BOOST_MD5} ${BOOST_URL} "${BOOST_SOURCES_DIR}") - - - ## - ## Generic configuration of Boost - ## - - if (CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-isystem ${BOOST_SOURCES_DIR}) - endif() - - include_directories( - ${BOOST_SOURCES_DIR} - ) - - add_definitions( - # Static build of Boost - -DBOOST_ALL_NO_LIB - -DBOOST_ALL_NOLIB - -DBOOST_DATE_TIME_NO_LIB - -DBOOST_THREAD_BUILD_LIB - -DBOOST_PROGRAM_OPTIONS_NO_LIB - -DBOOST_REGEX_NO_LIB - -DBOOST_SYSTEM_NO_LIB - -DBOOST_LOCALE_NO_LIB - ) - - set(BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp - ) - - if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") - add_definitions( - -DBOOST_SYSTEM_USE_STRERROR=1 - ) - - execute_process( - COMMAND ${PATCH_EXECUTABLE} -p0 -N -i - ${ORTHANC_ROOT}/Resources/Patches/boost-1.66.0-linux-standard-base.patch - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - ) - - if (FirstRun AND Failure) - message(FATAL_ERROR "Error while patching a file") - endif() - endif() - - - ## - ## Configuration of boost::thread - ## - - if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR - CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR - CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl64") - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/atomic/src/lockpool.cpp - ${BOOST_SOURCES_DIR}/libs/thread/src/pthread/once.cpp - ${BOOST_SOURCES_DIR}/libs/thread/src/pthread/thread.cpp - ) - - if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase" OR - CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl64") - add_definitions(-DBOOST_HAS_SCHED_YIELD=1) - endif() - - elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp - ${BOOST_SOURCES_DIR}/libs/thread/src/win32/thread.cpp - ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_pe.cpp - ) - - elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - # No support for threads in WebAssembly - - else() - message(FATAL_ERROR "Support your platform here") - endif() - - - ## - ## Configuration of boost::regex - ## - - aux_source_directory(${BOOST_SOURCES_DIR}/libs/regex/src BOOST_REGEX_SOURCES) - - list(APPEND BOOST_SOURCES - ${BOOST_REGEX_SOURCES} - ) - - - ## - ## Configuration of boost::datetime - ## - - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/date_time/src/gregorian/greg_month.cpp - ) - - - ## - ## Configuration of boost::filesystem - ## - - if (CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl64") - # boost::filesystem is not available on PNaCl - add_definitions( - -DBOOST_HAS_FILESYSTEM_V3=0 - -D__INTEGRITY=1 - ) - else() - add_definitions( - -DBOOST_HAS_FILESYSTEM_V3=1 - ) - list(APPEND BOOST_SOURCES - ${BOOST_NAME}/libs/filesystem/src/codecvt_error_category.cpp - ${BOOST_NAME}/libs/filesystem/src/operations.cpp - ${BOOST_NAME}/libs/filesystem/src/path.cpp - ${BOOST_NAME}/libs/filesystem/src/path_traits.cpp - ) - - if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR - CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/filesystem/src/utf8_codecvt_facet.cpp - ) - - elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") - list(APPEND BOOST_SOURCES - ${BOOST_NAME}/libs/filesystem/src/windows_file_codecvt.cpp - ) - endif() - endif() - - - ## - ## Configuration of boost::locale - ## - - if (NOT ENABLE_LOCALE) - message("boost::locale is disabled") - else() - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/generator.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/date_time.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/formatting.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/ids.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/localization_backend.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/message.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/shared/mo_lambda.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/util/codecvt_converter.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/util/default_locale.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/util/gregorian.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/util/info.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/util/locale_data.cpp - ) - - if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR - CMAKE_SYSTEM_VERSION STREQUAL "LinuxStandardBase") - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/locale/src/std/codecvt.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/std/collate.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/std/converter.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/std/numeric.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/std/std_backend.cpp - ) - - add_definitions( - -DBOOST_LOCALE_WITH_ICONV=1 - -DBOOST_LOCALE_NO_WINAPI_BACKEND=1 - -DBOOST_LOCALE_NO_POSIX_BACKEND=1 - ) - - elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR - CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR - CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" OR - CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR - CMAKE_SYSTEM_NAME STREQUAL "NaCl64" OR - CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # For WebAssembly or asm.js - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/locale/src/posix/codecvt.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/posix/collate.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/posix/converter.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/posix/numeric.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/posix/posix_backend.cpp - ) - - add_definitions( - -DBOOST_LOCALE_WITH_ICONV=1 - -DBOOST_LOCALE_NO_WINAPI_BACKEND=1 - -DBOOST_LOCALE_NO_STD_BACKEND=1 - ) - - elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") - list(APPEND BOOST_SOURCES - ${BOOST_SOURCES_DIR}/libs/locale/src/win32/collate.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/win32/converter.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/win32/lcid.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/win32/numeric.cpp - ${BOOST_SOURCES_DIR}/libs/locale/src/win32/win_backend.cpp - ) - - add_definitions( - -DBOOST_LOCALE_NO_POSIX_BACKEND=1 - -DBOOST_LOCALE_NO_STD_BACKEND=1 - ) - - # Starting with release 0.8.2, Orthanc statically links against - # libiconv, even on Windows. Indeed, the "WCONV" library of - # Windows XP seems not to support properly several codepages - # (notably "Latin3", "Hebrew", and "Arabic"). Set - # "USE_BOOST_ICONV" to "OFF" to use WCONV anyway. - - if (USE_BOOST_ICONV) - add_definitions(-DBOOST_LOCALE_WITH_ICONV=1) - else() - add_definitions(-DBOOST_LOCALE_WITH_WCONV=1) - endif() - - else() - message(FATAL_ERROR "Support your platform here") - endif() - endif() - - - source_group(ThirdParty\\boost REGULAR_EXPRESSION ${BOOST_SOURCES_DIR}/.*) - -endif()
--- a/Orthanc/Resources/CMake/Compiler.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -# This file sets all the compiler-related flags - -if (CMAKE_CROSSCOMPILING OR - "${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") - # Cross-compilation necessarily implies standalone and static build - SET(STATIC_BUILD ON) - SET(STANDALONE_BUILD ON) -endif() - -if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-long-long") - - # --std=c99 makes libcurl not to compile - # -pedantic gives a lot of warnings on OpenSSL - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wno-variadic-macros") - - if (CMAKE_CROSSCOMPILING) - # http://stackoverflow.com/a/3543845/881731 - set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -O coff -I<CMAKE_CURRENT_SOURCE_DIR> <SOURCE> <OBJECT>") - endif() - -elseif (MSVC) - # Use static runtime under Visual Studio - # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace - # http://stackoverflow.com/a/6510446 - foreach(flag_var - CMAKE_C_FLAGS_DEBUG - CMAKE_CXX_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_RELWITHDEBINFO) - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}") - endforeach(flag_var) - - # Add /Zm256 compiler option to Visual Studio to fix PCH errors - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zm256") - - add_definitions( - -D_CRT_SECURE_NO_WARNINGS=1 - -D_CRT_SECURE_NO_DEPRECATE=1 - ) - - if (MSVC_VERSION LESS 1600) - # Starting with Visual Studio >= 2010 (i.e. macro _MSC_VER >= - # 1600), Microsoft ships a standard-compliant <stdint.h> - # header. For earlier versions of Visual Studio, give access to a - # compatibility header. - # http://stackoverflow.com/a/70630/881731 - # https://en.wikibooks.org/wiki/C_Programming/C_Reference/stdint.h#External_links - include_directories(${ORTHANC_ROOT}/Resources/ThirdParty/VisualStudio) - endif() - - link_libraries(netapi32) -endif() - - -if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - # In FreeBSD/OpenBSD, the "/usr/local/" folder contains the ports and need to be imported - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib") -endif() - - -if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - - if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - # The "--no-undefined" linker flag makes the shared libraries - # (plugins ModalityWorklists and ServeFolders) fail to compile on OpenBSD - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") - endif() - - if (NOT DEFINED ENABLE_PLUGINS_VERSION_SCRIPT OR - ENABLE_PLUGINS_VERSION_SCRIPT) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${ORTHANC_ROOT}/Plugins/Samples/Common/VersionScript.map") - endif() - - # Remove the "-rdynamic" option - # http://www.mail-archive.com/cmake@cmake.org/msg08837.html - set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - link_libraries(pthread) - - if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - link_libraries(rt) - endif() - - if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND - NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - link_libraries(dl) - endif() - - if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND - NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - # The "--as-needed" linker flag is not available on FreeBSD and OpenBSD - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") - endif() - - if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" AND - NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - # FreeBSD/OpenBSD have just one single interface for file - # handling, which is 64bit clean, so there is no need to define macro - # for LFS (Large File Support). - # https://ohse.de/uwe/articles/lfs.html - add_definitions( - -D_LARGEFILE64_SOURCE=1 - -D_FILE_OFFSET_BITS=64 - ) - endif() - -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - if (MSVC) - message("MSVC compiler version = " ${MSVC_VERSION} "\n") - # Starting Visual Studio 2013 (version 1800), it is not possible - # to target Windows XP anymore - if (MSVC_VERSION LESS 1800) - add_definitions( - -DWINVER=0x0501 - -D_WIN32_WINNT=0x0501 - ) - endif() - else() - add_definitions( - -DWINVER=0x0501 - -D_WIN32_WINNT=0x0501 - ) - endif() - - add_definitions( - -D_CRT_SECURE_NO_WARNINGS=1 - ) - link_libraries(rpcrt4 ws2_32) - - if (CMAKE_COMPILER_IS_GNUCXX) - # Some additional C/C++ compiler flags for MinGW - SET(MINGW_NO_WARNINGS "-Wno-unused-function -Wno-unused-variable") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MINGW_NO_WARNINGS} -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MINGW_NO_WARNINGS}") - - # This is a patch for MinGW64 - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition -static-libgcc -static-libstdc++") - - CHECK_LIBRARY_EXISTS(winpthread pthread_create "" HAVE_WIN_PTHREAD) - if (HAVE_WIN_PTHREAD) - # This line is necessary to compile with recent versions of MinGW, - # otherwise "libwinpthread-1.dll" is not statically linked. - SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic") - add_definitions(-DHAVE_WIN_PTHREAD=1) - else() - add_definitions(-DHAVE_WIN_PTHREAD=0) - endif() - endif() - -elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${ORTHANC_ROOT}/Plugins/Samples/Common/ExportedSymbols.list") - - add_definitions( - -D_XOPEN_SOURCE=1 - ) - link_libraries(iconv) - -elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - message("Building using Emscripten (for WebAssembly or asm.js targets)") - - # The BINARYEN_TRAP_MODE specifies what to do when divisions per - # zero (and similar conditions like integer overflows) are - # encountered: The "clamp" mode avoids throwing errors, as they - # cannot be properly catched by "try {} catch (...)" constructions. - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -s BINARYEN_TRAP_MODE='\"clamp\"'") - -else() - message(FATAL_ERROR "Support your platform here") -endif() - - -if (DEFINED ENABLE_PROFILING AND ENABLE_PROFILING) - if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") - else() - message(FATAL_ERROR "Don't know how to enable profiling on your configuration") - endif() -endif() - - -if (CMAKE_COMPILER_IS_GNUCXX) - # "When creating a static library using binutils (ar) and there - # exist a duplicate object name (e.g. a/Foo.cpp.o, b/Foo.cpp.o), the - # resulting static library can end up having only one of the - # duplicate objects. [...] This bug only happens if there are many - # objects." The trick consists in replacing the "r" argument - # ("replace") provided to "ar" (as used in CMake < 3.1) by the "q" - # argument ("quick append"). This is because of the fact that CMake - # will invoke "ar" several times with several batches of ".o" - # objects, and using "r" would overwrite symbols defined in - # preceding batches. https://cmake.org/Bug/view.php?id=14874 - set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> q <TARGET> <OBJECTS>") -endif() - - -if (STATIC_BUILD) - add_definitions(-DORTHANC_STATIC=1) -else() - add_definitions(-DORTHANC_STATIC=0) -endif()
--- a/Orthanc/Resources/CMake/DownloadPackage.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -macro(GetUrlFilename TargetVariable Url) - string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${Url}") -endmacro() - - -macro(GetUrlExtension TargetVariable Url) - #string(REGEX REPLACE "^.*/[^.]*\\." "" TMP "${Url}") - string(REGEX REPLACE "^.*\\." "" TMP "${Url}") - string(TOLOWER "${TMP}" "${TargetVariable}") -endmacro() - - - -## -## Setup the patch command-line tool -## - -if (NOT ORTHANC_DISABLE_PATCH) - if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") - set(PATCH_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/patch/patch.exe) - if (NOT EXISTS ${PATCH_EXECUTABLE}) - message(FATAL_ERROR "Unable to find the patch.exe tool that is shipped with Orthanc") - endif() - - else () - find_program(PATCH_EXECUTABLE patch) - if (${PATCH_EXECUTABLE} MATCHES "PATCH_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Please install the 'patch' standard command-line tool") - endif() - endif() -endif() - - - -## -## Check the existence of the required decompression tools -## - -if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") - find_program(ZIP_EXECUTABLE 7z - PATHS - "$ENV{ProgramFiles}/7-Zip" - "$ENV{ProgramW6432}/7-Zip" - ) - - if (${ZIP_EXECUTABLE} MATCHES "ZIP_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)") - endif() - -else() - find_program(UNZIP_EXECUTABLE unzip) - if (${UNZIP_EXECUTABLE} MATCHES "UNZIP_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Please install the 'unzip' package") - endif() - - find_program(TAR_EXECUTABLE tar) - if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND") - message(FATAL_ERROR "Please install the 'tar' package") - endif() -endif() - - -macro(DownloadPackage MD5 Url TargetDirectory) - if (NOT IS_DIRECTORY "${TargetDirectory}") - GetUrlFilename(TMP_FILENAME "${Url}") - - set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") - if (NOT EXISTS "${TMP_PATH}") - message("Downloading ${Url}") - - # This fixes issue 6: "I think cmake shouldn't download the - # packages which are not in the system, it should stop and let - # user know." - # https://code.google.com/p/orthanc/issues/detail?id=6 - if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS) - message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON") - endif() - - file(DOWNLOAD "${Url}" "${TMP_PATH}" - SHOW_PROGRESS EXPECTED_MD5 "${MD5}" - TIMEOUT 60 INACTIVITY_TIMEOUT 60) - else() - message("Using local copy of ${Url}") - endif() - - GetUrlExtension(TMP_EXTENSION "${Url}") - #message(${TMP_EXTENSION}) - message("Uncompressing ${TMP_FILENAME}") - - if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") - # How to silently extract files using 7-zip - # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly - - if (("${TMP_EXTENSION}" STREQUAL "gz") OR - ("${TMP_EXTENSION}" STREQUAL "tgz") OR - ("${TMP_EXTENSION}" STREQUAL "xz")) - execute_process( - COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - OUTPUT_QUIET - ) - - if (Failure) - message(FATAL_ERROR "Error while running the uncompression tool") - endif() - - if ("${TMP_EXTENSION}" STREQUAL "tgz") - string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") - elseif ("${TMP_EXTENSION}" STREQUAL "gz") - string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") - elseif ("${TMP_EXTENSION}" STREQUAL "xz") - string(REGEX REPLACE ".xz" "" TMP_FILENAME2 "${TMP_FILENAME}") - endif() - - execute_process( - COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - OUTPUT_QUIET - ) - elseif ("${TMP_EXTENSION}" STREQUAL "zip") - execute_process( - COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - OUTPUT_QUIET - ) - else() - message(FATAL_ERROR "Support your platform here") - endif() - - else() - if ("${TMP_EXTENSION}" STREQUAL "zip") - execute_process( - COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - ) - elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) - #message("tar xvfz ${TMP_PATH}") - execute_process( - COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - ) - elseif ("${TMP_EXTENSION}" STREQUAL "bz2") - execute_process( - COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - ) - elseif ("${TMP_EXTENSION}" STREQUAL "xz") - execute_process( - COMMAND sh -c "${TAR_EXECUTABLE} xf ${TMP_PATH}" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE Failure - ) - else() - message(FATAL_ERROR "Unknown package format.") - endif() - endif() - - if (Failure) - message(FATAL_ERROR "Error while running the uncompression tool") - endif() - - if (NOT IS_DIRECTORY "${TargetDirectory}") - message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") - endif() - endif() -endmacro()
--- a/Orthanc/Resources/CMake/GoogleTestConfiguration.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -if (USE_GOOGLE_TEST_DEBIAN_PACKAGE) - find_path(GOOGLE_TEST_DEBIAN_SOURCES_DIR - NAMES src/gtest-all.cc - PATHS - /usr/src/gtest - /usr/src/googletest/googletest - PATH_SUFFIXES src - ) - - find_path(GOOGLE_TEST_DEBIAN_INCLUDE_DIR - NAMES gtest.h - PATHS - /usr/include/gtest - ) - - message("Path to the Debian Google Test sources: ${GOOGLE_TEST_DEBIAN_SOURCES_DIR}") - message("Path to the Debian Google Test includes: ${GOOGLE_TEST_DEBIAN_INCLUDE_DIR}") - - set(GOOGLE_TEST_SOURCES - ${GOOGLE_TEST_DEBIAN_SOURCES_DIR}/src/gtest-all.cc - ) - - include_directories(${GOOGLE_TEST_DEBIAN_SOURCES_DIR}) - - if (NOT EXISTS ${GOOGLE_TEST_SOURCES} OR - NOT EXISTS ${GOOGLE_TEST_DEBIAN_INCLUDE_DIR}/gtest.h) - message(FATAL_ERROR "Please install the libgtest-dev package") - endif() - -elseif (STATIC_BUILD OR NOT USE_SYSTEM_GOOGLE_TEST) - set(GOOGLE_TEST_SOURCES_DIR ${CMAKE_BINARY_DIR}/gtest-1.7.0) - set(GOOGLE_TEST_URL "http://www.orthanc-server.com/downloads/third-party/gtest-1.7.0.zip") - set(GOOGLE_TEST_MD5 "2d6ec8ccdf5c46b05ba54a9fd1d130d7") - - DownloadPackage(${GOOGLE_TEST_MD5} ${GOOGLE_TEST_URL} "${GOOGLE_TEST_SOURCES_DIR}") - - include_directories( - ${GOOGLE_TEST_SOURCES_DIR}/include - ${GOOGLE_TEST_SOURCES_DIR} - ) - - set(GOOGLE_TEST_SOURCES - ${GOOGLE_TEST_SOURCES_DIR}/src/gtest-all.cc - ) - - # https://code.google.com/p/googletest/issues/detail?id=412 - if (MSVC) # VS2012 does not support tuples correctly yet - add_definitions(/D _VARIADIC_MAX=10) - endif() - - if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") - add_definitions(-DGTEST_HAS_CLONE=0) - endif() - - source_group(ThirdParty\\GoogleTest REGULAR_EXPRESSION ${GOOGLE_TEST_SOURCES_DIR}/.*) - -else() - include(FindGTest) - if (NOT GTEST_FOUND) - message(FATAL_ERROR "Unable to find GoogleTest") - endif() - - include_directories(${GTEST_INCLUDE_DIRS}) - - # The variable GTEST_LIBRARIES contains the shared library of - # Google Test, create an alias for more uniformity - set(GOOGLE_TEST_LIBRARIES ${GTEST_LIBRARIES}) -endif()
--- a/Orthanc/Resources/CMake/JsonCppConfiguration.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -set(JSONCPP_CXX11 OFF) - -if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP) - if (USE_LEGACY_JSONCPP) - set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-0.10.6) - set(JSONCPP_URL "http://www.orthanc-server.com/downloads/third-party/jsoncpp-0.10.6.tar.gz") - set(JSONCPP_MD5 "13d1991d79697df8cadbc25c93e37c83") - add_definitions(-DORTHANC_LEGACY_JSONCPP=1) - else() - set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-1.8.4) - set(JSONCPP_URL "http://www.orthanc-server.com/downloads/third-party/jsoncpp-1.8.4.tar.gz") - set(JSONCPP_MD5 "fa47a3ab6b381869b6a5f20811198662") - add_definitions(-DORTHANC_LEGACY_JSONCPP=0) - set(JSONCPP_CXX11 ON) - endif() - - DownloadPackage(${JSONCPP_MD5} ${JSONCPP_URL} "${JSONCPP_SOURCES_DIR}") - - set(JSONCPP_SOURCES - ${JSONCPP_SOURCES_DIR}/src/lib_json/json_reader.cpp - ${JSONCPP_SOURCES_DIR}/src/lib_json/json_value.cpp - ${JSONCPP_SOURCES_DIR}/src/lib_json/json_writer.cpp - ) - - include_directories( - ${JSONCPP_SOURCES_DIR}/include - ) - - source_group(ThirdParty\\JsonCpp REGULAR_EXPRESSION ${JSONCPP_SOURCES_DIR}/.*) - -else() - find_path(JSONCPP_INCLUDE_DIR json/reader.h - /usr/include/jsoncpp - /usr/local/include/jsoncpp - ) - - message("JsonCpp include dir: ${JSONCPP_INCLUDE_DIR}") - include_directories(${JSONCPP_INCLUDE_DIR}) - link_libraries(jsoncpp) - - CHECK_INCLUDE_FILE_CXX(${JSONCPP_INCLUDE_DIR}/json/reader.h HAVE_JSONCPP_H) - if (NOT HAVE_JSONCPP_H) - 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 - 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) - set(JSONCPP_CXX11 ON) - endif() - else() - message("Unable to detect the major version of JsonCpp, assuming < 1.0.0") - endif() -endif() - - -if (JSONCPP_CXX11) - # Osimis has encountered problems when this macro is left at its - # default value (1000), so we increase this limit - # https://gitlab.kitware.com/third-party/jsoncpp/commit/56df2068470241f9043b676bfae415ed62a0c172 - add_definitions(-DJSONCPP_DEPRECATED_STACK_LIMIT=5000) - - if (CMAKE_COMPILER_IS_GNUCXX OR - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - message("Switching to C++11 standard in gcc/clang, as version of JsonCpp is >= 1.0.0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations") - endif() -endif()
--- a/Orthanc/Resources/CMake/UuidConfiguration.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - - if (STATIC_BUILD OR NOT USE_SYSTEM_UUID) - SET(E2FSPROGS_SOURCES_DIR ${CMAKE_BINARY_DIR}/e2fsprogs-1.43.8) - SET(E2FSPROGS_URL "http://www.orthanc-server.com/downloads/third-party/e2fsprogs-1.43.8.tar.gz") - SET(E2FSPROGS_MD5 "670b7a74a8ead5333acf21b9afc92b3c") - - DownloadPackage(${E2FSPROGS_MD5} ${E2FSPROGS_URL} "${E2FSPROGS_SOURCES_DIR}") - - include_directories( - ${E2FSPROGS_SOURCES_DIR}/lib - ) - - set(UUID_SOURCES - #${E2FSPROGS_SOURCES_DIR}/lib/uuid/tst_uuid.c - #${E2FSPROGS_SOURCES_DIR}/lib/uuid/uuid_time.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/clear.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/compare.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/copy.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/gen_uuid.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/isnull.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/pack.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/parse.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/unpack.c - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/unparse.c - ) - - check_include_file("net/if.h" HAVE_NET_IF_H) - check_include_file("net/if_dl.h" HAVE_NET_IF_DL_H) - check_include_file("netinet/in.h" HAVE_NETINET_IN_H) - check_include_file("stdlib.h" HAVE_STDLIB_H) - check_include_file("sys/file.h" HAVE_SYS_FILE_H) - check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) - check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H) - check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) - check_include_file("sys/sockio.h" HAVE_SYS_SOCKIO_H) - check_include_file("sys/syscall.h" HAVE_SYS_SYSCALL_H) - check_include_file("sys/time.h" HAVE_SYS_TIME_H) - check_include_file("sys/un.h" HAVE_SYS_UN_H) - check_include_file("unistd.h" HAVE_UNISTD_H) - - if (NOT HAVE_NET_IF_H) # This is the case of OpenBSD - unset(HAVE_NET_IF_H CACHE) - check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H) - endif() - - if (NOT HAVE_NETINET_TCP_H) # This is the case of OpenBSD - unset(HAVE_NETINET_TCP_H CACHE) - check_include_files("sys/socket.h;netinet/tcp.h" HAVE_NETINET_TCP_H) - endif() - - if (NOT EXISTS ${E2FSPROGS_SOURCES_DIR}/lib/uuid/config.h) - file(WRITE ${E2FSPROGS_SOURCES_DIR}/lib/uuid/config.h.cmake " -#cmakedefine HAVE_NET_IF_H \@HAVE_NET_IF_H\@ -#cmakedefine HAVE_NET_IF_DL_H \@HAVE_NET_IF_DL_H\@ -#cmakedefine HAVE_NETINET_IN_H \@HAVE_NETINET_IN_H\@ -#cmakedefine HAVE_STDLIB_H \@HAVE_STDLIB_H \@ -#cmakedefine HAVE_SYS_FILE_H \@HAVE_SYS_FILE_H\@ -#cmakedefine HAVE_SYS_IOCTL_H \@HAVE_SYS_IOCTL_H\@ -#cmakedefine HAVE_SYS_RESOURCE_H \@HAVE_SYS_RESOURCE_H\@ -#cmakedefine HAVE_SYS_SOCKET_H \@HAVE_SYS_SOCKET_H\@ -#cmakedefine HAVE_SYS_SOCKIO_H \@HAVE_SYS_SOCKIO_H\@ -#cmakedefine HAVE_SYS_SYSCALL_H \@HAVE_SYS_SYSCALL_H\@ -#cmakedefine HAVE_SYS_TIME_H \@HAVE_SYS_TIME_H\@ -#cmakedefine HAVE_SYS_UN_H \@HAVE_SYS_UN_H\@ -#cmakedefine HAVE_UNISTD_H \@HAVE_UNISTD_H\@ -") - endif() - - configure_file( - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/config.h.cmake - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/config.h - ) - - configure_file( - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/uuid.h.in - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/uuid.h - ) - - if (NOT EXISTS ${E2FSPROGS_SOURCES_DIR}/lib/uuid/uuid_types.h) - file(WRITE - ${E2FSPROGS_SOURCES_DIR}/lib/uuid/uuid_types.h - "#include <stdint.h>\n") - endif() - - source_group(ThirdParty\\uuid REGULAR_EXPRESSION ${E2FSPROGS_SOURCES_DIR}/.*) - - else() - CHECK_INCLUDE_FILE(uuid/uuid.h HAVE_UUID_H) - if (NOT HAVE_UUID_H) - message(FATAL_ERROR "Please install uuid-dev, e2fsprogs (OpenBSD) or e2fsprogs-libuuid (FreeBSD)") - endif() - - check_library_exists(uuid uuid_generate_random "" HAVE_UUID_LIB) - if (NOT HAVE_UUID_LIB) - message(FATAL_ERROR "Unable to find the uuid library") - endif() - - link_libraries(uuid) - endif() - -endif()
--- a/Orthanc/Resources/EmbedResources.py Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,431 +0,0 @@ -#!/usr/bin/python - -# Orthanc - A Lightweight, RESTful DICOM Store -# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics -# Department, University Hospital of Liege, Belgium -# Copyright (C) 2017-2018 Osimis S.A., Belgium -# -# This program is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# In addition, as a special exception, the copyright holders of this -# program give permission to link the code of its release with the -# OpenSSL project's "OpenSSL" library (or with modified versions of it -# that use the same license as the "OpenSSL" library), and distribute -# the linked executables. You must obey the GNU General Public License -# in all respects for all of the code used other than "OpenSSL". If you -# modify file(s) with this exception, you may extend this exception to -# your version of the file(s), but you are not obligated to do so. If -# you do not wish to do so, delete this exception statement from your -# version. If you delete this exception statement from all source files -# in the program, then also delete it here. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - -import sys -import os -import os.path -import pprint -import re - -UPCASE_CHECK = True -USE_SYSTEM_EXCEPTION = False -EXCEPTION_CLASS = 'OrthancException' -OUT_OF_RANGE_EXCEPTION = 'OrthancException(ErrorCode_ParameterOutOfRange)' -INEXISTENT_PATH_EXCEPTION = 'OrthancException(ErrorCode_InexistentItem)' -NAMESPACE = 'Orthanc' - -ARGS = [] -for i in range(len(sys.argv)): - if not sys.argv[i].startswith('--'): - ARGS.append(sys.argv[i]) - elif sys.argv[i].lower() == '--no-upcase-check': - UPCASE_CHECK = False - elif sys.argv[i].lower() == '--system-exception': - USE_SYSTEM_EXCEPTION = True - EXCEPTION_CLASS = '::std::runtime_error' - OUT_OF_RANGE_EXCEPTION = '%s("Parameter out of range")' % EXCEPTION_CLASS - INEXISTENT_PATH_EXCEPTION = '%s("Unknown path in a directory resource")' % EXCEPTION_CLASS - elif sys.argv[i].startswith('--namespace='): - NAMESPACE = sys.argv[i][sys.argv[i].find('=') + 1 : ] - -if len(ARGS) < 2 or len(ARGS) % 2 != 0: - print ('Usage:') - print ('python %s [--no-upcase-check] [--system-exception] [--namespace=<Namespace>] <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0]) - exit(-1) - -TARGET_BASE_FILENAME = ARGS[1] -SOURCES = ARGS[2:] - -try: - # Make sure the destination directory exists - os.makedirs(os.path.normpath(os.path.join(TARGET_BASE_FILENAME, '..'))) -except: - pass - - -##################################################################### -## Read each resource file -##################################################################### - -def CheckNoUpcase(s): - global UPCASE_CHECK - if (UPCASE_CHECK and - re.search('[A-Z]', s) != None): - raise Exception("Path in a directory with an upcase letter: %s" % s) - -resources = {} - -counter = 0 -i = 0 -while i < len(SOURCES): - resourceName = SOURCES[i].upper() - pathName = SOURCES[i + 1] - - if not os.path.exists(pathName): - raise Exception("Non existing path: %s" % pathName) - - if resourceName in resources: - raise Exception("Twice the same resource: " + resourceName) - - if os.path.isdir(pathName): - # The resource is a directory: Recursively explore its files - content = {} - for root, dirs, files in os.walk(pathName): - base = os.path.relpath(root, pathName) - - # Fix issue #24 (Build fails on OSX when directory has .DS_Store files): - # Ignore folders whose name starts with a dot (".") - if base.find('/.') != -1: - print('Ignoring folder: %s' % root) - continue - - for f in files: - if f.find('~') == -1: # Ignore Emacs backup files - if base == '.': - r = f - else: - r = os.path.join(base, f) - - CheckNoUpcase(r) - r = '/' + r.replace('\\', '/') - if r in content: - raise Exception("Twice the same filename (check case): " + r) - - content[r] = { - 'Filename' : os.path.join(root, f), - 'Index' : counter - } - counter += 1 - - resources[resourceName] = { - 'Type' : 'Directory', - 'Files' : content - } - - elif os.path.isfile(pathName): - resources[resourceName] = { - 'Type' : 'File', - 'Index' : counter, - 'Filename' : pathName - } - counter += 1 - - else: - raise Exception("Not a regular file, nor a directory: " + pathName) - - i += 2 - -#pprint.pprint(resources) - - -##################################################################### -## Write .h header -##################################################################### - -header = open(TARGET_BASE_FILENAME + '.h', 'w') - -header.write(""" -#pragma once - -#include <string> -#include <list> - -#if defined(_MSC_VER) -# pragma warning(disable: 4065) // "Switch statement contains 'default' but no 'case' labels" -#endif - -namespace %s -{ - namespace EmbeddedResources - { - enum FileResourceId - { -""" % NAMESPACE) - -isFirst = True -for name in resources: - if resources[name]['Type'] == 'File': - if isFirst: - isFirst = False - else: - header.write(',\n') - header.write(' %s' % name) - -header.write(""" - }; - - enum DirectoryResourceId - { -""") - -isFirst = True -for name in resources: - if resources[name]['Type'] == 'Directory': - if isFirst: - isFirst = False - else: - header.write(',\n') - header.write(' %s' % name) - -header.write(""" - }; - - const void* GetFileResourceBuffer(FileResourceId id); - size_t GetFileResourceSize(FileResourceId id); - void GetFileResource(std::string& result, FileResourceId id); - - const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path); - size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path); - void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path); - - void ListResources(std::list<std::string>& result, DirectoryResourceId id); - } -} -""") -header.close() - - - -##################################################################### -## Write the resource content in the .cpp source -##################################################################### - -PYTHON_MAJOR_VERSION = sys.version_info[0] - -def WriteResource(cpp, item): - cpp.write(' static const uint8_t resource%dBuffer[] = {' % item['Index']) - - f = open(item['Filename'], "rb") - content = f.read() - f.close() - - # http://stackoverflow.com/a/1035360 - pos = 0 - for b in content: - if PYTHON_MAJOR_VERSION == 2: - c = ord(b[0]) - else: - c = b - - if pos > 0: - cpp.write(', ') - - if (pos % 16) == 0: - cpp.write('\n ') - - if c < 0: - raise Exception("Internal error") - - cpp.write("0x%02x" % c) - pos += 1 - - # Zero-size array are disallowed, so we put one single void character in it. - if pos == 0: - cpp.write(' 0') - - cpp.write(' };\n') - cpp.write(' static const size_t resource%dSize = %d;\n' % (item['Index'], pos)) - - -cpp = open(TARGET_BASE_FILENAME + '.cpp', 'w') - -cpp.write('#include "%s.h"\n' % os.path.basename(TARGET_BASE_FILENAME)) - -if USE_SYSTEM_EXCEPTION: - cpp.write('#include <stdexcept>') -else: - cpp.write('#include "%s/Core/OrthancException.h"' % os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) - -cpp.write(""" -#include <stdint.h> -#include <string.h> - -namespace %s -{ - namespace EmbeddedResources - { -""" % NAMESPACE) - - -for name in resources: - if resources[name]['Type'] == 'File': - WriteResource(cpp, resources[name]) - else: - for f in resources[name]['Files']: - WriteResource(cpp, resources[name]['Files'][f]) - - - -##################################################################### -## Write the accessors to the file resources in .cpp -##################################################################### - -cpp.write(""" - const void* GetFileResourceBuffer(FileResourceId id) - { - switch (id) - { -""") -for name in resources: - if resources[name]['Type'] == 'File': - cpp.write(' case %s:\n' % name) - cpp.write(' return resource%dBuffer;\n' % resources[name]['Index']) - -cpp.write(""" - default: - throw %s; - } - } - - size_t GetFileResourceSize(FileResourceId id) - { - switch (id) - { -""" % OUT_OF_RANGE_EXCEPTION) - -for name in resources: - if resources[name]['Type'] == 'File': - cpp.write(' case %s:\n' % name) - cpp.write(' return resource%dSize;\n' % resources[name]['Index']) - -cpp.write(""" - default: - throw %s; - } - } -""" % OUT_OF_RANGE_EXCEPTION) - - - -##################################################################### -## Write the accessors to the directory resources in .cpp -##################################################################### - -cpp.write(""" - const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path) - { - switch (id) - { -""") - -for name in resources: - if resources[name]['Type'] == 'Directory': - cpp.write(' case %s:\n' % name) - isFirst = True - for path in resources[name]['Files']: - cpp.write(' if (!strcmp(path, "%s"))\n' % path) - cpp.write(' return resource%dBuffer;\n' % resources[name]['Files'][path]['Index']) - cpp.write(' throw %s;\n\n' % INEXISTENT_PATH_EXCEPTION) - -cpp.write(""" default: - throw %s; - } - } - - size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path) - { - switch (id) - { -""" % OUT_OF_RANGE_EXCEPTION) - -for name in resources: - if resources[name]['Type'] == 'Directory': - cpp.write(' case %s:\n' % name) - isFirst = True - for path in resources[name]['Files']: - cpp.write(' if (!strcmp(path, "%s"))\n' % path) - cpp.write(' return resource%dSize;\n' % resources[name]['Files'][path]['Index']) - cpp.write(' throw %s;\n\n' % INEXISTENT_PATH_EXCEPTION) - -cpp.write(""" default: - throw %s; - } - } -""" % OUT_OF_RANGE_EXCEPTION) - - - - -##################################################################### -## List the resources in a directory -##################################################################### - -cpp.write(""" - void ListResources(std::list<std::string>& result, DirectoryResourceId id) - { - result.clear(); - - switch (id) - { -""") - -for name in resources: - if resources[name]['Type'] == 'Directory': - cpp.write(' case %s:\n' % name) - for path in sorted(resources[name]['Files']): - cpp.write(' result.push_back("%s");\n' % path) - cpp.write(' break;\n\n') - -cpp.write(""" default: - throw %s; - } - } -""" % OUT_OF_RANGE_EXCEPTION) - - - - -##################################################################### -## Write the convenience wrappers in .cpp -##################################################################### - -cpp.write(""" - void GetFileResource(std::string& result, FileResourceId id) - { - size_t size = GetFileResourceSize(id); - result.resize(size); - if (size > 0) - memcpy(&result[0], GetFileResourceBuffer(id), size); - } - - void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path) - { - size_t size = GetDirectoryResourceSize(id, path); - result.resize(size); - if (size > 0) - memcpy(&result[0], GetDirectoryResourceBuffer(id, path), size); - } - } -} -""") -cpp.close()
--- a/Orthanc/Resources/LinuxStandardBaseToolchain.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON - -INCLUDE(CMakeForceCompiler) - -SET(LSB_PATH $ENV{LSB_PATH}) -SET(LSB_CC $ENV{LSB_CC}) -SET(LSB_CXX $ENV{LSB_CXX}) -SET(LSB_TARGET_VERSION "4.0") - -IF ("${LSB_PATH}" STREQUAL "") - SET(LSB_PATH "/opt/lsb") -ENDIF() - -IF (EXISTS ${LSB_PATH}/lib64) - SET(LSB_TARGET_PROCESSOR "x86_64") - SET(LSB_LIBPATH ${LSB_PATH}/lib64-${LSB_TARGET_VERSION}) -ELSEIF (EXISTS ${LSB_PATH}/lib) - SET(LSB_TARGET_PROCESSOR "x86") - SET(LSB_LIBPATH ${LSB_PATH}/lib-${LSB_TARGET_VERSION}) -ELSE() - MESSAGE(FATAL_ERROR "Unable to detect the target processor architecture. Check the LSB_PATH environment variable.") -ENDIF() - -SET(LSB_CPPPATH ${LSB_PATH}/include) -SET(PKG_CONFIG_PATH ${LSB_LIBPATH}/pkgconfig/) - -# the name of the target operating system -SET(CMAKE_SYSTEM_NAME Linux) -SET(CMAKE_SYSTEM_VERSION LinuxStandardBase) -SET(CMAKE_SYSTEM_PROCESSOR ${LSB_TARGET_PROCESSOR}) - -# which compilers to use for C and C++ -SET(CMAKE_C_COMPILER ${LSB_PATH}/bin/lsbcc) -CMAKE_FORCE_CXX_COMPILER(${LSB_PATH}/bin/lsbc++ GNU) - -# here is the target environment located -SET(CMAKE_FIND_ROOT_PATH ${LSB_PATH}) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - -SET(CMAKE_CROSSCOMPILING OFF) - - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include" CACHE INTERNAL "" FORCE) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward" CACHE INTERNAL "" FORCE) -SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) - -if (NOT "${LSB_CXX}" STREQUAL "") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cxx=${LSB_CXX}") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") -endif() - -if (NOT "${LSB_CC}" STREQUAL "") - SET(CMAKE_C_FLAGS "${CMAKE_CC_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cc=${LSB_CC}") -endif() -
--- a/Orthanc/Resources/MinGW-W64-Toolchain32.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -# the name of the target operating system -set(CMAKE_SYSTEM_NAME Windows) - -# which compilers to use for C and C++ -set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) -set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) -set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) - -# here is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- a/Orthanc/Resources/MinGW-W64-Toolchain64.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -# the name of the target operating system -set(CMAKE_SYSTEM_NAME Windows) - -# which compilers to use for C and C++ -set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) -set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) -set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) - -# here is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- a/Orthanc/Resources/MinGWToolchain.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -# the name of the target operating system -set(CMAKE_SYSTEM_NAME Windows) - -# which compilers to use for C and C++ -set(CMAKE_C_COMPILER i586-mingw32msvc-gcc) -set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++) -set(CMAKE_RC_COMPILER i586-mingw32msvc-windres) - -# here is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- a/Orthanc/Resources/Patches/boost-1.66.0-linux-standard-base.patch Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -diff -urEb boost_1_66_0.orig/boost/move/adl_move_swap.hpp boost_1_66_0/boost/move/adl_move_swap.hpp ---- boost_1_66_0.orig/boost/move/adl_move_swap.hpp 2018-04-11 11:56:16.761768726 +0200 -+++ boost_1_66_0/boost/move/adl_move_swap.hpp 2018-04-11 11:57:01.073881330 +0200 -@@ -28,6 +28,8 @@ - //Try to avoid including <algorithm>, as it's quite big - #if defined(_MSC_VER) && defined(BOOST_DINKUMWARE_STDLIB) - #include <utility> //Dinkum libraries define std::swap in utility which is lighter than algorithm -+#elif defined(__LSB_VERSION__) -+# include <utility> - #elif defined(BOOST_GNU_STDLIB) - //For non-GCC compilers, where GNUC version is not very reliable, or old GCC versions - //use the good old stl_algobase header, which is quite lightweight -Only in boost_1_66_0/boost/move: adl_move_swap.hpp~
--- a/Orthanc/Resources/ThirdParty/VisualStudio/stdint.h Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,259 +0,0 @@ -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2013 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of the product nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#if _MSC_VER >= 1600 // [ -#include <stdint.h> -#else // ] _MSC_VER >= 1600 [ - -#include <limits.h> - -// For Visual Studio 6 in C++ mode and for many Visual Studio versions when -// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#ifdef __cplusplus -extern "C" { -#endif -# include <wchar.h> -#ifdef __cplusplus -} -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types - -// Visual Studio 6 and Embedded Visual C++ 4 doesn't -// realize that, e.g. char has the same size as __int8 -// so we give up on __intX for them. -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef signed __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 signed int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h> -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>. -// Check out Issue 9 for the details. -#ifndef INTMAX_C // [ -# define INTMAX_C INT64_C -#endif // INTMAX_C ] -#ifndef UINTMAX_C // [ -# define UINTMAX_C UINT64_C -#endif // UINTMAX_C ] - -#endif // __STDC_CONSTANT_MACROS ] - -#endif // _MSC_VER >= 1600 ] - -#endif // _MSC_STDINT_H_ ]
--- a/Orthanc/Resources/WindowsResources.py Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -#!/usr/bin/python - -# Orthanc - A Lightweight, RESTful DICOM Store -# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics -# Department, University Hospital of Liege, Belgium -# Copyright (C) 2017-2018 Osimis S.A., Belgium -# -# This program is free software: you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# In addition, as a special exception, the copyright holders of this -# program give permission to link the code of its release with the -# OpenSSL project's "OpenSSL" library (or with modified versions of it -# that use the same license as the "OpenSSL" library), and distribute -# the linked executables. You must obey the GNU General Public License -# in all respects for all of the code used other than "OpenSSL". If you -# modify file(s) with this exception, you may extend this exception to -# your version of the file(s), but you are not obligated to do so. If -# you do not wish to do so, delete this exception statement from your -# version. If you delete this exception statement from all source files -# in the program, then also delete it here. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - -import os -import sys -import datetime - -if len(sys.argv) != 5: - sys.stderr.write('Usage: %s <Version> <ProductName> <Filename> <Description>\n\n' % sys.argv[0]) - sys.stderr.write('Example: %s 0.9.1 Orthanc Orthanc.exe "Lightweight, RESTful DICOM server for medical imaging"\n' % sys.argv[0]) - sys.exit(-1) - -SOURCE = os.path.join(os.path.dirname(__file__), 'WindowsResources.rc') - -VERSION = sys.argv[1] -PRODUCT = sys.argv[2] -FILENAME = sys.argv[3] -DESCRIPTION = sys.argv[4] - -if VERSION == 'mainline': - VERSION = '999.999.999' - RELEASE = 'This is a mainline build, not an official release' -else: - RELEASE = 'Release %s' % VERSION - -v = VERSION.split('.') -if len(v) != 2 and len(v) != 3: - sys.stderr.write('Bad version number: %s\n' % VERSION) - sys.exit(-1) - -if len(v) == 2: - v.append('0') - -extension = os.path.splitext(FILENAME)[1] -if extension.lower() == '.dll': - BLOCK = '040904E4' - TYPE = 'VFT_DLL' -elif extension.lower() == '.exe': - #BLOCK = '040904B0' # LANG_ENGLISH/SUBLANG_ENGLISH_US, - BLOCK = '040904E4' # Lang=US English, CharSet=Windows Multilingual - TYPE = 'VFT_APP' -else: - sys.stderr.write('Unsupported extension (.EXE or .DLL only): %s\n' % extension) - sys.exit(-1) - - -with open(SOURCE, 'r') as source: - content = source.read() - content = content.replace('${VERSION_MAJOR}', v[0]) - content = content.replace('${VERSION_MINOR}', v[1]) - content = content.replace('${VERSION_PATCH}', v[2]) - content = content.replace('${RELEASE}', RELEASE) - content = content.replace('${DESCRIPTION}', DESCRIPTION) - content = content.replace('${PRODUCT}', PRODUCT) - content = content.replace('${FILENAME}', FILENAME) - content = content.replace('${YEAR}', str(datetime.datetime.now().year)) - content = content.replace('${BLOCK}', BLOCK) - content = content.replace('${TYPE}', TYPE) - - sys.stdout.write(content)
--- a/Orthanc/Resources/WindowsResources.rc Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#include <winver.h> - -VS_VERSION_INFO VERSIONINFO - FILEVERSION ${VERSION_MAJOR},${VERSION_MINOR},0,${VERSION_PATCH} - PRODUCTVERSION ${VERSION_MAJOR},${VERSION_MINOR},0,0 - FILEOS VOS_NT_WINDOWS32 - FILETYPE ${TYPE} - BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "${BLOCK}" - BEGIN - VALUE "Comments", "${RELEASE}" - VALUE "CompanyName", "University Hospital of Liege, Belgium" - VALUE "FileDescription", "${DESCRIPTION}" - VALUE "FileVersion", "${VERSION_MAJOR}.${VERSION_MINOR}.0.${VERSION_PATCH}" - VALUE "InternalName", "${PRODUCT}" - VALUE "LegalCopyright", "(c) 2012-${YEAR}, Sebastien Jodogne, University Hospital of Liege, Belgium" - VALUE "LegalTrademarks", "Licensing information is available at http://www.orthanc-server.com/" - VALUE "OriginalFilename", "${FILENAME}" - VALUE "ProductName", "${PRODUCT}" - VALUE "ProductVersion", "${VERSION_MAJOR}.${VERSION_MINOR}" - END - END - - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1252 // U.S. English - END - END
--- a/Orthanc/Sdk-0.9.5/orthanc/OrthancCDatabasePlugin.h Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,808 +0,0 @@ -/** - * @ingroup CInterface - **/ - -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - - -#pragma once - -#include "OrthancCPlugin.h" - - -/** @{ */ - -#ifdef __cplusplus -extern "C" -{ -#endif - - - /** - * Opaque structure that represents the context of a custom database engine. - * @ingroup Callbacks - **/ - typedef struct _OrthancPluginDatabaseContext_t OrthancPluginDatabaseContext; - - -/*<! @cond Doxygen_Suppress */ - typedef enum - { - _OrthancPluginDatabaseAnswerType_None = 0, - - /* Events */ - _OrthancPluginDatabaseAnswerType_DeletedAttachment = 1, - _OrthancPluginDatabaseAnswerType_DeletedResource = 2, - _OrthancPluginDatabaseAnswerType_RemainingAncestor = 3, - - /* Return value */ - _OrthancPluginDatabaseAnswerType_Attachment = 10, - _OrthancPluginDatabaseAnswerType_Change = 11, - _OrthancPluginDatabaseAnswerType_DicomTag = 12, - _OrthancPluginDatabaseAnswerType_ExportedResource = 13, - _OrthancPluginDatabaseAnswerType_Int32 = 14, - _OrthancPluginDatabaseAnswerType_Int64 = 15, - _OrthancPluginDatabaseAnswerType_Resource = 16, - _OrthancPluginDatabaseAnswerType_String = 17, - - _OrthancPluginDatabaseAnswerType_INTERNAL = 0x7fffffff - } _OrthancPluginDatabaseAnswerType; - - - typedef struct - { - const char* uuid; - int32_t contentType; - uint64_t uncompressedSize; - const char* uncompressedHash; - int32_t compressionType; - uint64_t compressedSize; - const char* compressedHash; - } OrthancPluginAttachment; - - typedef struct - { - uint16_t group; - uint16_t element; - const char* value; - } OrthancPluginDicomTag; - - typedef struct - { - int64_t seq; - int32_t changeType; - OrthancPluginResourceType resourceType; - const char* publicId; - const char* date; - } OrthancPluginChange; - - typedef struct - { - int64_t seq; - OrthancPluginResourceType resourceType; - const char* publicId; - const char* modality; - const char* date; - const char* patientId; - const char* studyInstanceUid; - const char* seriesInstanceUid; - const char* sopInstanceUid; - } OrthancPluginExportedResource; - - - typedef struct - { - OrthancPluginDatabaseContext* database; - _OrthancPluginDatabaseAnswerType type; - int32_t valueInt32; - uint32_t valueUint32; - int64_t valueInt64; - const char *valueString; - const void *valueGeneric; - } _OrthancPluginDatabaseAnswer; - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerString( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const char* value) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_String; - params.valueString = value; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChange( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const OrthancPluginChange* change) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Change; - params.valueUint32 = 0; - params.valueGeneric = change; - - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChangesDone( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Change; - params.valueUint32 = 1; - params.valueGeneric = NULL; - - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt32( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - int32_t value) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Int32; - params.valueInt32 = value; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt64( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - int64_t value) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Int64; - params.valueInt64 = value; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResource( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const OrthancPluginExportedResource* exported) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_ExportedResource; - params.valueUint32 = 0; - params.valueGeneric = exported; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResourcesDone( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_ExportedResource; - params.valueUint32 = 1; - params.valueGeneric = NULL; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerDicomTag( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const OrthancPluginDicomTag* tag) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_DicomTag; - params.valueGeneric = tag; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerAttachment( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const OrthancPluginAttachment* attachment) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Attachment; - params.valueGeneric = attachment; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerResource( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - int64_t id, - OrthancPluginResourceType resourceType) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_Resource; - params.valueInt64 = id; - params.valueInt32 = (int32_t) resourceType; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedAttachment( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const OrthancPluginAttachment* attachment) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_DeletedAttachment; - params.valueGeneric = attachment; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedResource( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const char* publicId, - OrthancPluginResourceType resourceType) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_DeletedResource; - params.valueString = publicId; - params.valueInt32 = (int32_t) resourceType; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalRemainingAncestor( - OrthancPluginContext* context, - OrthancPluginDatabaseContext* database, - const char* ancestorId, - OrthancPluginResourceType ancestorType) - { - _OrthancPluginDatabaseAnswer params; - memset(¶ms, 0, sizeof(params)); - params.database = database; - params.type = _OrthancPluginDatabaseAnswerType_RemainingAncestor; - params.valueString = ancestorId; - params.valueInt32 = (int32_t) ancestorType; - context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); - } - - - - - - typedef struct - { - OrthancPluginErrorCode (*addAttachment) ( - /* inputs */ - void* payload, - int64_t id, - const OrthancPluginAttachment* attachment); - - OrthancPluginErrorCode (*attachChild) ( - /* inputs */ - void* payload, - int64_t parent, - int64_t child); - - OrthancPluginErrorCode (*clearChanges) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*clearExportedResources) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*createResource) ( - /* outputs */ - int64_t* id, - /* inputs */ - void* payload, - const char* publicId, - OrthancPluginResourceType resourceType); - - OrthancPluginErrorCode (*deleteAttachment) ( - /* inputs */ - void* payload, - int64_t id, - int32_t contentType); - - OrthancPluginErrorCode (*deleteMetadata) ( - /* inputs */ - void* payload, - int64_t id, - int32_t metadataType); - - OrthancPluginErrorCode (*deleteResource) ( - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*getAllPublicIds) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - OrthancPluginResourceType resourceType); - - /* Output: Use OrthancPluginDatabaseAnswerChange() and - * OrthancPluginDatabaseAnswerChangesDone() */ - OrthancPluginErrorCode (*getChanges) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t since, - uint32_t maxResult); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*getChildrenInternalId) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*getChildrenPublicId) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerExportedResource() and - * OrthancPluginDatabaseAnswerExportedResourcesDone() */ - OrthancPluginErrorCode (*getExportedResources) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t since, - uint32_t maxResult); - - /* Output: Use OrthancPluginDatabaseAnswerChange() */ - OrthancPluginErrorCode (*getLastChange) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload); - - /* Output: Use OrthancPluginDatabaseAnswerExportedResource() */ - OrthancPluginErrorCode (*getLastExportedResource) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload); - - /* Output: Use OrthancPluginDatabaseAnswerDicomTag() */ - OrthancPluginErrorCode (*getMainDicomTags) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*getPublicId) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - OrthancPluginErrorCode (*getResourceCount) ( - /* outputs */ - uint64_t* target, - /* inputs */ - void* payload, - OrthancPluginResourceType resourceType); - - OrthancPluginErrorCode (*getResourceType) ( - /* outputs */ - OrthancPluginResourceType* resourceType, - /* inputs */ - void* payload, - int64_t id); - - OrthancPluginErrorCode (*getTotalCompressedSize) ( - /* outputs */ - uint64_t* target, - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*getTotalUncompressedSize) ( - /* outputs */ - uint64_t* target, - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*isExistingResource) ( - /* outputs */ - int32_t* existing, - /* inputs */ - void* payload, - int64_t id); - - OrthancPluginErrorCode (*isProtectedPatient) ( - /* outputs */ - int32_t* isProtected, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerInt32() */ - OrthancPluginErrorCode (*listAvailableMetadata) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerInt32() */ - OrthancPluginErrorCode (*listAvailableAttachments) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - OrthancPluginErrorCode (*logChange) ( - /* inputs */ - void* payload, - const OrthancPluginChange* change); - - OrthancPluginErrorCode (*logExportedResource) ( - /* inputs */ - void* payload, - const OrthancPluginExportedResource* exported); - - /* Output: Use OrthancPluginDatabaseAnswerAttachment() */ - OrthancPluginErrorCode (*lookupAttachment) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id, - int32_t contentType); - - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*lookupGlobalProperty) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int32_t property); - - /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier3" - instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL. - Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*lookupIdentifier) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - const OrthancPluginDicomTag* tag); - - /* Unused starting with Orthanc 0.9.5 (db v6), can be set to NULL. - Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*lookupIdentifier2) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - const char* value); - - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*lookupMetadata) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id, - int32_t metadata); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*lookupParent) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerResource() */ - OrthancPluginErrorCode (*lookupResource) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - const char* publicId); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*selectPatientToRecycle) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*selectPatientToRecycle2) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - int64_t patientIdToAvoid); - - OrthancPluginErrorCode (*setGlobalProperty) ( - /* inputs */ - void* payload, - int32_t property, - const char* value); - - OrthancPluginErrorCode (*setMainDicomTag) ( - /* inputs */ - void* payload, - int64_t id, - const OrthancPluginDicomTag* tag); - - OrthancPluginErrorCode (*setIdentifierTag) ( - /* inputs */ - void* payload, - int64_t id, - const OrthancPluginDicomTag* tag); - - OrthancPluginErrorCode (*setMetadata) ( - /* inputs */ - void* payload, - int64_t id, - int32_t metadata, - const char* value); - - OrthancPluginErrorCode (*setProtectedPatient) ( - /* inputs */ - void* payload, - int64_t id, - int32_t isProtected); - - OrthancPluginErrorCode (*startTransaction) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*rollbackTransaction) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*commitTransaction) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*open) ( - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*close) ( - /* inputs */ - void* payload); - - } OrthancPluginDatabaseBackend; - - - typedef struct - { - /* Output: Use OrthancPluginDatabaseAnswerString() */ - OrthancPluginErrorCode (*getAllPublicIdsWithLimit) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - OrthancPluginResourceType resourceType, - uint64_t since, - uint64_t limit); - - OrthancPluginErrorCode (*getDatabaseVersion) ( - /* outputs */ - uint32_t* version, - /* inputs */ - void* payload); - - OrthancPluginErrorCode (*upgradeDatabase) ( - /* inputs */ - void* payload, - uint32_t targetVersion, - OrthancPluginStorageArea* storageArea); - - OrthancPluginErrorCode (*clearMainDicomTags) ( - /* inputs */ - void* payload, - int64_t id); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*getAllInternalIds) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - OrthancPluginResourceType resourceType); - - /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - OrthancPluginErrorCode (*lookupIdentifier3) ( - /* outputs */ - OrthancPluginDatabaseContext* context, - /* inputs */ - void* payload, - OrthancPluginResourceType resourceType, - const OrthancPluginDicomTag* tag, - OrthancPluginIdentifierConstraint constraint); - } OrthancPluginDatabaseExtensions; - -/*<! @endcond */ - - - typedef struct - { - OrthancPluginDatabaseContext** result; - const OrthancPluginDatabaseBackend* backend; - void* payload; - } _OrthancPluginRegisterDatabaseBackend; - - /** - * Register a custom database back-end. - * - * Instead of manually filling the OrthancPluginDatabaseBackend - * structure, you should instead implement a concrete C++ class - * deriving from ::OrthancPlugins::IDatabaseBackend, and register it - * using ::OrthancPlugins::DatabaseBackendAdapter::Register(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param backend The callbacks of the custom database engine. - * @param payload Pointer containing private information for the database engine. - * @return The context of the database engine (it must not be manually freed). - * @ingroup Callbacks - * @deprecated - * @see OrthancPluginRegisterDatabaseBackendV2 - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginDatabaseContext* OrthancPluginRegisterDatabaseBackend( - OrthancPluginContext* context, - const OrthancPluginDatabaseBackend* backend, - void* payload) - { - OrthancPluginDatabaseContext* result = NULL; - _OrthancPluginRegisterDatabaseBackend params; - - if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) - { - return NULL; - } - - memset(¶ms, 0, sizeof(params)); - params.backend = backend; - params.result = &result; - params.payload = payload; - - if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackend, ¶ms) || - result == NULL) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - typedef struct - { - OrthancPluginDatabaseContext** result; - const OrthancPluginDatabaseBackend* backend; - void* payload; - const OrthancPluginDatabaseExtensions* extensions; - uint32_t extensionsSize; - } _OrthancPluginRegisterDatabaseBackendV2; - - - /** - * Register a custom database back-end. - * - * Instead of manually filling the OrthancPluginDatabaseBackendV2 - * structure, you should instead implement a concrete C++ class - * deriving from ::OrthancPlugins::IDatabaseBackend, and register it - * using ::OrthancPlugins::DatabaseBackendAdapter::Register(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param backend The callbacks of the custom database engine. - * @param payload Pointer containing private information for the database engine. - * @param extensions Extensions to the base database SDK that was shipped until Orthanc 0.9.3. - * @return The context of the database engine (it must not be manually freed). - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginDatabaseContext* OrthancPluginRegisterDatabaseBackendV2( - OrthancPluginContext* context, - const OrthancPluginDatabaseBackend* backend, - const OrthancPluginDatabaseExtensions* extensions, - void* payload) - { - OrthancPluginDatabaseContext* result = NULL; - _OrthancPluginRegisterDatabaseBackendV2 params; - - if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) - { - return NULL; - } - - memset(¶ms, 0, sizeof(params)); - params.backend = backend; - params.result = &result; - params.payload = payload; - params.extensions = extensions; - params.extensionsSize = sizeof(OrthancPluginDatabaseExtensions); - - if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackendV2, ¶ms) || - result == NULL) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - -#ifdef __cplusplus -} -#endif - - -/** @} */ -
--- a/Orthanc/Sdk-0.9.5/orthanc/OrthancCPlugin.h Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4686 +0,0 @@ -/** - * \mainpage - * - * This C/C++ SDK allows external developers to create plugins that - * can be loaded into Orthanc to extend its functionality. Each - * Orthanc plugin must expose 4 public functions with the following - * signatures: - * - * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>: - * This function is invoked by Orthanc when it loads the plugin on startup. - * The plugin must: - * - Check its compatibility with the Orthanc version using - * ::OrthancPluginCheckVersion(). - * - Store the context pointer so that it can use the plugin - * services of Orthanc. - * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback(). - * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback(). - * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback(). - * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea(). - * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2(). - * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). - * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). - * -# <tt>void OrthancPluginFinalize()</tt>: - * This function is invoked by Orthanc during its shutdown. The plugin - * must free all its memory. - * -# <tt>const char* OrthancPluginGetName()</tt>: - * The plugin must return a short string to identify itself. - * -# <tt>const char* OrthancPluginGetVersion()</tt>: - * The plugin must return a string containing its version number. - * - * The name and the version of a plugin is only used to prevent it - * from being loaded twice. Note that, in C++, it is mandatory to - * declare these functions within an <tt>extern "C"</tt> section. - * - * To ensure multi-threading safety, the various REST callbacks are - * guaranteed to be executed in mutual exclusion since Orthanc - * 0.8.5. If this feature is undesired (notably when developing - * high-performance plugins handling simultaneous requests), use - * ::OrthancPluginRegisterRestCallbackNoLock(). - **/ - - - -/** - * @defgroup Images Images and compression - * @brief Functions to deal with images and compressed buffers. - * - * @defgroup REST REST - * @brief Functions to answer REST requests in a callback. - * - * @defgroup Callbacks Callbacks - * @brief Functions to register and manage callbacks by the plugins. - * - * @defgroup Worklists Worklists - * @brief Functions to register and manage worklists. - * - * @defgroup Orthanc Orthanc - * @brief Functions to access the content of the Orthanc server. - **/ - - - -/** - * @defgroup Toolbox Toolbox - * @brief Generic functions to help with the creation of plugins. - **/ - - - -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - - -#pragma once - - -#include <stdio.h> -#include <string.h> - -#ifdef WIN32 -#define ORTHANC_PLUGINS_API __declspec(dllexport) -#else -#define ORTHANC_PLUGINS_API -#endif - -#define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0 -#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 9 -#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 5 - - - -/******************************************************************** - ** Check that function inlining is properly supported. The use of - ** inlining is required, to avoid the duplication of object code - ** between two compilation modules that would use the Orthanc Plugin - ** API. - ********************************************************************/ - -/* If the auto-detection of the "inline" keyword below does not work - automatically and that your compiler is known to properly support - inlining, uncomment the following #define and adapt the definition - of "static inline". */ - -/* #define ORTHANC_PLUGIN_INLINE static inline */ - -#ifndef ORTHANC_PLUGIN_INLINE -# if __STDC_VERSION__ >= 199901L -/* This is C99 or above: http://predef.sourceforge.net/prestd.html */ -# define ORTHANC_PLUGIN_INLINE static inline -# elif defined(__cplusplus) -/* This is C++ */ -# define ORTHANC_PLUGIN_INLINE static inline -# elif defined(__GNUC__) -/* This is GCC running in C89 mode */ -# define ORTHANC_PLUGIN_INLINE static __inline -# elif defined(_MSC_VER) -/* This is Visual Studio running in C89 mode */ -# define ORTHANC_PLUGIN_INLINE static __inline -# else -# error Your compiler is not known to support the "inline" keyword -# endif -#endif - - - -/******************************************************************** - ** Inclusion of standard libraries. - ********************************************************************/ - -/** - * For Microsoft Visual Studio, a compatibility "stdint.h" can be - * downloaded at the following URL: - * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h - **/ -#include <stdint.h> - -#include <stdlib.h> - - - -/******************************************************************** - ** Definition of the Orthanc Plugin API. - ********************************************************************/ - -/** @{ */ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** - * The various error codes that can be returned by the Orthanc core. - **/ - typedef enum - { - OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, - OrthancPluginErrorCode_Success = 0 /*!< Success */, - OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, - OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */, - OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, - OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< Not enough memory */, - OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, - OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, - OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, - OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */, - OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */, - OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */, - OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */, - OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */, - OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */, - OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */, - OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */, - OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */, - OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */, - OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */, - OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */, - OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */, - OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */, - OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */, - OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */, - OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */, - OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */, - OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */, - OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */, - OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, - OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, - OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, - OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, - OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, - OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */, - OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, - OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, - OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, - OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, - OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */, - OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */, - OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */, - OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */, - OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */, - OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */, - OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */, - OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */, - OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */, - OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */, - OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */, - OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */, - OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */, - OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */, - OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */, - OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */, - OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is already in use */, - OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is already in use */, - OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */, - OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */, - OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */, - OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */, - OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */, - OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */, - OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */, - OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */, - OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */, - OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */, - OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */, - OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */, - OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */, - OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */, - OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */, - OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */, - OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */, - OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */, - OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */, - OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */, - OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, - OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, - OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, - OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, - OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, - OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, - OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, - OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, - OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, - OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, - OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, - OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, - OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, - OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, - OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */, - OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */, - OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */, - - _OrthancPluginErrorCode_INTERNAL = 0x7fffffff - } OrthancPluginErrorCode; - - - /** - * Forward declaration of one of the mandatory functions for Orthanc - * plugins. - **/ - ORTHANC_PLUGINS_API const char* OrthancPluginGetName(); - - - /** - * The various HTTP methods for a REST call. - **/ - typedef enum - { - OrthancPluginHttpMethod_Get = 1, /*!< GET request */ - OrthancPluginHttpMethod_Post = 2, /*!< POST request */ - OrthancPluginHttpMethod_Put = 3, /*!< PUT request */ - OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */ - - _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff - } OrthancPluginHttpMethod; - - - /** - * @brief The parameters of a REST request. - * @ingroup Callbacks - **/ - typedef struct - { - /** - * @brief The HTTP method. - **/ - OrthancPluginHttpMethod method; - - /** - * @brief The number of groups of the regular expression. - **/ - uint32_t groupsCount; - - /** - * @brief The matched values for the groups of the regular expression. - **/ - const char* const* groups; - - /** - * @brief For a GET request, the number of GET parameters. - **/ - uint32_t getCount; - - /** - * @brief For a GET request, the keys of the GET parameters. - **/ - const char* const* getKeys; - - /** - * @brief For a GET request, the values of the GET parameters. - **/ - const char* const* getValues; - - /** - * @brief For a PUT or POST request, the content of the body. - **/ - const char* body; - - /** - * @brief For a PUT or POST request, the number of bytes of the body. - **/ - uint32_t bodySize; - - - /* -------------------------------------------------- - New in version 0.8.1 - -------------------------------------------------- */ - - /** - * @brief The number of HTTP headers. - **/ - uint32_t headersCount; - - /** - * @brief The keys of the HTTP headers (always converted to low-case). - **/ - const char* const* headersKeys; - - /** - * @brief The values of the HTTP headers. - **/ - const char* const* headersValues; - - } OrthancPluginHttpRequest; - - - typedef enum - { - /* Generic services */ - _OrthancPluginService_LogInfo = 1, - _OrthancPluginService_LogWarning = 2, - _OrthancPluginService_LogError = 3, - _OrthancPluginService_GetOrthancPath = 4, - _OrthancPluginService_GetOrthancDirectory = 5, - _OrthancPluginService_GetConfigurationPath = 6, - _OrthancPluginService_SetPluginProperty = 7, - _OrthancPluginService_GetGlobalProperty = 8, - _OrthancPluginService_SetGlobalProperty = 9, - _OrthancPluginService_GetCommandLineArgumentsCount = 10, - _OrthancPluginService_GetCommandLineArgument = 11, - _OrthancPluginService_GetExpectedDatabaseVersion = 12, - _OrthancPluginService_GetConfiguration = 13, - _OrthancPluginService_BufferCompression = 14, - _OrthancPluginService_ReadFile = 15, - _OrthancPluginService_WriteFile = 16, - _OrthancPluginService_GetErrorDescription = 17, - _OrthancPluginService_CallHttpClient = 18, - _OrthancPluginService_RegisterErrorCode = 19, - _OrthancPluginService_RegisterDictionaryTag = 20, - _OrthancPluginService_DicomBufferToJson = 21, - _OrthancPluginService_DicomInstanceToJson = 22, - _OrthancPluginService_CreateDicom = 23, - _OrthancPluginService_ComputeMd5 = 24, - _OrthancPluginService_ComputeSha1 = 25, - _OrthancPluginService_LookupDictionary = 26, - - /* Registration of callbacks */ - _OrthancPluginService_RegisterRestCallback = 1000, - _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, - _OrthancPluginService_RegisterStorageArea = 1002, - _OrthancPluginService_RegisterOnChangeCallback = 1003, - _OrthancPluginService_RegisterRestCallbackNoLock = 1004, - _OrthancPluginService_RegisterWorklistCallback = 1005, - _OrthancPluginService_RegisterDecodeImageCallback = 1006, - - /* Sending answers to REST calls */ - _OrthancPluginService_AnswerBuffer = 2000, - _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */ - _OrthancPluginService_Redirect = 2002, - _OrthancPluginService_SendHttpStatusCode = 2003, - _OrthancPluginService_SendUnauthorized = 2004, - _OrthancPluginService_SendMethodNotAllowed = 2005, - _OrthancPluginService_SetCookie = 2006, - _OrthancPluginService_SetHttpHeader = 2007, - _OrthancPluginService_StartMultipartAnswer = 2008, - _OrthancPluginService_SendMultipartItem = 2009, - _OrthancPluginService_SendHttpStatus = 2010, - _OrthancPluginService_CompressAndAnswerImage = 2011, - - /* Access to the Orthanc database and API */ - _OrthancPluginService_GetDicomForInstance = 3000, - _OrthancPluginService_RestApiGet = 3001, - _OrthancPluginService_RestApiPost = 3002, - _OrthancPluginService_RestApiDelete = 3003, - _OrthancPluginService_RestApiPut = 3004, - _OrthancPluginService_LookupPatient = 3005, - _OrthancPluginService_LookupStudy = 3006, - _OrthancPluginService_LookupSeries = 3007, - _OrthancPluginService_LookupInstance = 3008, - _OrthancPluginService_LookupStudyWithAccessionNumber = 3009, - _OrthancPluginService_RestApiGetAfterPlugins = 3010, - _OrthancPluginService_RestApiPostAfterPlugins = 3011, - _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, - _OrthancPluginService_RestApiPutAfterPlugins = 3013, - _OrthancPluginService_ReconstructMainDicomTags = 3014, - _OrthancPluginService_RestApiGet2 = 3015, - - /* Access to DICOM instances */ - _OrthancPluginService_GetInstanceRemoteAet = 4000, - _OrthancPluginService_GetInstanceSize = 4001, - _OrthancPluginService_GetInstanceData = 4002, - _OrthancPluginService_GetInstanceJson = 4003, - _OrthancPluginService_GetInstanceSimplifiedJson = 4004, - _OrthancPluginService_HasInstanceMetadata = 4005, - _OrthancPluginService_GetInstanceMetadata = 4006, - _OrthancPluginService_GetInstanceOrigin = 4007, - - /* Services for plugins implementing a database back-end */ - _OrthancPluginService_RegisterDatabaseBackend = 5000, - _OrthancPluginService_DatabaseAnswer = 5001, - _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, - _OrthancPluginService_StorageAreaCreate = 5003, - _OrthancPluginService_StorageAreaRead = 5004, - _OrthancPluginService_StorageAreaRemove = 5005, - - /* Primitives for handling images */ - _OrthancPluginService_GetImagePixelFormat = 6000, - _OrthancPluginService_GetImageWidth = 6001, - _OrthancPluginService_GetImageHeight = 6002, - _OrthancPluginService_GetImagePitch = 6003, - _OrthancPluginService_GetImageBuffer = 6004, - _OrthancPluginService_UncompressImage = 6005, - _OrthancPluginService_FreeImage = 6006, - _OrthancPluginService_CompressImage = 6007, - _OrthancPluginService_ConvertPixelFormat = 6008, - _OrthancPluginService_GetFontsCount = 6009, - _OrthancPluginService_GetFontInfo = 6010, - _OrthancPluginService_DrawText = 6011, - _OrthancPluginService_CreateImage = 6012, - _OrthancPluginService_CreateImageAccessor = 6013, - _OrthancPluginService_DecodeDicomImage = 6014, - - /* Primitives for handling worklists */ - _OrthancPluginService_WorklistAddAnswer = 7000, - _OrthancPluginService_WorklistMarkIncomplete = 7001, - _OrthancPluginService_WorklistIsMatch = 7002, - _OrthancPluginService_WorklistGetDicomQuery = 7003, - - _OrthancPluginService_INTERNAL = 0x7fffffff - } _OrthancPluginService; - - - typedef enum - { - _OrthancPluginProperty_Description = 1, - _OrthancPluginProperty_RootUri = 2, - _OrthancPluginProperty_OrthancExplorer = 3, - - _OrthancPluginProperty_INTERNAL = 0x7fffffff - } _OrthancPluginProperty; - - - - /** - * The memory layout of the pixels of an image. - * @ingroup Images - **/ - typedef enum - { - /** - * @brief Graylevel 8bpp image. - * - * The image is graylevel. Each pixel is unsigned and stored in - * one byte. - **/ - OrthancPluginPixelFormat_Grayscale8 = 1, - - /** - * @brief Graylevel, unsigned 16bpp image. - * - * The image is graylevel. Each pixel is unsigned and stored in - * two bytes. - **/ - OrthancPluginPixelFormat_Grayscale16 = 2, - - /** - * @brief Graylevel, signed 16bpp image. - * - * The image is graylevel. Each pixel is signed and stored in two - * bytes. - **/ - OrthancPluginPixelFormat_SignedGrayscale16 = 3, - - /** - * @brief Color image in RGB24 format. - * - * This format describes a color image. The pixels are stored in 3 - * consecutive bytes. The memory layout is RGB. - **/ - OrthancPluginPixelFormat_RGB24 = 4, - - /** - * @brief Color image in RGBA32 format. - * - * This format describes a color image. The pixels are stored in 4 - * consecutive bytes. The memory layout is RGBA. - **/ - OrthancPluginPixelFormat_RGBA32 = 5, - - OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */ - - _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff - } OrthancPluginPixelFormat; - - - - /** - * The content types that are supported by Orthanc plugins. - **/ - typedef enum - { - OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */ - OrthancPluginContentType_Dicom = 1, /*!< DICOM */ - OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */ - - _OrthancPluginContentType_INTERNAL = 0x7fffffff - } OrthancPluginContentType; - - - - /** - * The supported types of DICOM resources. - **/ - typedef enum - { - OrthancPluginResourceType_Patient = 0, /*!< Patient */ - OrthancPluginResourceType_Study = 1, /*!< Study */ - OrthancPluginResourceType_Series = 2, /*!< Series */ - OrthancPluginResourceType_Instance = 3, /*!< Instance */ - OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ - - _OrthancPluginResourceType_INTERNAL = 0x7fffffff - } OrthancPluginResourceType; - - - - /** - * The supported types of changes that can happen to DICOM resources. - * @ingroup Callbacks - **/ - typedef enum - { - OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */ - OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */ - OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */ - OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */ - OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */ - OrthancPluginChangeType_NewSeries = 5, /*!< New series created */ - OrthancPluginChangeType_NewStudy = 6, /*!< New study created */ - OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ - OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ - OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ - OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ - OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ - OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ - OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ - - _OrthancPluginChangeType_INTERNAL = 0x7fffffff - } OrthancPluginChangeType; - - - /** - * The compression algorithms that are supported by the Orthanc core. - * @ingroup Images - **/ - typedef enum - { - OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */ - OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */ - OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */ - OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */ - - _OrthancPluginCompressionType_INTERNAL = 0x7fffffff - } OrthancPluginCompressionType; - - - /** - * The image formats that are supported by the Orthanc core. - * @ingroup Images - **/ - typedef enum - { - OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */ - OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */ - OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */ - - _OrthancPluginImageFormat_INTERNAL = 0x7fffffff - } OrthancPluginImageFormat; - - - /** - * The value representations present in the DICOM standard (version 2013). - * @ingroup Toolbox - **/ - typedef enum - { - OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */ - OrthancPluginValueRepresentation_AS = 2, /*!< Age String */ - OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */ - OrthancPluginValueRepresentation_CS = 4, /*!< Code String */ - OrthancPluginValueRepresentation_DA = 5, /*!< Date */ - OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */ - OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */ - OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */ - OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */ - OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */ - OrthancPluginValueRepresentation_LO = 11, /*!< Long String */ - OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */ - OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */ - OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */ - OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */ - OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */ - OrthancPluginValueRepresentation_SH = 17, /*!< Short String */ - OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */ - OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */ - OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */ - OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */ - OrthancPluginValueRepresentation_TM = 22, /*!< Time */ - OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */ - OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */ - OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */ - OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */ - OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */ - - _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff - } OrthancPluginValueRepresentation; - - - /** - * The possible output formats for a DICOM-to-JSON conversion. - * @ingroup Toolbox - * @see OrthancPluginDicomToJson() - **/ - typedef enum - { - OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */ - OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */ - OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */ - - _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff - } OrthancPluginDicomToJsonFormat; - - - /** - * Flags to customize a DICOM-to-JSON conversion. By default, binary - * tags are formatted using Data URI scheme. - * @ingroup Toolbox - **/ - typedef enum - { - OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */ - OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */ - OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */ - OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */ - OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */ - OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */ - - _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff - } OrthancPluginDicomToJsonFlags; - - - /** - * Flags to the creation of a DICOM file. - * @ingroup Toolbox - * @see OrthancPluginCreateDicom() - **/ - typedef enum - { - OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */ - OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */ - - _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff - } OrthancPluginCreateDicomFlags; - - - /** - * The constraints on the DICOM identifiers that must be supported - * by the database plugins. - **/ - typedef enum - { - OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */ - OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */ - OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */ - OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */ - - _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff - } OrthancPluginIdentifierConstraint; - - - /** - * The origin of a DICOM instance that has been received by Orthanc. - **/ - typedef enum - { - OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */ - OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */ - OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */ - OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */ - OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */ - - _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff - } OrthancPluginInstanceOrigin; - - - /** - * @brief A memory buffer allocated by the core system of Orthanc. - * - * A memory buffer allocated by the core system of Orthanc. When the - * content of the buffer is not useful anymore, it must be free by a - * call to ::OrthancPluginFreeMemoryBuffer(). - **/ - typedef struct - { - /** - * @brief The content of the buffer. - **/ - void* data; - - /** - * @brief The number of bytes in the buffer. - **/ - uint32_t size; - } OrthancPluginMemoryBuffer; - - - - - /** - * @brief Opaque structure that represents the HTTP connection to the client application. - * @ingroup Callback - **/ - typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; - - - - /** - * @brief Opaque structure that represents a DICOM instance received by Orthanc. - **/ - typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance; - - - - /** - * @brief Opaque structure that represents an image that is uncompressed in memory. - * @ingroup Images - **/ - typedef struct _OrthancPluginImage_t OrthancPluginImage; - - - - /** - * @brief Opaque structure that represents the storage area that is actually used by Orthanc. - * @ingroup Images - **/ - typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea; - - - - /** - * @brief Opaque structure to an object that represents a C-Find query. - * @ingroup Worklists - **/ - typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; - - - - /** - * @brief Opaque structure to an object that represents the answers to a C-Find query. - * @ingroup Worklists - **/ - typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; - - - - /** - * @brief Signature of a callback function that answers to a REST request. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) ( - OrthancPluginRestOutput* output, - const char* url, - const OrthancPluginHttpRequest* request); - - - - /** - * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) ( - OrthancPluginDicomInstance* instance, - const char* instanceId); - - - - /** - * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) ( - OrthancPluginChangeType changeType, - OrthancPluginResourceType resourceType, - const char* resourceId); - - - - /** - * @brief Signature of a callback function to decode a DICOM instance as an image. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) ( - OrthancPluginImage** target, - const void* dicom, - const uint32_t size, - uint32_t frameIndex); - - - - /** - * @brief Signature of a function to free dynamic memory. - **/ - typedef void (*OrthancPluginFree) (void* buffer); - - - - /** - * @brief Callback for writing to the storage area. - * - * Signature of a callback function that is triggered when Orthanc writes a file to the storage area. - * - * @param uuid The UUID of the file. - * @param content The content of the file. - * @param size The size of the file. - * @param type The content type corresponding to this file. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) ( - const char* uuid, - const void* content, - int64_t size, - OrthancPluginContentType type); - - - - /** - * @brief Callback for reading from the storage area. - * - * Signature of a callback function that is triggered when Orthanc reads a file from the storage area. - * - * @param content The content of the file (output). - * @param size The size of the file (output). - * @param uuid The UUID of the file of interest. - * @param type The content type corresponding to this file. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) ( - void** content, - int64_t* size, - const char* uuid, - OrthancPluginContentType type); - - - - /** - * @brief Callback for removing a file from the storage area. - * - * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area. - * - * @param uuid The UUID of the file to be removed. - * @param type The content type corresponding to this file. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) ( - const char* uuid, - OrthancPluginContentType type); - - - - /** - * @brief Callback to handle the C-Find SCP requests received by Orthanc. - * - * Signature of a callback function that is triggered when Orthanc - * receives a C-Find SCP request against modality worklists. - * - * @param answers The target structure where answers must be stored. - * @param query The worklist query. - * @param remoteAet The Application Entity Title (AET) of the modality from which the request originates. - * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. - * @return 0 if success, other value if error. - * @ingroup Worklists - **/ - typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( - OrthancPluginWorklistAnswers* answers, - const OrthancPluginWorklistQuery* query, - const char* remoteAet, - const char* calledAet); - - - - /** - * @brief Data structure that contains information about the Orthanc core. - **/ - typedef struct _OrthancPluginContext_t - { - void* pluginsManager; - const char* orthancVersion; - OrthancPluginFree Free; - OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context, - _OrthancPluginService service, - const void* params); - } OrthancPluginContext; - - - - /** - * @brief An entry in the dictionary of DICOM tags. - **/ - typedef struct - { - uint16_t group; /*!< The group of the tag */ - uint16_t element; /*!< The element of the tag */ - OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */ - uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */ - uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */ - } OrthancPluginDictionaryEntry; - - - - /** - * @brief Free a string. - * - * Free a string that was allocated by the core system of Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param str The string to be freed. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString( - OrthancPluginContext* context, - char* str) - { - if (str != NULL) - { - context->Free(str); - } - } - - - /** - * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. - * - * This function checks whether the version of this C header is - * compatible with the current version of Orthanc. The result of - * this function should always be checked in the - * OrthancPluginInitialize() entry point of the plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return 1 if and only if the versions are compatible. If the - * result is 0, the initialization of the plugin should fail. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( - OrthancPluginContext* context) - { - int major, minor, revision; - - if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || - sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || - sizeof(int32_t) != sizeof(_OrthancPluginService) || - sizeof(int32_t) != sizeof(_OrthancPluginProperty) || - sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || - sizeof(int32_t) != sizeof(OrthancPluginContentType) || - sizeof(int32_t) != sizeof(OrthancPluginResourceType) || - sizeof(int32_t) != sizeof(OrthancPluginChangeType) || - sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || - sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || - sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || - sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || - sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || - sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || - sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || - sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin)) - { - /* Mismatch in the size of the enumerations */ - return 0; - } - - /* Assume compatibility with the mainline */ - if (!strcmp(context->orthancVersion, "mainline")) - { - return 1; - } - - /* Parse the version of the Orthanc core */ - if ( -#ifdef _MSC_VER - sscanf_s -#else - sscanf -#endif - (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3) - { - return 0; - } - - /* Check the major number of the version */ - - if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) - { - return 1; - } - - if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) - { - return 0; - } - - /* Check the minor number of the version */ - - if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) - { - return 1; - } - - if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) - { - return 0; - } - - /* Check the revision number of the version */ - - if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER) - { - return 1; - } - else - { - return 0; - } - } - - - /** - * @brief Free a memory buffer. - * - * Free a memory buffer that was allocated by the core system of Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param buffer The memory buffer to release. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* buffer) - { - context->Free(buffer->data); - } - - - /** - * @brief Log an error. - * - * Log an error message using the Orthanc logging system. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param message The message to be logged. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( - OrthancPluginContext* context, - const char* message) - { - context->InvokeService(context, _OrthancPluginService_LogError, message); - } - - - /** - * @brief Log a warning. - * - * Log a warning message using the Orthanc logging system. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param message The message to be logged. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( - OrthancPluginContext* context, - const char* message) - { - context->InvokeService(context, _OrthancPluginService_LogWarning, message); - } - - - /** - * @brief Log an information. - * - * Log an information message using the Orthanc logging system. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param message The message to be logged. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( - OrthancPluginContext* context, - const char* message) - { - context->InvokeService(context, _OrthancPluginService_LogInfo, message); - } - - - - typedef struct - { - const char* pathRegularExpression; - OrthancPluginRestCallback callback; - } _OrthancPluginRestCallback; - - /** - * @brief Register a REST callback. - * - * This function registers a REST callback against a regular - * expression for a URI. This function must be called during the - * initialization of the plugin, i.e. inside the - * OrthancPluginInitialize() public function. - * - * Each REST callback is guaranteed to run in mutual exclusion. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param pathRegularExpression Regular expression for the URI. May contain groups. - * @param callback The callback function to handle the REST call. - * @see OrthancPluginRegisterRestCallbackNoLock() - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( - OrthancPluginContext* context, - const char* pathRegularExpression, - OrthancPluginRestCallback callback) - { - _OrthancPluginRestCallback params; - params.pathRegularExpression = pathRegularExpression; - params.callback = callback; - context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms); - } - - - - /** - * @brief Register a REST callback, without locking. - * - * This function registers a REST callback against a regular - * expression for a URI. This function must be called during the - * initialization of the plugin, i.e. inside the - * OrthancPluginInitialize() public function. - * - * Contrarily to OrthancPluginRegisterRestCallback(), the callback - * will NOT be invoked in mutual exclusion. This can be useful for - * high-performance plugins that must handle concurrent requests - * (Orthanc uses a pool of threads, one thread being assigned to - * each incoming HTTP request). Of course, it is up to the plugin to - * implement the required locking mechanisms. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param pathRegularExpression Regular expression for the URI. May contain groups. - * @param callback The callback function to handle the REST call. - * @see OrthancPluginRegisterRestCallback() - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock( - OrthancPluginContext* context, - const char* pathRegularExpression, - OrthancPluginRestCallback callback) - { - _OrthancPluginRestCallback params; - params.pathRegularExpression = pathRegularExpression; - params.callback = callback; - context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, ¶ms); - } - - - - typedef struct - { - OrthancPluginOnStoredInstanceCallback callback; - } _OrthancPluginOnStoredInstanceCallback; - - /** - * @brief Register a callback for received instances. - * - * This function registers a callback function that is called - * whenever a new DICOM instance is stored into the Orthanc core. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param callback The callback function. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback( - OrthancPluginContext* context, - OrthancPluginOnStoredInstanceCallback callback) - { - _OrthancPluginOnStoredInstanceCallback params; - params.callback = callback; - - context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms); - } - - - - typedef struct - { - OrthancPluginRestOutput* output; - const char* answer; - uint32_t answerSize; - const char* mimeType; - } _OrthancPluginAnswerBuffer; - - /** - * @brief Answer to a REST request. - * - * This function answers to a REST request with the content of a memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param answer Pointer to the memory buffer containing the answer. - * @param answerSize Number of bytes of the answer. - * @param mimeType The MIME type of the answer. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* answer, - uint32_t answerSize, - const char* mimeType) - { - _OrthancPluginAnswerBuffer params; - params.output = output; - params.answer = answer; - params.answerSize = answerSize; - params.mimeType = mimeType; - context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms); - } - - - typedef struct - { - OrthancPluginRestOutput* output; - OrthancPluginPixelFormat format; - uint32_t width; - uint32_t height; - uint32_t pitch; - const void* buffer; - } _OrthancPluginCompressAndAnswerPngImage; - - typedef struct - { - OrthancPluginRestOutput* output; - OrthancPluginImageFormat imageFormat; - OrthancPluginPixelFormat pixelFormat; - uint32_t width; - uint32_t height; - uint32_t pitch; - const void* buffer; - uint8_t quality; - } _OrthancPluginCompressAndAnswerImage; - - - /** - * @brief Answer to a REST request with a PNG image. - * - * This function answers to a REST request with a PNG image. The - * parameters of this function describe a memory buffer that - * contains an uncompressed image. The image will be automatically compressed - * as a PNG image by the core system of Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param format The memory layout of the uncompressed image. - * @param width The width of the image. - * @param height The height of the image. - * @param pitch The pitch of the image (i.e. the number of bytes - * between 2 successive lines of the image in the memory buffer). - * @param buffer The memory buffer containing the uncompressed image. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height, - uint32_t pitch, - const void* buffer) - { - _OrthancPluginCompressAndAnswerImage params; - params.output = output; - params.imageFormat = OrthancPluginImageFormat_Png; - params.pixelFormat = format; - params.width = width; - params.height = height; - params.pitch = pitch; - params.buffer = buffer; - params.quality = 0; /* No quality for PNG */ - context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); - } - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* instanceId; - } _OrthancPluginGetDicomForInstance; - - /** - * @brief Retrieve a DICOM instance using its Orthanc identifier. - * - * Retrieve a DICOM instance using its Orthanc identifier. The DICOM - * file is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param instanceId The Orthanc identifier of the DICOM instance of interest. - * @return 0 if success, or the error code if failure. - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* instanceId) - { - _OrthancPluginGetDicomForInstance params; - params.target = target; - params.instanceId = instanceId; - return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms); - } - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* uri; - } _OrthancPluginRestApiGet; - - /** - * @brief Make a GET call to the built-in Orthanc REST API. - * - * Make a GET call to the built-in Orthanc REST API. The result to - * the query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiGetAfterPlugins - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri) - { - _OrthancPluginRestApiGet params; - params.target = target; - params.uri = uri; - return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms); - } - - - - /** - * @brief Make a GET call to the REST API, as tainted by the plugins. - * - * Make a GET call to the Orthanc REST API, after all the plugins - * are applied. In other words, if some plugin overrides or adds the - * called URI to the built-in Orthanc REST API, this call will - * return the result provided by this plugin. The result to the - * query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiGet - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri) - { - _OrthancPluginRestApiGet params; - params.target = target; - params.uri = uri; - return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, ¶ms); - } - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* uri; - const char* body; - uint32_t bodySize; - } _OrthancPluginRestApiPostPut; - - /** - * @brief Make a POST call to the built-in Orthanc REST API. - * - * Make a POST call to the built-in Orthanc REST API. The result to - * the query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @param body The body of the POST request. - * @param bodySize The size of the body. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiPostAfterPlugins - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri, - const char* body, - uint32_t bodySize) - { - _OrthancPluginRestApiPostPut params; - params.target = target; - params.uri = uri; - params.body = body; - params.bodySize = bodySize; - return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms); - } - - - /** - * @brief Make a POST call to the REST API, as tainted by the plugins. - * - * Make a POST call to the Orthanc REST API, after all the plugins - * are applied. In other words, if some plugin overrides or adds the - * called URI to the built-in Orthanc REST API, this call will - * return the result provided by this plugin. The result to the - * query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @param body The body of the POST request. - * @param bodySize The size of the body. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiPost - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri, - const char* body, - uint32_t bodySize) - { - _OrthancPluginRestApiPostPut params; - params.target = target; - params.uri = uri; - params.body = body; - params.bodySize = bodySize; - return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, ¶ms); - } - - - - /** - * @brief Make a DELETE call to the built-in Orthanc REST API. - * - * Make a DELETE call to the built-in Orthanc REST API. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param uri The URI to delete in the built-in Orthanc API. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiDeleteAfterPlugins - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete( - OrthancPluginContext* context, - const char* uri) - { - return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri); - } - - - /** - * @brief Make a DELETE call to the REST API, as tainted by the plugins. - * - * Make a DELETE call to the Orthanc REST API, after all the plugins - * are applied. In other words, if some plugin overrides or adds the - * called URI to the built-in Orthanc REST API, this call will - * return the result provided by this plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param uri The URI to delete in the built-in Orthanc API. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiDelete - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins( - OrthancPluginContext* context, - const char* uri) - { - return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri); - } - - - - /** - * @brief Make a PUT call to the built-in Orthanc REST API. - * - * Make a PUT call to the built-in Orthanc REST API. The result to - * the query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @param body The body of the PUT request. - * @param bodySize The size of the body. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiPutAfterPlugins - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri, - const char* body, - uint32_t bodySize) - { - _OrthancPluginRestApiPostPut params; - params.target = target; - params.uri = uri; - params.body = body; - params.bodySize = bodySize; - return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms); - } - - - - /** - * @brief Make a PUT call to the REST API, as tainted by the plugins. - * - * Make a PUT call to the Orthanc REST API, after all the plugins - * are applied. In other words, if some plugin overrides or adds the - * called URI to the built-in Orthanc REST API, this call will - * return the result provided by this plugin. The result to the - * query is stored into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @param body The body of the PUT request. - * @param bodySize The size of the body. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiPut - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri, - const char* body, - uint32_t bodySize) - { - _OrthancPluginRestApiPostPut params; - params.target = target; - params.uri = uri; - params.body = body; - params.bodySize = bodySize; - return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, ¶ms); - } - - - - typedef struct - { - OrthancPluginRestOutput* output; - const char* argument; - } _OrthancPluginOutputPlusArgument; - - /** - * @brief Redirect a REST request. - * - * This function answers to a REST request by redirecting the user - * to another URI using HTTP status 301. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param redirection Where to redirect. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* redirection) - { - _OrthancPluginOutputPlusArgument params; - params.output = output; - params.argument = redirection; - context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms); - } - - - - typedef struct - { - char** result; - const char* argument; - } _OrthancPluginRetrieveDynamicString; - - /** - * @brief Look for a patient. - * - * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). - * This function uses the database index to run as fast as possible (it does not loop - * over all the stored patients). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param patientID The Patient ID of interest. - * @return The NULL value if the patient is non-existent, or a string containing the - * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( - OrthancPluginContext* context, - const char* patientID) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = patientID; - - if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Look for a study. - * - * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). - * This function uses the database index to run as fast as possible (it does not loop - * over all the stored studies). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param studyUID The Study Instance UID of interest. - * @return The NULL value if the study is non-existent, or a string containing the - * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( - OrthancPluginContext* context, - const char* studyUID) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = studyUID; - - if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Look for a study, using the accession number. - * - * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). - * This function uses the database index to run as fast as possible (it does not loop - * over all the stored studies). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param accessionNumber The Accession Number of interest. - * @return The NULL value if the study is non-existent, or a string containing the - * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber( - OrthancPluginContext* context, - const char* accessionNumber) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = accessionNumber; - - if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Look for a series. - * - * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). - * This function uses the database index to run as fast as possible (it does not loop - * over all the stored series). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param seriesUID The Series Instance UID of interest. - * @return The NULL value if the series is non-existent, or a string containing the - * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( - OrthancPluginContext* context, - const char* seriesUID) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = seriesUID; - - if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Look for an instance. - * - * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). - * This function uses the database index to run as fast as possible (it does not loop - * over all the stored instances). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param sopInstanceUID The SOP Instance UID of interest. - * @return The NULL value if the instance is non-existent, or a string containing the - * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( - OrthancPluginContext* context, - const char* sopInstanceUID) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = sopInstanceUID; - - if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginRestOutput* output; - uint16_t status; - } _OrthancPluginSendHttpStatusCode; - - /** - * @brief Send a HTTP status code. - * - * This function answers to a REST request by sending a HTTP status - * code (such as "400 - Bad Request"). Note that: - * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). - * - Redirections (status 301) must use ::OrthancPluginRedirect(). - * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). - * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param status The HTTP status code to be sent. - * @ingroup REST - * @see OrthancPluginSendHttpStatus() - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - uint16_t status) - { - _OrthancPluginSendHttpStatusCode params; - params.output = output; - params.status = status; - context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms); - } - - - /** - * @brief Signal that a REST request is not authorized. - * - * This function answers to a REST request by signaling that it is - * not authorized. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param realm The realm for the authorization process. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* realm) - { - _OrthancPluginOutputPlusArgument params; - params.output = output; - params.argument = realm; - context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms); - } - - - /** - * @brief Signal that this URI does not support this HTTP method. - * - * This function answers to a REST request by signaling that the - * queried URI does not support this method. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request). - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* allowedMethods) - { - _OrthancPluginOutputPlusArgument params; - params.output = output; - params.argument = allowedMethods; - context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms); - } - - - typedef struct - { - OrthancPluginRestOutput* output; - const char* key; - const char* value; - } _OrthancPluginSetHttpHeader; - - /** - * @brief Set a cookie. - * - * This function sets a cookie in the HTTP client. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param cookie The cookie to be set. - * @param value The value of the cookie. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* cookie, - const char* value) - { - _OrthancPluginSetHttpHeader params; - params.output = output; - params.key = cookie; - params.value = value; - context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms); - } - - - /** - * @brief Set some HTTP header. - * - * This function sets a HTTP header in the HTTP answer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param key The HTTP header to be set. - * @param value The value of the HTTP header. - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* key, - const char* value) - { - _OrthancPluginSetHttpHeader params; - params.output = output; - params.key = key; - params.value = value; - context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms); - } - - - typedef struct - { - char** resultStringToFree; - const char** resultString; - int64_t* resultInt64; - const char* key; - OrthancPluginDicomInstance* instance; - OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */ - } _OrthancPluginAccessDicomInstance; - - - /** - * @brief Get the AET of a DICOM instance. - * - * This function returns the Application Entity Title (AET) of the - * DICOM modality from which a DICOM instance originates. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The AET if success, NULL if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - const char* result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultString = &result; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Get the size of a DICOM file. - * - * This function returns the number of bytes of the given DICOM instance. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The size of the file, -1 in case of error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - int64_t size; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultInt64 = &size; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return -1; - } - else - { - return size; - } - } - - - /** - * @brief Get the data of a DICOM file. - * - * This function returns a pointer to the content of the given DICOM instance. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The pointer to the DICOM data, NULL in case of error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - const char* result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultString = &result; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Get the DICOM tag hierarchy as a JSON file. - * - * This function returns a pointer to a newly created string - * containing a JSON file. This JSON file encodes the tag hierarchy - * of the given DICOM instance. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The NULL value in case of error, or a string containing the JSON file. - * This string must be freed by OrthancPluginFreeString(). - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - char* result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultStringToFree = &result; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Get the DICOM tag hierarchy as a JSON file (with simplification). - * - * This function returns a pointer to a newly created string - * containing a JSON file. This JSON file encodes the tag hierarchy - * of the given DICOM instance. In contrast with - * ::OrthancPluginGetInstanceJson(), the returned JSON file is in - * its simplified version. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The NULL value in case of error, or a string containing the JSON file. - * This string must be freed by OrthancPluginFreeString(). - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - char* result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultStringToFree = &result; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Check whether a DICOM instance is associated with some metadata. - * - * This function checks whether the DICOM instance of interest is - * associated with some metadata. As of Orthanc 0.8.1, in the - * callbacks registered by - * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only - * possibly available metadata are "ReceptionDate", "RemoteAET" and - * "IndexInSeries". - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @param metadata The metadata of interest. - * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance, - const char* metadata) - { - int64_t result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultInt64 = &result; - params.instance = instance; - params.key = metadata; - - if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return -1; - } - else - { - return (result != 0); - } - } - - - /** - * @brief Get the value of some metadata associated with a given DICOM instance. - * - * This functions returns the value of some metadata that is associated with the DICOM instance of interest. - * Before calling this function, the existence of the metadata must have been checked with - * ::OrthancPluginHasInstanceMetadata(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @param metadata The metadata of interest. - * @return The metadata value if success, NULL if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance, - const char* metadata) - { - const char* result; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultString = &result; - params.instance = instance; - params.key = metadata; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginStorageCreate create; - OrthancPluginStorageRead read; - OrthancPluginStorageRemove remove; - OrthancPluginFree free; - } _OrthancPluginRegisterStorageArea; - - /** - * @brief Register a custom storage area. - * - * This function registers a custom storage area, to replace the - * built-in way Orthanc stores its files on the filesystem. This - * function must be called during the initialization of the plugin, - * i.e. inside the OrthancPluginInitialize() public function. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param create The callback function to store a file on the custom storage area. - * @param read The callback function to read a file from the custom storage area. - * @param remove The callback function to remove a file from the custom storage area. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea( - OrthancPluginContext* context, - OrthancPluginStorageCreate create, - OrthancPluginStorageRead read, - OrthancPluginStorageRemove remove) - { - _OrthancPluginRegisterStorageArea params; - params.create = create; - params.read = read; - params.remove = remove; - -#ifdef __cplusplus - params.free = ::free; -#else - params.free = free; -#endif - - context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms); - } - - - - /** - * @brief Return the path to the Orthanc executable. - * - * This function returns the path to the Orthanc executable. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return NULL in the case of an error, or a newly allocated string - * containing the path. This string must be freed by - * OrthancPluginFreeString(). - **/ - ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = NULL; - - if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Return the directory containing the Orthanc. - * - * This function returns the path to the directory containing the Orthanc executable. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return NULL in the case of an error, or a newly allocated string - * containing the path. This string must be freed by - * OrthancPluginFreeString(). - **/ - ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = NULL; - - if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Return the path to the configuration file(s). - * - * This function returns the path to the configuration file(s) that - * was specified when starting Orthanc. Since version 0.9.1, this - * path can refer to a folder that stores a set of configuration - * files. This function is deprecated in favor of - * OrthancPluginGetConfiguration(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return NULL in the case of an error, or a newly allocated string - * containing the path. This string must be freed by - * OrthancPluginFreeString(). - * @see OrthancPluginGetConfiguration() - **/ - ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = NULL; - - if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginOnChangeCallback callback; - } _OrthancPluginOnChangeCallback; - - /** - * @brief Register a callback to monitor changes. - * - * This function registers a callback function that is called - * whenever a change happens to some DICOM resource. - * - * @warning If your change callback has to call the REST API of - * Orthanc, you should make these calls in a separate thread (with - * the events passing through a message queue). Otherwise, this - * could result in deadlocks in the presence of other plugins or Lua - * script. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param callback The callback function. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback( - OrthancPluginContext* context, - OrthancPluginOnChangeCallback callback) - { - _OrthancPluginOnChangeCallback params; - params.callback = callback; - - context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, ¶ms); - } - - - - typedef struct - { - const char* plugin; - _OrthancPluginProperty property; - const char* value; - } _OrthancPluginSetPluginProperty; - - - /** - * @brief Set the URI where the plugin provides its Web interface. - * - * For plugins that come with a Web interface, this function - * declares the entry path where to find this interface. This - * information is notably used in the "Plugins" page of Orthanc - * Explorer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param uri The root URI for this plugin. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri( - OrthancPluginContext* context, - const char* uri) - { - _OrthancPluginSetPluginProperty params; - params.plugin = OrthancPluginGetName(); - params.property = _OrthancPluginProperty_RootUri; - params.value = uri; - - context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); - } - - - /** - * @brief Set a description for this plugin. - * - * Set a description for this plugin. It is displayed in the - * "Plugins" page of Orthanc Explorer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param description The description. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription( - OrthancPluginContext* context, - const char* description) - { - _OrthancPluginSetPluginProperty params; - params.plugin = OrthancPluginGetName(); - params.property = _OrthancPluginProperty_Description; - params.value = description; - - context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); - } - - - /** - * @brief Extend the JavaScript code of Orthanc Explorer. - * - * Add JavaScript code to customize the default behavior of Orthanc - * Explorer. This can for instance be used to add new buttons. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param javascript The custom JavaScript code. - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer( - OrthancPluginContext* context, - const char* javascript) - { - _OrthancPluginSetPluginProperty params; - params.plugin = OrthancPluginGetName(); - params.property = _OrthancPluginProperty_OrthancExplorer; - params.value = javascript; - - context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); - } - - - typedef struct - { - char** result; - int32_t property; - const char* value; - } _OrthancPluginGlobalProperty; - - - /** - * @brief Get the value of a global property. - * - * Get the value of a global property that is stored in the Orthanc database. Global - * properties whose index is below 1024 are reserved by Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param property The global property of interest. - * @param defaultValue The value to return, if the global property is unset. - * @return The value of the global property, or NULL in the case of an error. This - * string must be freed by OrthancPluginFreeString(). - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty( - OrthancPluginContext* context, - int32_t property, - const char* defaultValue) - { - char* result; - - _OrthancPluginGlobalProperty params; - params.result = &result; - params.property = property; - params.value = defaultValue; - - if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Set the value of a global property. - * - * Set the value of a global property into the Orthanc - * database. Setting a global property can be used by plugins to - * save their internal parameters. Plugins are only allowed to set - * properties whose index are above or equal to 1024 (properties - * below 1024 are read-only and reserved by Orthanc). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param property The global property of interest. - * @param value The value to be set in the global property. - * @return 0 if success, or the error code if failure. - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty( - OrthancPluginContext* context, - int32_t property, - const char* value) - { - _OrthancPluginGlobalProperty params; - params.result = NULL; - params.property = property; - params.value = value; - - return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, ¶ms); - } - - - - typedef struct - { - int32_t *resultInt32; - uint32_t *resultUint32; - int64_t *resultInt64; - uint64_t *resultUint64; - } _OrthancPluginReturnSingleValue; - - /** - * @brief Get the number of command-line arguments. - * - * Retrieve the number of command-line arguments that were used to launch Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return The number of arguments. - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount( - OrthancPluginContext* context) - { - uint32_t count = 0; - - _OrthancPluginReturnSingleValue params; - memset(¶ms, 0, sizeof(params)); - params.resultUint32 = &count; - - if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return 0; - } - else - { - return count; - } - } - - - - /** - * @brief Get the value of a command-line argument. - * - * Get the value of one of the command-line arguments that were used - * to launch Orthanc. The number of available arguments can be - * retrieved by OrthancPluginGetCommandLineArgumentsCount(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param argument The index of the argument. - * @return The value of the argument, or NULL in the case of an error. This - * string must be freed by OrthancPluginFreeString(). - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument( - OrthancPluginContext* context, - uint32_t argument) - { - char* result; - - _OrthancPluginGlobalProperty params; - params.result = &result; - params.property = (int32_t) argument; - params.value = NULL; - - if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @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. - * @ingroup Callbacks - * @deprecated Please instead use IDatabaseBackend::UpgradeDatabase() - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion( - OrthancPluginContext* context) - { - uint32_t count = 0; - - _OrthancPluginReturnSingleValue params; - memset(¶ms, 0, sizeof(params)); - params.resultUint32 = &count; - - if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return 0; - } - else - { - return count; - } - } - - - - /** - * @brief Return the content of the configuration file(s). - * - * This function returns the content of the configuration that is - * used by Orthanc, formatted as a JSON string. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return NULL in the case of an error, or a newly allocated string - * containing the configuration. This string must be freed by - * OrthancPluginFreeString(). - **/ - ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context) - { - char* result; - - _OrthancPluginRetrieveDynamicString params; - params.result = &result; - params.argument = NULL; - - if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginRestOutput* output; - const char* subType; - const char* contentType; - } _OrthancPluginStartMultipartAnswer; - - /** - * @brief Start an HTTP multipart answer. - * - * Initiates a HTTP multipart answer, as the result of a REST request. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param subType The sub-type of the multipart answer ("mixed" or "related"). - * @param contentType The MIME type of the items in the multipart answer. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginSendMultipartItem() - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* subType, - const char* contentType) - { - _OrthancPluginStartMultipartAnswer params; - params.output = output; - params.subType = subType; - params.contentType = contentType; - return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, ¶ms); - } - - - /** - * @brief Send an item as a part of some HTTP multipart answer. - * - * This function sends an item as a part of some HTTP multipart - * answer that was initiated by OrthancPluginStartMultipartAnswer(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param answer Pointer to the memory buffer containing the item. - * @param answerSize Number of bytes of the item. - * @return 0 if success, or the error code if failure (this notably happens - * if the connection is closed by the client). - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - const char* answer, - uint32_t answerSize) - { - _OrthancPluginAnswerBuffer params; - params.output = output; - params.answer = answer; - params.answerSize = answerSize; - params.mimeType = NULL; - return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, ¶ms); - } - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const void* source; - uint32_t size; - OrthancPluginCompressionType compression; - uint8_t uncompress; - } _OrthancPluginBufferCompression; - - - /** - * @brief Compress or decompress a buffer. - * - * This function compresses or decompresses a buffer, using the - * version of the zlib library that is used by the Orthanc core. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param source The source buffer. - * @param size The size in bytes of the source buffer. - * @param compression The compression algorithm. - * @param uncompress If set to "0", the buffer must be compressed. - * If set to "1", the buffer must be uncompressed. - * @return 0 if success, or the error code if failure. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const void* source, - uint32_t size, - OrthancPluginCompressionType compression, - uint8_t uncompress) - { - _OrthancPluginBufferCompression params; - params.target = target; - params.source = source; - params.size = size; - params.compression = compression; - params.uncompress = uncompress; - - return context->InvokeService(context, _OrthancPluginService_BufferCompression, ¶ms); - } - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* path; - } _OrthancPluginReadFile; - - /** - * @brief Read a file. - * - * Read the content of a file on the filesystem, and returns it into - * a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param path The path of the file to be read. - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* path) - { - _OrthancPluginReadFile params; - params.target = target; - params.path = path; - return context->InvokeService(context, _OrthancPluginService_ReadFile, ¶ms); - } - - - - typedef struct - { - const char* path; - const void* data; - uint32_t size; - } _OrthancPluginWriteFile; - - /** - * @brief Write a file. - * - * Write the content of a memory buffer to the filesystem. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param path The path of the file to be written. - * @param data The content of the memory buffer. - * @param size The size of the memory buffer. - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile( - OrthancPluginContext* context, - const char* path, - const void* data, - uint32_t size) - { - _OrthancPluginWriteFile params; - params.path = path; - params.data = data; - params.size = size; - return context->InvokeService(context, _OrthancPluginService_WriteFile, ¶ms); - } - - - - typedef struct - { - const char** target; - OrthancPluginErrorCode error; - } _OrthancPluginGetErrorDescription; - - /** - * @brief Get the description of a given error code. - * - * This function returns the description of a given error code. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param error The error code of interest. - * @return The error description. This is a statically-allocated - * string, do not free it. - **/ - ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( - OrthancPluginContext* context, - OrthancPluginErrorCode error) - { - const char* result = NULL; - - _OrthancPluginGetErrorDescription params; - params.target = &result; - params.error = error; - - if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) != OrthancPluginErrorCode_Success || - result == NULL) - { - return "Unknown error code"; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginRestOutput* output; - uint16_t status; - const char* body; - uint32_t bodySize; - } _OrthancPluginSendHttpStatus; - - /** - * @brief Send a HTTP status, with a custom body. - * - * This function answers to a HTTP request by sending a HTTP status - * code (such as "400 - Bad Request"), together with a body - * describing the error. The body will only be returned if the - * configuration option "HttpDescribeErrors" of Orthanc is set to "true". - * - * Note that: - * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). - * - Redirections (status 301) must use ::OrthancPluginRedirect(). - * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). - * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param status The HTTP status code to be sent. - * @param body The body of the answer. - * @param bodySize The size of the body. - * @see OrthancPluginSendHttpStatusCode() - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - uint16_t status, - const char* body, - uint32_t bodySize) - { - _OrthancPluginSendHttpStatus params; - params.output = output; - params.status = status; - params.body = body; - params.bodySize = bodySize; - context->InvokeService(context, _OrthancPluginService_SendHttpStatus, ¶ms); - } - - - - typedef struct - { - const OrthancPluginImage* image; - uint32_t* resultUint32; - OrthancPluginPixelFormat* resultPixelFormat; - void** resultBuffer; - } _OrthancPluginGetImageInfo; - - - /** - * @brief Return the pixel format of an image. - * - * This function returns the type of memory layout for the pixels of the given image. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image of interest. - * @return The pixel format. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat( - OrthancPluginContext* context, - const OrthancPluginImage* image) - { - OrthancPluginPixelFormat target; - - _OrthancPluginGetImageInfo params; - memset(¶ms, 0, sizeof(params)); - params.image = image; - params.resultPixelFormat = ⌖ - - if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, ¶ms) != OrthancPluginErrorCode_Success) - { - return OrthancPluginPixelFormat_Unknown; - } - else - { - return (OrthancPluginPixelFormat) target; - } - } - - - - /** - * @brief Return the width of an image. - * - * This function returns the width of the given image. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image of interest. - * @return The width. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth( - OrthancPluginContext* context, - const OrthancPluginImage* image) - { - uint32_t width; - - _OrthancPluginGetImageInfo params; - memset(¶ms, 0, sizeof(params)); - params.image = image; - params.resultUint32 = &width; - - if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, ¶ms) != OrthancPluginErrorCode_Success) - { - return 0; - } - else - { - return width; - } - } - - - - /** - * @brief Return the height of an image. - * - * This function returns the height of the given image. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image of interest. - * @return The height. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight( - OrthancPluginContext* context, - const OrthancPluginImage* image) - { - uint32_t height; - - _OrthancPluginGetImageInfo params; - memset(¶ms, 0, sizeof(params)); - params.image = image; - params.resultUint32 = &height; - - if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, ¶ms) != OrthancPluginErrorCode_Success) - { - return 0; - } - else - { - return height; - } - } - - - - /** - * @brief Return the pitch of an image. - * - * This function returns the pitch of the given image. The pitch is - * defined as the number of bytes between 2 successive lines of the - * image in the memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image of interest. - * @return The pitch. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch( - OrthancPluginContext* context, - const OrthancPluginImage* image) - { - uint32_t pitch; - - _OrthancPluginGetImageInfo params; - memset(¶ms, 0, sizeof(params)); - params.image = image; - params.resultUint32 = &pitch; - - if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, ¶ms) != OrthancPluginErrorCode_Success) - { - return 0; - } - else - { - return pitch; - } - } - - - - /** - * @brief Return a pointer to the content of an image. - * - * This function returns a pointer to the memory buffer that - * contains the pixels of the image. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image of interest. - * @return The pointer. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer( - OrthancPluginContext* context, - const OrthancPluginImage* image) - { - void* target = NULL; - - _OrthancPluginGetImageInfo params; - memset(¶ms, 0, sizeof(params)); - params.resultBuffer = ⌖ - params.image = image; - - if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - typedef struct - { - OrthancPluginImage** target; - const void* data; - uint32_t size; - OrthancPluginImageFormat format; - } _OrthancPluginUncompressImage; - - - /** - * @brief Decode a compressed image. - * - * This function decodes a compressed image from a memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param data Pointer to a memory buffer containing the compressed image. - * @param size Size of the memory buffer containing the compressed image. - * @param format The file format of the compressed image. - * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage( - OrthancPluginContext* context, - const void* data, - uint32_t size, - OrthancPluginImageFormat format) - { - OrthancPluginImage* target = NULL; - - _OrthancPluginUncompressImage params; - memset(¶ms, 0, sizeof(params)); - params.target = ⌖ - params.data = data; - params.size = size; - params.format = format; - - if (context->InvokeService(context, _OrthancPluginService_UncompressImage, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - - - typedef struct - { - OrthancPluginImage* image; - } _OrthancPluginFreeImage; - - /** - * @brief Free an image. - * - * This function frees an image that was decoded with OrthancPluginUncompressImage(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage( - OrthancPluginContext* context, - OrthancPluginImage* image) - { - _OrthancPluginFreeImage params; - params.image = image; - - context->InvokeService(context, _OrthancPluginService_FreeImage, ¶ms); - } - - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - OrthancPluginImageFormat imageFormat; - OrthancPluginPixelFormat pixelFormat; - uint32_t width; - uint32_t height; - uint32_t pitch; - const void* buffer; - uint8_t quality; - } _OrthancPluginCompressImage; - - - /** - * @brief Encode a PNG image. - * - * This function compresses the given memory buffer containing an - * image using the PNG specification, and stores the result of the - * compression into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param format The memory layout of the uncompressed image. - * @param width The width of the image. - * @param height The height of the image. - * @param pitch The pitch of the image (i.e. the number of bytes - * between 2 successive lines of the image in the memory buffer). - * @param buffer The memory buffer containing the uncompressed image. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginCompressAndAnswerPngImage() - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height, - uint32_t pitch, - const void* buffer) - { - _OrthancPluginCompressImage params; - memset(¶ms, 0, sizeof(params)); - params.target = target; - params.imageFormat = OrthancPluginImageFormat_Png; - params.pixelFormat = format; - params.width = width; - params.height = height; - params.pitch = pitch; - params.buffer = buffer; - params.quality = 0; /* Unused for PNG */ - - return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); - } - - - /** - * @brief Encode a JPEG image. - * - * This function compresses the given memory buffer containing an - * image using the JPEG specification, and stores the result of the - * compression into a newly allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param format The memory layout of the uncompressed image. - * @param width The width of the image. - * @param height The height of the image. - * @param pitch The pitch of the image (i.e. the number of bytes - * between 2 successive lines of the image in the memory buffer). - * @param buffer The memory buffer containing the uncompressed image. - * @param quality The quality of the JPEG encoding, between 1 (worst - * quality, best compression) and 100 (best quality, worst - * compression). - * @return 0 if success, or the error code if failure. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height, - uint32_t pitch, - const void* buffer, - uint8_t quality) - { - _OrthancPluginCompressImage params; - memset(¶ms, 0, sizeof(params)); - params.target = target; - params.imageFormat = OrthancPluginImageFormat_Jpeg; - params.pixelFormat = format; - params.width = width; - params.height = height; - params.pitch = pitch; - params.buffer = buffer; - params.quality = quality; - - return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); - } - - - - /** - * @brief Answer to a REST request with a JPEG image. - * - * This function answers to a REST request with a JPEG image. The - * parameters of this function describe a memory buffer that - * contains an uncompressed image. The image will be automatically compressed - * as a JPEG image by the core system of Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param output The HTTP connection to the client application. - * @param format The memory layout of the uncompressed image. - * @param width The width of the image. - * @param height The height of the image. - * @param pitch The pitch of the image (i.e. the number of bytes - * between 2 successive lines of the image in the memory buffer). - * @param buffer The memory buffer containing the uncompressed image. - * @param quality The quality of the JPEG encoding, between 1 (worst - * quality, best compression) and 100 (best quality, worst - * compression). - * @ingroup REST - **/ - ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage( - OrthancPluginContext* context, - OrthancPluginRestOutput* output, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height, - uint32_t pitch, - const void* buffer, - uint8_t quality) - { - _OrthancPluginCompressAndAnswerImage params; - params.output = output; - params.imageFormat = OrthancPluginImageFormat_Jpeg; - params.pixelFormat = format; - params.width = width; - params.height = height; - params.pitch = pitch; - params.buffer = buffer; - params.quality = quality; - context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); - } - - - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - OrthancPluginHttpMethod method; - const char* url; - const char* username; - const char* password; - const char* body; - uint32_t bodySize; - } _OrthancPluginCallHttpClient; - - - /** - * @brief Issue a HTTP GET call. - * - * Make a HTTP GET call to the given URL. The result to the query is - * stored into a newly allocated memory buffer. Favor - * OrthancPluginRestApiGet() if calling the built-in REST API of the - * Orthanc instance that hosts this plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param url The URL of interest. - * @param username The username (can be <tt>NULL</tt> if no password protection). - * @param password The password (can be <tt>NULL</tt> if no password protection). - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* url, - const char* username, - const char* password) - { - _OrthancPluginCallHttpClient params; - memset(¶ms, 0, sizeof(params)); - - params.target = target; - params.method = OrthancPluginHttpMethod_Get; - params.url = url; - params.username = username; - params.password = password; - - return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); - } - - - /** - * @brief Issue a HTTP POST call. - * - * Make a HTTP POST call to the given URL. The result to the query - * is stored into a newly allocated memory buffer. Favor - * OrthancPluginRestApiPost() if calling the built-in REST API of - * the Orthanc instance that hosts this plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param url The URL of interest. - * @param body The content of the body of the request. - * @param bodySize The size of the body of the request. - * @param username The username (can be <tt>NULL</tt> if no password protection). - * @param password The password (can be <tt>NULL</tt> if no password protection). - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* url, - const char* body, - uint32_t bodySize, - const char* username, - const char* password) - { - _OrthancPluginCallHttpClient params; - memset(¶ms, 0, sizeof(params)); - - params.target = target; - params.method = OrthancPluginHttpMethod_Post; - params.url = url; - params.body = body; - params.bodySize = bodySize; - params.username = username; - params.password = password; - - return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); - } - - - /** - * @brief Issue a HTTP PUT call. - * - * Make a HTTP PUT call to the given URL. The result to the query is - * stored into a newly allocated memory buffer. Favor - * OrthancPluginRestApiPut() if calling the built-in REST API of the - * Orthanc instance that hosts this plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param url The URL of interest. - * @param body The content of the body of the request. - * @param bodySize The size of the body of the request. - * @param username The username (can be <tt>NULL</tt> if no password protection). - * @param password The password (can be <tt>NULL</tt> if no password protection). - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* url, - const char* body, - uint32_t bodySize, - const char* username, - const char* password) - { - _OrthancPluginCallHttpClient params; - memset(¶ms, 0, sizeof(params)); - - params.target = target; - params.method = OrthancPluginHttpMethod_Put; - params.url = url; - params.body = body; - params.bodySize = bodySize; - params.username = username; - params.password = password; - - return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); - } - - - /** - * @brief Issue a HTTP DELETE call. - * - * Make a HTTP DELETE call to the given URL. Favor - * OrthancPluginRestApiDelete() if calling the built-in REST API of - * the Orthanc instance that hosts this plugin. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param url The URL of interest. - * @param username The username (can be <tt>NULL</tt> if no password protection). - * @param password The password (can be <tt>NULL</tt> if no password protection). - * @return 0 if success, or the error code if failure. - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete( - OrthancPluginContext* context, - const char* url, - const char* username, - const char* password) - { - _OrthancPluginCallHttpClient params; - memset(¶ms, 0, sizeof(params)); - - params.method = OrthancPluginHttpMethod_Delete; - params.url = url; - params.username = username; - params.password = password; - - return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); - } - - - - typedef struct - { - OrthancPluginImage** target; - const OrthancPluginImage* source; - OrthancPluginPixelFormat targetFormat; - } _OrthancPluginConvertPixelFormat; - - - /** - * @brief Change the pixel format of an image. - * - * This function creates a new image, changing the memory layout of the pixels. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param source The source image. - * @param targetFormat The target pixel format. - * @return The resulting image. It must be freed with OrthancPluginFreeImage(). - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat( - OrthancPluginContext* context, - const OrthancPluginImage* source, - OrthancPluginPixelFormat targetFormat) - { - OrthancPluginImage* target = NULL; - - _OrthancPluginConvertPixelFormat params; - params.target = ⌖ - params.source = source; - params.targetFormat = targetFormat; - - if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - - /** - * @brief Return the number of available fonts. - * - * This function returns the number of fonts that are built in the - * Orthanc core. These fonts can be used to draw texts on images - * through OrthancPluginDrawText(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @return The number of fonts. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount( - OrthancPluginContext* context) - { - uint32_t count = 0; - - _OrthancPluginReturnSingleValue params; - memset(¶ms, 0, sizeof(params)); - params.resultUint32 = &count; - - if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return 0; - } - else - { - return count; - } - } - - - - - typedef struct - { - uint32_t fontIndex; /* in */ - const char** name; /* out */ - uint32_t* size; /* out */ - } _OrthancPluginGetFontInfo; - - /** - * @brief Return the name of a font. - * - * This function returns the name of a font that is built in the Orthanc core. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). - * @return The font name. This is a statically-allocated string, do not free it. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName( - OrthancPluginContext* context, - uint32_t fontIndex) - { - const char* result = NULL; - - _OrthancPluginGetFontInfo params; - memset(¶ms, 0, sizeof(params)); - params.name = &result; - params.fontIndex = fontIndex; - - if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Return the size of a font. - * - * This function returns the size of a font that is built in the Orthanc core. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). - * @return The font size. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize( - OrthancPluginContext* context, - uint32_t fontIndex) - { - uint32_t result; - - _OrthancPluginGetFontInfo params; - memset(¶ms, 0, sizeof(params)); - params.size = &result; - params.fontIndex = fontIndex; - - if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) - { - return 0; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginImage* image; - uint32_t fontIndex; - const char* utf8Text; - int32_t x; - int32_t y; - uint8_t r; - uint8_t g; - uint8_t b; - } _OrthancPluginDrawText; - - - /** - * @brief Draw text on an image. - * - * This function draws some text on some image. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param image The image upon which to draw the text. - * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). - * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string. - * @param x The X position of the text over the image. - * @param y The Y position of the text over the image. - * @param r The value of the red color channel of the text. - * @param g The value of the green color channel of the text. - * @param b The value of the blue color channel of the text. - * @return 0 if success, other value if error. - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText( - OrthancPluginContext* context, - OrthancPluginImage* image, - uint32_t fontIndex, - const char* utf8Text, - int32_t x, - int32_t y, - uint8_t r, - uint8_t g, - uint8_t b) - { - _OrthancPluginDrawText params; - memset(¶ms, 0, sizeof(params)); - params.image = image; - params.fontIndex = fontIndex; - params.utf8Text = utf8Text; - params.x = x; - params.y = y; - params.r = r; - params.g = g; - params.b = b; - - return context->InvokeService(context, _OrthancPluginService_DrawText, ¶ms); - } - - - - typedef struct - { - OrthancPluginStorageArea* storageArea; - const char* uuid; - const void* content; - uint64_t size; - OrthancPluginContentType type; - } _OrthancPluginStorageAreaCreate; - - - /** - * @brief Create a file inside the storage area. - * - * This function creates a new file inside the storage area that is - * currently used by Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param storageArea The storage area. - * @param uuid The identifier of the file to be created. - * @param content The content to store in the newly created file. - * @param size The size of the content. - * @param type The type of the file content. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate( - OrthancPluginContext* context, - OrthancPluginStorageArea* storageArea, - const char* uuid, - const void* content, - uint64_t size, - OrthancPluginContentType type) - { - _OrthancPluginStorageAreaCreate params; - params.storageArea = storageArea; - params.uuid = uuid; - params.content = content; - params.size = size; - params.type = type; - - return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, ¶ms); - } - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - OrthancPluginStorageArea* storageArea; - const char* uuid; - OrthancPluginContentType type; - } _OrthancPluginStorageAreaRead; - - - /** - * @brief Read a file from the storage area. - * - * This function reads the content of a given file from the storage - * area that is currently used by Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param storageArea The storage area. - * @param uuid The identifier of the file to be read. - * @param type The type of the file content. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - OrthancPluginStorageArea* storageArea, - const char* uuid, - OrthancPluginContentType type) - { - _OrthancPluginStorageAreaRead params; - params.target = target; - params.storageArea = storageArea; - params.uuid = uuid; - params.type = type; - - return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, ¶ms); - } - - - typedef struct - { - OrthancPluginStorageArea* storageArea; - const char* uuid; - OrthancPluginContentType type; - } _OrthancPluginStorageAreaRemove; - - /** - * @brief Remove a file from the storage area. - * - * This function removes a given file from the storage area that is - * currently used by Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param storageArea The storage area. - * @param uuid The identifier of the file to be removed. - * @param type The type of the file content. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove( - OrthancPluginContext* context, - OrthancPluginStorageArea* storageArea, - const char* uuid, - OrthancPluginContentType type) - { - _OrthancPluginStorageAreaRemove params; - params.storageArea = storageArea; - params.uuid = uuid; - params.type = type; - - return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, ¶ms); - } - - - - typedef struct - { - OrthancPluginErrorCode* target; - int32_t code; - uint16_t httpStatus; - const char* message; - } _OrthancPluginRegisterErrorCode; - - /** - * @brief Declare a custom error code for this plugin. - * - * This function declares a custom error code that can be generated - * by this plugin. This declaration is used to enrich the body of - * the HTTP answer in the case of an error, and to set the proper - * HTTP status code. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param code The error code that is internal to this plugin. - * @param httpStatus The HTTP status corresponding to this error. - * @param message The description of the error. - * @return The error code that has been assigned inside the Orthanc core. - * @ingroup Toolbox - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode( - OrthancPluginContext* context, - int32_t code, - uint16_t httpStatus, - const char* message) - { - OrthancPluginErrorCode target; - - _OrthancPluginRegisterErrorCode params; - params.target = ⌖ - params.code = code; - params.httpStatus = httpStatus; - params.message = message; - - if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, ¶ms) == OrthancPluginErrorCode_Success) - { - return target; - } - else - { - /* There was an error while assigned the error. Use a generic code. */ - return OrthancPluginErrorCode_Plugin; - } - } - - - - typedef struct - { - uint16_t group; - uint16_t element; - OrthancPluginValueRepresentation vr; - const char* name; - uint32_t minMultiplicity; - uint32_t maxMultiplicity; - } _OrthancPluginRegisterDictionaryTag; - - /** - * @brief Register a new tag into the DICOM dictionary. - * - * This function declares a new tag in the dictionary of DICOM tags - * that are known to Orthanc. This function should be used in the - * OrthancPluginInitialize() callback. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param group The group of the tag. - * @param element The element of the tag. - * @param vr The value representation of the tag. - * @param name The nickname of the tag. - * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). - * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means - * an arbitrary multiplicity ("<tt>n</tt>"). - * @return 0 if success, other value if error. - * @ingroup Toolbox - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag( - OrthancPluginContext* context, - uint16_t group, - uint16_t element, - OrthancPluginValueRepresentation vr, - const char* name, - uint32_t minMultiplicity, - uint32_t maxMultiplicity) - { - _OrthancPluginRegisterDictionaryTag params; - params.group = group; - params.element = element; - params.vr = vr; - params.name = name; - params.minMultiplicity = minMultiplicity; - params.maxMultiplicity = maxMultiplicity; - - return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, ¶ms); - } - - - - - typedef struct - { - OrthancPluginStorageArea* storageArea; - OrthancPluginResourceType level; - } _OrthancPluginReconstructMainDicomTags; - - /** - * @brief Reconstruct the main DICOM tags. - * - * This function requests the Orthanc core to reconstruct the main - * DICOM tags of all the resources of the given type. This function - * can only be used as a part of the upgrade of a custom database - * back-end - * (cf. OrthancPlugins::IDatabaseBackend::UpgradeDatabase). A - * database transaction will be automatically setup. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param storageArea The storage area. - * @param level The type of the resources of interest. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( - OrthancPluginContext* context, - OrthancPluginStorageArea* storageArea, - OrthancPluginResourceType level) - { - _OrthancPluginReconstructMainDicomTags params; - params.level = level; - params.storageArea = storageArea; - - return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); - } - - - typedef struct - { - char** result; - const char* instanceId; - const char* buffer; - uint32_t size; - OrthancPluginDicomToJsonFormat format; - OrthancPluginDicomToJsonFlags flags; - uint32_t maxStringLength; - } _OrthancPluginDicomToJson; - - - /** - * @brief Format a DICOM memory buffer as a JSON string. - * - * This function takes as input a memory buffer containing a DICOM - * file, and outputs a JSON string representing the tags of this - * DICOM file. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param buffer The memory buffer containing the DICOM file. - * @param size The size of the memory buffer. - * @param format The output format. - * @param flags Flags governing the output. - * @param maxStringLength The maximum length of a field. Too long fields will - * be output as "null". The 0 value means no maximum length. - * @return The NULL value if the case of an error, or the JSON - * string. This string must be freed by OrthancPluginFreeString(). - * @ingroup Toolbox - * @see OrthancPluginDicomInstanceToJson - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( - OrthancPluginContext* context, - const char* buffer, - uint32_t size, - OrthancPluginDicomToJsonFormat format, - OrthancPluginDicomToJsonFlags flags, - uint32_t maxStringLength) - { - char* result; - - _OrthancPluginDicomToJson params; - memset(¶ms, 0, sizeof(params)); - params.result = &result; - params.buffer = buffer; - params.size = size; - params.format = format; - params.flags = flags; - params.maxStringLength = maxStringLength; - - if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Format a DICOM instance as a JSON string. - * - * This function formats a DICOM instance that is stored in Orthanc, - * and outputs a JSON string representing the tags of this DICOM - * instance. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instanceId The Orthanc identifier of the instance. - * @param format The output format. - * @param flags Flags governing the output. - * @param maxStringLength The maximum length of a field. Too long fields will - * be output as "null". The 0 value means no maximum length. - * @return The NULL value if the case of an error, or the JSON - * string. This string must be freed by OrthancPluginFreeString(). - * @ingroup Toolbox - * @see OrthancPluginDicomInstanceToJson - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( - OrthancPluginContext* context, - const char* instanceId, - OrthancPluginDicomToJsonFormat format, - OrthancPluginDicomToJsonFlags flags, - uint32_t maxStringLength) - { - char* result; - - _OrthancPluginDicomToJson params; - memset(¶ms, 0, sizeof(params)); - params.result = &result; - params.instanceId = instanceId; - params.format = format; - params.flags = flags; - params.maxStringLength = maxStringLength; - - if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* uri; - uint32_t headersCount; - const char* const* headersKeys; - const char* const* headersValues; - int32_t afterPlugins; - } _OrthancPluginRestApiGet2; - - /** - * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. - * - * Make a GET call to the Orthanc REST API with extended - * parameters. The result to the query is stored into a newly - * allocated memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param uri The URI in the built-in Orthanc API. - * @param headersCount The number of HTTP headers. - * @param headersKeys Array containing the keys of the HTTP headers. - * @param headersValues Array containing the values of the HTTP headers. - * @param afterPlugins If 0, the built-in API of Orthanc is used. - * If 1, the API is tainted by the plugins. - * @return 0 if success, or the error code if failure. - * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins - * @ingroup Orthanc - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* uri, - uint32_t headersCount, - const char* const* headersKeys, - const char* const* headersValues, - int32_t afterPlugins) - { - _OrthancPluginRestApiGet2 params; - params.target = target; - params.uri = uri; - params.headersCount = headersCount; - params.headersKeys = headersKeys; - params.headersValues = headersValues; - params.afterPlugins = afterPlugins; - - return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); - } - - - - typedef struct - { - OrthancPluginWorklistCallback callback; - } _OrthancPluginWorklistCallback; - - /** - * @brief Register a callback to handle modality worklists requests. - * - * This function registers a callback to handle C-Find SCP requests - * on modality worklists. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param callback The callback. - * @return 0 if success, other value if error. - * @ingroup Worklists - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback( - OrthancPluginContext* context, - OrthancPluginWorklistCallback callback) - { - _OrthancPluginWorklistCallback params; - params.callback = callback; - - return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, ¶ms); - } - - - - typedef struct - { - OrthancPluginWorklistAnswers* answers; - const OrthancPluginWorklistQuery* query; - const void* dicom; - uint32_t size; - } _OrthancPluginWorklistAnswersOperation; - - /** - * @brief Add one answer to some modality worklist request. - * - * This function adds one worklist (encoded as a DICOM file) to the - * set of answers corresponding to some C-Find SCP request against - * modality worklists. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param answers The set of answers. - * @param query The worklist query, as received by the callback. - * @param dicom The worklist to answer, encoded as a DICOM file. - * @param size The size of the DICOM file. - * @return 0 if success, other value if error. - * @ingroup Worklists - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer( - OrthancPluginContext* context, - OrthancPluginWorklistAnswers* answers, - const OrthancPluginWorklistQuery* query, - const void* dicom, - uint32_t size) - { - _OrthancPluginWorklistAnswersOperation params; - params.answers = answers; - params.query = query; - params.dicom = dicom; - params.size = size; - - return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, ¶ms); - } - - - /** - * @brief Mark the set of worklist answers as incomplete. - * - * This function marks as incomplete the set of answers - * corresponding to some C-Find SCP request against modality - * worklists. This must be used if canceling the handling of a - * request when too many answers are to be returned. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param answers The set of answers. - * @return 0 if success, other value if error. - * @ingroup Worklists - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete( - OrthancPluginContext* context, - OrthancPluginWorklistAnswers* answers) - { - _OrthancPluginWorklistAnswersOperation params; - params.answers = answers; - params.query = NULL; - params.dicom = NULL; - params.size = 0; - - return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, ¶ms); - } - - - typedef struct - { - const OrthancPluginWorklistQuery* query; - const void* dicom; - uint32_t size; - int32_t* isMatch; - OrthancPluginMemoryBuffer* target; - } _OrthancPluginWorklistQueryOperation; - - /** - * @brief Test whether a worklist matches the query. - * - * This function checks whether one worklist (encoded as a DICOM - * file) matches the C-Find SCP query against modality - * worklists. This function must be called before adding the - * worklist as an answer through OrthancPluginWorklistAddAnswer(). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param query The worklist query, as received by the callback. - * @param dicom The worklist to answer, encoded as a DICOM file. - * @param size The size of the DICOM file. - * @return 1 if the worklist matches the query, 0 otherwise. - * @ingroup Worklists - **/ - ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch( - OrthancPluginContext* context, - const OrthancPluginWorklistQuery* query, - const void* dicom, - uint32_t size) - { - int32_t isMatch = 0; - - _OrthancPluginWorklistQueryOperation params; - params.query = query; - params.dicom = dicom; - params.size = size; - params.isMatch = &isMatch; - params.target = NULL; - - if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, ¶ms) == OrthancPluginErrorCode_Success) - { - return isMatch; - } - else - { - /* Error: Assume non-match */ - return 0; - } - } - - - /** - * @brief Retrieve the worklist query as a DICOM file. - * - * This function retrieves the DICOM file that underlies a C-Find - * SCP query against modality worklists. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param query The worklist query, as received by the callback. - * @return 0 if success, other value if error. - * @ingroup Worklists - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const OrthancPluginWorklistQuery* query) - { - _OrthancPluginWorklistQueryOperation params; - params.query = query; - params.dicom = NULL; - params.size = 0; - params.isMatch = NULL; - params.target = target; - - return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, ¶ms); - } - - - /** - * @brief Get the origin of a DICOM file. - * - * This function returns the origin of a DICOM instance that has been received by Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param instance The instance of interest. - * @return The origin of the instance. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin( - OrthancPluginContext* context, - OrthancPluginDicomInstance* instance) - { - OrthancPluginInstanceOrigin origin; - - _OrthancPluginAccessDicomInstance params; - memset(¶ms, 0, sizeof(params)); - params.resultOrigin = &origin; - params.instance = instance; - - if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return OrthancPluginInstanceOrigin_Unknown; - } - else - { - return origin; - } - } - - - typedef struct - { - OrthancPluginMemoryBuffer* target; - const char* json; - const OrthancPluginImage* pixelData; - OrthancPluginCreateDicomFlags flags; - } _OrthancPluginCreateDicom; - - /** - * @brief Create a DICOM instance from a JSON string and an image. - * - * This function takes as input a string containing a JSON file - * describing the content of a DICOM instance. As an output, it - * writes the corresponding DICOM instance to a newly allocated - * memory buffer. Additionally, an image to be encoded within the - * DICOM instance can also be provided. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). - * @param json The input JSON file. - * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. - * @param flags Flags governing the output. - * @return 0 if success, other value if error. - * @ingroup Toolbox - * @see OrthancPluginDicomBufferToJson - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom( - OrthancPluginContext* context, - OrthancPluginMemoryBuffer* target, - const char* json, - const OrthancPluginImage* pixelData, - OrthancPluginCreateDicomFlags flags) - { - _OrthancPluginCreateDicom params; - params.target = target; - params.json = json; - params.pixelData = pixelData; - params.flags = flags; - - return context->InvokeService(context, _OrthancPluginService_CreateDicom, ¶ms); - } - - - typedef struct - { - OrthancPluginDecodeImageCallback callback; - } _OrthancPluginDecodeImageCallback; - - /** - * @brief Register a callback to handle the decoding of DICOM images. - * - * This function registers a custom callback to the decoding of - * DICOM images, replacing the built-in decoder of Orthanc. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param callback The callback. - * @return 0 if success, other value if error. - * @ingroup Callbacks - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback( - OrthancPluginContext* context, - OrthancPluginDecodeImageCallback callback) - { - _OrthancPluginDecodeImageCallback params; - params.callback = callback; - - return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, ¶ms); - } - - - - typedef struct - { - OrthancPluginImage** target; - OrthancPluginPixelFormat format; - uint32_t width; - uint32_t height; - uint32_t pitch; - void* buffer; - const void* constBuffer; - uint32_t bufferSize; - uint32_t frameIndex; - } _OrthancPluginCreateImage; - - - /** - * @brief Create an image. - * - * This function creates an image of given size and format. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param format The format of the pixels. - * @param width The width of the image. - * @param height The height of the image. - * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage( - OrthancPluginContext* context, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height) - { - OrthancPluginImage* target = NULL; - - _OrthancPluginCreateImage params; - memset(¶ms, 0, sizeof(params)); - params.target = ⌖ - params.format = format; - params.width = width; - params.height = height; - - if (context->InvokeService(context, _OrthancPluginService_CreateImage, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - /** - * @brief Create an image pointing to a memory buffer. - * - * This function creates an image whose content points to a memory - * buffer managed by the plugin. Note that the buffer is directly - * accessed, no memory is allocated and no data is copied. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param format The format of the pixels. - * @param width The width of the image. - * @param height The height of the image. - * @param pitch The pitch of the image (i.e. the number of bytes - * between 2 successive lines of the image in the memory buffer). - * @param buffer The memory buffer. - * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor( - OrthancPluginContext* context, - OrthancPluginPixelFormat format, - uint32_t width, - uint32_t height, - uint32_t pitch, - void* buffer) - { - OrthancPluginImage* target = NULL; - - _OrthancPluginCreateImage params; - memset(¶ms, 0, sizeof(params)); - params.target = ⌖ - params.format = format; - params.width = width; - params.height = height; - params.pitch = pitch; - params.buffer = buffer; - - if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - - /** - * @brief Decode one frame from a DICOM instance. - * - * This function decodes one frame of a DICOM image that is stored - * in a memory buffer. This function will give the same result as - * OrthancPluginUncompressImage() for single-frame DICOM images. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param buffer Pointer to a memory buffer containing the DICOM image. - * @param bufferSize Size of the memory buffer containing the DICOM image. - * @param frameIndex The index of the frame of interest in a multi-frame image. - * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). - * @ingroup Images - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage( - OrthancPluginContext* context, - const void* buffer, - uint32_t bufferSize, - uint32_t frameIndex) - { - OrthancPluginImage* target = NULL; - - _OrthancPluginCreateImage params; - memset(¶ms, 0, sizeof(params)); - params.target = ⌖ - params.constBuffer = buffer; - params.bufferSize = bufferSize; - params.frameIndex = frameIndex; - - if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, ¶ms) != OrthancPluginErrorCode_Success) - { - return NULL; - } - else - { - return target; - } - } - - - - typedef struct - { - char** result; - const void* buffer; - uint32_t size; - } _OrthancPluginComputeHash; - - /** - * @brief Compute an MD5 hash. - * - * This functions computes the MD5 cryptographic hash of the given memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param buffer The source memory buffer. - * @param size The size in bytes of the source buffer. - * @return The NULL value in case of error, or a string containing the cryptographic hash. - * This string must be freed by OrthancPluginFreeString(). - * @ingroup Toolbox - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5( - OrthancPluginContext* context, - const void* buffer, - uint32_t size) - { - char* result; - - _OrthancPluginComputeHash params; - params.result = &result; - params.buffer = buffer; - params.size = size; - - if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - /** - * @brief Compute a SHA-1 hash. - * - * This functions computes the SHA-1 cryptographic hash of the given memory buffer. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param buffer The source memory buffer. - * @param size The size in bytes of the source buffer. - * @return The NULL value in case of error, or a string containing the cryptographic hash. - * This string must be freed by OrthancPluginFreeString(). - * @ingroup Toolbox - **/ - ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1( - OrthancPluginContext* context, - const void* buffer, - uint32_t size) - { - char* result; - - _OrthancPluginComputeHash params; - params.result = &result; - params.buffer = buffer; - params.size = size; - - if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, ¶ms) != OrthancPluginErrorCode_Success) - { - /* Error */ - return NULL; - } - else - { - return result; - } - } - - - - typedef struct - { - OrthancPluginDictionaryEntry* target; - const char* name; - } _OrthancPluginLookupDictionary; - - /** - * @brief Get information about the given DICOM tag. - * - * This functions makes a lookup in the dictionary of DICOM tags - * that are known to Orthanc, and returns information about this - * tag. The tag can be specified using its human-readable name - * (e.g. "PatientName") or a set of two hexadecimal numbers - * (e.g. "0010-0020"). - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param target Where to store the information about the tag. - * @param name The name of the DICOM tag. - * @return 0 if success, other value if error. - * @ingroup Toolbox - **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary( - OrthancPluginContext* context, - OrthancPluginDictionaryEntry* target, - const char* name) - { - _OrthancPluginLookupDictionary params; - params.target = target; - params.name = name; - return context->InvokeService(context, _OrthancPluginService_LookupDictionary, ¶ms); - } - - -#ifdef __cplusplus -} -#endif - - -/** @} */ -
--- a/Orthanc/Sdk-0.9.5/orthanc/OrthancCppDatabasePlugin.h Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1895 +0,0 @@ -/** - * Orthanc - A Lightweight, RESTful DICOM Store - * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics - * Department, University Hospital of Liege, Belgium - * - * This program is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * In addition, as a special exception, the copyright holders of this - * program give permission to link the code of its release with the - * OpenSSL project's "OpenSSL" library (or with modified versions of it - * that use the same license as the "OpenSSL" library), and distribute - * the linked executables. You must obey the GNU General Public License - * in all respects for all of the code used other than "OpenSSL". If you - * modify file(s) with this exception, you may extend this exception to - * your version of the file(s), but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source files - * in the program, then also delete it here. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - **/ - - - -#pragma once - -#include "OrthancCDatabasePlugin.h" - -#include <stdexcept> -#include <list> -#include <string> - -namespace OrthancPlugins -{ -//! @cond Doxygen_Suppress - // This class mimics "boost::noncopyable" - class NonCopyable - { - private: - NonCopyable(const NonCopyable&); - - NonCopyable& operator= (const NonCopyable&); - - protected: - NonCopyable() - { - } - - ~NonCopyable() - { - } - }; -//! @endcond - - - /** - * @ingroup Callbacks - **/ - class DatabaseException - { - private: - OrthancPluginErrorCode code_; - - public: - DatabaseException() : code_(OrthancPluginErrorCode_DatabasePlugin) - { - } - - DatabaseException(OrthancPluginErrorCode code) : code_(code) - { - } - - OrthancPluginErrorCode GetErrorCode() const - { - return code_; - } - }; - - - /** - * @ingroup Callbacks - **/ - class DatabaseBackendOutput : public NonCopyable - { - friend class DatabaseBackendAdapter; - - private: - enum AllowedAnswers - { - AllowedAnswers_All, - AllowedAnswers_None, - AllowedAnswers_Attachment, - AllowedAnswers_Change, - AllowedAnswers_DicomTag, - AllowedAnswers_ExportedResource - }; - - OrthancPluginContext* context_; - OrthancPluginDatabaseContext* database_; - AllowedAnswers allowedAnswers_; - - void SetAllowedAnswers(AllowedAnswers allowed) - { - allowedAnswers_ = allowed; - } - - public: - DatabaseBackendOutput(OrthancPluginContext* context, - OrthancPluginDatabaseContext* database) : - context_(context), - database_(database), - allowedAnswers_(AllowedAnswers_All /* for unit tests */) - { - } - - OrthancPluginContext* GetContext() - { - return context_; - } - - void LogError(const std::string& message) - { - OrthancPluginLogError(context_, message.c_str()); - } - - void LogWarning(const std::string& message) - { - OrthancPluginLogWarning(context_, message.c_str()); - } - - void LogInfo(const std::string& message) - { - OrthancPluginLogInfo(context_, message.c_str()); - } - - void SignalDeletedAttachment(const std::string& uuid, - int32_t contentType, - uint64_t uncompressedSize, - const std::string& uncompressedHash, - int32_t compressionType, - uint64_t compressedSize, - const std::string& compressedHash) - { - OrthancPluginAttachment attachment; - attachment.uuid = uuid.c_str(); - attachment.contentType = contentType; - attachment.uncompressedSize = uncompressedSize; - attachment.uncompressedHash = uncompressedHash.c_str(); - attachment.compressionType = compressionType; - attachment.compressedSize = compressedSize; - attachment.compressedHash = compressedHash.c_str(); - - OrthancPluginDatabaseSignalDeletedAttachment(context_, database_, &attachment); - } - - void SignalDeletedResource(const std::string& publicId, - OrthancPluginResourceType resourceType) - { - OrthancPluginDatabaseSignalDeletedResource(context_, database_, publicId.c_str(), resourceType); - } - - void SignalRemainingAncestor(const std::string& ancestorId, - OrthancPluginResourceType ancestorType) - { - OrthancPluginDatabaseSignalRemainingAncestor(context_, database_, ancestorId.c_str(), ancestorType); - } - - void AnswerAttachment(const std::string& uuid, - int32_t contentType, - uint64_t uncompressedSize, - const std::string& uncompressedHash, - int32_t compressionType, - uint64_t compressedSize, - const std::string& compressedHash) - { - if (allowedAnswers_ != AllowedAnswers_All && - allowedAnswers_ != AllowedAnswers_Attachment) - { - throw std::runtime_error("Cannot answer with an attachment in the current state"); - } - - OrthancPluginAttachment attachment; - attachment.uuid = uuid.c_str(); - attachment.contentType = contentType; - attachment.uncompressedSize = uncompressedSize; - attachment.uncompressedHash = uncompressedHash.c_str(); - attachment.compressionType = compressionType; - attachment.compressedSize = compressedSize; - attachment.compressedHash = compressedHash.c_str(); - - OrthancPluginDatabaseAnswerAttachment(context_, database_, &attachment); - } - - void AnswerChange(int64_t seq, - int32_t changeType, - OrthancPluginResourceType resourceType, - const std::string& publicId, - const std::string& date) - { - if (allowedAnswers_ != AllowedAnswers_All && - allowedAnswers_ != AllowedAnswers_Change) - { - throw std::runtime_error("Cannot answer with a change in the current state"); - } - - OrthancPluginChange change; - change.seq = seq; - change.changeType = changeType; - change.resourceType = resourceType; - change.publicId = publicId.c_str(); - change.date = date.c_str(); - - OrthancPluginDatabaseAnswerChange(context_, database_, &change); - } - - void AnswerDicomTag(uint16_t group, - uint16_t element, - const std::string& value) - { - if (allowedAnswers_ != AllowedAnswers_All && - allowedAnswers_ != AllowedAnswers_DicomTag) - { - throw std::runtime_error("Cannot answer with a DICOM tag in the current state"); - } - - OrthancPluginDicomTag tag; - tag.group = group; - tag.element = element; - tag.value = value.c_str(); - - OrthancPluginDatabaseAnswerDicomTag(context_, database_, &tag); - } - - void AnswerExportedResource(int64_t seq, - OrthancPluginResourceType resourceType, - const std::string& publicId, - const std::string& modality, - const std::string& date, - const std::string& patientId, - const std::string& studyInstanceUid, - const std::string& seriesInstanceUid, - const std::string& sopInstanceUid) - { - if (allowedAnswers_ != AllowedAnswers_All && - allowedAnswers_ != AllowedAnswers_ExportedResource) - { - throw std::runtime_error("Cannot answer with an exported resource in the current state"); - } - - OrthancPluginExportedResource exported; - exported.seq = seq; - exported.resourceType = resourceType; - exported.publicId = publicId.c_str(); - exported.modality = modality.c_str(); - exported.date = date.c_str(); - exported.patientId = patientId.c_str(); - exported.studyInstanceUid = studyInstanceUid.c_str(); - exported.seriesInstanceUid = seriesInstanceUid.c_str(); - exported.sopInstanceUid = sopInstanceUid.c_str(); - - OrthancPluginDatabaseAnswerExportedResource(context_, database_, &exported); - } - }; - - - /** - * @ingroup Callbacks - **/ - class IDatabaseBackend : public NonCopyable - { - friend class DatabaseBackendAdapter; - - private: - DatabaseBackendOutput* output_; - - void Finalize() - { - if (output_ != NULL) - { - delete output_; - output_ = NULL; - } - } - - protected: - DatabaseBackendOutput& GetOutput() - { - return *output_; - } - - public: - IDatabaseBackend() : output_(NULL) - { - } - - virtual ~IDatabaseBackend() - { - Finalize(); - } - - // This takes the ownership - void RegisterOutput(DatabaseBackendOutput* output) - { - Finalize(); - output_ = output; - } - - virtual void Open() = 0; - - virtual void Close() = 0; - - virtual void AddAttachment(int64_t id, - const OrthancPluginAttachment& attachment) = 0; - - virtual void AttachChild(int64_t parent, - int64_t child) = 0; - - virtual void ClearChanges() = 0; - - virtual void ClearExportedResources() = 0; - - virtual int64_t CreateResource(const char* publicId, - OrthancPluginResourceType type) = 0; - - virtual void DeleteAttachment(int64_t id, - int32_t attachment) = 0; - - virtual void DeleteMetadata(int64_t id, - int32_t metadataType) = 0; - - virtual void DeleteResource(int64_t id) = 0; - - virtual void GetAllInternalIds(std::list<int64_t>& target, - OrthancPluginResourceType resourceType) = 0; - - virtual void GetAllPublicIds(std::list<std::string>& target, - OrthancPluginResourceType resourceType) = 0; - - virtual void GetAllPublicIds(std::list<std::string>& target, - OrthancPluginResourceType resourceType, - uint64_t since, - uint64_t limit) = 0; - - /* Use GetOutput().AnswerChange() */ - virtual void GetChanges(bool& done /*out*/, - int64_t since, - uint32_t maxResults) = 0; - - virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, - int64_t id) = 0; - - virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, - int64_t id) = 0; - - /* Use GetOutput().AnswerExportedResource() */ - virtual void GetExportedResources(bool& done /*out*/, - int64_t since, - uint32_t maxResults) = 0; - - /* Use GetOutput().AnswerChange() */ - virtual void GetLastChange() = 0; - - /* Use GetOutput().AnswerExportedResource() */ - virtual void GetLastExportedResource() = 0; - - /* Use GetOutput().AnswerDicomTag() */ - virtual void GetMainDicomTags(int64_t id) = 0; - - virtual std::string GetPublicId(int64_t resourceId) = 0; - - virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) = 0; - - virtual OrthancPluginResourceType GetResourceType(int64_t resourceId) = 0; - - virtual uint64_t GetTotalCompressedSize() = 0; - - virtual uint64_t GetTotalUncompressedSize() = 0; - - virtual bool IsExistingResource(int64_t internalId) = 0; - - virtual bool IsProtectedPatient(int64_t internalId) = 0; - - virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, - int64_t id) = 0; - - virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, - int64_t id) = 0; - - virtual void LogChange(const OrthancPluginChange& change) = 0; - - virtual void LogExportedResource(const OrthancPluginExportedResource& resource) = 0; - - /* Use GetOutput().AnswerAttachment() */ - virtual bool LookupAttachment(int64_t id, - int32_t contentType) = 0; - - virtual bool LookupGlobalProperty(std::string& target /*out*/, - int32_t property) = 0; - - virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, - OrthancPluginResourceType resourceType, - uint16_t group, - uint16_t element, - OrthancPluginIdentifierConstraint constraint, - const char* value) = 0; - - virtual bool LookupMetadata(std::string& target /*out*/, - int64_t id, - int32_t metadataType) = 0; - - virtual bool LookupParent(int64_t& parentId /*out*/, - int64_t resourceId) = 0; - - virtual bool LookupResource(int64_t& id /*out*/, - OrthancPluginResourceType& type /*out*/, - const char* publicId) = 0; - - virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) = 0; - - virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, - int64_t patientIdToAvoid) = 0; - - virtual void SetGlobalProperty(int32_t property, - const char* value) = 0; - - virtual void SetMainDicomTag(int64_t id, - uint16_t group, - uint16_t element, - const char* value) = 0; - - virtual void SetIdentifierTag(int64_t id, - uint16_t group, - uint16_t element, - const char* value) = 0; - - virtual void SetMetadata(int64_t id, - int32_t metadataType, - const char* value) = 0; - - virtual void SetProtectedPatient(int64_t internalId, - bool isProtected) = 0; - - virtual void StartTransaction() = 0; - - virtual void RollbackTransaction() = 0; - - virtual void CommitTransaction() = 0; - - virtual uint32_t GetDatabaseVersion() = 0; - - /** - * Upgrade the database to the specified version of the database - * schema. The upgrade script is allowed to make calls to - * OrthancPluginReconstructMainDicomTags(). - **/ - virtual void UpgradeDatabase(uint32_t targetVersion, - OrthancPluginStorageArea* storageArea) = 0; - - virtual void ClearMainDicomTags(int64_t internalId) = 0; - }; - - - - /** - * @brief Bridge between C and C++ database engines. - * - * Class creating the bridge between the C low-level primitives for - * custom database engines, and the high-level IDatabaseBackend C++ - * interface. - * - * @ingroup Callbacks - **/ - class DatabaseBackendAdapter - { - private: - // This class cannot be instantiated - DatabaseBackendAdapter() - { - } - - static void LogError(IDatabaseBackend* backend, - const std::runtime_error& e) - { - backend->GetOutput().LogError("Exception in database back-end: " + std::string(e.what())); - } - - - static OrthancPluginErrorCode AddAttachment(void* payload, - int64_t id, - const OrthancPluginAttachment* attachment) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->AddAttachment(id, *attachment); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode AttachChild(void* payload, - int64_t parent, - int64_t child) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->AttachChild(parent, child); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode ClearChanges(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->ClearChanges(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode ClearExportedResources(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->ClearExportedResources(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode CreateResource(int64_t* id, - void* payload, - const char* publicId, - OrthancPluginResourceType resourceType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *id = backend->CreateResource(publicId, resourceType); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode DeleteAttachment(void* payload, - int64_t id, - int32_t contentType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->DeleteAttachment(id, contentType); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode DeleteMetadata(void* payload, - int64_t id, - int32_t metadataType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->DeleteMetadata(id, metadataType); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode DeleteResource(void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->DeleteResource(id); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetAllInternalIds(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<int64_t> target; - backend->GetAllInternalIds(target, resourceType); - - for (std::list<int64_t>::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetAllPublicIds(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<std::string> ids; - backend->GetAllPublicIds(ids, resourceType); - - for (std::list<std::string>::const_iterator - it = ids.begin(); it != ids.end(); ++it) - { - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, - it->c_str()); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetAllPublicIdsWithLimit(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType, - uint64_t since, - uint64_t limit) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<std::string> ids; - backend->GetAllPublicIds(ids, resourceType, since, limit); - - for (std::list<std::string>::const_iterator - it = ids.begin(); it != ids.end(); ++it) - { - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, - it->c_str()); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetChanges(OrthancPluginDatabaseContext* context, - void* payload, - int64_t since, - uint32_t maxResult) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); - - try - { - bool done; - backend->GetChanges(done, since, maxResult); - - if (done) - { - OrthancPluginDatabaseAnswerChangesDone(backend->GetOutput().context_, - backend->GetOutput().database_); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetChildrenInternalId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<int64_t> target; - backend->GetChildrenInternalId(target, id); - - for (std::list<int64_t>::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetChildrenPublicId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<std::string> ids; - backend->GetChildrenPublicId(ids, id); - - for (std::list<std::string>::const_iterator - it = ids.begin(); it != ids.end(); ++it) - { - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, - it->c_str()); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetExportedResources(OrthancPluginDatabaseContext* context, - void* payload, - int64_t since, - uint32_t maxResult) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); - - try - { - bool done; - backend->GetExportedResources(done, since, maxResult); - - if (done) - { - OrthancPluginDatabaseAnswerExportedResourcesDone(backend->GetOutput().context_, - backend->GetOutput().database_); - } - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetLastChange(OrthancPluginDatabaseContext* context, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); - - try - { - backend->GetLastChange(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetLastExportedResource(OrthancPluginDatabaseContext* context, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); - - try - { - backend->GetLastExportedResource(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetMainDicomTags(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_DicomTag); - - try - { - backend->GetMainDicomTags(id); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetPublicId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::string s = backend->GetPublicId(id); - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, - s.c_str()); - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetResourceCount(uint64_t* target, - void* payload, - OrthancPluginResourceType resourceType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *target = backend->GetResourceCount(resourceType); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetResourceType(OrthancPluginResourceType* resourceType, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *resourceType = backend->GetResourceType(id); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetTotalCompressedSize(uint64_t* target, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *target = backend->GetTotalCompressedSize(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetTotalUncompressedSize(uint64_t* target, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *target = backend->GetTotalUncompressedSize(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode IsExistingResource(int32_t* existing, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *existing = backend->IsExistingResource(id); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode IsProtectedPatient(int32_t* isProtected, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - *isProtected = backend->IsProtectedPatient(id); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode ListAvailableMetadata(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<int32_t> target; - backend->ListAvailableMetadata(target, id); - - for (std::list<int32_t>::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt32(backend->GetOutput().context_, - backend->GetOutput().database_, - *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode ListAvailableAttachments(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<int32_t> target; - backend->ListAvailableAttachments(target, id); - - for (std::list<int32_t>::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt32(backend->GetOutput().context_, - backend->GetOutput().database_, - *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LogChange(void* payload, - const OrthancPluginChange* change) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->LogChange(*change); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LogExportedResource(void* payload, - const OrthancPluginExportedResource* exported) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->LogExportedResource(*exported); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupAttachment(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id, - int32_t contentType) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Attachment); - - try - { - backend->LookupAttachment(id, contentType); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupGlobalProperty(OrthancPluginDatabaseContext* context, - void* payload, - int32_t property) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::string s; - if (backend->LookupGlobalProperty(s, property)) - { - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, - s.c_str()); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupIdentifier3(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType, - const OrthancPluginDicomTag* tag, - OrthancPluginIdentifierConstraint constraint) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::list<int64_t> target; - backend->LookupIdentifier(target, resourceType, tag->group, tag->element, constraint, tag->value); - - for (std::list<int64_t>::const_iterator - it = target.begin(); it != target.end(); ++it) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, *it); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupMetadata(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id, - int32_t metadata) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - std::string s; - if (backend->LookupMetadata(s, id, metadata)) - { - OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, - backend->GetOutput().database_, s.c_str()); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupParent(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - int64_t parent; - if (backend->LookupParent(parent, id)) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, parent); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode LookupResource(OrthancPluginDatabaseContext* context, - void* payload, - const char* publicId) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - int64_t id; - OrthancPluginResourceType type; - if (backend->LookupResource(id, type, publicId)) - { - OrthancPluginDatabaseAnswerResource(backend->GetOutput().context_, - backend->GetOutput().database_, - id, type); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SelectPatientToRecycle(OrthancPluginDatabaseContext* context, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - int64_t id; - if (backend->SelectPatientToRecycle(id)) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, id); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SelectPatientToRecycle2(OrthancPluginDatabaseContext* context, - void* payload, - int64_t patientIdToAvoid) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - int64_t id; - if (backend->SelectPatientToRecycle(id, patientIdToAvoid)) - { - OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, - backend->GetOutput().database_, id); - } - - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SetGlobalProperty(void* payload, - int32_t property, - const char* value) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->SetGlobalProperty(property, value); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SetMainDicomTag(void* payload, - int64_t id, - const OrthancPluginDicomTag* tag) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->SetMainDicomTag(id, tag->group, tag->element, tag->value); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SetIdentifierTag(void* payload, - int64_t id, - const OrthancPluginDicomTag* tag) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->SetIdentifierTag(id, tag->group, tag->element, tag->value); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SetMetadata(void* payload, - int64_t id, - int32_t metadata, - const char* value) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->SetMetadata(id, metadata, value); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode SetProtectedPatient(void* payload, - int64_t id, - int32_t isProtected) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->SetProtectedPatient(id, (isProtected != 0)); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode StartTransaction(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->StartTransaction(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode RollbackTransaction(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->RollbackTransaction(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode CommitTransaction(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->CommitTransaction(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode Open(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->Open(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode Close(void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); - - try - { - backend->Close(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode GetDatabaseVersion(uint32_t* version, - void* payload) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - - try - { - *version = backend->GetDatabaseVersion(); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode UpgradeDatabase(void* payload, - uint32_t targetVersion, - OrthancPluginStorageArea* storageArea) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - - try - { - backend->UpgradeDatabase(targetVersion, storageArea); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - static OrthancPluginErrorCode ClearMainDicomTags(void* payload, - int64_t internalId) - { - IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); - - try - { - backend->ClearMainDicomTags(internalId); - return OrthancPluginErrorCode_Success; - } - catch (std::runtime_error& e) - { - LogError(backend, e); - return OrthancPluginErrorCode_DatabasePlugin; - } - catch (DatabaseException& e) - { - return e.GetErrorCode(); - } - } - - - public: - /** - * Register a custom database back-end written in C++. - * - * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). - * @param backend Your custom database engine. - **/ - - static void Register(OrthancPluginContext* context, - IDatabaseBackend& backend) - { - OrthancPluginDatabaseBackend params; - memset(¶ms, 0, sizeof(params)); - - OrthancPluginDatabaseExtensions extensions; - memset(&extensions, 0, sizeof(extensions)); - - params.addAttachment = AddAttachment; - params.attachChild = AttachChild; - params.clearChanges = ClearChanges; - params.clearExportedResources = ClearExportedResources; - params.createResource = CreateResource; - params.deleteAttachment = DeleteAttachment; - params.deleteMetadata = DeleteMetadata; - params.deleteResource = DeleteResource; - params.getAllPublicIds = GetAllPublicIds; - params.getChanges = GetChanges; - params.getChildrenInternalId = GetChildrenInternalId; - params.getChildrenPublicId = GetChildrenPublicId; - params.getExportedResources = GetExportedResources; - params.getLastChange = GetLastChange; - params.getLastExportedResource = GetLastExportedResource; - params.getMainDicomTags = GetMainDicomTags; - params.getPublicId = GetPublicId; - params.getResourceCount = GetResourceCount; - params.getResourceType = GetResourceType; - params.getTotalCompressedSize = GetTotalCompressedSize; - params.getTotalUncompressedSize = GetTotalUncompressedSize; - params.isExistingResource = IsExistingResource; - params.isProtectedPatient = IsProtectedPatient; - params.listAvailableMetadata = ListAvailableMetadata; - params.listAvailableAttachments = ListAvailableAttachments; - params.logChange = LogChange; - params.logExportedResource = LogExportedResource; - params.lookupAttachment = LookupAttachment; - params.lookupGlobalProperty = LookupGlobalProperty; - params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) - params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) - params.lookupMetadata = LookupMetadata; - params.lookupParent = LookupParent; - params.lookupResource = LookupResource; - params.selectPatientToRecycle = SelectPatientToRecycle; - params.selectPatientToRecycle2 = SelectPatientToRecycle2; - params.setGlobalProperty = SetGlobalProperty; - params.setMainDicomTag = SetMainDicomTag; - params.setIdentifierTag = SetIdentifierTag; - params.setMetadata = SetMetadata; - params.setProtectedPatient = SetProtectedPatient; - params.startTransaction = StartTransaction; - params.rollbackTransaction = RollbackTransaction; - params.commitTransaction = CommitTransaction; - params.open = Open; - params.close = Close; - - extensions.getAllPublicIdsWithLimit = GetAllPublicIdsWithLimit; - extensions.getDatabaseVersion = GetDatabaseVersion; - extensions.upgradeDatabase = UpgradeDatabase; - extensions.clearMainDicomTags = ClearMainDicomTags; - extensions.getAllInternalIds = GetAllInternalIds; // New in Orthanc 0.9.5 (db v6) - extensions.lookupIdentifier3 = LookupIdentifier3; // New in Orthanc 0.9.5 (db v6) - - OrthancPluginDatabaseContext* database = OrthancPluginRegisterDatabaseBackendV2(context, ¶ms, &extensions, &backend); - if (!context) - { - throw std::runtime_error("Unable to register the database backend"); - } - - backend.RegisterOutput(new DatabaseBackendOutput(context, database)); - } - }; -}
--- a/Resources/CMake/LinuxStandardBaseToolchain.cmake Wed Apr 11 16:24:01 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON - -INCLUDE(CMakeForceCompiler) - -SET(LSB_PATH $ENV{LSB_PATH}) -SET(LSB_CC $ENV{LSB_CC}) -SET(LSB_CXX $ENV{LSB_CXX}) -SET(LSB_TARGET_VERSION "4.0") - -IF ("${LSB_PATH}" STREQUAL "") - SET(LSB_PATH "/opt/lsb") -ENDIF() - -IF (EXISTS ${LSB_PATH}/lib64) - SET(LSB_TARGET_PROCESSOR "x86_64") - SET(LSB_LIBPATH ${LSB_PATH}/lib64-${LSB_TARGET_VERSION}) -ELSEIF (EXISTS ${LSB_PATH}/lib) - SET(LSB_TARGET_PROCESSOR "x86") - SET(LSB_LIBPATH ${LSB_PATH}/lib-${LSB_TARGET_VERSION}) -ELSE() - MESSAGE(FATAL_ERROR "Unable to detect the target processor architecture. Check the LSB_PATH environment variable.") -ENDIF() - -SET(LSB_CPPPATH ${LSB_PATH}/include) -SET(PKG_CONFIG_PATH ${LSB_LIBPATH}/pkgconfig/) - -# the name of the target operating system -SET(CMAKE_SYSTEM_NAME Linux) -SET(CMAKE_SYSTEM_VERSION LinuxStandardBase) -SET(CMAKE_SYSTEM_PROCESSOR ${LSB_TARGET_PROCESSOR}) - -# which compilers to use for C and C++ -SET(CMAKE_C_COMPILER ${LSB_PATH}/bin/lsbcc) -CMAKE_FORCE_CXX_COMPILER(${LSB_PATH}/bin/lsbc++ GNU) - -# here is the target environment located -SET(CMAKE_FIND_ROOT_PATH ${LSB_PATH}) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - -SET(CMAKE_CROSSCOMPILING OFF) - - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include" CACHE INTERNAL "" FORCE) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward" CACHE INTERNAL "" FORCE) -SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) - -if (NOT "${LSB_CXX}" STREQUAL "") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cxx=${LSB_CXX}") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") -endif() - -if (NOT "${LSB_CC}" STREQUAL "") - SET(CMAKE_C_FLAGS "${CMAKE_CC_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cc=${LSB_CC}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cc=${LSB_CC}") -endif() -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/DownloadOrthancFramework.cmake Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,314 @@ +# Orthanc - A Lightweight, RESTful DICOM Store +# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics +# Department, University Hospital of Liege, Belgium +# Copyright (C) 2017-2018 Osimis S.A., Belgium +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# In addition, as a special exception, the copyright holders of this +# program give permission to link the code of its release with the +# OpenSSL project's "OpenSSL" library (or with modified versions of it +# that use the same license as the "OpenSSL" library), and distribute +# the linked executables. You must obey the GNU General Public License +# in all respects for all of the code used other than "OpenSSL". If you +# modify file(s) with this exception, you may extend this exception to +# your version of the file(s), but you are not obligated to do so. If +# you do not wish to do so, delete this exception statement from your +# version. If you delete this exception statement from all source files +# in the program, then also delete it here. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + + +## +## Check whether the parent script sets the mandatory variables +## + +if (NOT DEFINED ORTHANC_FRAMEWORK_SOURCE OR + (NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" AND + NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "web" AND + NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" AND + NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")) + message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_SOURCE must be set to \"hg\", \"web\", \"archive\" or \"path\"") +endif() + + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" OR + ORTHANC_FRAMEWORK_SOURCE STREQUAL "web") + if (NOT STATIC_BUILD AND + NOT ALLOW_DOWNLOADS) + message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON") + endif() +endif() + + + +## +## Detection of the requested version +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" OR + ORTHANC_FRAMEWORK_SOURCE STREQUAL "web") + if (NOT DEFINED ORTHANC_FRAMEWORK_VERSION) + message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_VERSION must be set") + endif() + + if (DEFINED ORTHANC_FRAMEWORK_MAJOR OR + DEFINED ORTHANC_FRAMEWORK_MINOR OR + DEFINED ORTHANC_FRAMEWORK_REVISION) + message(FATAL_ERROR "Some internal variable has been set") + endif() + + if (ORTHANC_FRAMEWORK_VERSION STREQUAL "mainline") + set(ORTHANC_FRAMEWORK_BRANCH "default") + + else() + set(ORTHANC_FRAMEWORK_BRANCH "Orthanc-${ORTHANC_FRAMEWORK_VERSION}") + + set(RE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") + string(REGEX REPLACE ${RE} "\\1" ORTHANC_FRAMEWORK_MAJOR ${ORTHANC_FRAMEWORK_VERSION}) + string(REGEX REPLACE ${RE} "\\2" ORTHANC_FRAMEWORK_MINOR ${ORTHANC_FRAMEWORK_VERSION}) + string(REGEX REPLACE ${RE} "\\3" ORTHANC_FRAMEWORK_REVISION ${ORTHANC_FRAMEWORK_VERSION}) + + if (NOT ORTHANC_FRAMEWORK_MAJOR MATCHES "^[0-9]+$" OR + NOT ORTHANC_FRAMEWORK_MINOR MATCHES "^[0-9]+$" OR + NOT ORTHANC_FRAMEWORK_REVISION MATCHES "^[0-9]+$") + message("Bad version of the Orthanc framework: ${ORTHANC_FRAMEWORK_VERSION}") + endif() + endif() +endif() + + + +## +## Detection of the third-party software +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg") + find_program(ORTHANC_FRAMEWORK_HG hg) + + if (${ORTHANC_FRAMEWORK_HG} MATCHES "ORTHANC_FRAMEWORK_HG-NOTFOUND") + message(FATAL_ERROR "Please install Mercurial") + endif() +endif() + + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR + ORTHANC_FRAMEWORK_SOURCE STREQUAL "web") + if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") + find_program(ORTHANC_FRAMEWORK_7ZIP 7z + PATHS + "$ENV{ProgramFiles}/7-Zip" + "$ENV{ProgramW6432}/7-Zip" + ) + + if (${ORTHANC_FRAMEWORK_7ZIP} MATCHES "ORTHANC_FRAMEWORK_7ZIP-NOTFOUND") + message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)") + endif() + + else() + find_program(ORTHANC_FRAMEWORK_TAR tar) + if (${ORTHANC_FRAMEWORK_TAR} MATCHES "ORTHANC_FRAMEWORK_TAR-NOTFOUND") + message(FATAL_ERROR "Please install the 'tar' package") + endif() + endif() +endif() + + + +## +## Case of the Orthanc framework specified as a path on the filesystem +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path") + if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT) + 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 a version of Orthanc: ${ORTHANC_FRAMEWORK_ROOT}") + endif() + + set(ORTHANC_ROOT ${ORTHANC_FRAMEWORK_ROOT}) +endif() + + + +## +## Case of the Orthanc framework cloned using Mercurial +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg") + set(ORTHANC_ROOT ${CMAKE_BINARY_DIR}/orthanc) + + if (NOT EXISTS ${ORTHANC_ROOT}) + message("Forking the Orthanc source repository using Mercurial") + + execute_process( + COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://bitbucket.org/sjodogne/orthanc" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + ) + + if (Failure OR NOT EXISTS ${ORTHANC_ROOT}) + message(FATAL_ERROR "Cannot fork the Orthanc repository") + endif() + endif() + + message("Setting branch of the Orthanc repository to: ${ORTHANC_FRAMEWORK_BRANCH}") + + execute_process( + COMMAND ${ORTHANC_FRAMEWORK_HG} update -c ${ORTHANC_FRAMEWORK_BRANCH} + WORKING_DIRECTORY ${ORTHANC_ROOT} + RESULT_VARIABLE Failure + ) + + if (Failure) + message(FATAL_ERROR "Error while running Mercurial") + endif() +endif() + + + +## +## Case of the Orthanc framework provided as a source archive on the +## filesystem +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive") + if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE) + message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc") + endif() + + set(RE "^.*/Orthanc-([0-9]+)\\.([0-9]+)\\.([0-9]+).tar.gz$") + string(REGEX REPLACE ${RE} "\\1" ORTHANC_FRAMEWORK_MAJOR ${ORTHANC_FRAMEWORK_ARCHIVE}) + string(REGEX REPLACE ${RE} "\\2" ORTHANC_FRAMEWORK_MINOR ${ORTHANC_FRAMEWORK_ARCHIVE}) + string(REGEX REPLACE ${RE} "\\3" ORTHANC_FRAMEWORK_REVISION ${ORTHANC_FRAMEWORK_ARCHIVE}) + + if (NOT ORTHANC_FRAMEWORK_MAJOR MATCHES "^[0-9]+$" OR + NOT ORTHANC_FRAMEWORK_MINOR MATCHES "^[0-9]+$" OR + NOT ORTHANC_FRAMEWORK_REVISION MATCHES "^[0-9]+$") + message("Cannot detect the version of this release of Orthanc: ${ORTHANC_FRAMEWORK_ARCHIVE}") + endif() + + set(ORTHANC_FRAMEWORK_VERSION ${ORTHANC_FRAMEWORK_MAJOR}.${ORTHANC_FRAMEWORK_MINOR}.${ORTHANC_FRAMEWORK_REVISION}) + message("Detected version of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}") +endif() + + + +## +## Case of the Orthanc framework downloaded from the official Web site +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "web") + set(ORTHANC_FRAMEMORK_FILENAME Orthanc-${ORTHANC_FRAMEWORK_VERSION}.tar.gz) + set(ORTHANC_FRAMEWORK_URL "https://www.orthanc-server.com/downloads/get.php?path=/orthanc/${ORTHANC_FRAMEMORK_FILENAME}") + + if (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.1") + set(ORTHANC_FRAMEWORK_MD5 "dac95bd6cf86fb19deaf4e612961f378") + else() + message(FATAL_ERROR "Unknown release of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}") + endif() + + set(ORTHANC_FRAMEWORK_ARCHIVE "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${ORTHANC_FRAMEMORK_FILENAME}") + + if (NOT EXISTS "${ORTHANC_FRAMEWORK_ARCHIVE}") + message("Downloading ${ORTHANC_FRAMEWORK_ARCHIVE}") + + file(DOWNLOAD + "${ORTHANC_FRAMEWORK_URL}" "${ORTHANC_FRAMEWORK_ARCHIVE}" + SHOW_PROGRESS EXPECTED_MD5 "${ORTHANC_FRAMEWORK_MD5}" + TIMEOUT 60 + INACTIVITY_TIMEOUT 60 + ) + else() + message("Using local copy of ${ORTHANC_FRAMEWORK_URL}") + + file(MD5 ${ORTHANC_FRAMEWORK_ARCHIVE} ActualMD5) + if (NOT "${ActualMD5}" STREQUAL "${ORTHANC_FRAMEWORK_MD5}") + message(FATAL_ERROR "The MD5 hash of a previously download file is invalid: ${ORTHANC_FRAMEWORK_ARCHIVE}") + endif() + endif() +endif() + + + + +## +## Uncompressing the Orthanc framework, if it was retrieved from a +## source archive on the filesystem, or from the official Web site +## + +if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR + ORTHANC_FRAMEWORK_SOURCE STREQUAL "web") + + if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR + NOT DEFINED ORTHANC_FRAMEWORK_VERSION) + message(FATAL_ERROR "Internal error") + endif() + + set(ORTHANC_ROOT "${CMAKE_BINARY_DIR}/Orthanc-${ORTHANC_FRAMEWORK_VERSION}") + + if (NOT IS_DIRECTORY "${ORTHANC_ROOT}") + if (NOT ORTHANC_FRAMEWORK_ARCHIVE MATCHES ".tar.gz$") + message(FATAL_ERROR "Archive should have the \".tar.gz\" extension: ${ORTHANC_FRAMEWORK_ARCHIVE}") + endif() + + message("Uncompressing ${ORTHANC_FRAMEWORK_ARCHIVE}") + + if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") + # How to silently extract files using 7-zip + # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly + + execute_process( + COMMAND ${ORTHANC_FRAMEWORK_7ZIP} e -y ${ORTHANC_FRAMEWORK_ARCHIVE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + OUTPUT_QUIET + ) + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + string(REGEX REPLACE ".gz$" "" TMP "${ORTHANC_FRAMEWORK_ARCHIVE}") + + execute_process( + COMMAND ${ORTHANC_FRAMEWORK_7ZIP} x -y ${TMP_FILENAME2} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + OUTPUT_QUIET + ) + + else() + execute_process( + COMMAND sh -c "${ORTHANC_FRAMEWORK_TAR} xfz ${ORTHANC_FRAMEWORK_ARCHIVE}" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + ) + endif() + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + if (NOT IS_DIRECTORY "${ORTHANC_ROOT}") + message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.") + endif() + endif() +endif()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/LinuxStandardBaseToolchain.cmake Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,66 @@ +# LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON + +INCLUDE(CMakeForceCompiler) + +SET(LSB_PATH $ENV{LSB_PATH}) +SET(LSB_CC $ENV{LSB_CC}) +SET(LSB_CXX $ENV{LSB_CXX}) +SET(LSB_TARGET_VERSION "4.0") + +IF ("${LSB_PATH}" STREQUAL "") + SET(LSB_PATH "/opt/lsb") +ENDIF() + +IF (EXISTS ${LSB_PATH}/lib64) + SET(LSB_TARGET_PROCESSOR "x86_64") + SET(LSB_LIBPATH ${LSB_PATH}/lib64-${LSB_TARGET_VERSION}) +ELSEIF (EXISTS ${LSB_PATH}/lib) + SET(LSB_TARGET_PROCESSOR "x86") + SET(LSB_LIBPATH ${LSB_PATH}/lib-${LSB_TARGET_VERSION}) +ELSE() + MESSAGE(FATAL_ERROR "Unable to detect the target processor architecture. Check the LSB_PATH environment variable.") +ENDIF() + +SET(LSB_CPPPATH ${LSB_PATH}/include) +SET(PKG_CONFIG_PATH ${LSB_LIBPATH}/pkgconfig/) + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Linux) +SET(CMAKE_SYSTEM_VERSION LinuxStandardBase) +SET(CMAKE_SYSTEM_PROCESSOR ${LSB_TARGET_PROCESSOR}) + +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER ${LSB_PATH}/bin/lsbcc) +CMAKE_FORCE_CXX_COMPILER(${LSB_PATH}/bin/lsbc++ GNU) + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH ${LSB_PATH}) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + +SET(CMAKE_CROSSCOMPILING OFF) + + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include" CACHE INTERNAL "" FORCE) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward" CACHE INTERNAL "" FORCE) +SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) + +if (NOT "${LSB_CXX}" STREQUAL "") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cxx=${LSB_CXX}") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") +endif() + +if (NOT "${LSB_CC}" STREQUAL "") + SET(CMAKE_C_FLAGS "${CMAKE_CC_FLAGS} --lsb-cc=${LSB_CC}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cc=${LSB_CC}") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cc=${LSB_CC}") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cc=${LSB_CC}") +endif() +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/MinGW-W64-Toolchain32.cmake Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,17 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) +set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/MinGW-W64-Toolchain64.cmake Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,17 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/MinGWToolchain.cmake Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,17 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER i586-mingw32msvc-gcc) +set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++) +set(CMAKE_RC_COMPILER i586-mingw32msvc-windres) + +# here is the target environment located +set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/README.txt Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,3 @@ +This folder contains an excerpt of the source code of Orthanc. It is +automatically generated using the "/Resources/SyncOrthancFolder.py" +script.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCDatabasePlugin.h Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,808 @@ +/** + * @ingroup CInterface + **/ + +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + + +#pragma once + +#include "OrthancCPlugin.h" + + +/** @{ */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + + /** + * Opaque structure that represents the context of a custom database engine. + * @ingroup Callbacks + **/ + typedef struct _OrthancPluginDatabaseContext_t OrthancPluginDatabaseContext; + + +/*<! @cond Doxygen_Suppress */ + typedef enum + { + _OrthancPluginDatabaseAnswerType_None = 0, + + /* Events */ + _OrthancPluginDatabaseAnswerType_DeletedAttachment = 1, + _OrthancPluginDatabaseAnswerType_DeletedResource = 2, + _OrthancPluginDatabaseAnswerType_RemainingAncestor = 3, + + /* Return value */ + _OrthancPluginDatabaseAnswerType_Attachment = 10, + _OrthancPluginDatabaseAnswerType_Change = 11, + _OrthancPluginDatabaseAnswerType_DicomTag = 12, + _OrthancPluginDatabaseAnswerType_ExportedResource = 13, + _OrthancPluginDatabaseAnswerType_Int32 = 14, + _OrthancPluginDatabaseAnswerType_Int64 = 15, + _OrthancPluginDatabaseAnswerType_Resource = 16, + _OrthancPluginDatabaseAnswerType_String = 17, + + _OrthancPluginDatabaseAnswerType_INTERNAL = 0x7fffffff + } _OrthancPluginDatabaseAnswerType; + + + typedef struct + { + const char* uuid; + int32_t contentType; + uint64_t uncompressedSize; + const char* uncompressedHash; + int32_t compressionType; + uint64_t compressedSize; + const char* compressedHash; + } OrthancPluginAttachment; + + typedef struct + { + uint16_t group; + uint16_t element; + const char* value; + } OrthancPluginDicomTag; + + typedef struct + { + int64_t seq; + int32_t changeType; + OrthancPluginResourceType resourceType; + const char* publicId; + const char* date; + } OrthancPluginChange; + + typedef struct + { + int64_t seq; + OrthancPluginResourceType resourceType; + const char* publicId; + const char* modality; + const char* date; + const char* patientId; + const char* studyInstanceUid; + const char* seriesInstanceUid; + const char* sopInstanceUid; + } OrthancPluginExportedResource; + + + typedef struct + { + OrthancPluginDatabaseContext* database; + _OrthancPluginDatabaseAnswerType type; + int32_t valueInt32; + uint32_t valueUint32; + int64_t valueInt64; + const char *valueString; + const void *valueGeneric; + } _OrthancPluginDatabaseAnswer; + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerString( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const char* value) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_String; + params.valueString = value; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChange( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginChange* change) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Change; + params.valueUint32 = 0; + params.valueGeneric = change; + + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerChangesDone( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Change; + params.valueUint32 = 1; + params.valueGeneric = NULL; + + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt32( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + int32_t value) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Int32; + params.valueInt32 = value; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerInt64( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + int64_t value) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Int64; + params.valueInt64 = value; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResource( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginExportedResource* exported) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_ExportedResource; + params.valueUint32 = 0; + params.valueGeneric = exported; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerExportedResourcesDone( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_ExportedResource; + params.valueUint32 = 1; + params.valueGeneric = NULL; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerDicomTag( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginDicomTag* tag) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_DicomTag; + params.valueGeneric = tag; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerAttachment( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginAttachment* attachment) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Attachment; + params.valueGeneric = attachment; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseAnswerResource( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + int64_t id, + OrthancPluginResourceType resourceType) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_Resource; + params.valueInt64 = id; + params.valueInt32 = (int32_t) resourceType; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedAttachment( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const OrthancPluginAttachment* attachment) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_DeletedAttachment; + params.valueGeneric = attachment; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalDeletedResource( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const char* publicId, + OrthancPluginResourceType resourceType) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_DeletedResource; + params.valueString = publicId; + params.valueInt32 = (int32_t) resourceType; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + ORTHANC_PLUGIN_INLINE void OrthancPluginDatabaseSignalRemainingAncestor( + OrthancPluginContext* context, + OrthancPluginDatabaseContext* database, + const char* ancestorId, + OrthancPluginResourceType ancestorType) + { + _OrthancPluginDatabaseAnswer params; + memset(¶ms, 0, sizeof(params)); + params.database = database; + params.type = _OrthancPluginDatabaseAnswerType_RemainingAncestor; + params.valueString = ancestorId; + params.valueInt32 = (int32_t) ancestorType; + context->InvokeService(context, _OrthancPluginService_DatabaseAnswer, ¶ms); + } + + + + + + typedef struct + { + OrthancPluginErrorCode (*addAttachment) ( + /* inputs */ + void* payload, + int64_t id, + const OrthancPluginAttachment* attachment); + + OrthancPluginErrorCode (*attachChild) ( + /* inputs */ + void* payload, + int64_t parent, + int64_t child); + + OrthancPluginErrorCode (*clearChanges) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*clearExportedResources) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*createResource) ( + /* outputs */ + int64_t* id, + /* inputs */ + void* payload, + const char* publicId, + OrthancPluginResourceType resourceType); + + OrthancPluginErrorCode (*deleteAttachment) ( + /* inputs */ + void* payload, + int64_t id, + int32_t contentType); + + OrthancPluginErrorCode (*deleteMetadata) ( + /* inputs */ + void* payload, + int64_t id, + int32_t metadataType); + + OrthancPluginErrorCode (*deleteResource) ( + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*getAllPublicIds) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType); + + /* Output: Use OrthancPluginDatabaseAnswerChange() and + * OrthancPluginDatabaseAnswerChangesDone() */ + OrthancPluginErrorCode (*getChanges) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t since, + uint32_t maxResult); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*getChildrenInternalId) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*getChildrenPublicId) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerExportedResource() and + * OrthancPluginDatabaseAnswerExportedResourcesDone() */ + OrthancPluginErrorCode (*getExportedResources) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t since, + uint32_t maxResult); + + /* Output: Use OrthancPluginDatabaseAnswerChange() */ + OrthancPluginErrorCode (*getLastChange) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload); + + /* Output: Use OrthancPluginDatabaseAnswerExportedResource() */ + OrthancPluginErrorCode (*getLastExportedResource) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload); + + /* Output: Use OrthancPluginDatabaseAnswerDicomTag() */ + OrthancPluginErrorCode (*getMainDicomTags) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*getPublicId) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + OrthancPluginErrorCode (*getResourceCount) ( + /* outputs */ + uint64_t* target, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType); + + OrthancPluginErrorCode (*getResourceType) ( + /* outputs */ + OrthancPluginResourceType* resourceType, + /* inputs */ + void* payload, + int64_t id); + + OrthancPluginErrorCode (*getTotalCompressedSize) ( + /* outputs */ + uint64_t* target, + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*getTotalUncompressedSize) ( + /* outputs */ + uint64_t* target, + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*isExistingResource) ( + /* outputs */ + int32_t* existing, + /* inputs */ + void* payload, + int64_t id); + + OrthancPluginErrorCode (*isProtectedPatient) ( + /* outputs */ + int32_t* isProtected, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerInt32() */ + OrthancPluginErrorCode (*listAvailableMetadata) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerInt32() */ + OrthancPluginErrorCode (*listAvailableAttachments) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + OrthancPluginErrorCode (*logChange) ( + /* inputs */ + void* payload, + const OrthancPluginChange* change); + + OrthancPluginErrorCode (*logExportedResource) ( + /* inputs */ + void* payload, + const OrthancPluginExportedResource* exported); + + /* Output: Use OrthancPluginDatabaseAnswerAttachment() */ + OrthancPluginErrorCode (*lookupAttachment) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id, + int32_t contentType); + + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*lookupGlobalProperty) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int32_t property); + + /* Use "OrthancPluginDatabaseExtensions::lookupIdentifier3" + instead of this function as of Orthanc 0.9.5 (db v6), can be set to NULL. + Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifier) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + const OrthancPluginDicomTag* tag); + + /* Unused starting with Orthanc 0.9.5 (db v6), can be set to NULL. + Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifier2) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + const char* value); + + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*lookupMetadata) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id, + int32_t metadata); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupParent) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerResource() */ + OrthancPluginErrorCode (*lookupResource) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + const char* publicId); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*selectPatientToRecycle) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*selectPatientToRecycle2) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + int64_t patientIdToAvoid); + + OrthancPluginErrorCode (*setGlobalProperty) ( + /* inputs */ + void* payload, + int32_t property, + const char* value); + + OrthancPluginErrorCode (*setMainDicomTag) ( + /* inputs */ + void* payload, + int64_t id, + const OrthancPluginDicomTag* tag); + + OrthancPluginErrorCode (*setIdentifierTag) ( + /* inputs */ + void* payload, + int64_t id, + const OrthancPluginDicomTag* tag); + + OrthancPluginErrorCode (*setMetadata) ( + /* inputs */ + void* payload, + int64_t id, + int32_t metadata, + const char* value); + + OrthancPluginErrorCode (*setProtectedPatient) ( + /* inputs */ + void* payload, + int64_t id, + int32_t isProtected); + + OrthancPluginErrorCode (*startTransaction) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*rollbackTransaction) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*commitTransaction) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*open) ( + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*close) ( + /* inputs */ + void* payload); + + } OrthancPluginDatabaseBackend; + + + typedef struct + { + /* Output: Use OrthancPluginDatabaseAnswerString() */ + OrthancPluginErrorCode (*getAllPublicIdsWithLimit) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType, + uint64_t since, + uint64_t limit); + + OrthancPluginErrorCode (*getDatabaseVersion) ( + /* outputs */ + uint32_t* version, + /* inputs */ + void* payload); + + OrthancPluginErrorCode (*upgradeDatabase) ( + /* inputs */ + void* payload, + uint32_t targetVersion, + OrthancPluginStorageArea* storageArea); + + OrthancPluginErrorCode (*clearMainDicomTags) ( + /* inputs */ + void* payload, + int64_t id); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*getAllInternalIds) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType); + + /* Output: Use OrthancPluginDatabaseAnswerInt64() */ + OrthancPluginErrorCode (*lookupIdentifier3) ( + /* outputs */ + OrthancPluginDatabaseContext* context, + /* inputs */ + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag, + OrthancPluginIdentifierConstraint constraint); + } OrthancPluginDatabaseExtensions; + +/*<! @endcond */ + + + typedef struct + { + OrthancPluginDatabaseContext** result; + const OrthancPluginDatabaseBackend* backend; + void* payload; + } _OrthancPluginRegisterDatabaseBackend; + + /** + * Register a custom database back-end. + * + * Instead of manually filling the OrthancPluginDatabaseBackend + * structure, you should instead implement a concrete C++ class + * deriving from ::OrthancPlugins::IDatabaseBackend, and register it + * using ::OrthancPlugins::DatabaseBackendAdapter::Register(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param backend The callbacks of the custom database engine. + * @param payload Pointer containing private information for the database engine. + * @return The context of the database engine (it must not be manually freed). + * @ingroup Callbacks + * @deprecated + * @see OrthancPluginRegisterDatabaseBackendV2 + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginDatabaseContext* OrthancPluginRegisterDatabaseBackend( + OrthancPluginContext* context, + const OrthancPluginDatabaseBackend* backend, + void* payload) + { + OrthancPluginDatabaseContext* result = NULL; + _OrthancPluginRegisterDatabaseBackend params; + + if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) + { + return NULL; + } + + memset(¶ms, 0, sizeof(params)); + params.backend = backend; + params.result = &result; + params.payload = payload; + + if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackend, ¶ms) || + result == NULL) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + typedef struct + { + OrthancPluginDatabaseContext** result; + const OrthancPluginDatabaseBackend* backend; + void* payload; + const OrthancPluginDatabaseExtensions* extensions; + uint32_t extensionsSize; + } _OrthancPluginRegisterDatabaseBackendV2; + + + /** + * Register a custom database back-end. + * + * Instead of manually filling the OrthancPluginDatabaseBackendV2 + * structure, you should instead implement a concrete C++ class + * deriving from ::OrthancPlugins::IDatabaseBackend, and register it + * using ::OrthancPlugins::DatabaseBackendAdapter::Register(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param backend The callbacks of the custom database engine. + * @param payload Pointer containing private information for the database engine. + * @param extensions Extensions to the base database SDK that was shipped until Orthanc 0.9.3. + * @return The context of the database engine (it must not be manually freed). + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginDatabaseContext* OrthancPluginRegisterDatabaseBackendV2( + OrthancPluginContext* context, + const OrthancPluginDatabaseBackend* backend, + const OrthancPluginDatabaseExtensions* extensions, + void* payload) + { + OrthancPluginDatabaseContext* result = NULL; + _OrthancPluginRegisterDatabaseBackendV2 params; + + if (sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType)) + { + return NULL; + } + + memset(¶ms, 0, sizeof(params)); + params.backend = backend; + params.result = &result; + params.payload = payload; + params.extensions = extensions; + params.extensionsSize = sizeof(OrthancPluginDatabaseExtensions); + + if (context->InvokeService(context, _OrthancPluginService_RegisterDatabaseBackendV2, ¶ms) || + result == NULL) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + +#ifdef __cplusplus +} +#endif + + +/** @} */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCPlugin.h Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,4686 @@ +/** + * \mainpage + * + * This C/C++ SDK allows external developers to create plugins that + * can be loaded into Orthanc to extend its functionality. Each + * Orthanc plugin must expose 4 public functions with the following + * signatures: + * + * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>: + * This function is invoked by Orthanc when it loads the plugin on startup. + * The plugin must: + * - Check its compatibility with the Orthanc version using + * ::OrthancPluginCheckVersion(). + * - Store the context pointer so that it can use the plugin + * services of Orthanc. + * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback(). + * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback(). + * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback(). + * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea(). + * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV2(). + * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). + * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). + * -# <tt>void OrthancPluginFinalize()</tt>: + * This function is invoked by Orthanc during its shutdown. The plugin + * must free all its memory. + * -# <tt>const char* OrthancPluginGetName()</tt>: + * The plugin must return a short string to identify itself. + * -# <tt>const char* OrthancPluginGetVersion()</tt>: + * The plugin must return a string containing its version number. + * + * The name and the version of a plugin is only used to prevent it + * from being loaded twice. Note that, in C++, it is mandatory to + * declare these functions within an <tt>extern "C"</tt> section. + * + * To ensure multi-threading safety, the various REST callbacks are + * guaranteed to be executed in mutual exclusion since Orthanc + * 0.8.5. If this feature is undesired (notably when developing + * high-performance plugins handling simultaneous requests), use + * ::OrthancPluginRegisterRestCallbackNoLock(). + **/ + + + +/** + * @defgroup Images Images and compression + * @brief Functions to deal with images and compressed buffers. + * + * @defgroup REST REST + * @brief Functions to answer REST requests in a callback. + * + * @defgroup Callbacks Callbacks + * @brief Functions to register and manage callbacks by the plugins. + * + * @defgroup Worklists Worklists + * @brief Functions to register and manage worklists. + * + * @defgroup Orthanc Orthanc + * @brief Functions to access the content of the Orthanc server. + **/ + + + +/** + * @defgroup Toolbox Toolbox + * @brief Generic functions to help with the creation of plugins. + **/ + + + +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + + +#pragma once + + +#include <stdio.h> +#include <string.h> + +#ifdef WIN32 +#define ORTHANC_PLUGINS_API __declspec(dllexport) +#else +#define ORTHANC_PLUGINS_API +#endif + +#define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0 +#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 9 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 5 + + + +/******************************************************************** + ** Check that function inlining is properly supported. The use of + ** inlining is required, to avoid the duplication of object code + ** between two compilation modules that would use the Orthanc Plugin + ** API. + ********************************************************************/ + +/* If the auto-detection of the "inline" keyword below does not work + automatically and that your compiler is known to properly support + inlining, uncomment the following #define and adapt the definition + of "static inline". */ + +/* #define ORTHANC_PLUGIN_INLINE static inline */ + +#ifndef ORTHANC_PLUGIN_INLINE +# if __STDC_VERSION__ >= 199901L +/* This is C99 or above: http://predef.sourceforge.net/prestd.html */ +# define ORTHANC_PLUGIN_INLINE static inline +# elif defined(__cplusplus) +/* This is C++ */ +# define ORTHANC_PLUGIN_INLINE static inline +# elif defined(__GNUC__) +/* This is GCC running in C89 mode */ +# define ORTHANC_PLUGIN_INLINE static __inline +# elif defined(_MSC_VER) +/* This is Visual Studio running in C89 mode */ +# define ORTHANC_PLUGIN_INLINE static __inline +# else +# error Your compiler is not known to support the "inline" keyword +# endif +#endif + + + +/******************************************************************** + ** Inclusion of standard libraries. + ********************************************************************/ + +/** + * For Microsoft Visual Studio, a compatibility "stdint.h" can be + * downloaded at the following URL: + * https://orthanc.googlecode.com/hg/Resources/ThirdParty/VisualStudio/stdint.h + **/ +#include <stdint.h> + +#include <stdlib.h> + + + +/******************************************************************** + ** Definition of the Orthanc Plugin API. + ********************************************************************/ + +/** @{ */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * The various error codes that can be returned by the Orthanc core. + **/ + typedef enum + { + OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */, + OrthancPluginErrorCode_Success = 0 /*!< Success */, + OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */, + OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */, + OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */, + OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< Not enough memory */, + OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */, + OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */, + OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */, + OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */, + OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */, + OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */, + OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */, + OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */, + OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */, + OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */, + OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */, + OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */, + OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */, + OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */, + OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */, + OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */, + OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */, + OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */, + OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */, + OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */, + OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */, + OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */, + OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */, + OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */, + OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */, + OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */, + OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */, + OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */, + OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */, + OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */, + OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */, + OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */, + OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */, + OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */, + OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */, + OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */, + OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */, + OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */, + OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */, + OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */, + OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */, + OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */, + OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */, + OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */, + OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */, + OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */, + OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */, + OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */, + OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */, + OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is already in use */, + OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is already in use */, + OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */, + OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */, + OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */, + OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */, + OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */, + OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */, + OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */, + OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */, + OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */, + OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */, + OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */, + OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */, + OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */, + OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */, + OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */, + OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */, + OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */, + OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */, + OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */, + OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */, + OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */, + OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */, + OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */, + OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */, + OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */, + OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */, + OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */, + OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */, + OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */, + OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */, + OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */, + OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */, + OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */, + OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */, + OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */, + OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */, + OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */, + + _OrthancPluginErrorCode_INTERNAL = 0x7fffffff + } OrthancPluginErrorCode; + + + /** + * Forward declaration of one of the mandatory functions for Orthanc + * plugins. + **/ + ORTHANC_PLUGINS_API const char* OrthancPluginGetName(); + + + /** + * The various HTTP methods for a REST call. + **/ + typedef enum + { + OrthancPluginHttpMethod_Get = 1, /*!< GET request */ + OrthancPluginHttpMethod_Post = 2, /*!< POST request */ + OrthancPluginHttpMethod_Put = 3, /*!< PUT request */ + OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */ + + _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff + } OrthancPluginHttpMethod; + + + /** + * @brief The parameters of a REST request. + * @ingroup Callbacks + **/ + typedef struct + { + /** + * @brief The HTTP method. + **/ + OrthancPluginHttpMethod method; + + /** + * @brief The number of groups of the regular expression. + **/ + uint32_t groupsCount; + + /** + * @brief The matched values for the groups of the regular expression. + **/ + const char* const* groups; + + /** + * @brief For a GET request, the number of GET parameters. + **/ + uint32_t getCount; + + /** + * @brief For a GET request, the keys of the GET parameters. + **/ + const char* const* getKeys; + + /** + * @brief For a GET request, the values of the GET parameters. + **/ + const char* const* getValues; + + /** + * @brief For a PUT or POST request, the content of the body. + **/ + const char* body; + + /** + * @brief For a PUT or POST request, the number of bytes of the body. + **/ + uint32_t bodySize; + + + /* -------------------------------------------------- + New in version 0.8.1 + -------------------------------------------------- */ + + /** + * @brief The number of HTTP headers. + **/ + uint32_t headersCount; + + /** + * @brief The keys of the HTTP headers (always converted to low-case). + **/ + const char* const* headersKeys; + + /** + * @brief The values of the HTTP headers. + **/ + const char* const* headersValues; + + } OrthancPluginHttpRequest; + + + typedef enum + { + /* Generic services */ + _OrthancPluginService_LogInfo = 1, + _OrthancPluginService_LogWarning = 2, + _OrthancPluginService_LogError = 3, + _OrthancPluginService_GetOrthancPath = 4, + _OrthancPluginService_GetOrthancDirectory = 5, + _OrthancPluginService_GetConfigurationPath = 6, + _OrthancPluginService_SetPluginProperty = 7, + _OrthancPluginService_GetGlobalProperty = 8, + _OrthancPluginService_SetGlobalProperty = 9, + _OrthancPluginService_GetCommandLineArgumentsCount = 10, + _OrthancPluginService_GetCommandLineArgument = 11, + _OrthancPluginService_GetExpectedDatabaseVersion = 12, + _OrthancPluginService_GetConfiguration = 13, + _OrthancPluginService_BufferCompression = 14, + _OrthancPluginService_ReadFile = 15, + _OrthancPluginService_WriteFile = 16, + _OrthancPluginService_GetErrorDescription = 17, + _OrthancPluginService_CallHttpClient = 18, + _OrthancPluginService_RegisterErrorCode = 19, + _OrthancPluginService_RegisterDictionaryTag = 20, + _OrthancPluginService_DicomBufferToJson = 21, + _OrthancPluginService_DicomInstanceToJson = 22, + _OrthancPluginService_CreateDicom = 23, + _OrthancPluginService_ComputeMd5 = 24, + _OrthancPluginService_ComputeSha1 = 25, + _OrthancPluginService_LookupDictionary = 26, + + /* Registration of callbacks */ + _OrthancPluginService_RegisterRestCallback = 1000, + _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, + _OrthancPluginService_RegisterStorageArea = 1002, + _OrthancPluginService_RegisterOnChangeCallback = 1003, + _OrthancPluginService_RegisterRestCallbackNoLock = 1004, + _OrthancPluginService_RegisterWorklistCallback = 1005, + _OrthancPluginService_RegisterDecodeImageCallback = 1006, + + /* Sending answers to REST calls */ + _OrthancPluginService_AnswerBuffer = 2000, + _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */ + _OrthancPluginService_Redirect = 2002, + _OrthancPluginService_SendHttpStatusCode = 2003, + _OrthancPluginService_SendUnauthorized = 2004, + _OrthancPluginService_SendMethodNotAllowed = 2005, + _OrthancPluginService_SetCookie = 2006, + _OrthancPluginService_SetHttpHeader = 2007, + _OrthancPluginService_StartMultipartAnswer = 2008, + _OrthancPluginService_SendMultipartItem = 2009, + _OrthancPluginService_SendHttpStatus = 2010, + _OrthancPluginService_CompressAndAnswerImage = 2011, + + /* Access to the Orthanc database and API */ + _OrthancPluginService_GetDicomForInstance = 3000, + _OrthancPluginService_RestApiGet = 3001, + _OrthancPluginService_RestApiPost = 3002, + _OrthancPluginService_RestApiDelete = 3003, + _OrthancPluginService_RestApiPut = 3004, + _OrthancPluginService_LookupPatient = 3005, + _OrthancPluginService_LookupStudy = 3006, + _OrthancPluginService_LookupSeries = 3007, + _OrthancPluginService_LookupInstance = 3008, + _OrthancPluginService_LookupStudyWithAccessionNumber = 3009, + _OrthancPluginService_RestApiGetAfterPlugins = 3010, + _OrthancPluginService_RestApiPostAfterPlugins = 3011, + _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, + _OrthancPluginService_RestApiPutAfterPlugins = 3013, + _OrthancPluginService_ReconstructMainDicomTags = 3014, + _OrthancPluginService_RestApiGet2 = 3015, + + /* Access to DICOM instances */ + _OrthancPluginService_GetInstanceRemoteAet = 4000, + _OrthancPluginService_GetInstanceSize = 4001, + _OrthancPluginService_GetInstanceData = 4002, + _OrthancPluginService_GetInstanceJson = 4003, + _OrthancPluginService_GetInstanceSimplifiedJson = 4004, + _OrthancPluginService_HasInstanceMetadata = 4005, + _OrthancPluginService_GetInstanceMetadata = 4006, + _OrthancPluginService_GetInstanceOrigin = 4007, + + /* Services for plugins implementing a database back-end */ + _OrthancPluginService_RegisterDatabaseBackend = 5000, + _OrthancPluginService_DatabaseAnswer = 5001, + _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, + _OrthancPluginService_StorageAreaCreate = 5003, + _OrthancPluginService_StorageAreaRead = 5004, + _OrthancPluginService_StorageAreaRemove = 5005, + + /* Primitives for handling images */ + _OrthancPluginService_GetImagePixelFormat = 6000, + _OrthancPluginService_GetImageWidth = 6001, + _OrthancPluginService_GetImageHeight = 6002, + _OrthancPluginService_GetImagePitch = 6003, + _OrthancPluginService_GetImageBuffer = 6004, + _OrthancPluginService_UncompressImage = 6005, + _OrthancPluginService_FreeImage = 6006, + _OrthancPluginService_CompressImage = 6007, + _OrthancPluginService_ConvertPixelFormat = 6008, + _OrthancPluginService_GetFontsCount = 6009, + _OrthancPluginService_GetFontInfo = 6010, + _OrthancPluginService_DrawText = 6011, + _OrthancPluginService_CreateImage = 6012, + _OrthancPluginService_CreateImageAccessor = 6013, + _OrthancPluginService_DecodeDicomImage = 6014, + + /* Primitives for handling worklists */ + _OrthancPluginService_WorklistAddAnswer = 7000, + _OrthancPluginService_WorklistMarkIncomplete = 7001, + _OrthancPluginService_WorklistIsMatch = 7002, + _OrthancPluginService_WorklistGetDicomQuery = 7003, + + _OrthancPluginService_INTERNAL = 0x7fffffff + } _OrthancPluginService; + + + typedef enum + { + _OrthancPluginProperty_Description = 1, + _OrthancPluginProperty_RootUri = 2, + _OrthancPluginProperty_OrthancExplorer = 3, + + _OrthancPluginProperty_INTERNAL = 0x7fffffff + } _OrthancPluginProperty; + + + + /** + * The memory layout of the pixels of an image. + * @ingroup Images + **/ + typedef enum + { + /** + * @brief Graylevel 8bpp image. + * + * The image is graylevel. Each pixel is unsigned and stored in + * one byte. + **/ + OrthancPluginPixelFormat_Grayscale8 = 1, + + /** + * @brief Graylevel, unsigned 16bpp image. + * + * The image is graylevel. Each pixel is unsigned and stored in + * two bytes. + **/ + OrthancPluginPixelFormat_Grayscale16 = 2, + + /** + * @brief Graylevel, signed 16bpp image. + * + * The image is graylevel. Each pixel is signed and stored in two + * bytes. + **/ + OrthancPluginPixelFormat_SignedGrayscale16 = 3, + + /** + * @brief Color image in RGB24 format. + * + * This format describes a color image. The pixels are stored in 3 + * consecutive bytes. The memory layout is RGB. + **/ + OrthancPluginPixelFormat_RGB24 = 4, + + /** + * @brief Color image in RGBA32 format. + * + * This format describes a color image. The pixels are stored in 4 + * consecutive bytes. The memory layout is RGBA. + **/ + OrthancPluginPixelFormat_RGBA32 = 5, + + OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */ + + _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff + } OrthancPluginPixelFormat; + + + + /** + * The content types that are supported by Orthanc plugins. + **/ + typedef enum + { + OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */ + OrthancPluginContentType_Dicom = 1, /*!< DICOM */ + OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */ + + _OrthancPluginContentType_INTERNAL = 0x7fffffff + } OrthancPluginContentType; + + + + /** + * The supported types of DICOM resources. + **/ + typedef enum + { + OrthancPluginResourceType_Patient = 0, /*!< Patient */ + OrthancPluginResourceType_Study = 1, /*!< Study */ + OrthancPluginResourceType_Series = 2, /*!< Series */ + OrthancPluginResourceType_Instance = 3, /*!< Instance */ + OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */ + + _OrthancPluginResourceType_INTERNAL = 0x7fffffff + } OrthancPluginResourceType; + + + + /** + * The supported types of changes that can happen to DICOM resources. + * @ingroup Callbacks + **/ + typedef enum + { + OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */ + OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */ + OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */ + OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */ + OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */ + OrthancPluginChangeType_NewSeries = 5, /*!< New series created */ + OrthancPluginChangeType_NewStudy = 6, /*!< New study created */ + OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */ + OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */ + OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */ + OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */ + OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */ + OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */ + OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */ + + _OrthancPluginChangeType_INTERNAL = 0x7fffffff + } OrthancPluginChangeType; + + + /** + * The compression algorithms that are supported by the Orthanc core. + * @ingroup Images + **/ + typedef enum + { + OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */ + OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */ + OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */ + OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */ + + _OrthancPluginCompressionType_INTERNAL = 0x7fffffff + } OrthancPluginCompressionType; + + + /** + * The image formats that are supported by the Orthanc core. + * @ingroup Images + **/ + typedef enum + { + OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */ + OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */ + OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */ + + _OrthancPluginImageFormat_INTERNAL = 0x7fffffff + } OrthancPluginImageFormat; + + + /** + * The value representations present in the DICOM standard (version 2013). + * @ingroup Toolbox + **/ + typedef enum + { + OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */ + OrthancPluginValueRepresentation_AS = 2, /*!< Age String */ + OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */ + OrthancPluginValueRepresentation_CS = 4, /*!< Code String */ + OrthancPluginValueRepresentation_DA = 5, /*!< Date */ + OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */ + OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */ + OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */ + OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */ + OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */ + OrthancPluginValueRepresentation_LO = 11, /*!< Long String */ + OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */ + OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */ + OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */ + OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */ + OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */ + OrthancPluginValueRepresentation_SH = 17, /*!< Short String */ + OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */ + OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */ + OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */ + OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */ + OrthancPluginValueRepresentation_TM = 22, /*!< Time */ + OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */ + OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */ + OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */ + OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */ + OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */ + + _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff + } OrthancPluginValueRepresentation; + + + /** + * The possible output formats for a DICOM-to-JSON conversion. + * @ingroup Toolbox + * @see OrthancPluginDicomToJson() + **/ + typedef enum + { + OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */ + OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */ + OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */ + + _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff + } OrthancPluginDicomToJsonFormat; + + + /** + * Flags to customize a DICOM-to-JSON conversion. By default, binary + * tags are formatted using Data URI scheme. + * @ingroup Toolbox + **/ + typedef enum + { + OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */ + OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */ + OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */ + OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */ + OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */ + OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */ + + _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff + } OrthancPluginDicomToJsonFlags; + + + /** + * Flags to the creation of a DICOM file. + * @ingroup Toolbox + * @see OrthancPluginCreateDicom() + **/ + typedef enum + { + OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */ + OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */ + + _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff + } OrthancPluginCreateDicomFlags; + + + /** + * The constraints on the DICOM identifiers that must be supported + * by the database plugins. + **/ + typedef enum + { + OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */ + OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */ + OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */ + OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */ + + _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff + } OrthancPluginIdentifierConstraint; + + + /** + * The origin of a DICOM instance that has been received by Orthanc. + **/ + typedef enum + { + OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */ + OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */ + OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */ + OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */ + OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */ + + _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff + } OrthancPluginInstanceOrigin; + + + /** + * @brief A memory buffer allocated by the core system of Orthanc. + * + * A memory buffer allocated by the core system of Orthanc. When the + * content of the buffer is not useful anymore, it must be free by a + * call to ::OrthancPluginFreeMemoryBuffer(). + **/ + typedef struct + { + /** + * @brief The content of the buffer. + **/ + void* data; + + /** + * @brief The number of bytes in the buffer. + **/ + uint32_t size; + } OrthancPluginMemoryBuffer; + + + + + /** + * @brief Opaque structure that represents the HTTP connection to the client application. + * @ingroup Callback + **/ + typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput; + + + + /** + * @brief Opaque structure that represents a DICOM instance received by Orthanc. + **/ + typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance; + + + + /** + * @brief Opaque structure that represents an image that is uncompressed in memory. + * @ingroup Images + **/ + typedef struct _OrthancPluginImage_t OrthancPluginImage; + + + + /** + * @brief Opaque structure that represents the storage area that is actually used by Orthanc. + * @ingroup Images + **/ + typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea; + + + + /** + * @brief Opaque structure to an object that represents a C-Find query. + * @ingroup Worklists + **/ + typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; + + + + /** + * @brief Opaque structure to an object that represents the answers to a C-Find query. + * @ingroup Worklists + **/ + typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; + + + + /** + * @brief Signature of a callback function that answers to a REST request. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) ( + OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request); + + + + /** + * @brief Signature of a callback function that is triggered when Orthanc receives a DICOM instance. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) ( + OrthancPluginDicomInstance* instance, + const char* instanceId); + + + + /** + * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) ( + OrthancPluginChangeType changeType, + OrthancPluginResourceType resourceType, + const char* resourceId); + + + + /** + * @brief Signature of a callback function to decode a DICOM instance as an image. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) ( + OrthancPluginImage** target, + const void* dicom, + const uint32_t size, + uint32_t frameIndex); + + + + /** + * @brief Signature of a function to free dynamic memory. + **/ + typedef void (*OrthancPluginFree) (void* buffer); + + + + /** + * @brief Callback for writing to the storage area. + * + * Signature of a callback function that is triggered when Orthanc writes a file to the storage area. + * + * @param uuid The UUID of the file. + * @param content The content of the file. + * @param size The size of the file. + * @param type The content type corresponding to this file. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) ( + const char* uuid, + const void* content, + int64_t size, + OrthancPluginContentType type); + + + + /** + * @brief Callback for reading from the storage area. + * + * Signature of a callback function that is triggered when Orthanc reads a file from the storage area. + * + * @param content The content of the file (output). + * @param size The size of the file (output). + * @param uuid The UUID of the file of interest. + * @param type The content type corresponding to this file. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) ( + void** content, + int64_t* size, + const char* uuid, + OrthancPluginContentType type); + + + + /** + * @brief Callback for removing a file from the storage area. + * + * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area. + * + * @param uuid The UUID of the file to be removed. + * @param type The content type corresponding to this file. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) ( + const char* uuid, + OrthancPluginContentType type); + + + + /** + * @brief Callback to handle the C-Find SCP requests received by Orthanc. + * + * Signature of a callback function that is triggered when Orthanc + * receives a C-Find SCP request against modality worklists. + * + * @param answers The target structure where answers must be stored. + * @param query The worklist query. + * @param remoteAet The Application Entity Title (AET) of the modality from which the request originates. + * @param calledAet The Application Entity Title (AET) of the modality that is called by the request. + * @return 0 if success, other value if error. + * @ingroup Worklists + **/ + typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( + OrthancPluginWorklistAnswers* answers, + const OrthancPluginWorklistQuery* query, + const char* remoteAet, + const char* calledAet); + + + + /** + * @brief Data structure that contains information about the Orthanc core. + **/ + typedef struct _OrthancPluginContext_t + { + void* pluginsManager; + const char* orthancVersion; + OrthancPluginFree Free; + OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context, + _OrthancPluginService service, + const void* params); + } OrthancPluginContext; + + + + /** + * @brief An entry in the dictionary of DICOM tags. + **/ + typedef struct + { + uint16_t group; /*!< The group of the tag */ + uint16_t element; /*!< The element of the tag */ + OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */ + uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */ + uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */ + } OrthancPluginDictionaryEntry; + + + + /** + * @brief Free a string. + * + * Free a string that was allocated by the core system of Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param str The string to be freed. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString( + OrthancPluginContext* context, + char* str) + { + if (str != NULL) + { + context->Free(str); + } + } + + + /** + * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. + * + * This function checks whether the version of this C header is + * compatible with the current version of Orthanc. The result of + * this function should always be checked in the + * OrthancPluginInitialize() entry point of the plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return 1 if and only if the versions are compatible. If the + * result is 0, the initialization of the plugin should fail. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( + OrthancPluginContext* context) + { + int major, minor, revision; + + if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || + sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || + sizeof(int32_t) != sizeof(_OrthancPluginService) || + sizeof(int32_t) != sizeof(_OrthancPluginProperty) || + sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || + sizeof(int32_t) != sizeof(OrthancPluginContentType) || + sizeof(int32_t) != sizeof(OrthancPluginResourceType) || + sizeof(int32_t) != sizeof(OrthancPluginChangeType) || + sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || + sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || + sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || + sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || + sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) || + sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || + sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin)) + { + /* Mismatch in the size of the enumerations */ + return 0; + } + + /* Assume compatibility with the mainline */ + if (!strcmp(context->orthancVersion, "mainline")) + { + return 1; + } + + /* Parse the version of the Orthanc core */ + if ( +#ifdef _MSC_VER + sscanf_s +#else + sscanf +#endif + (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3) + { + return 0; + } + + /* Check the major number of the version */ + + if (major > ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) + { + return 1; + } + + if (major < ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER) + { + return 0; + } + + /* Check the minor number of the version */ + + if (minor > ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) + { + return 1; + } + + if (minor < ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER) + { + return 0; + } + + /* Check the revision number of the version */ + + if (revision >= ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER) + { + return 1; + } + else + { + return 0; + } + } + + + /** + * @brief Free a memory buffer. + * + * Free a memory buffer that was allocated by the core system of Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param buffer The memory buffer to release. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* buffer) + { + context->Free(buffer->data); + } + + + /** + * @brief Log an error. + * + * Log an error message using the Orthanc logging system. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param message The message to be logged. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginLogError( + OrthancPluginContext* context, + const char* message) + { + context->InvokeService(context, _OrthancPluginService_LogError, message); + } + + + /** + * @brief Log a warning. + * + * Log a warning message using the Orthanc logging system. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param message The message to be logged. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning( + OrthancPluginContext* context, + const char* message) + { + context->InvokeService(context, _OrthancPluginService_LogWarning, message); + } + + + /** + * @brief Log an information. + * + * Log an information message using the Orthanc logging system. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param message The message to be logged. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo( + OrthancPluginContext* context, + const char* message) + { + context->InvokeService(context, _OrthancPluginService_LogInfo, message); + } + + + + typedef struct + { + const char* pathRegularExpression; + OrthancPluginRestCallback callback; + } _OrthancPluginRestCallback; + + /** + * @brief Register a REST callback. + * + * This function registers a REST callback against a regular + * expression for a URI. This function must be called during the + * initialization of the plugin, i.e. inside the + * OrthancPluginInitialize() public function. + * + * Each REST callback is guaranteed to run in mutual exclusion. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param pathRegularExpression Regular expression for the URI. May contain groups. + * @param callback The callback function to handle the REST call. + * @see OrthancPluginRegisterRestCallbackNoLock() + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback( + OrthancPluginContext* context, + const char* pathRegularExpression, + OrthancPluginRestCallback callback) + { + _OrthancPluginRestCallback params; + params.pathRegularExpression = pathRegularExpression; + params.callback = callback; + context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, ¶ms); + } + + + + /** + * @brief Register a REST callback, without locking. + * + * This function registers a REST callback against a regular + * expression for a URI. This function must be called during the + * initialization of the plugin, i.e. inside the + * OrthancPluginInitialize() public function. + * + * Contrarily to OrthancPluginRegisterRestCallback(), the callback + * will NOT be invoked in mutual exclusion. This can be useful for + * high-performance plugins that must handle concurrent requests + * (Orthanc uses a pool of threads, one thread being assigned to + * each incoming HTTP request). Of course, it is up to the plugin to + * implement the required locking mechanisms. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param pathRegularExpression Regular expression for the URI. May contain groups. + * @param callback The callback function to handle the REST call. + * @see OrthancPluginRegisterRestCallback() + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock( + OrthancPluginContext* context, + const char* pathRegularExpression, + OrthancPluginRestCallback callback) + { + _OrthancPluginRestCallback params; + params.pathRegularExpression = pathRegularExpression; + params.callback = callback; + context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, ¶ms); + } + + + + typedef struct + { + OrthancPluginOnStoredInstanceCallback callback; + } _OrthancPluginOnStoredInstanceCallback; + + /** + * @brief Register a callback for received instances. + * + * This function registers a callback function that is called + * whenever a new DICOM instance is stored into the Orthanc core. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The callback function. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback( + OrthancPluginContext* context, + OrthancPluginOnStoredInstanceCallback callback) + { + _OrthancPluginOnStoredInstanceCallback params; + params.callback = callback; + + context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, ¶ms); + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* answer; + uint32_t answerSize; + const char* mimeType; + } _OrthancPluginAnswerBuffer; + + /** + * @brief Answer to a REST request. + * + * This function answers to a REST request with the content of a memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param answer Pointer to the memory buffer containing the answer. + * @param answerSize Number of bytes of the answer. + * @param mimeType The MIME type of the answer. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* answer, + uint32_t answerSize, + const char* mimeType) + { + _OrthancPluginAnswerBuffer params; + params.output = output; + params.answer = answer; + params.answerSize = answerSize; + params.mimeType = mimeType; + context->InvokeService(context, _OrthancPluginService_AnswerBuffer, ¶ms); + } + + + typedef struct + { + OrthancPluginRestOutput* output; + OrthancPluginPixelFormat format; + uint32_t width; + uint32_t height; + uint32_t pitch; + const void* buffer; + } _OrthancPluginCompressAndAnswerPngImage; + + typedef struct + { + OrthancPluginRestOutput* output; + OrthancPluginImageFormat imageFormat; + OrthancPluginPixelFormat pixelFormat; + uint32_t width; + uint32_t height; + uint32_t pitch; + const void* buffer; + uint8_t quality; + } _OrthancPluginCompressAndAnswerImage; + + + /** + * @brief Answer to a REST request with a PNG image. + * + * This function answers to a REST request with a PNG image. The + * parameters of this function describe a memory buffer that + * contains an uncompressed image. The image will be automatically compressed + * as a PNG image by the core system of Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param format The memory layout of the uncompressed image. + * @param width The width of the image. + * @param height The height of the image. + * @param pitch The pitch of the image (i.e. the number of bytes + * between 2 successive lines of the image in the memory buffer). + * @param buffer The memory buffer containing the uncompressed image. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + const void* buffer) + { + _OrthancPluginCompressAndAnswerImage params; + params.output = output; + params.imageFormat = OrthancPluginImageFormat_Png; + params.pixelFormat = format; + params.width = width; + params.height = height; + params.pitch = pitch; + params.buffer = buffer; + params.quality = 0; /* No quality for PNG */ + context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* instanceId; + } _OrthancPluginGetDicomForInstance; + + /** + * @brief Retrieve a DICOM instance using its Orthanc identifier. + * + * Retrieve a DICOM instance using its Orthanc identifier. The DICOM + * file is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param instanceId The Orthanc identifier of the DICOM instance of interest. + * @return 0 if success, or the error code if failure. + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* instanceId) + { + _OrthancPluginGetDicomForInstance params; + params.target = target; + params.instanceId = instanceId; + return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* uri; + } _OrthancPluginRestApiGet; + + /** + * @brief Make a GET call to the built-in Orthanc REST API. + * + * Make a GET call to the built-in Orthanc REST API. The result to + * the query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiGetAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri) + { + _OrthancPluginRestApiGet params; + params.target = target; + params.uri = uri; + return context->InvokeService(context, _OrthancPluginService_RestApiGet, ¶ms); + } + + + + /** + * @brief Make a GET call to the REST API, as tainted by the plugins. + * + * Make a GET call to the Orthanc REST API, after all the plugins + * are applied. In other words, if some plugin overrides or adds the + * called URI to the built-in Orthanc REST API, this call will + * return the result provided by this plugin. The result to the + * query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiGet + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri) + { + _OrthancPluginRestApiGet params; + params.target = target; + params.uri = uri; + return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* uri; + const char* body; + uint32_t bodySize; + } _OrthancPluginRestApiPostPut; + + /** + * @brief Make a POST call to the built-in Orthanc REST API. + * + * Make a POST call to the built-in Orthanc REST API. The result to + * the query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @param body The body of the POST request. + * @param bodySize The size of the body. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiPostAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const char* body, + uint32_t bodySize) + { + _OrthancPluginRestApiPostPut params; + params.target = target; + params.uri = uri; + params.body = body; + params.bodySize = bodySize; + return context->InvokeService(context, _OrthancPluginService_RestApiPost, ¶ms); + } + + + /** + * @brief Make a POST call to the REST API, as tainted by the plugins. + * + * Make a POST call to the Orthanc REST API, after all the plugins + * are applied. In other words, if some plugin overrides or adds the + * called URI to the built-in Orthanc REST API, this call will + * return the result provided by this plugin. The result to the + * query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @param body The body of the POST request. + * @param bodySize The size of the body. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiPost + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const char* body, + uint32_t bodySize) + { + _OrthancPluginRestApiPostPut params; + params.target = target; + params.uri = uri; + params.body = body; + params.bodySize = bodySize; + return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, ¶ms); + } + + + + /** + * @brief Make a DELETE call to the built-in Orthanc REST API. + * + * Make a DELETE call to the built-in Orthanc REST API. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param uri The URI to delete in the built-in Orthanc API. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiDeleteAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete( + OrthancPluginContext* context, + const char* uri) + { + return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri); + } + + + /** + * @brief Make a DELETE call to the REST API, as tainted by the plugins. + * + * Make a DELETE call to the Orthanc REST API, after all the plugins + * are applied. In other words, if some plugin overrides or adds the + * called URI to the built-in Orthanc REST API, this call will + * return the result provided by this plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param uri The URI to delete in the built-in Orthanc API. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiDelete + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins( + OrthancPluginContext* context, + const char* uri) + { + return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri); + } + + + + /** + * @brief Make a PUT call to the built-in Orthanc REST API. + * + * Make a PUT call to the built-in Orthanc REST API. The result to + * the query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @param body The body of the PUT request. + * @param bodySize The size of the body. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiPutAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const char* body, + uint32_t bodySize) + { + _OrthancPluginRestApiPostPut params; + params.target = target; + params.uri = uri; + params.body = body; + params.bodySize = bodySize; + return context->InvokeService(context, _OrthancPluginService_RestApiPut, ¶ms); + } + + + + /** + * @brief Make a PUT call to the REST API, as tainted by the plugins. + * + * Make a PUT call to the Orthanc REST API, after all the plugins + * are applied. In other words, if some plugin overrides or adds the + * called URI to the built-in Orthanc REST API, this call will + * return the result provided by this plugin. The result to the + * query is stored into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @param body The body of the PUT request. + * @param bodySize The size of the body. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiPut + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const char* body, + uint32_t bodySize) + { + _OrthancPluginRestApiPostPut params; + params.target = target; + params.uri = uri; + params.body = body; + params.bodySize = bodySize; + return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, ¶ms); + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* argument; + } _OrthancPluginOutputPlusArgument; + + /** + * @brief Redirect a REST request. + * + * This function answers to a REST request by redirecting the user + * to another URI using HTTP status 301. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param redirection Where to redirect. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* redirection) + { + _OrthancPluginOutputPlusArgument params; + params.output = output; + params.argument = redirection; + context->InvokeService(context, _OrthancPluginService_Redirect, ¶ms); + } + + + + typedef struct + { + char** result; + const char* argument; + } _OrthancPluginRetrieveDynamicString; + + /** + * @brief Look for a patient. + * + * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020). + * This function uses the database index to run as fast as possible (it does not loop + * over all the stored patients). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param patientID The Patient ID of interest. + * @return The NULL value if the patient is non-existent, or a string containing the + * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient( + OrthancPluginContext* context, + const char* patientID) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = patientID; + + if (context->InvokeService(context, _OrthancPluginService_LookupPatient, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for a study. + * + * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d). + * This function uses the database index to run as fast as possible (it does not loop + * over all the stored studies). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param studyUID The Study Instance UID of interest. + * @return The NULL value if the study is non-existent, or a string containing the + * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy( + OrthancPluginContext* context, + const char* studyUID) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = studyUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupStudy, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for a study, using the accession number. + * + * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050). + * This function uses the database index to run as fast as possible (it does not loop + * over all the stored studies). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param accessionNumber The Accession Number of interest. + * @return The NULL value if the study is non-existent, or a string containing the + * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber( + OrthancPluginContext* context, + const char* accessionNumber) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = accessionNumber; + + if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for a series. + * + * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e). + * This function uses the database index to run as fast as possible (it does not loop + * over all the stored series). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param seriesUID The Series Instance UID of interest. + * @return The NULL value if the series is non-existent, or a string containing the + * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries( + OrthancPluginContext* context, + const char* seriesUID) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = seriesUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupSeries, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Look for an instance. + * + * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018). + * This function uses the database index to run as fast as possible (it does not loop + * over all the stored instances). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param sopInstanceUID The SOP Instance UID of interest. + * @return The NULL value if the instance is non-existent, or a string containing the + * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance( + OrthancPluginContext* context, + const char* sopInstanceUID) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = sopInstanceUID; + + if (context->InvokeService(context, _OrthancPluginService_LookupInstance, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + uint16_t status; + } _OrthancPluginSendHttpStatusCode; + + /** + * @brief Send a HTTP status code. + * + * This function answers to a REST request by sending a HTTP status + * code (such as "400 - Bad Request"). Note that: + * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). + * - Redirections (status 301) must use ::OrthancPluginRedirect(). + * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). + * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param status The HTTP status code to be sent. + * @ingroup REST + * @see OrthancPluginSendHttpStatus() + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + uint16_t status) + { + _OrthancPluginSendHttpStatusCode params; + params.output = output; + params.status = status; + context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, ¶ms); + } + + + /** + * @brief Signal that a REST request is not authorized. + * + * This function answers to a REST request by signaling that it is + * not authorized. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param realm The realm for the authorization process. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* realm) + { + _OrthancPluginOutputPlusArgument params; + params.output = output; + params.argument = realm; + context->InvokeService(context, _OrthancPluginService_SendUnauthorized, ¶ms); + } + + + /** + * @brief Signal that this URI does not support this HTTP method. + * + * This function answers to a REST request by signaling that the + * queried URI does not support this method. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request). + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* allowedMethods) + { + _OrthancPluginOutputPlusArgument params; + params.output = output; + params.argument = allowedMethods; + context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, ¶ms); + } + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* key; + const char* value; + } _OrthancPluginSetHttpHeader; + + /** + * @brief Set a cookie. + * + * This function sets a cookie in the HTTP client. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param cookie The cookie to be set. + * @param value The value of the cookie. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* cookie, + const char* value) + { + _OrthancPluginSetHttpHeader params; + params.output = output; + params.key = cookie; + params.value = value; + context->InvokeService(context, _OrthancPluginService_SetCookie, ¶ms); + } + + + /** + * @brief Set some HTTP header. + * + * This function sets a HTTP header in the HTTP answer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param key The HTTP header to be set. + * @param value The value of the HTTP header. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* key, + const char* value) + { + _OrthancPluginSetHttpHeader params; + params.output = output; + params.key = key; + params.value = value; + context->InvokeService(context, _OrthancPluginService_SetHttpHeader, ¶ms); + } + + + typedef struct + { + char** resultStringToFree; + const char** resultString; + int64_t* resultInt64; + const char* key; + OrthancPluginDicomInstance* instance; + OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */ + } _OrthancPluginAccessDicomInstance; + + + /** + * @brief Get the AET of a DICOM instance. + * + * This function returns the Application Entity Title (AET) of the + * DICOM modality from which a DICOM instance originates. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The AET if success, NULL if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + const char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultString = &result; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Get the size of a DICOM file. + * + * This function returns the number of bytes of the given DICOM instance. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The size of the file, -1 in case of error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + int64_t size; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultInt64 = &size; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return -1; + } + else + { + return size; + } + } + + + /** + * @brief Get the data of a DICOM file. + * + * This function returns a pointer to the content of the given DICOM instance. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The pointer to the DICOM data, NULL in case of error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceData( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + const char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultString = &result; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Get the DICOM tag hierarchy as a JSON file. + * + * This function returns a pointer to a newly created string + * containing a JSON file. This JSON file encodes the tag hierarchy + * of the given DICOM instance. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The NULL value in case of error, or a string containing the JSON file. + * This string must be freed by OrthancPluginFreeString(). + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultStringToFree = &result; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Get the DICOM tag hierarchy as a JSON file (with simplification). + * + * This function returns a pointer to a newly created string + * containing a JSON file. This JSON file encodes the tag hierarchy + * of the given DICOM instance. In contrast with + * ::OrthancPluginGetInstanceJson(), the returned JSON file is in + * its simplified version. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The NULL value in case of error, or a string containing the JSON file. + * This string must be freed by OrthancPluginFreeString(). + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultStringToFree = &result; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Check whether a DICOM instance is associated with some metadata. + * + * This function checks whether the DICOM instance of interest is + * associated with some metadata. As of Orthanc 0.8.1, in the + * callbacks registered by + * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only + * possibly available metadata are "ReceptionDate", "RemoteAET" and + * "IndexInSeries". + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @param metadata The metadata of interest. + * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE int OrthancPluginHasInstanceMetadata( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance, + const char* metadata) + { + int64_t result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultInt64 = &result; + params.instance = instance; + params.key = metadata; + + if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return -1; + } + else + { + return (result != 0); + } + } + + + /** + * @brief Get the value of some metadata associated with a given DICOM instance. + * + * This functions returns the value of some metadata that is associated with the DICOM instance of interest. + * Before calling this function, the existence of the metadata must have been checked with + * ::OrthancPluginHasInstanceMetadata(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @param metadata The metadata of interest. + * @return The metadata value if success, NULL if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance, + const char* metadata) + { + const char* result; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultString = &result; + params.instance = instance; + params.key = metadata; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginStorageCreate create; + OrthancPluginStorageRead read; + OrthancPluginStorageRemove remove; + OrthancPluginFree free; + } _OrthancPluginRegisterStorageArea; + + /** + * @brief Register a custom storage area. + * + * This function registers a custom storage area, to replace the + * built-in way Orthanc stores its files on the filesystem. This + * function must be called during the initialization of the plugin, + * i.e. inside the OrthancPluginInitialize() public function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param create The callback function to store a file on the custom storage area. + * @param read The callback function to read a file from the custom storage area. + * @param remove The callback function to remove a file from the custom storage area. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea( + OrthancPluginContext* context, + OrthancPluginStorageCreate create, + OrthancPluginStorageRead read, + OrthancPluginStorageRemove remove) + { + _OrthancPluginRegisterStorageArea params; + params.create = create; + params.read = read; + params.remove = remove; + +#ifdef __cplusplus + params.free = ::free; +#else + params.free = free; +#endif + + context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, ¶ms); + } + + + + /** + * @brief Return the path to the Orthanc executable. + * + * This function returns the path to the Orthanc executable. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return NULL in the case of an error, or a newly allocated string + * containing the path. This string must be freed by + * OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Return the directory containing the Orthanc. + * + * This function returns the path to the directory containing the Orthanc executable. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return NULL in the case of an error, or a newly allocated string + * containing the path. This string must be freed by + * OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Return the path to the configuration file(s). + * + * This function returns the path to the configuration file(s) that + * was specified when starting Orthanc. Since version 0.9.1, this + * path can refer to a folder that stores a set of configuration + * files. This function is deprecated in favor of + * OrthancPluginGetConfiguration(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return NULL in the case of an error, or a newly allocated string + * containing the path. This string must be freed by + * OrthancPluginFreeString(). + * @see OrthancPluginGetConfiguration() + **/ + ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginOnChangeCallback callback; + } _OrthancPluginOnChangeCallback; + + /** + * @brief Register a callback to monitor changes. + * + * This function registers a callback function that is called + * whenever a change happens to some DICOM resource. + * + * @warning If your change callback has to call the REST API of + * Orthanc, you should make these calls in a separate thread (with + * the events passing through a message queue). Otherwise, this + * could result in deadlocks in the presence of other plugins or Lua + * script. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The callback function. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback( + OrthancPluginContext* context, + OrthancPluginOnChangeCallback callback) + { + _OrthancPluginOnChangeCallback params; + params.callback = callback; + + context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, ¶ms); + } + + + + typedef struct + { + const char* plugin; + _OrthancPluginProperty property; + const char* value; + } _OrthancPluginSetPluginProperty; + + + /** + * @brief Set the URI where the plugin provides its Web interface. + * + * For plugins that come with a Web interface, this function + * declares the entry path where to find this interface. This + * information is notably used in the "Plugins" page of Orthanc + * Explorer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param uri The root URI for this plugin. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri( + OrthancPluginContext* context, + const char* uri) + { + _OrthancPluginSetPluginProperty params; + params.plugin = OrthancPluginGetName(); + params.property = _OrthancPluginProperty_RootUri; + params.value = uri; + + context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); + } + + + /** + * @brief Set a description for this plugin. + * + * Set a description for this plugin. It is displayed in the + * "Plugins" page of Orthanc Explorer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param description The description. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription( + OrthancPluginContext* context, + const char* description) + { + _OrthancPluginSetPluginProperty params; + params.plugin = OrthancPluginGetName(); + params.property = _OrthancPluginProperty_Description; + params.value = description; + + context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); + } + + + /** + * @brief Extend the JavaScript code of Orthanc Explorer. + * + * Add JavaScript code to customize the default behavior of Orthanc + * Explorer. This can for instance be used to add new buttons. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param javascript The custom JavaScript code. + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer( + OrthancPluginContext* context, + const char* javascript) + { + _OrthancPluginSetPluginProperty params; + params.plugin = OrthancPluginGetName(); + params.property = _OrthancPluginProperty_OrthancExplorer; + params.value = javascript; + + context->InvokeService(context, _OrthancPluginService_SetPluginProperty, ¶ms); + } + + + typedef struct + { + char** result; + int32_t property; + const char* value; + } _OrthancPluginGlobalProperty; + + + /** + * @brief Get the value of a global property. + * + * Get the value of a global property that is stored in the Orthanc database. Global + * properties whose index is below 1024 are reserved by Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param property The global property of interest. + * @param defaultValue The value to return, if the global property is unset. + * @return The value of the global property, or NULL in the case of an error. This + * string must be freed by OrthancPluginFreeString(). + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty( + OrthancPluginContext* context, + int32_t property, + const char* defaultValue) + { + char* result; + + _OrthancPluginGlobalProperty params; + params.result = &result; + params.property = property; + params.value = defaultValue; + + if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Set the value of a global property. + * + * Set the value of a global property into the Orthanc + * database. Setting a global property can be used by plugins to + * save their internal parameters. Plugins are only allowed to set + * properties whose index are above or equal to 1024 (properties + * below 1024 are read-only and reserved by Orthanc). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param property The global property of interest. + * @param value The value to be set in the global property. + * @return 0 if success, or the error code if failure. + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty( + OrthancPluginContext* context, + int32_t property, + const char* value) + { + _OrthancPluginGlobalProperty params; + params.result = NULL; + params.property = property; + params.value = value; + + return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, ¶ms); + } + + + + typedef struct + { + int32_t *resultInt32; + uint32_t *resultUint32; + int64_t *resultInt64; + uint64_t *resultUint64; + } _OrthancPluginReturnSingleValue; + + /** + * @brief Get the number of command-line arguments. + * + * Retrieve the number of command-line arguments that were used to launch Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return The number of arguments. + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount( + OrthancPluginContext* context) + { + uint32_t count = 0; + + _OrthancPluginReturnSingleValue params; + memset(¶ms, 0, sizeof(params)); + params.resultUint32 = &count; + + if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return 0; + } + else + { + return count; + } + } + + + + /** + * @brief Get the value of a command-line argument. + * + * Get the value of one of the command-line arguments that were used + * to launch Orthanc. The number of available arguments can be + * retrieved by OrthancPluginGetCommandLineArgumentsCount(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param argument The index of the argument. + * @return The value of the argument, or NULL in the case of an error. This + * string must be freed by OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument( + OrthancPluginContext* context, + uint32_t argument) + { + char* result; + + _OrthancPluginGlobalProperty params; + params.result = &result; + params.property = (int32_t) argument; + params.value = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @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. + * @ingroup Callbacks + * @deprecated Please instead use IDatabaseBackend::UpgradeDatabase() + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion( + OrthancPluginContext* context) + { + uint32_t count = 0; + + _OrthancPluginReturnSingleValue params; + memset(¶ms, 0, sizeof(params)); + params.resultUint32 = &count; + + if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return 0; + } + else + { + return count; + } + } + + + + /** + * @brief Return the content of the configuration file(s). + * + * This function returns the content of the configuration that is + * used by Orthanc, formatted as a JSON string. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return NULL in the case of an error, or a newly allocated string + * containing the configuration. This string must be freed by + * OrthancPluginFreeString(). + **/ + ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* subType; + const char* contentType; + } _OrthancPluginStartMultipartAnswer; + + /** + * @brief Start an HTTP multipart answer. + * + * Initiates a HTTP multipart answer, as the result of a REST request. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param subType The sub-type of the multipart answer ("mixed" or "related"). + * @param contentType The MIME type of the items in the multipart answer. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginSendMultipartItem() + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* subType, + const char* contentType) + { + _OrthancPluginStartMultipartAnswer params; + params.output = output; + params.subType = subType; + params.contentType = contentType; + return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, ¶ms); + } + + + /** + * @brief Send an item as a part of some HTTP multipart answer. + * + * This function sends an item as a part of some HTTP multipart + * answer that was initiated by OrthancPluginStartMultipartAnswer(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param answer Pointer to the memory buffer containing the item. + * @param answerSize Number of bytes of the item. + * @return 0 if success, or the error code if failure (this notably happens + * if the connection is closed by the client). + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* answer, + uint32_t answerSize) + { + _OrthancPluginAnswerBuffer params; + params.output = output; + params.answer = answer; + params.answerSize = answerSize; + params.mimeType = NULL; + return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const void* source; + uint32_t size; + OrthancPluginCompressionType compression; + uint8_t uncompress; + } _OrthancPluginBufferCompression; + + + /** + * @brief Compress or decompress a buffer. + * + * This function compresses or decompresses a buffer, using the + * version of the zlib library that is used by the Orthanc core. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param source The source buffer. + * @param size The size in bytes of the source buffer. + * @param compression The compression algorithm. + * @param uncompress If set to "0", the buffer must be compressed. + * If set to "1", the buffer must be uncompressed. + * @return 0 if success, or the error code if failure. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const void* source, + uint32_t size, + OrthancPluginCompressionType compression, + uint8_t uncompress) + { + _OrthancPluginBufferCompression params; + params.target = target; + params.source = source; + params.size = size; + params.compression = compression; + params.uncompress = uncompress; + + return context->InvokeService(context, _OrthancPluginService_BufferCompression, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* path; + } _OrthancPluginReadFile; + + /** + * @brief Read a file. + * + * Read the content of a file on the filesystem, and returns it into + * a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param path The path of the file to be read. + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* path) + { + _OrthancPluginReadFile params; + params.target = target; + params.path = path; + return context->InvokeService(context, _OrthancPluginService_ReadFile, ¶ms); + } + + + + typedef struct + { + const char* path; + const void* data; + uint32_t size; + } _OrthancPluginWriteFile; + + /** + * @brief Write a file. + * + * Write the content of a memory buffer to the filesystem. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param path The path of the file to be written. + * @param data The content of the memory buffer. + * @param size The size of the memory buffer. + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile( + OrthancPluginContext* context, + const char* path, + const void* data, + uint32_t size) + { + _OrthancPluginWriteFile params; + params.path = path; + params.data = data; + params.size = size; + return context->InvokeService(context, _OrthancPluginService_WriteFile, ¶ms); + } + + + + typedef struct + { + const char** target; + OrthancPluginErrorCode error; + } _OrthancPluginGetErrorDescription; + + /** + * @brief Get the description of a given error code. + * + * This function returns the description of a given error code. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param error The error code of interest. + * @return The error description. This is a statically-allocated + * string, do not free it. + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription( + OrthancPluginContext* context, + OrthancPluginErrorCode error) + { + const char* result = NULL; + + _OrthancPluginGetErrorDescription params; + params.target = &result; + params.error = error; + + if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, ¶ms) != OrthancPluginErrorCode_Success || + result == NULL) + { + return "Unknown error code"; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + uint16_t status; + const char* body; + uint32_t bodySize; + } _OrthancPluginSendHttpStatus; + + /** + * @brief Send a HTTP status, with a custom body. + * + * This function answers to a HTTP request by sending a HTTP status + * code (such as "400 - Bad Request"), together with a body + * describing the error. The body will only be returned if the + * configuration option "HttpDescribeErrors" of Orthanc is set to "true". + * + * Note that: + * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer(). + * - Redirections (status 301) must use ::OrthancPluginRedirect(). + * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized(). + * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param status The HTTP status code to be sent. + * @param body The body of the answer. + * @param bodySize The size of the body. + * @see OrthancPluginSendHttpStatusCode() + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + uint16_t status, + const char* body, + uint32_t bodySize) + { + _OrthancPluginSendHttpStatus params; + params.output = output; + params.status = status; + params.body = body; + params.bodySize = bodySize; + context->InvokeService(context, _OrthancPluginService_SendHttpStatus, ¶ms); + } + + + + typedef struct + { + const OrthancPluginImage* image; + uint32_t* resultUint32; + OrthancPluginPixelFormat* resultPixelFormat; + void** resultBuffer; + } _OrthancPluginGetImageInfo; + + + /** + * @brief Return the pixel format of an image. + * + * This function returns the type of memory layout for the pixels of the given image. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image of interest. + * @return The pixel format. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat( + OrthancPluginContext* context, + const OrthancPluginImage* image) + { + OrthancPluginPixelFormat target; + + _OrthancPluginGetImageInfo params; + memset(¶ms, 0, sizeof(params)); + params.image = image; + params.resultPixelFormat = ⌖ + + if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, ¶ms) != OrthancPluginErrorCode_Success) + { + return OrthancPluginPixelFormat_Unknown; + } + else + { + return (OrthancPluginPixelFormat) target; + } + } + + + + /** + * @brief Return the width of an image. + * + * This function returns the width of the given image. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image of interest. + * @return The width. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth( + OrthancPluginContext* context, + const OrthancPluginImage* image) + { + uint32_t width; + + _OrthancPluginGetImageInfo params; + memset(¶ms, 0, sizeof(params)); + params.image = image; + params.resultUint32 = &width; + + if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, ¶ms) != OrthancPluginErrorCode_Success) + { + return 0; + } + else + { + return width; + } + } + + + + /** + * @brief Return the height of an image. + * + * This function returns the height of the given image. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image of interest. + * @return The height. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight( + OrthancPluginContext* context, + const OrthancPluginImage* image) + { + uint32_t height; + + _OrthancPluginGetImageInfo params; + memset(¶ms, 0, sizeof(params)); + params.image = image; + params.resultUint32 = &height; + + if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, ¶ms) != OrthancPluginErrorCode_Success) + { + return 0; + } + else + { + return height; + } + } + + + + /** + * @brief Return the pitch of an image. + * + * This function returns the pitch of the given image. The pitch is + * defined as the number of bytes between 2 successive lines of the + * image in the memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image of interest. + * @return The pitch. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch( + OrthancPluginContext* context, + const OrthancPluginImage* image) + { + uint32_t pitch; + + _OrthancPluginGetImageInfo params; + memset(¶ms, 0, sizeof(params)); + params.image = image; + params.resultUint32 = &pitch; + + if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, ¶ms) != OrthancPluginErrorCode_Success) + { + return 0; + } + else + { + return pitch; + } + } + + + + /** + * @brief Return a pointer to the content of an image. + * + * This function returns a pointer to the memory buffer that + * contains the pixels of the image. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image of interest. + * @return The pointer. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer( + OrthancPluginContext* context, + const OrthancPluginImage* image) + { + void* target = NULL; + + _OrthancPluginGetImageInfo params; + memset(¶ms, 0, sizeof(params)); + params.resultBuffer = ⌖ + params.image = image; + + if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + typedef struct + { + OrthancPluginImage** target; + const void* data; + uint32_t size; + OrthancPluginImageFormat format; + } _OrthancPluginUncompressImage; + + + /** + * @brief Decode a compressed image. + * + * This function decodes a compressed image from a memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param data Pointer to a memory buffer containing the compressed image. + * @param size Size of the memory buffer containing the compressed image. + * @param format The file format of the compressed image. + * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage( + OrthancPluginContext* context, + const void* data, + uint32_t size, + OrthancPluginImageFormat format) + { + OrthancPluginImage* target = NULL; + + _OrthancPluginUncompressImage params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.data = data; + params.size = size; + params.format = format; + + if (context->InvokeService(context, _OrthancPluginService_UncompressImage, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + + + typedef struct + { + OrthancPluginImage* image; + } _OrthancPluginFreeImage; + + /** + * @brief Free an image. + * + * This function frees an image that was decoded with OrthancPluginUncompressImage(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage( + OrthancPluginContext* context, + OrthancPluginImage* image) + { + _OrthancPluginFreeImage params; + params.image = image; + + context->InvokeService(context, _OrthancPluginService_FreeImage, ¶ms); + } + + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + OrthancPluginImageFormat imageFormat; + OrthancPluginPixelFormat pixelFormat; + uint32_t width; + uint32_t height; + uint32_t pitch; + const void* buffer; + uint8_t quality; + } _OrthancPluginCompressImage; + + + /** + * @brief Encode a PNG image. + * + * This function compresses the given memory buffer containing an + * image using the PNG specification, and stores the result of the + * compression into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param format The memory layout of the uncompressed image. + * @param width The width of the image. + * @param height The height of the image. + * @param pitch The pitch of the image (i.e. the number of bytes + * between 2 successive lines of the image in the memory buffer). + * @param buffer The memory buffer containing the uncompressed image. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginCompressAndAnswerPngImage() + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + const void* buffer) + { + _OrthancPluginCompressImage params; + memset(¶ms, 0, sizeof(params)); + params.target = target; + params.imageFormat = OrthancPluginImageFormat_Png; + params.pixelFormat = format; + params.width = width; + params.height = height; + params.pitch = pitch; + params.buffer = buffer; + params.quality = 0; /* Unused for PNG */ + + return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); + } + + + /** + * @brief Encode a JPEG image. + * + * This function compresses the given memory buffer containing an + * image using the JPEG specification, and stores the result of the + * compression into a newly allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param format The memory layout of the uncompressed image. + * @param width The width of the image. + * @param height The height of the image. + * @param pitch The pitch of the image (i.e. the number of bytes + * between 2 successive lines of the image in the memory buffer). + * @param buffer The memory buffer containing the uncompressed image. + * @param quality The quality of the JPEG encoding, between 1 (worst + * quality, best compression) and 100 (best quality, worst + * compression). + * @return 0 if success, or the error code if failure. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + const void* buffer, + uint8_t quality) + { + _OrthancPluginCompressImage params; + memset(¶ms, 0, sizeof(params)); + params.target = target; + params.imageFormat = OrthancPluginImageFormat_Jpeg; + params.pixelFormat = format; + params.width = width; + params.height = height; + params.pitch = pitch; + params.buffer = buffer; + params.quality = quality; + + return context->InvokeService(context, _OrthancPluginService_CompressImage, ¶ms); + } + + + + /** + * @brief Answer to a REST request with a JPEG image. + * + * This function answers to a REST request with a JPEG image. The + * parameters of this function describe a memory buffer that + * contains an uncompressed image. The image will be automatically compressed + * as a JPEG image by the core system of Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param format The memory layout of the uncompressed image. + * @param width The width of the image. + * @param height The height of the image. + * @param pitch The pitch of the image (i.e. the number of bytes + * between 2 successive lines of the image in the memory buffer). + * @param buffer The memory buffer containing the uncompressed image. + * @param quality The quality of the JPEG encoding, between 1 (worst + * quality, best compression) and 100 (best quality, worst + * compression). + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + const void* buffer, + uint8_t quality) + { + _OrthancPluginCompressAndAnswerImage params; + params.output = output; + params.imageFormat = OrthancPluginImageFormat_Jpeg; + params.pixelFormat = format; + params.width = width; + params.height = height; + params.pitch = pitch; + params.buffer = buffer; + params.quality = quality; + context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, ¶ms); + } + + + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + OrthancPluginHttpMethod method; + const char* url; + const char* username; + const char* password; + const char* body; + uint32_t bodySize; + } _OrthancPluginCallHttpClient; + + + /** + * @brief Issue a HTTP GET call. + * + * Make a HTTP GET call to the given URL. The result to the query is + * stored into a newly allocated memory buffer. Favor + * OrthancPluginRestApiGet() if calling the built-in REST API of the + * Orthanc instance that hosts this plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param url The URL of interest. + * @param username The username (can be <tt>NULL</tt> if no password protection). + * @param password The password (can be <tt>NULL</tt> if no password protection). + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* url, + const char* username, + const char* password) + { + _OrthancPluginCallHttpClient params; + memset(¶ms, 0, sizeof(params)); + + params.target = target; + params.method = OrthancPluginHttpMethod_Get; + params.url = url; + params.username = username; + params.password = password; + + return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); + } + + + /** + * @brief Issue a HTTP POST call. + * + * Make a HTTP POST call to the given URL. The result to the query + * is stored into a newly allocated memory buffer. Favor + * OrthancPluginRestApiPost() if calling the built-in REST API of + * the Orthanc instance that hosts this plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param url The URL of interest. + * @param body The content of the body of the request. + * @param bodySize The size of the body of the request. + * @param username The username (can be <tt>NULL</tt> if no password protection). + * @param password The password (can be <tt>NULL</tt> if no password protection). + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* url, + const char* body, + uint32_t bodySize, + const char* username, + const char* password) + { + _OrthancPluginCallHttpClient params; + memset(¶ms, 0, sizeof(params)); + + params.target = target; + params.method = OrthancPluginHttpMethod_Post; + params.url = url; + params.body = body; + params.bodySize = bodySize; + params.username = username; + params.password = password; + + return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); + } + + + /** + * @brief Issue a HTTP PUT call. + * + * Make a HTTP PUT call to the given URL. The result to the query is + * stored into a newly allocated memory buffer. Favor + * OrthancPluginRestApiPut() if calling the built-in REST API of the + * Orthanc instance that hosts this plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param url The URL of interest. + * @param body The content of the body of the request. + * @param bodySize The size of the body of the request. + * @param username The username (can be <tt>NULL</tt> if no password protection). + * @param password The password (can be <tt>NULL</tt> if no password protection). + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* url, + const char* body, + uint32_t bodySize, + const char* username, + const char* password) + { + _OrthancPluginCallHttpClient params; + memset(¶ms, 0, sizeof(params)); + + params.target = target; + params.method = OrthancPluginHttpMethod_Put; + params.url = url; + params.body = body; + params.bodySize = bodySize; + params.username = username; + params.password = password; + + return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); + } + + + /** + * @brief Issue a HTTP DELETE call. + * + * Make a HTTP DELETE call to the given URL. Favor + * OrthancPluginRestApiDelete() if calling the built-in REST API of + * the Orthanc instance that hosts this plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param url The URL of interest. + * @param username The username (can be <tt>NULL</tt> if no password protection). + * @param password The password (can be <tt>NULL</tt> if no password protection). + * @return 0 if success, or the error code if failure. + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete( + OrthancPluginContext* context, + const char* url, + const char* username, + const char* password) + { + _OrthancPluginCallHttpClient params; + memset(¶ms, 0, sizeof(params)); + + params.method = OrthancPluginHttpMethod_Delete; + params.url = url; + params.username = username; + params.password = password; + + return context->InvokeService(context, _OrthancPluginService_CallHttpClient, ¶ms); + } + + + + typedef struct + { + OrthancPluginImage** target; + const OrthancPluginImage* source; + OrthancPluginPixelFormat targetFormat; + } _OrthancPluginConvertPixelFormat; + + + /** + * @brief Change the pixel format of an image. + * + * This function creates a new image, changing the memory layout of the pixels. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param source The source image. + * @param targetFormat The target pixel format. + * @return The resulting image. It must be freed with OrthancPluginFreeImage(). + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat( + OrthancPluginContext* context, + const OrthancPluginImage* source, + OrthancPluginPixelFormat targetFormat) + { + OrthancPluginImage* target = NULL; + + _OrthancPluginConvertPixelFormat params; + params.target = ⌖ + params.source = source; + params.targetFormat = targetFormat; + + if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + + /** + * @brief Return the number of available fonts. + * + * This function returns the number of fonts that are built in the + * Orthanc core. These fonts can be used to draw texts on images + * through OrthancPluginDrawText(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return The number of fonts. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount( + OrthancPluginContext* context) + { + uint32_t count = 0; + + _OrthancPluginReturnSingleValue params; + memset(¶ms, 0, sizeof(params)); + params.resultUint32 = &count; + + if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return 0; + } + else + { + return count; + } + } + + + + + typedef struct + { + uint32_t fontIndex; /* in */ + const char** name; /* out */ + uint32_t* size; /* out */ + } _OrthancPluginGetFontInfo; + + /** + * @brief Return the name of a font. + * + * This function returns the name of a font that is built in the Orthanc core. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). + * @return The font name. This is a statically-allocated string, do not free it. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName( + OrthancPluginContext* context, + uint32_t fontIndex) + { + const char* result = NULL; + + _OrthancPluginGetFontInfo params; + memset(¶ms, 0, sizeof(params)); + params.name = &result; + params.fontIndex = fontIndex; + + if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Return the size of a font. + * + * This function returns the size of a font that is built in the Orthanc core. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). + * @return The font size. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize( + OrthancPluginContext* context, + uint32_t fontIndex) + { + uint32_t result; + + _OrthancPluginGetFontInfo params; + memset(¶ms, 0, sizeof(params)); + params.size = &result; + params.fontIndex = fontIndex; + + if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, ¶ms) != OrthancPluginErrorCode_Success) + { + return 0; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginImage* image; + uint32_t fontIndex; + const char* utf8Text; + int32_t x; + int32_t y; + uint8_t r; + uint8_t g; + uint8_t b; + } _OrthancPluginDrawText; + + + /** + * @brief Draw text on an image. + * + * This function draws some text on some image. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param image The image upon which to draw the text. + * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount(). + * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string. + * @param x The X position of the text over the image. + * @param y The Y position of the text over the image. + * @param r The value of the red color channel of the text. + * @param g The value of the green color channel of the text. + * @param b The value of the blue color channel of the text. + * @return 0 if success, other value if error. + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText( + OrthancPluginContext* context, + OrthancPluginImage* image, + uint32_t fontIndex, + const char* utf8Text, + int32_t x, + int32_t y, + uint8_t r, + uint8_t g, + uint8_t b) + { + _OrthancPluginDrawText params; + memset(¶ms, 0, sizeof(params)); + params.image = image; + params.fontIndex = fontIndex; + params.utf8Text = utf8Text; + params.x = x; + params.y = y; + params.r = r; + params.g = g; + params.b = b; + + return context->InvokeService(context, _OrthancPluginService_DrawText, ¶ms); + } + + + + typedef struct + { + OrthancPluginStorageArea* storageArea; + const char* uuid; + const void* content; + uint64_t size; + OrthancPluginContentType type; + } _OrthancPluginStorageAreaCreate; + + + /** + * @brief Create a file inside the storage area. + * + * This function creates a new file inside the storage area that is + * currently used by Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param storageArea The storage area. + * @param uuid The identifier of the file to be created. + * @param content The content to store in the newly created file. + * @param size The size of the content. + * @param type The type of the file content. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate( + OrthancPluginContext* context, + OrthancPluginStorageArea* storageArea, + const char* uuid, + const void* content, + uint64_t size, + OrthancPluginContentType type) + { + _OrthancPluginStorageAreaCreate params; + params.storageArea = storageArea; + params.uuid = uuid; + params.content = content; + params.size = size; + params.type = type; + + return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, ¶ms); + } + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + OrthancPluginStorageArea* storageArea; + const char* uuid; + OrthancPluginContentType type; + } _OrthancPluginStorageAreaRead; + + + /** + * @brief Read a file from the storage area. + * + * This function reads the content of a given file from the storage + * area that is currently used by Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param storageArea The storage area. + * @param uuid The identifier of the file to be read. + * @param type The type of the file content. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + OrthancPluginStorageArea* storageArea, + const char* uuid, + OrthancPluginContentType type) + { + _OrthancPluginStorageAreaRead params; + params.target = target; + params.storageArea = storageArea; + params.uuid = uuid; + params.type = type; + + return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, ¶ms); + } + + + typedef struct + { + OrthancPluginStorageArea* storageArea; + const char* uuid; + OrthancPluginContentType type; + } _OrthancPluginStorageAreaRemove; + + /** + * @brief Remove a file from the storage area. + * + * This function removes a given file from the storage area that is + * currently used by Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param storageArea The storage area. + * @param uuid The identifier of the file to be removed. + * @param type The type of the file content. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove( + OrthancPluginContext* context, + OrthancPluginStorageArea* storageArea, + const char* uuid, + OrthancPluginContentType type) + { + _OrthancPluginStorageAreaRemove params; + params.storageArea = storageArea; + params.uuid = uuid; + params.type = type; + + return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, ¶ms); + } + + + + typedef struct + { + OrthancPluginErrorCode* target; + int32_t code; + uint16_t httpStatus; + const char* message; + } _OrthancPluginRegisterErrorCode; + + /** + * @brief Declare a custom error code for this plugin. + * + * This function declares a custom error code that can be generated + * by this plugin. This declaration is used to enrich the body of + * the HTTP answer in the case of an error, and to set the proper + * HTTP status code. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param code The error code that is internal to this plugin. + * @param httpStatus The HTTP status corresponding to this error. + * @param message The description of the error. + * @return The error code that has been assigned inside the Orthanc core. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode( + OrthancPluginContext* context, + int32_t code, + uint16_t httpStatus, + const char* message) + { + OrthancPluginErrorCode target; + + _OrthancPluginRegisterErrorCode params; + params.target = ⌖ + params.code = code; + params.httpStatus = httpStatus; + params.message = message; + + if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, ¶ms) == OrthancPluginErrorCode_Success) + { + return target; + } + else + { + /* There was an error while assigned the error. Use a generic code. */ + return OrthancPluginErrorCode_Plugin; + } + } + + + + typedef struct + { + uint16_t group; + uint16_t element; + OrthancPluginValueRepresentation vr; + const char* name; + uint32_t minMultiplicity; + uint32_t maxMultiplicity; + } _OrthancPluginRegisterDictionaryTag; + + /** + * @brief Register a new tag into the DICOM dictionary. + * + * This function declares a new tag in the dictionary of DICOM tags + * that are known to Orthanc. This function should be used in the + * OrthancPluginInitialize() callback. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param group The group of the tag. + * @param element The element of the tag. + * @param vr The value representation of the tag. + * @param name The nickname of the tag. + * @param minMultiplicity The minimum multiplicity of the tag (must be above 0). + * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means + * an arbitrary multiplicity ("<tt>n</tt>"). + * @return 0 if success, other value if error. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag( + OrthancPluginContext* context, + uint16_t group, + uint16_t element, + OrthancPluginValueRepresentation vr, + const char* name, + uint32_t minMultiplicity, + uint32_t maxMultiplicity) + { + _OrthancPluginRegisterDictionaryTag params; + params.group = group; + params.element = element; + params.vr = vr; + params.name = name; + params.minMultiplicity = minMultiplicity; + params.maxMultiplicity = maxMultiplicity; + + return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, ¶ms); + } + + + + + typedef struct + { + OrthancPluginStorageArea* storageArea; + OrthancPluginResourceType level; + } _OrthancPluginReconstructMainDicomTags; + + /** + * @brief Reconstruct the main DICOM tags. + * + * This function requests the Orthanc core to reconstruct the main + * DICOM tags of all the resources of the given type. This function + * can only be used as a part of the upgrade of a custom database + * back-end + * (cf. OrthancPlugins::IDatabaseBackend::UpgradeDatabase). A + * database transaction will be automatically setup. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param storageArea The storage area. + * @param level The type of the resources of interest. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( + OrthancPluginContext* context, + OrthancPluginStorageArea* storageArea, + OrthancPluginResourceType level) + { + _OrthancPluginReconstructMainDicomTags params; + params.level = level; + params.storageArea = storageArea; + + return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); + } + + + typedef struct + { + char** result; + const char* instanceId; + const char* buffer; + uint32_t size; + OrthancPluginDicomToJsonFormat format; + OrthancPluginDicomToJsonFlags flags; + uint32_t maxStringLength; + } _OrthancPluginDicomToJson; + + + /** + * @brief Format a DICOM memory buffer as a JSON string. + * + * This function takes as input a memory buffer containing a DICOM + * file, and outputs a JSON string representing the tags of this + * DICOM file. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param buffer The memory buffer containing the DICOM file. + * @param size The size of the memory buffer. + * @param format The output format. + * @param flags Flags governing the output. + * @param maxStringLength The maximum length of a field. Too long fields will + * be output as "null". The 0 value means no maximum length. + * @return The NULL value if the case of an error, or the JSON + * string. This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + * @see OrthancPluginDicomInstanceToJson + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson( + OrthancPluginContext* context, + const char* buffer, + uint32_t size, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength) + { + char* result; + + _OrthancPluginDicomToJson params; + memset(¶ms, 0, sizeof(params)); + params.result = &result; + params.buffer = buffer; + params.size = size; + params.format = format; + params.flags = flags; + params.maxStringLength = maxStringLength; + + if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Format a DICOM instance as a JSON string. + * + * This function formats a DICOM instance that is stored in Orthanc, + * and outputs a JSON string representing the tags of this DICOM + * instance. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instanceId The Orthanc identifier of the instance. + * @param format The output format. + * @param flags Flags governing the output. + * @param maxStringLength The maximum length of a field. Too long fields will + * be output as "null". The 0 value means no maximum length. + * @return The NULL value if the case of an error, or the JSON + * string. This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + * @see OrthancPluginDicomInstanceToJson + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson( + OrthancPluginContext* context, + const char* instanceId, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength) + { + char* result; + + _OrthancPluginDicomToJson params; + memset(¶ms, 0, sizeof(params)); + params.result = &result; + params.instanceId = instanceId; + params.format = format; + params.flags = flags; + params.maxStringLength = maxStringLength; + + if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* uri; + uint32_t headersCount; + const char* const* headersKeys; + const char* const* headersValues; + int32_t afterPlugins; + } _OrthancPluginRestApiGet2; + + /** + * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. + * + * Make a GET call to the Orthanc REST API with extended + * parameters. The result to the query is stored into a newly + * allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param uri The URI in the built-in Orthanc API. + * @param headersCount The number of HTTP headers. + * @param headersKeys Array containing the keys of the HTTP headers. + * @param headersValues Array containing the values of the HTTP headers. + * @param afterPlugins If 0, the built-in API of Orthanc is used. + * If 1, the API is tainted by the plugins. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues, + int32_t afterPlugins) + { + _OrthancPluginRestApiGet2 params; + params.target = target; + params.uri = uri; + params.headersCount = headersCount; + params.headersKeys = headersKeys; + params.headersValues = headersValues; + params.afterPlugins = afterPlugins; + + return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); + } + + + + typedef struct + { + OrthancPluginWorklistCallback callback; + } _OrthancPluginWorklistCallback; + + /** + * @brief Register a callback to handle modality worklists requests. + * + * This function registers a callback to handle C-Find SCP requests + * on modality worklists. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The callback. + * @return 0 if success, other value if error. + * @ingroup Worklists + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback( + OrthancPluginContext* context, + OrthancPluginWorklistCallback callback) + { + _OrthancPluginWorklistCallback params; + params.callback = callback; + + return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, ¶ms); + } + + + + typedef struct + { + OrthancPluginWorklistAnswers* answers; + const OrthancPluginWorklistQuery* query; + const void* dicom; + uint32_t size; + } _OrthancPluginWorklistAnswersOperation; + + /** + * @brief Add one answer to some modality worklist request. + * + * This function adds one worklist (encoded as a DICOM file) to the + * set of answers corresponding to some C-Find SCP request against + * modality worklists. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answers The set of answers. + * @param query The worklist query, as received by the callback. + * @param dicom The worklist to answer, encoded as a DICOM file. + * @param size The size of the DICOM file. + * @return 0 if success, other value if error. + * @ingroup Worklists + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer( + OrthancPluginContext* context, + OrthancPluginWorklistAnswers* answers, + const OrthancPluginWorklistQuery* query, + const void* dicom, + uint32_t size) + { + _OrthancPluginWorklistAnswersOperation params; + params.answers = answers; + params.query = query; + params.dicom = dicom; + params.size = size; + + return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, ¶ms); + } + + + /** + * @brief Mark the set of worklist answers as incomplete. + * + * This function marks as incomplete the set of answers + * corresponding to some C-Find SCP request against modality + * worklists. This must be used if canceling the handling of a + * request when too many answers are to be returned. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answers The set of answers. + * @return 0 if success, other value if error. + * @ingroup Worklists + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete( + OrthancPluginContext* context, + OrthancPluginWorklistAnswers* answers) + { + _OrthancPluginWorklistAnswersOperation params; + params.answers = answers; + params.query = NULL; + params.dicom = NULL; + params.size = 0; + + return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, ¶ms); + } + + + typedef struct + { + const OrthancPluginWorklistQuery* query; + const void* dicom; + uint32_t size; + int32_t* isMatch; + OrthancPluginMemoryBuffer* target; + } _OrthancPluginWorklistQueryOperation; + + /** + * @brief Test whether a worklist matches the query. + * + * This function checks whether one worklist (encoded as a DICOM + * file) matches the C-Find SCP query against modality + * worklists. This function must be called before adding the + * worklist as an answer through OrthancPluginWorklistAddAnswer(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The worklist query, as received by the callback. + * @param dicom The worklist to answer, encoded as a DICOM file. + * @param size The size of the DICOM file. + * @return 1 if the worklist matches the query, 0 otherwise. + * @ingroup Worklists + **/ + ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch( + OrthancPluginContext* context, + const OrthancPluginWorklistQuery* query, + const void* dicom, + uint32_t size) + { + int32_t isMatch = 0; + + _OrthancPluginWorklistQueryOperation params; + params.query = query; + params.dicom = dicom; + params.size = size; + params.isMatch = &isMatch; + params.target = NULL; + + if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, ¶ms) == OrthancPluginErrorCode_Success) + { + return isMatch; + } + else + { + /* Error: Assume non-match */ + return 0; + } + } + + + /** + * @brief Retrieve the worklist query as a DICOM file. + * + * This function retrieves the DICOM file that underlies a C-Find + * SCP query against modality worklists. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param query The worklist query, as received by the callback. + * @return 0 if success, other value if error. + * @ingroup Worklists + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const OrthancPluginWorklistQuery* query) + { + _OrthancPluginWorklistQueryOperation params; + params.query = query; + params.dicom = NULL; + params.size = 0; + params.isMatch = NULL; + params.target = target; + + return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, ¶ms); + } + + + /** + * @brief Get the origin of a DICOM file. + * + * This function returns the origin of a DICOM instance that has been received by Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param instance The instance of interest. + * @return The origin of the instance. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin( + OrthancPluginContext* context, + OrthancPluginDicomInstance* instance) + { + OrthancPluginInstanceOrigin origin; + + _OrthancPluginAccessDicomInstance params; + memset(¶ms, 0, sizeof(params)); + params.resultOrigin = &origin; + params.instance = instance; + + if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return OrthancPluginInstanceOrigin_Unknown; + } + else + { + return origin; + } + } + + + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* json; + const OrthancPluginImage* pixelData; + OrthancPluginCreateDicomFlags flags; + } _OrthancPluginCreateDicom; + + /** + * @brief Create a DICOM instance from a JSON string and an image. + * + * This function takes as input a string containing a JSON file + * describing the content of a DICOM instance. As an output, it + * writes the corresponding DICOM instance to a newly allocated + * memory buffer. Additionally, an image to be encoded within the + * DICOM instance can also be provided. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param json The input JSON file. + * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme. + * @param flags Flags governing the output. + * @return 0 if success, other value if error. + * @ingroup Toolbox + * @see OrthancPluginDicomBufferToJson + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* json, + const OrthancPluginImage* pixelData, + OrthancPluginCreateDicomFlags flags) + { + _OrthancPluginCreateDicom params; + params.target = target; + params.json = json; + params.pixelData = pixelData; + params.flags = flags; + + return context->InvokeService(context, _OrthancPluginService_CreateDicom, ¶ms); + } + + + typedef struct + { + OrthancPluginDecodeImageCallback callback; + } _OrthancPluginDecodeImageCallback; + + /** + * @brief Register a callback to handle the decoding of DICOM images. + * + * This function registers a custom callback to the decoding of + * DICOM images, replacing the built-in decoder of Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The callback. + * @return 0 if success, other value if error. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback( + OrthancPluginContext* context, + OrthancPluginDecodeImageCallback callback) + { + _OrthancPluginDecodeImageCallback params; + params.callback = callback; + + return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, ¶ms); + } + + + + typedef struct + { + OrthancPluginImage** target; + OrthancPluginPixelFormat format; + uint32_t width; + uint32_t height; + uint32_t pitch; + void* buffer; + const void* constBuffer; + uint32_t bufferSize; + uint32_t frameIndex; + } _OrthancPluginCreateImage; + + + /** + * @brief Create an image. + * + * This function creates an image of given size and format. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param format The format of the pixels. + * @param width The width of the image. + * @param height The height of the image. + * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage( + OrthancPluginContext* context, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height) + { + OrthancPluginImage* target = NULL; + + _OrthancPluginCreateImage params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.format = format; + params.width = width; + params.height = height; + + if (context->InvokeService(context, _OrthancPluginService_CreateImage, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + /** + * @brief Create an image pointing to a memory buffer. + * + * This function creates an image whose content points to a memory + * buffer managed by the plugin. Note that the buffer is directly + * accessed, no memory is allocated and no data is copied. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param format The format of the pixels. + * @param width The width of the image. + * @param height The height of the image. + * @param pitch The pitch of the image (i.e. the number of bytes + * between 2 successive lines of the image in the memory buffer). + * @param buffer The memory buffer. + * @return The newly allocated image. It must be freed with OrthancPluginFreeImage(). + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor( + OrthancPluginContext* context, + OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + void* buffer) + { + OrthancPluginImage* target = NULL; + + _OrthancPluginCreateImage params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.format = format; + params.width = width; + params.height = height; + params.pitch = pitch; + params.buffer = buffer; + + if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + + /** + * @brief Decode one frame from a DICOM instance. + * + * This function decodes one frame of a DICOM image that is stored + * in a memory buffer. This function will give the same result as + * OrthancPluginUncompressImage() for single-frame DICOM images. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param buffer Pointer to a memory buffer containing the DICOM image. + * @param bufferSize Size of the memory buffer containing the DICOM image. + * @param frameIndex The index of the frame of interest in a multi-frame image. + * @return The uncompressed image. It must be freed with OrthancPluginFreeImage(). + * @ingroup Images + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage( + OrthancPluginContext* context, + const void* buffer, + uint32_t bufferSize, + uint32_t frameIndex) + { + OrthancPluginImage* target = NULL; + + _OrthancPluginCreateImage params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.constBuffer = buffer; + params.bufferSize = bufferSize; + params.frameIndex = frameIndex; + + if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + + typedef struct + { + char** result; + const void* buffer; + uint32_t size; + } _OrthancPluginComputeHash; + + /** + * @brief Compute an MD5 hash. + * + * This functions computes the MD5 cryptographic hash of the given memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param buffer The source memory buffer. + * @param size The size in bytes of the source buffer. + * @return The NULL value in case of error, or a string containing the cryptographic hash. + * This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5( + OrthancPluginContext* context, + const void* buffer, + uint32_t size) + { + char* result; + + _OrthancPluginComputeHash params; + params.result = &result; + params.buffer = buffer; + params.size = size; + + if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Compute a SHA-1 hash. + * + * This functions computes the SHA-1 cryptographic hash of the given memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param buffer The source memory buffer. + * @param size The size in bytes of the source buffer. + * @return The NULL value in case of error, or a string containing the cryptographic hash. + * This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1( + OrthancPluginContext* context, + const void* buffer, + uint32_t size) + { + char* result; + + _OrthancPluginComputeHash params; + params.result = &result; + params.buffer = buffer; + params.size = size; + + if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + OrthancPluginDictionaryEntry* target; + const char* name; + } _OrthancPluginLookupDictionary; + + /** + * @brief Get information about the given DICOM tag. + * + * This functions makes a lookup in the dictionary of DICOM tags + * that are known to Orthanc, and returns information about this + * tag. The tag can be specified using its human-readable name + * (e.g. "PatientName") or a set of two hexadecimal numbers + * (e.g. "0010-0020"). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target Where to store the information about the tag. + * @param name The name of the DICOM tag. + * @return 0 if success, other value if error. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary( + OrthancPluginContext* context, + OrthancPluginDictionaryEntry* target, + const char* name) + { + _OrthancPluginLookupDictionary params; + params.target = target; + params.name = name; + return context->InvokeService(context, _OrthancPluginService_LookupDictionary, ¶ms); + } + + +#ifdef __cplusplus +} +#endif + + +/** @} */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Sdk-0.9.5/orthanc/OrthancCppDatabasePlugin.h Mon Apr 16 17:19:57 2018 +0200 @@ -0,0 +1,1895 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + + +#pragma once + +#include "OrthancCDatabasePlugin.h" + +#include <stdexcept> +#include <list> +#include <string> + +namespace OrthancPlugins +{ +//! @cond Doxygen_Suppress + // This class mimics "boost::noncopyable" + class NonCopyable + { + private: + NonCopyable(const NonCopyable&); + + NonCopyable& operator= (const NonCopyable&); + + protected: + NonCopyable() + { + } + + ~NonCopyable() + { + } + }; +//! @endcond + + + /** + * @ingroup Callbacks + **/ + class DatabaseException + { + private: + OrthancPluginErrorCode code_; + + public: + DatabaseException() : code_(OrthancPluginErrorCode_DatabasePlugin) + { + } + + DatabaseException(OrthancPluginErrorCode code) : code_(code) + { + } + + OrthancPluginErrorCode GetErrorCode() const + { + return code_; + } + }; + + + /** + * @ingroup Callbacks + **/ + class DatabaseBackendOutput : public NonCopyable + { + friend class DatabaseBackendAdapter; + + private: + enum AllowedAnswers + { + AllowedAnswers_All, + AllowedAnswers_None, + AllowedAnswers_Attachment, + AllowedAnswers_Change, + AllowedAnswers_DicomTag, + AllowedAnswers_ExportedResource + }; + + OrthancPluginContext* context_; + OrthancPluginDatabaseContext* database_; + AllowedAnswers allowedAnswers_; + + void SetAllowedAnswers(AllowedAnswers allowed) + { + allowedAnswers_ = allowed; + } + + public: + DatabaseBackendOutput(OrthancPluginContext* context, + OrthancPluginDatabaseContext* database) : + context_(context), + database_(database), + allowedAnswers_(AllowedAnswers_All /* for unit tests */) + { + } + + OrthancPluginContext* GetContext() + { + return context_; + } + + void LogError(const std::string& message) + { + OrthancPluginLogError(context_, message.c_str()); + } + + void LogWarning(const std::string& message) + { + OrthancPluginLogWarning(context_, message.c_str()); + } + + void LogInfo(const std::string& message) + { + OrthancPluginLogInfo(context_, message.c_str()); + } + + void SignalDeletedAttachment(const std::string& uuid, + int32_t contentType, + uint64_t uncompressedSize, + const std::string& uncompressedHash, + int32_t compressionType, + uint64_t compressedSize, + const std::string& compressedHash) + { + OrthancPluginAttachment attachment; + attachment.uuid = uuid.c_str(); + attachment.contentType = contentType; + attachment.uncompressedSize = uncompressedSize; + attachment.uncompressedHash = uncompressedHash.c_str(); + attachment.compressionType = compressionType; + attachment.compressedSize = compressedSize; + attachment.compressedHash = compressedHash.c_str(); + + OrthancPluginDatabaseSignalDeletedAttachment(context_, database_, &attachment); + } + + void SignalDeletedResource(const std::string& publicId, + OrthancPluginResourceType resourceType) + { + OrthancPluginDatabaseSignalDeletedResource(context_, database_, publicId.c_str(), resourceType); + } + + void SignalRemainingAncestor(const std::string& ancestorId, + OrthancPluginResourceType ancestorType) + { + OrthancPluginDatabaseSignalRemainingAncestor(context_, database_, ancestorId.c_str(), ancestorType); + } + + void AnswerAttachment(const std::string& uuid, + int32_t contentType, + uint64_t uncompressedSize, + const std::string& uncompressedHash, + int32_t compressionType, + uint64_t compressedSize, + const std::string& compressedHash) + { + if (allowedAnswers_ != AllowedAnswers_All && + allowedAnswers_ != AllowedAnswers_Attachment) + { + throw std::runtime_error("Cannot answer with an attachment in the current state"); + } + + OrthancPluginAttachment attachment; + attachment.uuid = uuid.c_str(); + attachment.contentType = contentType; + attachment.uncompressedSize = uncompressedSize; + attachment.uncompressedHash = uncompressedHash.c_str(); + attachment.compressionType = compressionType; + attachment.compressedSize = compressedSize; + attachment.compressedHash = compressedHash.c_str(); + + OrthancPluginDatabaseAnswerAttachment(context_, database_, &attachment); + } + + void AnswerChange(int64_t seq, + int32_t changeType, + OrthancPluginResourceType resourceType, + const std::string& publicId, + const std::string& date) + { + if (allowedAnswers_ != AllowedAnswers_All && + allowedAnswers_ != AllowedAnswers_Change) + { + throw std::runtime_error("Cannot answer with a change in the current state"); + } + + OrthancPluginChange change; + change.seq = seq; + change.changeType = changeType; + change.resourceType = resourceType; + change.publicId = publicId.c_str(); + change.date = date.c_str(); + + OrthancPluginDatabaseAnswerChange(context_, database_, &change); + } + + void AnswerDicomTag(uint16_t group, + uint16_t element, + const std::string& value) + { + if (allowedAnswers_ != AllowedAnswers_All && + allowedAnswers_ != AllowedAnswers_DicomTag) + { + throw std::runtime_error("Cannot answer with a DICOM tag in the current state"); + } + + OrthancPluginDicomTag tag; + tag.group = group; + tag.element = element; + tag.value = value.c_str(); + + OrthancPluginDatabaseAnswerDicomTag(context_, database_, &tag); + } + + void AnswerExportedResource(int64_t seq, + OrthancPluginResourceType resourceType, + const std::string& publicId, + const std::string& modality, + const std::string& date, + const std::string& patientId, + const std::string& studyInstanceUid, + const std::string& seriesInstanceUid, + const std::string& sopInstanceUid) + { + if (allowedAnswers_ != AllowedAnswers_All && + allowedAnswers_ != AllowedAnswers_ExportedResource) + { + throw std::runtime_error("Cannot answer with an exported resource in the current state"); + } + + OrthancPluginExportedResource exported; + exported.seq = seq; + exported.resourceType = resourceType; + exported.publicId = publicId.c_str(); + exported.modality = modality.c_str(); + exported.date = date.c_str(); + exported.patientId = patientId.c_str(); + exported.studyInstanceUid = studyInstanceUid.c_str(); + exported.seriesInstanceUid = seriesInstanceUid.c_str(); + exported.sopInstanceUid = sopInstanceUid.c_str(); + + OrthancPluginDatabaseAnswerExportedResource(context_, database_, &exported); + } + }; + + + /** + * @ingroup Callbacks + **/ + class IDatabaseBackend : public NonCopyable + { + friend class DatabaseBackendAdapter; + + private: + DatabaseBackendOutput* output_; + + void Finalize() + { + if (output_ != NULL) + { + delete output_; + output_ = NULL; + } + } + + protected: + DatabaseBackendOutput& GetOutput() + { + return *output_; + } + + public: + IDatabaseBackend() : output_(NULL) + { + } + + virtual ~IDatabaseBackend() + { + Finalize(); + } + + // This takes the ownership + void RegisterOutput(DatabaseBackendOutput* output) + { + Finalize(); + output_ = output; + } + + virtual void Open() = 0; + + virtual void Close() = 0; + + virtual void AddAttachment(int64_t id, + const OrthancPluginAttachment& attachment) = 0; + + virtual void AttachChild(int64_t parent, + int64_t child) = 0; + + virtual void ClearChanges() = 0; + + virtual void ClearExportedResources() = 0; + + virtual int64_t CreateResource(const char* publicId, + OrthancPluginResourceType type) = 0; + + virtual void DeleteAttachment(int64_t id, + int32_t attachment) = 0; + + virtual void DeleteMetadata(int64_t id, + int32_t metadataType) = 0; + + virtual void DeleteResource(int64_t id) = 0; + + virtual void GetAllInternalIds(std::list<int64_t>& target, + OrthancPluginResourceType resourceType) = 0; + + virtual void GetAllPublicIds(std::list<std::string>& target, + OrthancPluginResourceType resourceType) = 0; + + virtual void GetAllPublicIds(std::list<std::string>& target, + OrthancPluginResourceType resourceType, + uint64_t since, + uint64_t limit) = 0; + + /* Use GetOutput().AnswerChange() */ + virtual void GetChanges(bool& done /*out*/, + int64_t since, + uint32_t maxResults) = 0; + + virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, + int64_t id) = 0; + + virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, + int64_t id) = 0; + + /* Use GetOutput().AnswerExportedResource() */ + virtual void GetExportedResources(bool& done /*out*/, + int64_t since, + uint32_t maxResults) = 0; + + /* Use GetOutput().AnswerChange() */ + virtual void GetLastChange() = 0; + + /* Use GetOutput().AnswerExportedResource() */ + virtual void GetLastExportedResource() = 0; + + /* Use GetOutput().AnswerDicomTag() */ + virtual void GetMainDicomTags(int64_t id) = 0; + + virtual std::string GetPublicId(int64_t resourceId) = 0; + + virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) = 0; + + virtual OrthancPluginResourceType GetResourceType(int64_t resourceId) = 0; + + virtual uint64_t GetTotalCompressedSize() = 0; + + virtual uint64_t GetTotalUncompressedSize() = 0; + + virtual bool IsExistingResource(int64_t internalId) = 0; + + virtual bool IsProtectedPatient(int64_t internalId) = 0; + + virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, + int64_t id) = 0; + + virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, + int64_t id) = 0; + + virtual void LogChange(const OrthancPluginChange& change) = 0; + + virtual void LogExportedResource(const OrthancPluginExportedResource& resource) = 0; + + /* Use GetOutput().AnswerAttachment() */ + virtual bool LookupAttachment(int64_t id, + int32_t contentType) = 0; + + virtual bool LookupGlobalProperty(std::string& target /*out*/, + int32_t property) = 0; + + virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, + OrthancPluginResourceType resourceType, + uint16_t group, + uint16_t element, + OrthancPluginIdentifierConstraint constraint, + const char* value) = 0; + + virtual bool LookupMetadata(std::string& target /*out*/, + int64_t id, + int32_t metadataType) = 0; + + virtual bool LookupParent(int64_t& parentId /*out*/, + int64_t resourceId) = 0; + + virtual bool LookupResource(int64_t& id /*out*/, + OrthancPluginResourceType& type /*out*/, + const char* publicId) = 0; + + virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) = 0; + + virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, + int64_t patientIdToAvoid) = 0; + + virtual void SetGlobalProperty(int32_t property, + const char* value) = 0; + + virtual void SetMainDicomTag(int64_t id, + uint16_t group, + uint16_t element, + const char* value) = 0; + + virtual void SetIdentifierTag(int64_t id, + uint16_t group, + uint16_t element, + const char* value) = 0; + + virtual void SetMetadata(int64_t id, + int32_t metadataType, + const char* value) = 0; + + virtual void SetProtectedPatient(int64_t internalId, + bool isProtected) = 0; + + virtual void StartTransaction() = 0; + + virtual void RollbackTransaction() = 0; + + virtual void CommitTransaction() = 0; + + virtual uint32_t GetDatabaseVersion() = 0; + + /** + * Upgrade the database to the specified version of the database + * schema. The upgrade script is allowed to make calls to + * OrthancPluginReconstructMainDicomTags(). + **/ + virtual void UpgradeDatabase(uint32_t targetVersion, + OrthancPluginStorageArea* storageArea) = 0; + + virtual void ClearMainDicomTags(int64_t internalId) = 0; + }; + + + + /** + * @brief Bridge between C and C++ database engines. + * + * Class creating the bridge between the C low-level primitives for + * custom database engines, and the high-level IDatabaseBackend C++ + * interface. + * + * @ingroup Callbacks + **/ + class DatabaseBackendAdapter + { + private: + // This class cannot be instantiated + DatabaseBackendAdapter() + { + } + + static void LogError(IDatabaseBackend* backend, + const std::runtime_error& e) + { + backend->GetOutput().LogError("Exception in database back-end: " + std::string(e.what())); + } + + + static OrthancPluginErrorCode AddAttachment(void* payload, + int64_t id, + const OrthancPluginAttachment* attachment) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->AddAttachment(id, *attachment); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode AttachChild(void* payload, + int64_t parent, + int64_t child) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->AttachChild(parent, child); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode ClearChanges(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->ClearChanges(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode ClearExportedResources(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->ClearExportedResources(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode CreateResource(int64_t* id, + void* payload, + const char* publicId, + OrthancPluginResourceType resourceType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *id = backend->CreateResource(publicId, resourceType); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode DeleteAttachment(void* payload, + int64_t id, + int32_t contentType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->DeleteAttachment(id, contentType); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode DeleteMetadata(void* payload, + int64_t id, + int32_t metadataType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->DeleteMetadata(id, metadataType); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode DeleteResource(void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->DeleteResource(id); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetAllInternalIds(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<int64_t> target; + backend->GetAllInternalIds(target, resourceType); + + for (std::list<int64_t>::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetAllPublicIds(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<std::string> ids; + backend->GetAllPublicIds(ids, resourceType); + + for (std::list<std::string>::const_iterator + it = ids.begin(); it != ids.end(); ++it) + { + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, + it->c_str()); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetAllPublicIdsWithLimit(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType, + uint64_t since, + uint64_t limit) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<std::string> ids; + backend->GetAllPublicIds(ids, resourceType, since, limit); + + for (std::list<std::string>::const_iterator + it = ids.begin(); it != ids.end(); ++it) + { + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, + it->c_str()); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetChanges(OrthancPluginDatabaseContext* context, + void* payload, + int64_t since, + uint32_t maxResult) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); + + try + { + bool done; + backend->GetChanges(done, since, maxResult); + + if (done) + { + OrthancPluginDatabaseAnswerChangesDone(backend->GetOutput().context_, + backend->GetOutput().database_); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetChildrenInternalId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<int64_t> target; + backend->GetChildrenInternalId(target, id); + + for (std::list<int64_t>::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetChildrenPublicId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<std::string> ids; + backend->GetChildrenPublicId(ids, id); + + for (std::list<std::string>::const_iterator + it = ids.begin(); it != ids.end(); ++it) + { + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, + it->c_str()); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetExportedResources(OrthancPluginDatabaseContext* context, + void* payload, + int64_t since, + uint32_t maxResult) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); + + try + { + bool done; + backend->GetExportedResources(done, since, maxResult); + + if (done) + { + OrthancPluginDatabaseAnswerExportedResourcesDone(backend->GetOutput().context_, + backend->GetOutput().database_); + } + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetLastChange(OrthancPluginDatabaseContext* context, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); + + try + { + backend->GetLastChange(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetLastExportedResource(OrthancPluginDatabaseContext* context, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); + + try + { + backend->GetLastExportedResource(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetMainDicomTags(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_DicomTag); + + try + { + backend->GetMainDicomTags(id); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetPublicId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::string s = backend->GetPublicId(id); + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, + s.c_str()); + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetResourceCount(uint64_t* target, + void* payload, + OrthancPluginResourceType resourceType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *target = backend->GetResourceCount(resourceType); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetResourceType(OrthancPluginResourceType* resourceType, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *resourceType = backend->GetResourceType(id); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetTotalCompressedSize(uint64_t* target, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *target = backend->GetTotalCompressedSize(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetTotalUncompressedSize(uint64_t* target, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *target = backend->GetTotalUncompressedSize(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode IsExistingResource(int32_t* existing, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *existing = backend->IsExistingResource(id); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode IsProtectedPatient(int32_t* isProtected, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + *isProtected = backend->IsProtectedPatient(id); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode ListAvailableMetadata(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<int32_t> target; + backend->ListAvailableMetadata(target, id); + + for (std::list<int32_t>::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt32(backend->GetOutput().context_, + backend->GetOutput().database_, + *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode ListAvailableAttachments(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<int32_t> target; + backend->ListAvailableAttachments(target, id); + + for (std::list<int32_t>::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt32(backend->GetOutput().context_, + backend->GetOutput().database_, + *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LogChange(void* payload, + const OrthancPluginChange* change) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->LogChange(*change); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LogExportedResource(void* payload, + const OrthancPluginExportedResource* exported) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->LogExportedResource(*exported); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupAttachment(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id, + int32_t contentType) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Attachment); + + try + { + backend->LookupAttachment(id, contentType); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupGlobalProperty(OrthancPluginDatabaseContext* context, + void* payload, + int32_t property) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::string s; + if (backend->LookupGlobalProperty(s, property)) + { + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, + s.c_str()); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupIdentifier3(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType, + const OrthancPluginDicomTag* tag, + OrthancPluginIdentifierConstraint constraint) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::list<int64_t> target; + backend->LookupIdentifier(target, resourceType, tag->group, tag->element, constraint, tag->value); + + for (std::list<int64_t>::const_iterator + it = target.begin(); it != target.end(); ++it) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, *it); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupMetadata(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id, + int32_t metadata) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + std::string s; + if (backend->LookupMetadata(s, id, metadata)) + { + OrthancPluginDatabaseAnswerString(backend->GetOutput().context_, + backend->GetOutput().database_, s.c_str()); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupParent(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + int64_t parent; + if (backend->LookupParent(parent, id)) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, parent); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode LookupResource(OrthancPluginDatabaseContext* context, + void* payload, + const char* publicId) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + int64_t id; + OrthancPluginResourceType type; + if (backend->LookupResource(id, type, publicId)) + { + OrthancPluginDatabaseAnswerResource(backend->GetOutput().context_, + backend->GetOutput().database_, + id, type); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SelectPatientToRecycle(OrthancPluginDatabaseContext* context, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + int64_t id; + if (backend->SelectPatientToRecycle(id)) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, id); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SelectPatientToRecycle2(OrthancPluginDatabaseContext* context, + void* payload, + int64_t patientIdToAvoid) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + int64_t id; + if (backend->SelectPatientToRecycle(id, patientIdToAvoid)) + { + OrthancPluginDatabaseAnswerInt64(backend->GetOutput().context_, + backend->GetOutput().database_, id); + } + + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SetGlobalProperty(void* payload, + int32_t property, + const char* value) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->SetGlobalProperty(property, value); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SetMainDicomTag(void* payload, + int64_t id, + const OrthancPluginDicomTag* tag) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->SetMainDicomTag(id, tag->group, tag->element, tag->value); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SetIdentifierTag(void* payload, + int64_t id, + const OrthancPluginDicomTag* tag) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->SetIdentifierTag(id, tag->group, tag->element, tag->value); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SetMetadata(void* payload, + int64_t id, + int32_t metadata, + const char* value) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->SetMetadata(id, metadata, value); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode SetProtectedPatient(void* payload, + int64_t id, + int32_t isProtected) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->SetProtectedPatient(id, (isProtected != 0)); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode StartTransaction(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->StartTransaction(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode RollbackTransaction(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->RollbackTransaction(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode CommitTransaction(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->CommitTransaction(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode Open(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->Open(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode Close(void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); + + try + { + backend->Close(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode GetDatabaseVersion(uint32_t* version, + void* payload) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + + try + { + *version = backend->GetDatabaseVersion(); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode UpgradeDatabase(void* payload, + uint32_t targetVersion, + OrthancPluginStorageArea* storageArea) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + + try + { + backend->UpgradeDatabase(targetVersion, storageArea); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + static OrthancPluginErrorCode ClearMainDicomTags(void* payload, + int64_t internalId) + { + IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); + + try + { + backend->ClearMainDicomTags(internalId); + return OrthancPluginErrorCode_Success; + } + catch (std::runtime_error& e) + { + LogError(backend, e); + return OrthancPluginErrorCode_DatabasePlugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); + } + } + + + public: + /** + * Register a custom database back-end written in C++. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param backend Your custom database engine. + **/ + + static void Register(OrthancPluginContext* context, + IDatabaseBackend& backend) + { + OrthancPluginDatabaseBackend params; + memset(¶ms, 0, sizeof(params)); + + OrthancPluginDatabaseExtensions extensions; + memset(&extensions, 0, sizeof(extensions)); + + params.addAttachment = AddAttachment; + params.attachChild = AttachChild; + params.clearChanges = ClearChanges; + params.clearExportedResources = ClearExportedResources; + params.createResource = CreateResource; + params.deleteAttachment = DeleteAttachment; + params.deleteMetadata = DeleteMetadata; + params.deleteResource = DeleteResource; + params.getAllPublicIds = GetAllPublicIds; + params.getChanges = GetChanges; + params.getChildrenInternalId = GetChildrenInternalId; + params.getChildrenPublicId = GetChildrenPublicId; + params.getExportedResources = GetExportedResources; + params.getLastChange = GetLastChange; + params.getLastExportedResource = GetLastExportedResource; + params.getMainDicomTags = GetMainDicomTags; + params.getPublicId = GetPublicId; + params.getResourceCount = GetResourceCount; + params.getResourceType = GetResourceType; + params.getTotalCompressedSize = GetTotalCompressedSize; + params.getTotalUncompressedSize = GetTotalUncompressedSize; + params.isExistingResource = IsExistingResource; + params.isProtectedPatient = IsProtectedPatient; + params.listAvailableMetadata = ListAvailableMetadata; + params.listAvailableAttachments = ListAvailableAttachments; + params.logChange = LogChange; + params.logExportedResource = LogExportedResource; + params.lookupAttachment = LookupAttachment; + params.lookupGlobalProperty = LookupGlobalProperty; + params.lookupIdentifier = NULL; // Unused starting with Orthanc 0.9.5 (db v6) + params.lookupIdentifier2 = NULL; // Unused starting with Orthanc 0.9.5 (db v6) + params.lookupMetadata = LookupMetadata; + params.lookupParent = LookupParent; + params.lookupResource = LookupResource; + params.selectPatientToRecycle = SelectPatientToRecycle; + params.selectPatientToRecycle2 = SelectPatientToRecycle2; + params.setGlobalProperty = SetGlobalProperty; + params.setMainDicomTag = SetMainDicomTag; + params.setIdentifierTag = SetIdentifierTag; + params.setMetadata = SetMetadata; + params.setProtectedPatient = SetProtectedPatient; + params.startTransaction = StartTransaction; + params.rollbackTransaction = RollbackTransaction; + params.commitTransaction = CommitTransaction; + params.open = Open; + params.close = Close; + + extensions.getAllPublicIdsWithLimit = GetAllPublicIdsWithLimit; + extensions.getDatabaseVersion = GetDatabaseVersion; + extensions.upgradeDatabase = UpgradeDatabase; + extensions.clearMainDicomTags = ClearMainDicomTags; + extensions.getAllInternalIds = GetAllInternalIds; // New in Orthanc 0.9.5 (db v6) + extensions.lookupIdentifier3 = LookupIdentifier3; // New in Orthanc 0.9.5 (db v6) + + OrthancPluginDatabaseContext* database = OrthancPluginRegisterDatabaseBackendV2(context, ¶ms, &extensions, &backend); + if (!context) + { + throw std::runtime_error("Unable to register the database backend"); + } + + backend.RegisterOutput(new DatabaseBackendOutput(context, database)); + } + }; +}
--- a/Resources/SyncOrthancFolder.py Wed Apr 11 16:24:01 2018 +0200 +++ b/Resources/SyncOrthancFolder.py Mon Apr 16 17:19:57 2018 +0200 @@ -10,38 +10,16 @@ import stat import urllib2 -TARGET = os.path.join(os.path.dirname(__file__), '..', 'Orthanc') +TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc') PLUGIN_SDK_VERSION = '0.9.5' REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw' FILES = [ - 'NEWS', - 'Core/Endianness.h', - 'Plugins/Samples/Common/ExportedSymbols.list', - 'Plugins/Samples/Common/VersionScript.map', - 'Resources/CMake/AutoGeneratedCode.cmake', - 'Resources/CMake/BoostConfiguration.cmake', - 'Resources/CMake/Compiler.cmake', - 'Resources/CMake/DownloadPackage.cmake', - 'Resources/CMake/GoogleTestConfiguration.cmake', - 'Resources/CMake/JsonCppConfiguration.cmake', - 'Resources/CMake/UuidConfiguration.cmake', - 'Resources/EmbedResources.py', - 'Resources/LinuxStandardBaseToolchain.cmake', - 'Resources/MinGW-W64-Toolchain32.cmake', - 'Resources/MinGW-W64-Toolchain64.cmake', - 'Resources/MinGWToolchain.cmake', - 'Resources/Patches/boost-1.66.0-linux-standard-base.patch', - 'Resources/ThirdParty/VisualStudio/stdint.h', - 'Resources/WindowsResources.py', - 'Resources/WindowsResources.rc', - - # NB: The "patch.exe" for Windows is not necessary, - # as the only patch applies to Linux Standard Base - #'Resources/ThirdParty/patch/NOTES.txt', - #'Resources/ThirdParty/patch/msys-1.0.dll', - #'Resources/ThirdParty/patch/patch.exe', - #'Resources/ThirdParty/patch/patch.exe.manifest', + 'DownloadOrthancFramework.cmake', + 'LinuxStandardBaseToolchain.cmake', + 'MinGW-W64-Toolchain32.cmake', + 'MinGW-W64-Toolchain64.cmake', + 'MinGWToolchain.cmake', ] SDK = [ @@ -53,7 +31,6 @@ EXE = [ ] - def Download(x): branch = x[0] source = x[1] @@ -74,7 +51,9 @@ commands = [] for f in FILES: - commands.append([ 'default', f, f ]) + commands.append([ 'default', + os.path.join('Resources', f), + f ]) for f in SDK: commands.append([