# HG changeset patch # User Sebastien Jodogne # Date 1585245010 -3600 # Node ID fef9a239df5c9cc862fb859ad787337ad8c65cfd # Parent 7ed502b17b8f54de8885d96a413c9679f694ad4b adding auto-generated files diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Core/Compatibility.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Core/Compatibility.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,105 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2020 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 . + **/ + + +#pragma once + +//#define Orthanc_Compatibility_h_STR2(x) #x +//#define Orthanc_Compatibility_h_STR1(x) Orthanc_Compatibility_h_STR2(x) + +//#pragma message("__cplusplus = " Orthanc_Compatibility_h_STR1(__cplusplus)) + +#if (defined _MSC_VER) +//# pragma message("_MSC_VER = " Orthanc_Compatibility_h_STR1(_MSC_VER)) +//# pragma message("_MSVC_LANG = " Orthanc_Compatibility_h_STR1(_MSVC_LANG)) +// The __cplusplus macro cannot be used in Visual C++ < 1914 (VC++ 15.7) +// However, even in recent versions, __cplusplus will only be correct (that is, +// correctly defines the supported C++ version) if a special flag is passed to +// the compiler ("/Zc:__cplusplus") +// To make this header more robust, we use the _MSVC_LANG equivalent macro. + +// please note that not all C++11 features are supported when _MSC_VER == 1600 +// (or higher). This header file can be made for fine-grained, if required, +// based on specific _MSC_VER values + +# if _MSC_VER >= 1600 +# define ORTHANC_Cxx03_DETECTED 0 +# else +# define ORTHANC_Cxx03_DETECTED 1 +# endif + +#else +// of _MSC_VER is not defined, we assume __cplusplus is correctly defined +// if __cplusplus is not defined (very old compilers??), then the following +// test will compare 0 < 201103L and will be true --> safe. +# if __cplusplus < 201103L +# define ORTHANC_Cxx03_DETECTED 1 +# else +# define ORTHANC_Cxx03_DETECTED 0 +# endif +#endif + +#if ORTHANC_Cxx03_DETECTED == 1 +//#pragma message("C++ 11 support is not present.") + +/** + * "std::unique_ptr" was introduced in C++11, and "std::auto_ptr" was + * removed in C++17. We emulate "std::auto_ptr" using boost: "The + * smart pointer unique_ptr [is] a drop-in replacement for + * std::unique_ptr, usable also from C++03 compilers." This is only + * available if Boost >= 1.57.0 (from November 2014). + * https://www.boost.org/doc/libs/1_57_0/doc/html/move/reference.html#header.boost.move.unique_ptr_hpp + **/ + +#include + +namespace std +{ + template + class unique_ptr : public boost::movelib::unique_ptr + { + public: + explicit unique_ptr() : + boost::movelib::unique_ptr() + { + } + + explicit unique_ptr(T* p) : + boost::movelib::unique_ptr(p) + { + } + }; +} +#else +//# pragma message("C++ 11 support is present.") +# include +#endif diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,3180 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2020 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 . + **/ + + +#include "OrthancPluginCppWrapper.h" + +#include +#include +#include +#include +#include + + +namespace OrthancPlugins +{ + static OrthancPluginContext* globalContext_ = NULL; + + + void SetGlobalContext(OrthancPluginContext* context) + { + if (context == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); + } + else if (globalContext_ == NULL) + { + globalContext_ = context; + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); + } + } + + + bool HasGlobalContext() + { + return globalContext_ != NULL; + } + + + OrthancPluginContext* GetGlobalContext() + { + if (globalContext_ == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); + } + else + { + return globalContext_; + } + } + + + void MemoryBuffer::Check(OrthancPluginErrorCode code) + { + if (code != OrthancPluginErrorCode_Success) + { + // Prevent using garbage information + buffer_.data = NULL; + buffer_.size = 0; + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); + } + } + + + bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code) + { + if (code != OrthancPluginErrorCode_Success) + { + // Prevent using garbage information + buffer_.data = NULL; + buffer_.size = 0; + } + + if (code == OrthancPluginErrorCode_Success) + { + return true; + } + else if (code == OrthancPluginErrorCode_UnknownResource || + code == OrthancPluginErrorCode_InexistentItem) + { + return false; + } + else + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); + } + } + + + MemoryBuffer::MemoryBuffer() + { + buffer_.data = NULL; + buffer_.size = 0; + } + + + void MemoryBuffer::Clear() + { + if (buffer_.data != NULL) + { + OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); + buffer_.data = NULL; + buffer_.size = 0; + } + } + + + void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) + { + Clear(); + + buffer_.data = other.data; + buffer_.size = other.size; + + other.data = NULL; + other.size = 0; + } + + + void MemoryBuffer::Swap(MemoryBuffer& other) + { + std::swap(buffer_.data, other.buffer_.data); + std::swap(buffer_.size, other.buffer_.size); + } + + + OrthancPluginMemoryBuffer MemoryBuffer::Release() + { + OrthancPluginMemoryBuffer result = buffer_; + + buffer_.data = NULL; + buffer_.size = 0; + + return result; + } + + + void MemoryBuffer::ToString(std::string& target) const + { + if (buffer_.size == 0) + { + target.clear(); + } + else + { + target.assign(reinterpret_cast(buffer_.data), buffer_.size); + } + } + + + void MemoryBuffer::ToJson(Json::Value& target) const + { + if (buffer_.data == NULL || + buffer_.size == 0) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + const char* tmp = reinterpret_cast(buffer_.data); + + Json::Reader reader; + if (!reader.parse(tmp, tmp + buffer_.size, target)) + { + LogError("Cannot convert some memory buffer to JSON"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + + + bool MemoryBuffer::RestApiGet(const std::string& uri, + bool applyPlugins) + { + Clear(); + + if (applyPlugins) + { + return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); + } + else + { + return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); + } + } + + bool MemoryBuffer::RestApiGet(const std::string& uri, + const std::map& httpHeaders, + bool applyPlugins) + { + Clear(); + + std::vector headersKeys; + std::vector headersValues; + + for (std::map::const_iterator + it = httpHeaders.begin(); it != httpHeaders.end(); it++) + { + headersKeys.push_back(it->first.c_str()); + headersValues.push_back(it->second.c_str()); + } + + return CheckHttp(OrthancPluginRestApiGet2( + GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(), + (headersKeys.empty() ? NULL : &headersKeys[0]), + (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins)); + } + + bool MemoryBuffer::RestApiPost(const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins) + { + Clear(); + + // Cast for compatibility with Orthanc SDK <= 1.5.6 + const char* b = reinterpret_cast(body); + + if (applyPlugins) + { + return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); + } + else + { + return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); + } + } + + + bool MemoryBuffer::RestApiPut(const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins) + { + Clear(); + + // Cast for compatibility with Orthanc SDK <= 1.5.6 + const char* b = reinterpret_cast(body); + + if (applyPlugins) + { + return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); + } + else + { + return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); + } + } + + + bool MemoryBuffer::RestApiPost(const std::string& uri, + const Json::Value& body, + bool applyPlugins) + { + Json::FastWriter writer; + return RestApiPost(uri, writer.write(body), applyPlugins); + } + + + bool MemoryBuffer::RestApiPut(const std::string& uri, + const Json::Value& body, + bool applyPlugins) + { + Json::FastWriter writer; + return RestApiPut(uri, writer.write(body), applyPlugins); + } + + + void MemoryBuffer::CreateDicom(const Json::Value& tags, + OrthancPluginCreateDicomFlags flags) + { + Clear(); + + Json::FastWriter writer; + std::string s = writer.write(tags); + + Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); + } + + void MemoryBuffer::CreateDicom(const Json::Value& tags, + const OrthancImage& pixelData, + OrthancPluginCreateDicomFlags flags) + { + Clear(); + + Json::FastWriter writer; + std::string s = writer.write(tags); + + Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); + } + + + void MemoryBuffer::ReadFile(const std::string& path) + { + Clear(); + Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); + } + + + void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) + { + Clear(); + Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); + } + + + void OrthancString::Assign(char* str) + { + Clear(); + + if (str != NULL) + { + str_ = str; + } + } + + + void OrthancString::Clear() + { + if (str_ != NULL) + { + OrthancPluginFreeString(GetGlobalContext(), str_); + str_ = NULL; + } + } + + + void OrthancString::ToString(std::string& target) const + { + if (str_ == NULL) + { + target.clear(); + } + else + { + target.assign(str_); + } + } + + + void OrthancString::ToJson(Json::Value& target) const + { + if (str_ == NULL) + { + LogError("Cannot convert an empty memory buffer to JSON"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Json::Reader reader; + if (!reader.parse(str_, target)) + { + LogError("Cannot convert some memory buffer to JSON"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + + + void MemoryBuffer::DicomToJson(Json::Value& target, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength) + { + OrthancString str; + str.Assign(OrthancPluginDicomBufferToJson + (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); + str.ToJson(target); + } + + + bool MemoryBuffer::HttpGet(const std::string& url, + const std::string& username, + const std::string& password) + { + Clear(); + return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), + username.empty() ? NULL : username.c_str(), + password.empty() ? NULL : password.c_str())); + } + + + bool MemoryBuffer::HttpPost(const std::string& url, + const std::string& body, + const std::string& username, + const std::string& password) + { + Clear(); + return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), + body.c_str(), body.size(), + username.empty() ? NULL : username.c_str(), + password.empty() ? NULL : password.c_str())); + } + + + bool MemoryBuffer::HttpPut(const std::string& url, + const std::string& body, + const std::string& username, + const std::string& password) + { + Clear(); + return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), + body.empty() ? NULL : body.c_str(), + body.size(), + username.empty() ? NULL : username.c_str(), + password.empty() ? NULL : password.c_str())); + } + + + void MemoryBuffer::GetDicomInstance(const std::string& instanceId) + { + Clear(); + Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); + } + + + bool HttpDelete(const std::string& url, + const std::string& username, + const std::string& password) + { + OrthancPluginErrorCode error = OrthancPluginHttpDelete + (GetGlobalContext(), url.c_str(), + username.empty() ? NULL : username.c_str(), + password.empty() ? NULL : password.c_str()); + + if (error == OrthancPluginErrorCode_Success) + { + return true; + } + else if (error == OrthancPluginErrorCode_UnknownResource || + error == OrthancPluginErrorCode_InexistentItem) + { + return false; + } + else + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); + } + } + + + void LogError(const std::string& message) + { + if (HasGlobalContext()) + { + OrthancPluginLogError(GetGlobalContext(), message.c_str()); + } + } + + + void LogWarning(const std::string& message) + { + if (HasGlobalContext()) + { + OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); + } + } + + + void LogInfo(const std::string& message) + { + if (HasGlobalContext()) + { + OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); + } + } + + + void OrthancConfiguration::LoadConfiguration() + { + OrthancString str; + str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); + + if (str.GetContent() == NULL) + { + LogError("Cannot access the Orthanc configuration"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + str.ToJson(configuration_); + + if (configuration_.type() != Json::objectValue) + { + LogError("Unable to read the Orthanc configuration"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + } + + + OrthancConfiguration::OrthancConfiguration() + { + LoadConfiguration(); + } + + + OrthancConfiguration::OrthancConfiguration(bool loadConfiguration) + { + if (loadConfiguration) + { + LoadConfiguration(); + } + else + { + configuration_ = Json::objectValue; + } + } + + + std::string OrthancConfiguration::GetPath(const std::string& key) const + { + if (path_.empty()) + { + return key; + } + else + { + return path_ + "." + key; + } + } + + + bool OrthancConfiguration::IsSection(const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + return (configuration_.isMember(key) && + configuration_[key].type() == Json::objectValue); + } + + + void OrthancConfiguration::GetSection(OrthancConfiguration& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + target.path_ = GetPath(key); + + if (!configuration_.isMember(key)) + { + target.configuration_ = Json::objectValue; + } + else + { + if (configuration_[key].type() != Json::objectValue) + { + LogError("The configuration section \"" + target.path_ + + "\" is not an associative array as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + + target.configuration_ = configuration_[key]; + } + } + + + bool OrthancConfiguration::LookupStringValue(std::string& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + if (!configuration_.isMember(key)) + { + return false; + } + + if (configuration_[key].type() != Json::stringValue) + { + LogError("The configuration option \"" + GetPath(key) + + "\" is not a string as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + + target = configuration_[key].asString(); + return true; + } + + + bool OrthancConfiguration::LookupIntegerValue(int& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + if (!configuration_.isMember(key)) + { + return false; + } + + switch (configuration_[key].type()) + { + case Json::intValue: + target = configuration_[key].asInt(); + return true; + + case Json::uintValue: + target = configuration_[key].asUInt(); + return true; + + default: + LogError("The configuration option \"" + GetPath(key) + + "\" is not an integer as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + + + bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, + const std::string& key) const + { + int tmp; + if (!LookupIntegerValue(tmp, key)) + { + return false; + } + + if (tmp < 0) + { + LogError("The configuration option \"" + GetPath(key) + + "\" is not a positive integer as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + else + { + target = static_cast(tmp); + return true; + } + } + + + bool OrthancConfiguration::LookupBooleanValue(bool& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + if (!configuration_.isMember(key)) + { + return false; + } + + if (configuration_[key].type() != Json::booleanValue) + { + LogError("The configuration option \"" + GetPath(key) + + "\" is not a Boolean as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + + target = configuration_[key].asBool(); + return true; + } + + + bool OrthancConfiguration::LookupFloatValue(float& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + if (!configuration_.isMember(key)) + { + return false; + } + + switch (configuration_[key].type()) + { + case Json::realValue: + target = configuration_[key].asFloat(); + return true; + + case Json::intValue: + target = static_cast(configuration_[key].asInt()); + return true; + + case Json::uintValue: + target = static_cast(configuration_[key].asUInt()); + return true; + + default: + LogError("The configuration option \"" + GetPath(key) + + "\" is not an integer as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + + + bool OrthancConfiguration::LookupListOfStrings(std::list& target, + const std::string& key, + bool allowSingleString) const + { + assert(configuration_.type() == Json::objectValue); + + target.clear(); + + if (!configuration_.isMember(key)) + { + return false; + } + + switch (configuration_[key].type()) + { + case Json::arrayValue: + { + bool ok = true; + + for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) + { + if (configuration_[key][i].type() == Json::stringValue) + { + target.push_back(configuration_[key][i].asString()); + } + else + { + ok = false; + } + } + + if (ok) + { + return true; + } + + break; + } + + case Json::stringValue: + if (allowSingleString) + { + target.push_back(configuration_[key].asString()); + return true; + } + + break; + + default: + break; + } + + LogError("The configuration option \"" + GetPath(key) + + "\" is not a list of strings as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + + + bool OrthancConfiguration::LookupSetOfStrings(std::set& target, + const std::string& key, + bool allowSingleString) const + { + std::list lst; + + if (LookupListOfStrings(lst, key, allowSingleString)) + { + target.clear(); + + for (std::list::const_iterator + it = lst.begin(); it != lst.end(); ++it) + { + target.insert(*it); + } + + return true; + } + else + { + return false; + } + } + + + std::string OrthancConfiguration::GetStringValue(const std::string& key, + const std::string& defaultValue) const + { + std::string tmp; + if (LookupStringValue(tmp, key)) + { + return tmp; + } + else + { + return defaultValue; + } + } + + + int OrthancConfiguration::GetIntegerValue(const std::string& key, + int defaultValue) const + { + int tmp; + if (LookupIntegerValue(tmp, key)) + { + return tmp; + } + else + { + return defaultValue; + } + } + + + unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, + unsigned int defaultValue) const + { + unsigned int tmp; + if (LookupUnsignedIntegerValue(tmp, key)) + { + return tmp; + } + else + { + return defaultValue; + } + } + + + bool OrthancConfiguration::GetBooleanValue(const std::string& key, + bool defaultValue) const + { + bool tmp; + if (LookupBooleanValue(tmp, key)) + { + return tmp; + } + else + { + return defaultValue; + } + } + + + float OrthancConfiguration::GetFloatValue(const std::string& key, + float defaultValue) const + { + float tmp; + if (LookupFloatValue(tmp, key)) + { + return tmp; + } + else + { + return defaultValue; + } + } + + + void OrthancConfiguration::GetDictionary(std::map& target, + const std::string& key) const + { + assert(configuration_.type() == Json::objectValue); + + target.clear(); + + if (!configuration_.isMember(key)) + { + return; + } + + if (configuration_[key].type() != Json::objectValue) + { + LogError("The configuration option \"" + GetPath(key) + + "\" is not a string as expected"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + + Json::Value::Members members = configuration_[key].getMemberNames(); + + for (size_t i = 0; i < members.size(); i++) + { + const Json::Value& value = configuration_[key][members[i]]; + + if (value.type() == Json::stringValue) + { + target[members[i]] = value.asString(); + } + else + { + LogError("The configuration option \"" + GetPath(key) + + "\" is not a dictionary mapping strings to strings"); + + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + } + + + void OrthancImage::Clear() + { + if (image_ != NULL) + { + OrthancPluginFreeImage(GetGlobalContext(), image_); + image_ = NULL; + } + } + + + void OrthancImage::CheckImageAvailable() const + { + if (image_ == NULL) + { + LogError("Trying to access a NULL image"); + ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + } + } + + + OrthancImage::OrthancImage() : + image_(NULL) + { + } + + + OrthancImage::OrthancImage(OrthancPluginImage* image) : + image_(image) + { + } + + + OrthancImage::OrthancImage(OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height) + { + image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); + + if (image_ == NULL) + { + LogError("Cannot create an image"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + } + + + OrthancImage::OrthancImage(OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + void* buffer) + { + image_ = OrthancPluginCreateImageAccessor + (GetGlobalContext(), format, width, height, pitch, buffer); + + if (image_ == NULL) + { + LogError("Cannot create an image accessor"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + } + + void OrthancImage::UncompressPngImage(const void* data, + size_t size) + { + Clear(); + + image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); + + if (image_ == NULL) + { + LogError("Cannot uncompress a PNG image"); + ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + } + } + + + void OrthancImage::UncompressJpegImage(const void* data, + size_t size) + { + Clear(); + image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); + if (image_ == NULL) + { + LogError("Cannot uncompress a JPEG image"); + ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + } + } + + + void OrthancImage::DecodeDicomImage(const void* data, + size_t size, + unsigned int frame) + { + Clear(); + image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); + if (image_ == NULL) + { + LogError("Cannot uncompress a DICOM image"); + ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + } + } + + + OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const + { + CheckImageAvailable(); + return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); + } + + + unsigned int OrthancImage::GetWidth() const + { + CheckImageAvailable(); + return OrthancPluginGetImageWidth(GetGlobalContext(), image_); + } + + + unsigned int OrthancImage::GetHeight() const + { + CheckImageAvailable(); + return OrthancPluginGetImageHeight(GetGlobalContext(), image_); + } + + + unsigned int OrthancImage::GetPitch() const + { + CheckImageAvailable(); + return OrthancPluginGetImagePitch(GetGlobalContext(), image_); + } + + + const void* OrthancImage::GetBuffer() const + { + CheckImageAvailable(); + return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); + } + + + void OrthancImage::CompressPngImage(MemoryBuffer& target) const + { + CheckImageAvailable(); + + OrthancPlugins::MemoryBuffer answer; + OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), + GetWidth(), GetHeight(), GetPitch(), GetBuffer()); + + target.Swap(answer); + } + + + void OrthancImage::CompressJpegImage(MemoryBuffer& target, + uint8_t quality) const + { + CheckImageAvailable(); + + OrthancPlugins::MemoryBuffer answer; + OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), + GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); + + target.Swap(answer); + } + + + void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const + { + CheckImageAvailable(); + OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), + GetWidth(), GetHeight(), GetPitch(), GetBuffer()); + } + + + void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, + uint8_t quality) const + { + CheckImageAvailable(); + OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), + GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); + } + + + +#if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 + FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : + matcher_(NULL), + worklist_(worklist) + { + if (worklist_ == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); + } + } + + + void FindMatcher::SetupDicom(const void* query, + uint32_t size) + { + worklist_ = NULL; + + matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); + if (matcher_ == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + } + + + FindMatcher::~FindMatcher() + { + // The "worklist_" field + + if (matcher_ != NULL) + { + OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); + } + } + + + + bool FindMatcher::IsMatch(const void* dicom, + uint32_t size) const + { + int32_t result; + + if (matcher_ != NULL) + { + result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); + } + else if (worklist_ != NULL) + { + result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + if (result == 0) + { + return false; + } + else if (result == 1) + { + return true; + } + else + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + } + +#endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ + + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output + ) + { + Json::StyledWriter writer; + std::string bodyString = writer.write(value); + + OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); + } + + void AnswerString(const std::string& answer, + const char* mimeType, + OrthancPluginRestOutput* output + ) + { + OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); + } + + void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) + { + OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); + } + + void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); + } + + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins) + { + MemoryBuffer answer; + if (!answer.RestApiGet(uri, applyPlugins)) + { + return false; + } + else + { + answer.ToString(result); + return true; + } + } + + bool RestApiGetString(std::string& result, + const std::string& uri, + const std::map& httpHeaders, + bool applyPlugins) + { + MemoryBuffer answer; + if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) + { + return false; + } + else + { + answer.ToString(result); + return true; + } + } + + + + bool RestApiGet(Json::Value& result, + const std::string& uri, + bool applyPlugins) + { + MemoryBuffer answer; + + if (!answer.RestApiGet(uri, applyPlugins)) + { + return false; + } + else + { + if (!answer.IsEmpty()) + { + answer.ToJson(result); + } + return true; + } + } + + + bool RestApiPost(std::string& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins) + { + MemoryBuffer answer; + + if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) + { + return false; + } + else + { + if (!answer.IsEmpty()) + { + result.assign(answer.GetData(), answer.GetSize()); + } + return true; + } + } + + + bool RestApiPost(Json::Value& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins) + { + MemoryBuffer answer; + + if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) + { + return false; + } + else + { + if (!answer.IsEmpty()) + { + answer.ToJson(result); + } + return true; + } + } + + + bool RestApiPost(Json::Value& result, + const std::string& uri, + const Json::Value& body, + bool applyPlugins) + { + Json::FastWriter writer; + return RestApiPost(result, uri, writer.write(body), applyPlugins); + } + + + bool RestApiPut(Json::Value& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins) + { + MemoryBuffer answer; + + if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) + { + return false; + } + else + { + if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response + { + answer.ToJson(result); + } + return true; + } + } + + + bool RestApiPut(Json::Value& result, + const std::string& uri, + const Json::Value& body, + bool applyPlugins) + { + Json::FastWriter writer; + return RestApiPut(result, uri, writer.write(body), applyPlugins); + } + + + bool RestApiDelete(const std::string& uri, + bool applyPlugins) + { + OrthancPluginErrorCode error; + + if (applyPlugins) + { + error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); + } + else + { + error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); + } + + if (error == OrthancPluginErrorCode_Success) + { + return true; + } + else if (error == OrthancPluginErrorCode_UnknownResource || + error == OrthancPluginErrorCode_InexistentItem) + { + return false; + } + else + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); + } + } + + + void ReportMinimalOrthancVersion(unsigned int major, + unsigned int minor, + unsigned int revision) + { + LogError("Your version of the Orthanc core (" + + std::string(GetGlobalContext()->orthancVersion) + + ") is too old to run this plugin (version " + + boost::lexical_cast(major) + "." + + boost::lexical_cast(minor) + "." + + boost::lexical_cast(revision) + + " is required)"); + } + + + bool CheckMinimalOrthancVersion(unsigned int major, + unsigned int minor, + unsigned int revision) + { + if (!HasGlobalContext()) + { + LogError("Bad Orthanc context in the plugin"); + return false; + } + + if (!strcmp(GetGlobalContext()->orthancVersion, "mainline")) + { + // Assume compatibility with the mainline + return true; + } + + // Parse the version of the Orthanc core + int aa, bb, cc; + if ( +#ifdef _MSC_VER + sscanf_s +#else + sscanf +#endif + (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || + aa < 0 || + bb < 0 || + cc < 0) + { + return false; + } + + unsigned int a = static_cast(aa); + unsigned int b = static_cast(bb); + unsigned int c = static_cast(cc); + + // Check the major version number + + if (a > major) + { + return true; + } + + if (a < major) + { + return false; + } + + + // Check the minor version number + assert(a == major); + + if (b > minor) + { + return true; + } + + if (b < minor) + { + return false; + } + + // Check the patch level version number + assert(a == major && b == minor); + + if (c >= revision) + { + return true; + } + else + { + return false; + } + } + + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) + const char* AutodetectMimeType(const std::string& path) + { + const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); + + if (mime == NULL) + { + // Should never happen, just for safety + return "application/octet-stream"; + } + else + { + return mime; + } + } +#endif + + +#if HAS_ORTHANC_PLUGIN_PEERS == 1 + size_t OrthancPeers::GetPeerIndex(const std::string& name) const + { + size_t index; + if (LookupName(index, name)) + { + return index; + } + else + { + LogError("Inexistent peer: " + name); + ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); + } + } + + + OrthancPeers::OrthancPeers() : + peers_(NULL), + timeout_(0) + { + peers_ = OrthancPluginGetPeers(GetGlobalContext()); + + if (peers_ == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + + uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); + + for (uint32_t i = 0; i < count; i++) + { + const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); + if (name == NULL) + { + OrthancPluginFreePeers(GetGlobalContext(), peers_); + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + + index_[name] = i; + } + } + + + OrthancPeers::~OrthancPeers() + { + if (peers_ != NULL) + { + OrthancPluginFreePeers(GetGlobalContext(), peers_); + } + } + + + bool OrthancPeers::LookupName(size_t& target, + const std::string& name) const + { + Index::const_iterator found = index_.find(name); + + if (found == index_.end()) + { + return false; + } + else + { + target = found->second; + return true; + } + } + + + std::string OrthancPeers::GetPeerName(size_t index) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + else + { + const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast(index)); + if (s == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + else + { + return s; + } + } + } + + + std::string OrthancPeers::GetPeerUrl(size_t index) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + else + { + const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast(index)); + if (s == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + else + { + return s; + } + } + } + + + std::string OrthancPeers::GetPeerUrl(const std::string& name) const + { + return GetPeerUrl(GetPeerIndex(name)); + } + + + bool OrthancPeers::LookupUserProperty(std::string& value, + size_t index, + const std::string& key) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + else + { + const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast(index), key.c_str()); + if (s == NULL) + { + return false; + } + else + { + value.assign(s); + return true; + } + } + } + + + bool OrthancPeers::LookupUserProperty(std::string& value, + const std::string& peer, + const std::string& key) const + { + return LookupUserProperty(value, GetPeerIndex(peer), key); + } + + + bool OrthancPeers::DoGet(MemoryBuffer& target, + size_t index, + const std::string& uri) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + + OrthancPlugins::MemoryBuffer answer; + uint16_t status; + OrthancPluginErrorCode code = OrthancPluginCallPeerApi + (GetGlobalContext(), *answer, NULL, &status, peers_, + static_cast(index), OrthancPluginHttpMethod_Get, uri.c_str(), + 0, NULL, NULL, NULL, 0, timeout_); + + if (code == OrthancPluginErrorCode_Success) + { + target.Swap(answer); + return (status == 200); + } + else + { + return false; + } + } + + + bool OrthancPeers::DoGet(MemoryBuffer& target, + const std::string& name, + const std::string& uri) const + { + size_t index; + return (LookupName(index, name) && + DoGet(target, index, uri)); + } + + + bool OrthancPeers::DoGet(Json::Value& target, + size_t index, + const std::string& uri) const + { + MemoryBuffer buffer; + + if (DoGet(buffer, index, uri)) + { + buffer.ToJson(target); + return true; + } + else + { + return false; + } + } + + + bool OrthancPeers::DoGet(Json::Value& target, + const std::string& name, + const std::string& uri) const + { + MemoryBuffer buffer; + + if (DoGet(buffer, name, uri)) + { + buffer.ToJson(target); + return true; + } + else + { + return false; + } + } + + + bool OrthancPeers::DoPost(MemoryBuffer& target, + const std::string& name, + const std::string& uri, + const std::string& body) const + { + size_t index; + return (LookupName(index, name) && + DoPost(target, index, uri, body)); + } + + + bool OrthancPeers::DoPost(Json::Value& target, + size_t index, + const std::string& uri, + const std::string& body) const + { + MemoryBuffer buffer; + + if (DoPost(buffer, index, uri, body)) + { + buffer.ToJson(target); + return true; + } + else + { + return false; + } + } + + + bool OrthancPeers::DoPost(Json::Value& target, + const std::string& name, + const std::string& uri, + const std::string& body) const + { + MemoryBuffer buffer; + + if (DoPost(buffer, name, uri, body)) + { + buffer.ToJson(target); + return true; + } + else + { + return false; + } + } + + + bool OrthancPeers::DoPost(MemoryBuffer& target, + size_t index, + const std::string& uri, + const std::string& body) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + + OrthancPlugins::MemoryBuffer answer; + uint16_t status; + OrthancPluginErrorCode code = OrthancPluginCallPeerApi + (GetGlobalContext(), *answer, NULL, &status, peers_, + static_cast(index), OrthancPluginHttpMethod_Post, uri.c_str(), + 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); + + if (code == OrthancPluginErrorCode_Success) + { + target.Swap(answer); + return (status == 200); + } + else + { + return false; + } + } + + + bool OrthancPeers::DoPut(size_t index, + const std::string& uri, + const std::string& body) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + + OrthancPlugins::MemoryBuffer answer; + uint16_t status; + OrthancPluginErrorCode code = OrthancPluginCallPeerApi + (GetGlobalContext(), *answer, NULL, &status, peers_, + static_cast(index), OrthancPluginHttpMethod_Put, uri.c_str(), + 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); + + if (code == OrthancPluginErrorCode_Success) + { + return (status == 200); + } + else + { + return false; + } + } + + + bool OrthancPeers::DoPut(const std::string& name, + const std::string& uri, + const std::string& body) const + { + size_t index; + return (LookupName(index, name) && + DoPut(index, uri, body)); + } + + + bool OrthancPeers::DoDelete(size_t index, + const std::string& uri) const + { + if (index >= index_.size()) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + + OrthancPlugins::MemoryBuffer answer; + uint16_t status; + OrthancPluginErrorCode code = OrthancPluginCallPeerApi + (GetGlobalContext(), *answer, NULL, &status, peers_, + static_cast(index), OrthancPluginHttpMethod_Delete, uri.c_str(), + 0, NULL, NULL, NULL, 0, timeout_); + + if (code == OrthancPluginErrorCode_Success) + { + return (status == 200); + } + else + { + return false; + } + } + + + bool OrthancPeers::DoDelete(const std::string& name, + const std::string& uri) const + { + size_t index; + return (LookupName(index, name) && + DoDelete(index, uri)); + } +#endif + + + + + + /****************************************************************** + ** JOBS + ******************************************************************/ + +#if HAS_ORTHANC_PLUGIN_JOB == 1 + void OrthancJob::CallbackFinalize(void* job) + { + if (job != NULL) + { + delete reinterpret_cast(job); + } + } + + + float OrthancJob::CallbackGetProgress(void* job) + { + assert(job != NULL); + + try + { + return reinterpret_cast(job)->progress_; + } + catch (...) + { + return 0; + } + } + + + const char* OrthancJob::CallbackGetContent(void* job) + { + assert(job != NULL); + + try + { + return reinterpret_cast(job)->content_.c_str(); + } + catch (...) + { + return 0; + } + } + + + const char* OrthancJob::CallbackGetSerialized(void* job) + { + assert(job != NULL); + + try + { + const OrthancJob& tmp = *reinterpret_cast(job); + + if (tmp.hasSerialized_) + { + return tmp.serialized_.c_str(); + } + else + { + return NULL; + } + } + catch (...) + { + return 0; + } + } + + + OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) + { + assert(job != NULL); + + try + { + return reinterpret_cast(job)->Step(); + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) + { + return OrthancPluginJobStepStatus_Failure; + } + catch (...) + { + return OrthancPluginJobStepStatus_Failure; + } + } + + + OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, + OrthancPluginJobStopReason reason) + { + assert(job != NULL); + + try + { + reinterpret_cast(job)->Stop(reason); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + + + OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) + { + assert(job != NULL); + + try + { + reinterpret_cast(job)->Reset(); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + + + void OrthancJob::ClearContent() + { + Json::Value empty = Json::objectValue; + UpdateContent(empty); + } + + + void OrthancJob::UpdateContent(const Json::Value& content) + { + if (content.type() != Json::objectValue) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); + } + else + { + Json::FastWriter writer; + content_ = writer.write(content); + } + } + + + void OrthancJob::ClearSerialized() + { + hasSerialized_ = false; + serialized_.clear(); + } + + + void OrthancJob::UpdateSerialized(const Json::Value& serialized) + { + if (serialized.type() != Json::objectValue) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); + } + else + { + Json::FastWriter writer; + serialized_ = writer.write(serialized); + hasSerialized_ = true; + } + } + + + void OrthancJob::UpdateProgress(float progress) + { + if (progress < 0 || + progress > 1) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + } + + progress_ = progress; + } + + + OrthancJob::OrthancJob(const std::string& jobType) : + jobType_(jobType), + progress_(0) + { + ClearContent(); + ClearSerialized(); + } + + + OrthancPluginJob* OrthancJob::Create(OrthancJob* job) + { + if (job == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); + } + + OrthancPluginJob* orthanc = OrthancPluginCreateJob( + GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), + CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, + CallbackStep, CallbackStop, CallbackReset); + + if (orthanc == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + else + { + return orthanc; + } + } + + + std::string OrthancJob::Submit(OrthancJob* job, + int priority) + { + if (job == NULL) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); + } + + OrthancPluginJob* orthanc = Create(job); + + char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); + + if (id == NULL) + { + LogError("Plugin cannot submit job"); + OrthancPluginFreeJob(GetGlobalContext(), orthanc); + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); + } + else + { + std::string tmp(id); + tmp.assign(id); + OrthancPluginFreeString(GetGlobalContext(), id); + + return tmp; + } + } + + + void OrthancJob::SubmitAndWait(Json::Value& result, + OrthancJob* job /* takes ownership */, + int priority) + { + std::string id = Submit(job, priority); + + for (;;) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + + Json::Value status; + if (!RestApiGet(status, "/jobs/" + id, false) || + !status.isMember("State") || + status["State"].type() != Json::stringValue) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem); + } + + const std::string state = status["State"].asString(); + if (state == "Success") + { + if (status.isMember("Content")) + { + result = status["Content"]; + } + else + { + result = Json::objectValue; + } + + return; + } + else if (state == "Running") + { + continue; + } + else if (!status.isMember("ErrorCode") || + status["ErrorCode"].type() != Json::intValue) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError); + } + else + { + if (!status.isMember("ErrorDescription") || + status["ErrorDescription"].type() != Json::stringValue) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); + } + else + { +#if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(static_cast(status["ErrorCode"].asInt()), + status["ErrorDescription"].asString()); +#else + LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); +#endif + } + } + } + } + + + void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output, + const Json::Value& body, + OrthancJob* job) + { + static const char* KEY_SYNCHRONOUS = "Synchronous"; + static const char* KEY_ASYNCHRONOUS = "Asynchronous"; + static const char* KEY_PRIORITY = "Priority"; + + boost::movelib::unique_ptr protection(job); + + if (body.type() != Json::objectValue) + { +#if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, + "Expected a JSON object in the body"); +#else + LogError("Expected a JSON object in the body"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); +#endif + } + + bool synchronous = true; + + if (body.isMember(KEY_SYNCHRONOUS)) + { + if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue) + { +#if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, + "Option \"" + std::string(KEY_SYNCHRONOUS) + + "\" must be Boolean"); +#else + LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); +#endif + } + else + { + synchronous = body[KEY_SYNCHRONOUS].asBool(); + } + } + + if (body.isMember(KEY_ASYNCHRONOUS)) + { + if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue) + { +#if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, + "Option \"" + std::string(KEY_ASYNCHRONOUS) + + "\" must be Boolean"); +#else + LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); +#endif + } + else + { + synchronous = !body[KEY_ASYNCHRONOUS].asBool(); + } + } + + int priority = 0; + + if (body.isMember(KEY_PRIORITY)) + { + if (body[KEY_PRIORITY].type() != Json::booleanValue) + { +#if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, + "Option \"" + std::string(KEY_PRIORITY) + + "\" must be an integer"); +#else + LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); +#endif + } + else + { + priority = !body[KEY_PRIORITY].asInt(); + } + } + + Json::Value result; + + if (synchronous) + { + OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority); + } + else + { + std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority); + + result = Json::objectValue; + result["ID"] = id; + result["Path"] = "/jobs/" + id; + } + + std::string s = result.toStyledString(); + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), + s.size(), "application/json"); + } + +#endif + + + + + /****************************************************************** + ** METRICS + ******************************************************************/ + +#if HAS_ORTHANC_PLUGIN_METRICS == 1 + MetricsTimer::MetricsTimer(const char* name) : + name_(name) + { + start_ = boost::posix_time::microsec_clock::universal_time(); + } + + MetricsTimer::~MetricsTimer() + { + const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time(); + const boost::posix_time::time_duration diff = stop - start_; + OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast(diff.total_milliseconds()), + OrthancPluginMetricsType_Timer); + } +#endif + + + + + /****************************************************************** + ** HTTP CLIENT + ******************************************************************/ + +#if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 + class HttpClient::RequestBodyWrapper : public boost::noncopyable + { + private: + static RequestBodyWrapper& GetObject(void* body) + { + assert(body != NULL); + return *reinterpret_cast(body); + } + + IRequestBody& body_; + bool done_; + std::string chunk_; + + public: + RequestBodyWrapper(IRequestBody& body) : + body_(body), + done_(false) + { + } + + static uint8_t IsDone(void* body) + { + return GetObject(body).done_; + } + + static const void* GetChunkData(void* body) + { + return GetObject(body).chunk_.c_str(); + } + + static uint32_t GetChunkSize(void* body) + { + return static_cast(GetObject(body).chunk_.size()); + } + + static OrthancPluginErrorCode Next(void* body) + { + RequestBodyWrapper& that = GetObject(body); + + if (that.done_) + { + return OrthancPluginErrorCode_BadSequenceOfCalls; + } + else + { + try + { + that.done_ = !that.body_.ReadNextChunk(that.chunk_); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_InternalError; + } + } + } + }; + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer, + const char* key, + const char* value) + { + assert(answer != NULL && key != NULL && value != NULL); + + try + { + reinterpret_cast(answer)->AddHeader(key, value); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } +#endif + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer, + const void* data, + uint32_t size) + { + assert(answer != NULL); + + try + { + reinterpret_cast(answer)->AddChunk(data, size); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } +#endif + + + HttpClient::HttpClient() : + httpStatus_(0), + method_(OrthancPluginHttpMethod_Get), + timeout_(0), + pkcs11_(false), + chunkedBody_(NULL), + allowChunkedTransfers_(true) + { + } + + + void HttpClient::AddHeaders(const HttpHeaders& headers) + { + for (HttpHeaders::const_iterator it = headers.begin(); + it != headers.end(); ++it) + { + headers_[it->first] = it->second; + } + } + + + void HttpClient::SetCredentials(const std::string& username, + const std::string& password) + { + username_ = username; + password_ = password; + } + + + void HttpClient::ClearCredentials() + { + username_.empty(); + password_.empty(); + } + + + void HttpClient::SetCertificate(const std::string& certificateFile, + const std::string& keyFile, + const std::string& keyPassword) + { + certificateFile_ = certificateFile; + certificateKeyFile_ = keyFile; + certificateKeyPassword_ = keyPassword; + } + + + void HttpClient::ClearCertificate() + { + certificateFile_.clear(); + certificateKeyFile_.clear(); + certificateKeyPassword_.clear(); + } + + + void HttpClient::ClearBody() + { + fullBody_.clear(); + chunkedBody_ = NULL; + } + + + void HttpClient::SwapBody(std::string& body) + { + fullBody_.swap(body); + chunkedBody_ = NULL; + } + + + void HttpClient::SetBody(const std::string& body) + { + fullBody_ = body; + chunkedBody_ = NULL; + } + + + void HttpClient::SetBody(IRequestBody& body) + { + fullBody_.clear(); + chunkedBody_ = &body; + } + + + namespace + { + class HeadersWrapper : public boost::noncopyable + { + private: + std::vector headersKeys_; + std::vector headersValues_; + + public: + HeadersWrapper(const HttpClient::HttpHeaders& headers) + { + headersKeys_.reserve(headers.size()); + headersValues_.reserve(headers.size()); + + for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) + { + headersKeys_.push_back(it->first.c_str()); + headersValues_.push_back(it->second.c_str()); + } + } + + void AddStaticString(const char* key, + const char* value) + { + headersKeys_.push_back(key); + headersValues_.push_back(value); + } + + uint32_t GetCount() const + { + return headersKeys_.size(); + } + + const char* const* GetKeys() const + { + return headersKeys_.empty() ? NULL : &headersKeys_[0]; + } + + const char* const* GetValues() const + { + return headersValues_.empty() ? NULL : &headersValues_[0]; + } + }; + + + class MemoryRequestBody : public HttpClient::IRequestBody + { + private: + std::string body_; + bool done_; + + public: + MemoryRequestBody(const std::string& body) : + body_(body), + done_(false) + { + if (body_.empty()) + { + done_ = true; + } + } + + virtual bool ReadNextChunk(std::string& chunk) + { + if (done_) + { + return false; + } + else + { + chunk.swap(body_); + done_ = true; + return true; + } + } + }; + + + // This class mimics Orthanc::ChunkedBuffer + class ChunkedBuffer : public boost::noncopyable + { + private: + typedef std::list Content; + + Content content_; + size_t size_; + + public: + ChunkedBuffer() : + size_(0) + { + } + + ~ChunkedBuffer() + { + Clear(); + } + + void Clear() + { + for (Content::iterator it = content_.begin(); it != content_.end(); ++it) + { + assert(*it != NULL); + delete *it; + } + + content_.clear(); + } + + void Flatten(std::string& target) const + { + target.resize(size_); + + size_t pos = 0; + + for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) + { + assert(*it != NULL); + size_t s = (*it)->size(); + + if (s != 0) + { + memcpy(&target[pos], (*it)->c_str(), s); + pos += s; + } + } + + assert(size_ == 0 || + pos == target.size()); + } + + void AddChunk(const void* data, + size_t size) + { + content_.push_back(new std::string(reinterpret_cast(data), size)); + size_ += size; + } + + void AddChunk(const std::string& chunk) + { + content_.push_back(new std::string(chunk)); + size_ += chunk.size(); + } + }; + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + class MemoryAnswer : public HttpClient::IAnswer + { + private: + HttpClient::HttpHeaders headers_; + ChunkedBuffer body_; + + public: + const HttpClient::HttpHeaders& GetHeaders() const + { + return headers_; + } + + const ChunkedBuffer& GetBody() const + { + return body_; + } + + virtual void AddHeader(const std::string& key, + const std::string& value) + { + headers_[key] = value; + } + + virtual void AddChunk(const void* data, + size_t size) + { + body_.AddChunk(data, size); + } + }; +#endif + } + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + void HttpClient::ExecuteWithStream(uint16_t& httpStatus, + IAnswer& answer, + IRequestBody& body) const + { + HeadersWrapper h(headers_); + + if (method_ == OrthancPluginHttpMethod_Post || + method_ == OrthancPluginHttpMethod_Put) + { + // Automatically set the "Transfer-Encoding" header if absent + bool found = false; + + for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) + { + if (boost::iequals(it->first, "Transfer-Encoding")) + { + found = true; + break; + } + } + + if (!found) + { + h.AddStaticString("Transfer-Encoding", "chunked"); + } + } + + RequestBodyWrapper request(body); + + OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( + GetGlobalContext(), + &answer, + AnswerAddChunkCallback, + AnswerAddHeaderCallback, + &httpStatus, + method_, + url_.c_str(), + h.GetCount(), + h.GetKeys(), + h.GetValues(), + &request, + RequestBodyWrapper::IsDone, + RequestBodyWrapper::GetChunkData, + RequestBodyWrapper::GetChunkSize, + RequestBodyWrapper::Next, + username_.empty() ? NULL : username_.c_str(), + password_.empty() ? NULL : password_.c_str(), + timeout_, + certificateFile_.empty() ? NULL : certificateFile_.c_str(), + certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), + certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), + pkcs11_ ? 1 : 0); + + if (error != OrthancPluginErrorCode_Success) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); + } + } +#endif + + + void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus, + HttpHeaders& answerHeaders, + std::string& answerBody, + const std::string& body) const + { + HeadersWrapper headers(headers_); + + MemoryBuffer answerBodyBuffer, answerHeadersBuffer; + + OrthancPluginErrorCode error = OrthancPluginHttpClient( + GetGlobalContext(), + *answerBodyBuffer, + *answerHeadersBuffer, + &httpStatus, + method_, + url_.c_str(), + headers.GetCount(), + headers.GetKeys(), + headers.GetValues(), + body.empty() ? NULL : body.c_str(), + body.size(), + username_.empty() ? NULL : username_.c_str(), + password_.empty() ? NULL : password_.c_str(), + timeout_, + certificateFile_.empty() ? NULL : certificateFile_.c_str(), + certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), + certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), + pkcs11_ ? 1 : 0); + + if (error != OrthancPluginErrorCode_Success) + { + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); + } + + Json::Value v; + answerHeadersBuffer.ToJson(v); + + if (v.type() != Json::objectValue) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Json::Value::Members members = v.getMemberNames(); + answerHeaders.clear(); + + for (size_t i = 0; i < members.size(); i++) + { + const Json::Value& h = v[members[i]]; + if (h.type() != Json::stringValue) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + else + { + answerHeaders[members[i]] = h.asString(); + } + } + + answerBodyBuffer.ToString(answerBody); + } + + + void HttpClient::Execute(IAnswer& answer) + { +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + if (allowChunkedTransfers_) + { + if (chunkedBody_ != NULL) + { + ExecuteWithStream(httpStatus_, answer, *chunkedBody_); + } + else + { + MemoryRequestBody wrapper(fullBody_); + ExecuteWithStream(httpStatus_, answer, wrapper); + } + + return; + } +#endif + + // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked + // transfers are disabled. This results in higher memory usage + // (all chunks from the answer body are sent at once) + + HttpHeaders answerHeaders; + std::string answerBody; + Execute(answerHeaders, answerBody); + + for (HttpHeaders::const_iterator it = answerHeaders.begin(); + it != answerHeaders.end(); ++it) + { + answer.AddHeader(it->first, it->second); + } + + if (!answerBody.empty()) + { + answer.AddChunk(answerBody.c_str(), answerBody.size()); + } + } + + + void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, + std::string& answerBody /* out */) + { +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + if (allowChunkedTransfers_) + { + MemoryAnswer answer; + Execute(answer); + answerHeaders = answer.GetHeaders(); + answer.GetBody().Flatten(answerBody); + return; + } +#endif + + // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked + // transfers are disabled. This results in higher memory usage + // (all chunks from the request body are sent at once) + + if (chunkedBody_ != NULL) + { + ChunkedBuffer buffer; + + std::string chunk; + while (chunkedBody_->ReadNextChunk(chunk)) + { + buffer.AddChunk(chunk); + } + + std::string body; + buffer.Flatten(body); + + ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body); + } + else + { + ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); + } + } + + + void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, + Json::Value& answerBody /* out */) + { + std::string body; + Execute(answerHeaders, body); + + Json::Reader reader; + if (!reader.parse(body, answerBody)) + { + LogError("Cannot convert HTTP answer body to JSON"); + ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); + } + } + + + void HttpClient::Execute() + { + HttpHeaders answerHeaders; + std::string body; + Execute(answerHeaders, body); + } + +#endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ + + + + + + /****************************************************************** + ** CHUNKED HTTP SERVER + ******************************************************************/ + + namespace Internals + { + void NullRestCallback(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) + { + } + + IChunkedRequestReader *NullChunkedRestCallback(const char* url, + const OrthancPluginHttpRequest* request) + { + return NULL; + } + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 + + OrthancPluginErrorCode ChunkedRequestReaderAddChunk( + OrthancPluginServerChunkedRequestReader* reader, + const void* data, + uint32_t size) + { + try + { + if (reader == NULL) + { + return OrthancPluginErrorCode_InternalError; + } + + reinterpret_cast(reader)->AddChunk(data, size); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (boost::bad_lexical_cast&) + { + return OrthancPluginErrorCode_BadFileFormat; + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + + + OrthancPluginErrorCode ChunkedRequestReaderExecute( + OrthancPluginServerChunkedRequestReader* reader, + OrthancPluginRestOutput* output) + { + try + { + if (reader == NULL) + { + return OrthancPluginErrorCode_InternalError; + } + + reinterpret_cast(reader)->Execute(output); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (boost::bad_lexical_cast&) + { + return OrthancPluginErrorCode_BadFileFormat; + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + + + void ChunkedRequestReaderFinalize( + OrthancPluginServerChunkedRequestReader* reader) + { + if (reader != NULL) + { + delete reinterpret_cast(reader); + } + } + +#else + + OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request, + RestCallback GetHandler, + ChunkedRestCallback PostHandler, + RestCallback DeleteHandler, + ChunkedRestCallback PutHandler) + { + try + { + std::string allowed; + + if (GetHandler != Internals::NullRestCallback) + { + allowed += "GET"; + } + + if (PostHandler != Internals::NullChunkedRestCallback) + { + if (!allowed.empty()) + { + allowed += ","; + } + + allowed += "POST"; + } + + if (DeleteHandler != Internals::NullRestCallback) + { + if (!allowed.empty()) + { + allowed += ","; + } + + allowed += "DELETE"; + } + + if (PutHandler != Internals::NullChunkedRestCallback) + { + if (!allowed.empty()) + { + allowed += ","; + } + + allowed += "PUT"; + } + + switch (request->method) + { + case OrthancPluginHttpMethod_Get: + if (GetHandler == Internals::NullRestCallback) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); + } + else + { + GetHandler(output, url, request); + } + + break; + + case OrthancPluginHttpMethod_Post: + if (PostHandler == Internals::NullChunkedRestCallback) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); + } + else + { + boost::movelib::unique_ptr reader(PostHandler(url, request)); + if (reader.get() == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); + } + else + { + reader->AddChunk(request->body, request->bodySize); + reader->Execute(output); + } + } + + break; + + case OrthancPluginHttpMethod_Delete: + if (DeleteHandler == Internals::NullRestCallback) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); + } + else + { + DeleteHandler(output, url, request); + } + + break; + + case OrthancPluginHttpMethod_Put: + if (PutHandler == Internals::NullChunkedRestCallback) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); + } + else + { + boost::movelib::unique_ptr reader(PutHandler(url, request)); + if (reader.get() == NULL) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); + } + else + { + reader->AddChunk(request->body, request->bodySize); + reader->Execute(output); + } + } + + break; + + default: + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { +#if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 + if (HasGlobalContext() && + e.HasDetails()) + { + // The "false" instructs Orthanc not to log the detailed + // error message. This is to avoid duplicating the details, + // because "OrthancException" already does it on construction. + OrthancPluginSetHttpErrorDetails + (GetGlobalContext(), output, e.GetDetails(), false); + } +#endif + + return static_cast(e.GetErrorCode()); + } + catch (boost::bad_lexical_cast&) + { + return OrthancPluginErrorCode_BadFileFormat; + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } +#endif + } + + +#if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 + OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup( + OrthancPluginStorageCommitmentFailureReason* target, + void* rawHandler, + const char* sopClassUid, + const char* sopInstanceUid) + { + assert(target != NULL && + rawHandler != NULL); + + try + { + IStorageCommitmentScpHandler& handler = *reinterpret_cast(rawHandler); + *target = handler.Lookup(sopClassUid, sopInstanceUid); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } +#endif + + +#if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 + void IStorageCommitmentScpHandler::Destructor(void* rawHandler) + { + assert(rawHandler != NULL); + delete reinterpret_cast(rawHandler); + } +#endif +} diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,1131 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2020 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 . + **/ + + +#pragma once + +#include "OrthancPluginException.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) +#define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ + (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ + (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) +#endif + + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0) +// The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0 +# define HAS_ORTHANC_PLUGIN_FIND_MATCHER 1 +#else +# define HAS_ORTHANC_PLUGIN_FIND_MATCHER 0 +#endif + + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 4, 2) +# define HAS_ORTHANC_PLUGIN_PEERS 1 +# define HAS_ORTHANC_PLUGIN_JOB 1 +#else +# define HAS_ORTHANC_PLUGIN_PEERS 0 +# define HAS_ORTHANC_PLUGIN_JOB 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) +# define HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS 1 +#else +# define HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) +# define HAS_ORTHANC_PLUGIN_METRICS 1 +#else +# define HAS_ORTHANC_PLUGIN_METRICS 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 1, 0) +# define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 1 +#else +# define HAS_ORTHANC_PLUGIN_HTTP_CLIENT 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7) +# define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT 1 +#else +# define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 7) +# define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER 1 +#else +# define HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER 0 +#endif + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 0) +# define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1 +#else +# define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0 +#endif + + + +namespace OrthancPlugins +{ + typedef void (*RestCallback) (OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request); + + void SetGlobalContext(OrthancPluginContext* context); + + bool HasGlobalContext(); + + OrthancPluginContext* GetGlobalContext(); + + + class OrthancImage; + + + class MemoryBuffer : public boost::noncopyable + { + private: + OrthancPluginMemoryBuffer buffer_; + + void Check(OrthancPluginErrorCode code); + + bool CheckHttp(OrthancPluginErrorCode code); + + public: + MemoryBuffer(); + + ~MemoryBuffer() + { + Clear(); + } + + OrthancPluginMemoryBuffer* operator*() + { + return &buffer_; + } + + // This transfers ownership from "other" to "this" + void Assign(OrthancPluginMemoryBuffer& other); + + void Swap(MemoryBuffer& other); + + OrthancPluginMemoryBuffer Release(); + + const char* GetData() const + { + if (buffer_.size > 0) + { + return reinterpret_cast(buffer_.data); + } + else + { + return NULL; + } + } + + size_t GetSize() const + { + return buffer_.size; + } + + bool IsEmpty() const + { + return GetSize() == 0 || GetData() == NULL; + } + + void Clear(); + + void ToString(std::string& target) const; + + void ToJson(Json::Value& target) const; + + bool RestApiGet(const std::string& uri, + bool applyPlugins); + + bool RestApiGet(const std::string& uri, + const std::map& httpHeaders, + bool applyPlugins); + + bool RestApiPost(const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins); + + bool RestApiPut(const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins); + + bool RestApiPost(const std::string& uri, + const Json::Value& body, + bool applyPlugins); + + bool RestApiPut(const std::string& uri, + const Json::Value& body, + bool applyPlugins); + + bool RestApiPost(const std::string& uri, + const std::string& body, + bool applyPlugins) + { + return RestApiPost(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins); + } + + bool RestApiPut(const std::string& uri, + const std::string& body, + bool applyPlugins) + { + return RestApiPut(uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins); + } + + void CreateDicom(const Json::Value& tags, + OrthancPluginCreateDicomFlags flags); + + void CreateDicom(const Json::Value& tags, + const OrthancImage& pixelData, + OrthancPluginCreateDicomFlags flags); + + void ReadFile(const std::string& path); + + void GetDicomQuery(const OrthancPluginWorklistQuery* query); + + void DicomToJson(Json::Value& target, + OrthancPluginDicomToJsonFormat format, + OrthancPluginDicomToJsonFlags flags, + uint32_t maxStringLength); + + bool HttpGet(const std::string& url, + const std::string& username, + const std::string& password); + + bool HttpPost(const std::string& url, + const std::string& body, + const std::string& username, + const std::string& password); + + bool HttpPut(const std::string& url, + const std::string& body, + const std::string& username, + const std::string& password); + + void GetDicomInstance(const std::string& instanceId); + }; + + + class OrthancString : public boost::noncopyable + { + private: + char* str_; + + void Clear(); + + public: + OrthancString() : + str_(NULL) + { + } + + ~OrthancString() + { + Clear(); + } + + // This transfers ownership, warning: The string must have been + // allocated by the Orthanc core + void Assign(char* str); + + const char* GetContent() const + { + return str_; + } + + void ToString(std::string& target) const; + + void ToJson(Json::Value& target) const; + }; + + + class OrthancConfiguration : public boost::noncopyable + { + private: + Json::Value configuration_; // Necessarily a Json::objectValue + std::string path_; + + std::string GetPath(const std::string& key) const; + + void LoadConfiguration(); + + public: + OrthancConfiguration(); + + OrthancConfiguration(bool load); + + const Json::Value& GetJson() const + { + return configuration_; + } + + bool IsSection(const std::string& key) const; + + void GetSection(OrthancConfiguration& target, + const std::string& key) const; + + bool LookupStringValue(std::string& target, + const std::string& key) const; + + bool LookupIntegerValue(int& target, + const std::string& key) const; + + bool LookupUnsignedIntegerValue(unsigned int& target, + const std::string& key) const; + + bool LookupBooleanValue(bool& target, + const std::string& key) const; + + bool LookupFloatValue(float& target, + const std::string& key) const; + + bool LookupListOfStrings(std::list& target, + const std::string& key, + bool allowSingleString) const; + + bool LookupSetOfStrings(std::set& target, + const std::string& key, + bool allowSingleString) const; + + std::string GetStringValue(const std::string& key, + const std::string& defaultValue) const; + + int GetIntegerValue(const std::string& key, + int defaultValue) const; + + unsigned int GetUnsignedIntegerValue(const std::string& key, + unsigned int defaultValue) const; + + bool GetBooleanValue(const std::string& key, + bool defaultValue) const; + + float GetFloatValue(const std::string& key, + float defaultValue) const; + + void GetDictionary(std::map& target, + const std::string& key) const; + }; + + class OrthancImage : public boost::noncopyable + { + private: + OrthancPluginImage* image_; + + void Clear(); + + void CheckImageAvailable() const; + + public: + OrthancImage(); + + OrthancImage(OrthancPluginImage* image); + + OrthancImage(OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height); + + OrthancImage(OrthancPluginPixelFormat format, + uint32_t width, + uint32_t height, + uint32_t pitch, + void* buffer + ); + + ~OrthancImage() + { + Clear(); + } + + void UncompressPngImage(const void* data, + size_t size); + + void UncompressJpegImage(const void* data, + size_t size); + + void DecodeDicomImage(const void* data, + size_t size, + unsigned int frame); + + OrthancPluginPixelFormat GetPixelFormat() const; + + unsigned int GetWidth() const; + + unsigned int GetHeight() const; + + unsigned int GetPitch() const; + + const void* GetBuffer() const; + + const OrthancPluginImage* GetObject() const + { + return image_; + } + + void CompressPngImage(MemoryBuffer& target) const; + + void CompressJpegImage(MemoryBuffer& target, + uint8_t quality) const; + + void AnswerPngImage(OrthancPluginRestOutput* output) const; + + void AnswerJpegImage(OrthancPluginRestOutput* output, + uint8_t quality) const; + }; + + +#if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 + class FindMatcher : public boost::noncopyable + { + private: + OrthancPluginFindMatcher* matcher_; + const OrthancPluginWorklistQuery* worklist_; + + void SetupDicom(const void* query, + uint32_t size); + + public: + FindMatcher(const OrthancPluginWorklistQuery* worklist); + + FindMatcher(const void* query, + uint32_t size) + { + SetupDicom(query, size); + } + + FindMatcher(const MemoryBuffer& dicom) + { + SetupDicom(dicom.GetData(), dicom.GetSize()); + } + + ~FindMatcher(); + + bool IsMatch(const void* dicom, + uint32_t size) const; + + bool IsMatch(const MemoryBuffer& dicom) const + { + return IsMatch(dicom.GetData(), dicom.GetSize()); + } + }; +#endif + + + bool RestApiGet(Json::Value& result, + const std::string& uri, + bool applyPlugins); + + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins); + + bool RestApiGetString(std::string& result, + const std::string& uri, + const std::map& httpHeaders, + bool applyPlugins); + + bool RestApiPost(std::string& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins); + + bool RestApiPost(Json::Value& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins); + + bool RestApiPost(Json::Value& result, + const std::string& uri, + const Json::Value& body, + bool applyPlugins); + + inline bool RestApiPost(Json::Value& result, + const std::string& uri, + const std::string& body, + bool applyPlugins) + { + return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(), + body.size(), applyPlugins); + } + + inline bool RestApiPost(Json::Value& result, + const std::string& uri, + const MemoryBuffer& body, + bool applyPlugins) + { + return RestApiPost(result, uri, body.GetData(), + body.GetSize(), applyPlugins); + } + + bool RestApiPut(Json::Value& result, + const std::string& uri, + const void* body, + size_t bodySize, + bool applyPlugins); + + bool RestApiPut(Json::Value& result, + const std::string& uri, + const Json::Value& body, + bool applyPlugins); + + inline bool RestApiPut(Json::Value& result, + const std::string& uri, + const std::string& body, + bool applyPlugins) + { + return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(), + body.size(), applyPlugins); + } + + bool RestApiDelete(const std::string& uri, + bool applyPlugins); + + bool HttpDelete(const std::string& url, + const std::string& username, + const std::string& password); + + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output); + + void AnswerString(const std::string& answer, + const char* mimeType, + OrthancPluginRestOutput* output); + + void AnswerHttpError(uint16_t httpError, + OrthancPluginRestOutput* output); + + void AnswerMethodNotAllowed(OrthancPluginRestOutput* output, const char* allowedMethods); + +#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) + const char* AutodetectMimeType(const std::string& path); +#endif + + void LogError(const std::string& message); + + void LogWarning(const std::string& message); + + void LogInfo(const std::string& message); + + void ReportMinimalOrthancVersion(unsigned int major, + unsigned int minor, + unsigned int revision); + + bool CheckMinimalOrthancVersion(unsigned int major, + unsigned int minor, + unsigned int revision); + + + namespace Internals + { + template + static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) + { + try + { + Callback(output, url, request); + return OrthancPluginErrorCode_Success; + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { +#if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 + if (HasGlobalContext() && + e.HasDetails()) + { + // The "false" instructs Orthanc not to log the detailed + // error message. This is to avoid duplicating the details, + // because "OrthancException" already does it on construction. + OrthancPluginSetHttpErrorDetails + (GetGlobalContext(), output, e.GetDetails(), false); + } +#endif + + return static_cast(e.GetErrorCode()); + } + catch (boost::bad_lexical_cast&) + { + return OrthancPluginErrorCode_BadFileFormat; + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + } + + + template + void RegisterRestCallback(const std::string& uri, + bool isThreadSafe) + { + if (isThreadSafe) + { + OrthancPluginRegisterRestCallbackNoLock + (GetGlobalContext(), uri.c_str(), Internals::Protect); + } + else + { + OrthancPluginRegisterRestCallback + (GetGlobalContext(), uri.c_str(), Internals::Protect); + } + } + + +#if HAS_ORTHANC_PLUGIN_PEERS == 1 + class OrthancPeers : public boost::noncopyable + { + private: + typedef std::map Index; + + OrthancPluginPeers *peers_; + Index index_; + uint32_t timeout_; + + size_t GetPeerIndex(const std::string& name) const; + + public: + OrthancPeers(); + + ~OrthancPeers(); + + uint32_t GetTimeout() const + { + return timeout_; + } + + void SetTimeout(uint32_t timeout) + { + timeout_ = timeout; + } + + bool LookupName(size_t& target, + const std::string& name) const; + + std::string GetPeerName(size_t index) const; + + std::string GetPeerUrl(size_t index) const; + + std::string GetPeerUrl(const std::string& name) const; + + size_t GetPeersCount() const + { + return index_.size(); + } + + bool LookupUserProperty(std::string& value, + size_t index, + const std::string& key) const; + + bool LookupUserProperty(std::string& value, + const std::string& peer, + const std::string& key) const; + + bool DoGet(MemoryBuffer& target, + size_t index, + const std::string& uri) const; + + bool DoGet(MemoryBuffer& target, + const std::string& name, + const std::string& uri) const; + + bool DoGet(Json::Value& target, + size_t index, + const std::string& uri) const; + + bool DoGet(Json::Value& target, + const std::string& name, + const std::string& uri) const; + + bool DoPost(MemoryBuffer& target, + size_t index, + const std::string& uri, + const std::string& body) const; + + bool DoPost(MemoryBuffer& target, + const std::string& name, + const std::string& uri, + const std::string& body) const; + + bool DoPost(Json::Value& target, + size_t index, + const std::string& uri, + const std::string& body) const; + + bool DoPost(Json::Value& target, + const std::string& name, + const std::string& uri, + const std::string& body) const; + + bool DoPut(size_t index, + const std::string& uri, + const std::string& body) const; + + bool DoPut(const std::string& name, + const std::string& uri, + const std::string& body) const; + + bool DoDelete(size_t index, + const std::string& uri) const; + + bool DoDelete(const std::string& name, + const std::string& uri) const; + }; +#endif + + + +#if HAS_ORTHANC_PLUGIN_JOB == 1 + class OrthancJob : public boost::noncopyable + { + private: + std::string jobType_; + std::string content_; + bool hasSerialized_; + std::string serialized_; + float progress_; + + static void CallbackFinalize(void* job); + + static float CallbackGetProgress(void* job); + + static const char* CallbackGetContent(void* job); + + static const char* CallbackGetSerialized(void* job); + + static OrthancPluginJobStepStatus CallbackStep(void* job); + + static OrthancPluginErrorCode CallbackStop(void* job, + OrthancPluginJobStopReason reason); + + static OrthancPluginErrorCode CallbackReset(void* job); + + protected: + void ClearContent(); + + void UpdateContent(const Json::Value& content); + + void ClearSerialized(); + + void UpdateSerialized(const Json::Value& serialized); + + void UpdateProgress(float progress); + + public: + OrthancJob(const std::string& jobType); + + virtual ~OrthancJob() + { + } + + virtual OrthancPluginJobStepStatus Step() = 0; + + virtual void Stop(OrthancPluginJobStopReason reason) = 0; + + virtual void Reset() = 0; + + static OrthancPluginJob* Create(OrthancJob* job /* takes ownership */); + + static std::string Submit(OrthancJob* job /* takes ownership */, + int priority); + + static void SubmitAndWait(Json::Value& result, + OrthancJob* job /* takes ownership */, + int priority); + + // Submit a job from a POST on the REST API with the same + // conventions as in the Orthanc core (according to the + // "Synchronous" and "Priority" options) + static void SubmitFromRestApiPost(OrthancPluginRestOutput* output, + const Json::Value& body, + OrthancJob* job); + }; +#endif + + +#if HAS_ORTHANC_PLUGIN_METRICS == 1 + inline void SetMetricsValue(char* name, + float value) + { + OrthancPluginSetMetricsValue(GetGlobalContext(), name, + value, OrthancPluginMetricsType_Default); + } + + class MetricsTimer : public boost::noncopyable + { + private: + std::string name_; + boost::posix_time::ptime start_; + + public: + MetricsTimer(const char* name); + + ~MetricsTimer(); + }; +#endif + + +#if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 + class HttpClient : public boost::noncopyable + { + public: + typedef std::map HttpHeaders; + + class IRequestBody : public boost::noncopyable + { + public: + virtual ~IRequestBody() + { + } + + virtual bool ReadNextChunk(std::string& chunk) = 0; + }; + + + class IAnswer : public boost::noncopyable + { + public: + virtual ~IAnswer() + { + } + + virtual void AddHeader(const std::string& key, + const std::string& value) = 0; + + virtual void AddChunk(const void* data, + size_t size) = 0; + }; + + + private: + class RequestBodyWrapper; + + uint16_t httpStatus_; + OrthancPluginHttpMethod method_; + std::string url_; + HttpHeaders headers_; + std::string username_; + std::string password_; + uint32_t timeout_; + std::string certificateFile_; + std::string certificateKeyFile_; + std::string certificateKeyPassword_; + bool pkcs11_; + std::string fullBody_; + IRequestBody* chunkedBody_; + bool allowChunkedTransfers_; + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 + void ExecuteWithStream(uint16_t& httpStatus, // out + IAnswer& answer, // out + IRequestBody& body) const; +#endif + + void ExecuteWithoutStream(uint16_t& httpStatus, // out + HttpHeaders& answerHeaders, // out + std::string& answerBody, // out + const std::string& body) const; + + public: + HttpClient(); + + uint16_t GetHttpStatus() const + { + return httpStatus_; + } + + void SetMethod(OrthancPluginHttpMethod method) + { + method_ = method; + } + + const std::string& GetUrl() const + { + return url_; + } + + void SetUrl(const std::string& url) + { + url_ = url; + } + + void SetHeaders(const HttpHeaders& headers) + { + headers_ = headers; + } + + void AddHeader(const std::string& key, + const std::string& value) + { + headers_[key] = value; + } + + void AddHeaders(const HttpHeaders& headers); + + void SetCredentials(const std::string& username, + const std::string& password); + + void ClearCredentials(); + + void SetTimeout(unsigned int timeout) // 0 for default timeout + { + timeout_ = timeout; + } + + void SetCertificate(const std::string& certificateFile, + const std::string& keyFile, + const std::string& keyPassword); + + void ClearCertificate(); + + void SetPkcs11(bool pkcs11) + { + pkcs11_ = pkcs11; + } + + void ClearBody(); + + void SwapBody(std::string& body); + + void SetBody(const std::string& body); + + void SetBody(IRequestBody& body); + + // This function can be used to disable chunked transfers if the + // remote server is Orthanc with a version <= 1.5.6. + void SetChunkedTransfersAllowed(bool allow) + { + allowChunkedTransfers_ = allow; + } + + bool IsChunkedTransfersAllowed() const + { + return allowChunkedTransfers_; + } + + void Execute(IAnswer& answer); + + void Execute(HttpHeaders& answerHeaders /* out */, + std::string& answerBody /* out */); + + void Execute(HttpHeaders& answerHeaders /* out */, + Json::Value& answerBody /* out */); + + void Execute(); + }; +#endif + + + + class IChunkedRequestReader : public boost::noncopyable + { + public: + virtual ~IChunkedRequestReader() + { + } + + virtual void AddChunk(const void* data, + size_t size) = 0; + + virtual void Execute(OrthancPluginRestOutput* output) = 0; + }; + + + typedef IChunkedRequestReader* (*ChunkedRestCallback) (const char* url, + const OrthancPluginHttpRequest* request); + + + namespace Internals + { + void NullRestCallback(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request); + + IChunkedRequestReader *NullChunkedRestCallback(const char* url, + const OrthancPluginHttpRequest* request); + + +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 + template + static OrthancPluginErrorCode ChunkedProtect(OrthancPluginServerChunkedRequestReader** reader, + const char* url, + const OrthancPluginHttpRequest* request) + { + try + { + if (reader == NULL) + { + return OrthancPluginErrorCode_InternalError; + } + else + { + *reader = reinterpret_cast(Callback(url, request)); + if (*reader == NULL) + { + return OrthancPluginErrorCode_Plugin; + } + else + { + return OrthancPluginErrorCode_Success; + } + } + } + catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) + { + return static_cast(e.GetErrorCode()); + } + catch (boost::bad_lexical_cast&) + { + return OrthancPluginErrorCode_BadFileFormat; + } + catch (...) + { + return OrthancPluginErrorCode_Plugin; + } + } + + OrthancPluginErrorCode ChunkedRequestReaderAddChunk( + OrthancPluginServerChunkedRequestReader* reader, + const void* data, + uint32_t size); + + OrthancPluginErrorCode ChunkedRequestReaderExecute( + OrthancPluginServerChunkedRequestReader* reader, + OrthancPluginRestOutput* output); + + void ChunkedRequestReaderFinalize( + OrthancPluginServerChunkedRequestReader* reader); + +#else + + OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request, + RestCallback GetHandler, + ChunkedRestCallback PostHandler, + RestCallback DeleteHandler, + ChunkedRestCallback PutHandler); + + template< + RestCallback GetHandler, + ChunkedRestCallback PostHandler, + RestCallback DeleteHandler, + ChunkedRestCallback PutHandler + > + inline OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) + { + return ChunkedRestCompatibility(output, url, request, GetHandler, + PostHandler, DeleteHandler, PutHandler); + } +#endif + } + + + + // NB: We use a templated class instead of a templated function, because + // default values are only available in functions since C++11 + template< + RestCallback GetHandler = Internals::NullRestCallback, + ChunkedRestCallback PostHandler = Internals::NullChunkedRestCallback, + RestCallback DeleteHandler = Internals::NullRestCallback, + ChunkedRestCallback PutHandler = Internals::NullChunkedRestCallback + > + class ChunkedRestRegistration : public boost::noncopyable + { + public: + static void Apply(const std::string& uri) + { +#if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 + OrthancPluginRegisterChunkedRestCallback( + GetGlobalContext(), uri.c_str(), + GetHandler == Internals::NullRestCallback ? NULL : Internals::Protect, + PostHandler == Internals::NullChunkedRestCallback ? NULL : Internals::ChunkedProtect, + DeleteHandler == Internals::NullRestCallback ? NULL : Internals::Protect, + PutHandler == Internals::NullChunkedRestCallback ? NULL : Internals::ChunkedProtect, + Internals::ChunkedRequestReaderAddChunk, + Internals::ChunkedRequestReaderExecute, + Internals::ChunkedRequestReaderFinalize); +#else + OrthancPluginRegisterRestCallbackNoLock( + GetGlobalContext(), uri.c_str(), + Internals::ChunkedRestCompatibility); +#endif + } + }; + + + +#if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 + class IStorageCommitmentScpHandler : public boost::noncopyable + { + public: + virtual ~IStorageCommitmentScpHandler() + { + } + + virtual OrthancPluginStorageCommitmentFailureReason Lookup(const std::string& sopClassUid, + const std::string& sopInstanceUid) = 0; + + static OrthancPluginErrorCode Lookup(OrthancPluginStorageCommitmentFailureReason* target, + void* rawHandler, + const char* sopClassUid, + const char* sopInstanceUid); + + static void Destructor(void* rawHandler); + }; +#endif +} diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Plugins/Samples/Common/OrthancPluginException.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginException.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,101 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2020 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 . + **/ + + +#pragma once + +#if !defined(HAS_ORTHANC_EXCEPTION) +# error The macro HAS_ORTHANC_EXCEPTION must be defined +#endif + + +#if HAS_ORTHANC_EXCEPTION == 1 +# include "../../../Core/OrthancException.h" +# define ORTHANC_PLUGINS_ERROR_ENUMERATION ::Orthanc::ErrorCode +# define ORTHANC_PLUGINS_EXCEPTION_CLASS ::Orthanc::OrthancException +# define ORTHANC_PLUGINS_GET_ERROR_CODE(code) ::Orthanc::ErrorCode_ ## code +#else +# include +# define ORTHANC_PLUGINS_ERROR_ENUMERATION ::OrthancPluginErrorCode +# define ORTHANC_PLUGINS_EXCEPTION_CLASS ::OrthancPlugins::PluginException +# define ORTHANC_PLUGINS_GET_ERROR_CODE(code) ::OrthancPluginErrorCode_ ## code +#endif + + +#define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code) \ + throw ORTHANC_PLUGINS_EXCEPTION_CLASS(static_cast(code)); + + +#define ORTHANC_PLUGINS_THROW_EXCEPTION(code) \ + throw ORTHANC_PLUGINS_EXCEPTION_CLASS(ORTHANC_PLUGINS_GET_ERROR_CODE(code)); + + +#define ORTHANC_PLUGINS_CHECK_ERROR(code) \ + if (code != ORTHANC_PLUGINS_GET_ERROR_CODE(Success)) \ + { \ + ORTHANC_PLUGINS_THROW_EXCEPTION(code); \ + } + + +namespace OrthancPlugins +{ +#if HAS_ORTHANC_EXCEPTION == 0 + class PluginException + { + private: + OrthancPluginErrorCode code_; + + public: + explicit PluginException(OrthancPluginErrorCode code) : code_(code) + { + } + + OrthancPluginErrorCode GetErrorCode() const + { + return code_; + } + + const char* What(OrthancPluginContext* context) const + { + const char* description = OrthancPluginGetErrorDescription(context, code_); + if (description) + { + return description; + } + else + { + return "No description available"; + } + } + }; +#endif +} diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Plugins/Samples/Common/VersionScript.map --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Plugins/Samples/Common/VersionScript.map Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,12 @@ +# This is a version-script for Orthanc plugins + +{ +global: + OrthancPluginInitialize; + OrthancPluginFinalize; + OrthancPluginGetName; + OrthancPluginGetVersion; + +local: + *; +}; diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,383 @@ +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() + + + # Patch by xnox to fix issue #166 (CMake find_boost version is now + # broken with newer boost/cmake) + # https://bitbucket.org/sjodogne/orthanc/issues/166/ + if (POLICY CMP0093) + set(BOOST144 1.44) + else() + set(BOOST144 104400) + 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 ${BOOST144}) + 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_69_0) + set(BOOST_VERSION 1.69.0) + set(BOOST_BCP_SUFFIX bcpdigest-1.5.6) + set(BOOST_MD5 "579bccc0ea4d1a261c1d0c5e27446c3d") + set(BOOST_URL "http://orthanc.osimis.io/ThirdPartyDownloads/${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}") + + + ## + ## Patching boost + ## + + execute_process( + COMMAND ${PATCH_EXECUTABLE} -p0 -N -i + ${ORTHANC_ROOT}/Resources/Patches/boost-${BOOST_VERSION}-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() + + + ## + ## Generic configuration of Boost + ## + + if (CMAKE_COMPILER_IS_GNUCXX) + add_definitions(-isystem ${BOOST_SOURCES_DIR}) + endif() + + include_directories( + BEFORE ${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 + + # In static builds, explicitly prevent Boost from using the system + # locale in lexical casts. This is notably important if + # "boost::lexical_cast()" is applied to strings containing + # "," instead of "." as decimal separators. Check out function + # "OrthancStone::LinearAlgebra::ParseVector()". + -DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE + ) + + set(BOOST_SOURCES + ${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp + ) + + if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase" OR + "${CMAKE_SYSTEM_NAME}" STREQUAL "Android") + add_definitions( + -DBOOST_SYSTEM_USE_STRERROR=1 + ) + 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" OR + CMAKE_SYSTEM_NAME STREQUAL "Android") + 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() + + # Fix for error: "boost_1_69_0/boost/chrono/detail/inlined/mac/thread_clock.hpp:54:28: + # error: use of undeclared identifier 'pthread_mach_thread_np'" + # https://github.com/envoyproxy/envoy/pull/1785 + if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + add_definitions(-D_DARWIN_C_SOURCE=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 asm.js/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" OR + CMAKE_SYSTEM_NAME STREQUAL "Android") + # 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() + set(BOOST_ICU_SOURCES + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/boundary.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/codecvt.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/collator.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/conversion.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/date_time.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/formatter.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/icu_backend.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/numeric.cpp + ${BOOST_SOURCES_DIR}/libs/locale/src/icu/time_zone.cpp + ) + + 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") + add_definitions( + -DBOOST_LOCALE_NO_WINAPI_BACKEND=1 + -DBOOST_LOCALE_NO_POSIX_BACKEND=1 + ) + + 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 + ) + + if (BOOST_LOCALE_BACKEND STREQUAL "gcc" OR + BOOST_LOCALE_BACKEND STREQUAL "libiconv") + add_definitions(-DBOOST_LOCALE_WITH_ICONV=1) + elseif (BOOST_LOCALE_BACKEND STREQUAL "icu") + add_definitions(-DBOOST_LOCALE_WITH_ICU=1) + list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES}) + else() + message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND: ${BOOST_LOCALE_BACKEND}") + endif() + + 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 + add_definitions( + -DBOOST_LOCALE_NO_WINAPI_BACKEND=1 + -DBOOST_LOCALE_NO_STD_BACKEND=1 + ) + + 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 + ) + + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR + BOOST_LOCALE_BACKEND STREQUAL "gcc" OR + BOOST_LOCALE_BACKEND STREQUAL "libiconv") + # In WebAssembly or asm.js, we rely on the version of iconv + # that is shipped with the stdlib + add_definitions(-DBOOST_LOCALE_WITH_ICONV=1) + elseif (BOOST_LOCALE_BACKEND STREQUAL "icu") + add_definitions(-DBOOST_LOCALE_WITH_ICU=1) + list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES}) + else() + message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND: ${BOOST_LOCALE_BACKEND}") + endif() + + elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_definitions( + -DBOOST_LOCALE_NO_POSIX_BACKEND=1 + -DBOOST_LOCALE_NO_STD_BACKEND=1 + ) + + 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 + ) + + # Starting with release 0.8.2, Orthanc statically links against + # libiconv on Windows. Indeed, the "WCONV" library of Windows XP + # seems not to support properly several codepages (notably + # "Latin3", "Hebrew", and "Arabic"). Set "BOOST_LOCALE_BACKEND" + # to "wconv" to use WCONV anyway. + + if (BOOST_LOCALE_BACKEND STREQUAL "libiconv") + add_definitions(-DBOOST_LOCALE_WITH_ICONV=1) + elseif (BOOST_LOCALE_BACKEND STREQUAL "icu") + add_definitions(-DBOOST_LOCALE_WITH_ICU=1) + list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES}) + elseif (BOOST_LOCALE_BACKEND STREQUAL "wconv") + message("Using Window's wconv") + add_definitions(-DBOOST_LOCALE_WITH_WCONV=1) + else() + message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND on Windows: ${BOOST_LOCALE_BACKEND}") + endif() + + else() + message(FATAL_ERROR "Support your platform here") + endif() + endif() + + + source_group(ThirdParty\\boost REGULAR_EXPRESSION ${BOOST_SOURCES_DIR}/.*) + +endif() diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/CMake/Compiler.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/CMake/Compiler.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,260 @@ +# 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_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase") + # Cache the environment variables "LSB_CC" and "LSB_CXX" for further + # use by "ExternalProject" in CMake + SET(CMAKE_LSB_CC $ENV{LSB_CC} CACHE STRING "") + SET(CMAKE_LSB_CXX $ENV{LSB_CXX} CACHE STRING "") +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 " -O coff -I ") + 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") + + # New in Orthanc 1.5.5 + if (MSVC_MULTIPLE_PROCESSES) + # "If you omit the processMax argument in the /MP option, the + # compiler obtains the number of effective processors from the + # operating system, and then creates one process per effective + # processor" + # https://blog.kitware.com/cmake-building-with-all-your-cores/ + # https://docs.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + endif() + + 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 + # 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" AND + NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") + # The "--no-undefined" linker flag makes the shared libraries + # (plugins ModalityWorklists and ServeFolders) fail to compile on + # OpenBSD, and make the PostgreSQL plugin complain about missing + # "environ" global variable in FreeBSD + 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}") + + if (DYNAMIC_MINGW_STDLIB) + else() + # This is a patch for MinGW64 + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_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++") + endif() + + CHECK_LIBRARY_EXISTS(winpthread pthread_create "" HAVE_WIN_PTHREAD) + if (HAVE_WIN_PTHREAD) + if (DYNAMIC_MINGW_STDLIB) + else() + # 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") + endif() + 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. + # Setting this option to "ON" fixes error: "shared:ERROR: + # BINARYEN_TRAP_MODE is not supported by the LLVM wasm backend" if + # using the "upstream" backend of Emscripten. + if (NOT EMSCRIPTEN_SET_LLVM_WASM_BACKEND) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s BINARYEN_TRAP_MODE='\"clamp\"'") + endif() + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") + +elseif (CMAKE_SYSTEM_NAME STREQUAL "Android") + +else() + message("Unknown target platform: ${CMAKE_SYSTEM_NAME}") + 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 " q ") +endif() + + +if (STATIC_BUILD) + add_definitions(-DORTHANC_STATIC=1) +else() + add_definitions(-DORTHANC_STATIC=0) +endif() diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/CMake/DownloadPackage.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/CMake/DownloadPackage.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,261 @@ +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() + + find_program(GUNZIP_EXECUTABLE gunzip) + if (${GUNZIP_EXECUTABLE} MATCHES "GUNZIP_EXECUTABLE-NOTFOUND") + message(FATAL_ERROR "Please install the 'gzip' package") + endif() +endif() + + +macro(DownloadFile MD5 Url) + 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() + + if ("${MD5}" STREQUAL "no-check") + message(WARNING "Not checking the MD5 of: ${Url}") + file(DOWNLOAD "${Url}" "${TMP_PATH}" + SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60 + STATUS Failure) + else() + file(DOWNLOAD "${Url}" "${TMP_PATH}" + SHOW_PROGRESS TIMEOUT 300 INACTIVITY_TIMEOUT 60 + EXPECTED_MD5 "${MD5}" STATUS Failure) + endif() + + list(GET Failure 0 Status) + if (NOT Status EQUAL 0) + message(FATAL_ERROR "Cannot download file: ${Url}") + endif() + + else() + message("Using local copy of ${Url}") + + if ("${MD5}" STREQUAL "no-check") + message(WARNING "Not checking the MD5 of: ${Url}") + else() + file(MD5 ${TMP_PATH} ActualMD5) + if (NOT "${ActualMD5}" STREQUAL "${MD5}") + message(FATAL_ERROR "The MD5 hash of a previously download file is invalid: ${TMP_PATH}") + endif() + endif() + endif() +endmacro() + + +macro(DownloadPackage MD5 Url TargetDirectory) + if (NOT IS_DIRECTORY "${TargetDirectory}") + DownloadFile("${MD5}" "${Url}") + + 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 "Unsupported package extension: ${TMP_EXTENSION}") + 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 "Unsupported package extension: ${TMP_EXTENSION}") + 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() + + + +macro(DownloadCompressedFile MD5 Url TargetFile) + message(${MD5}) + message(${Url}) + message(${TargetFile}) + if (NOT EXISTS "${TargetFile}") + DownloadFile("${MD5}" "${Url}") + + 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") + execute_process( + # "-so" writes uncompressed file to stdout + COMMAND ${ZIP_EXECUTABLE} e -so -y ${TMP_PATH} + OUTPUT_FILE "${TargetFile}" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + RESULT_VARIABLE Failure + OUTPUT_QUIET + ) + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + else() + message(FATAL_ERROR "Unsupported file extension: ${TMP_EXTENSION}") + endif() + + else() + if ("${TMP_EXTENSION}" STREQUAL "gz") + execute_process( + COMMAND sh -c "${GUNZIP_EXECUTABLE} -c ${TMP_PATH}" + OUTPUT_FILE "${TargetFile}" + RESULT_VARIABLE Failure + ) + else() + message(FATAL_ERROR "Unsupported file extension: ${TMP_EXTENSION}") + endif() + endif() + + if (Failure) + message(FATAL_ERROR "Error while running the uncompression tool") + endif() + + if (NOT EXISTS "${TargetFile}") + message(FATAL_ERROR "The file was not uncompressed at the proper location. Check the CMake instructions.") + endif() + endif() +endmacro() diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,88 @@ +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.7) + set(JSONCPP_URL "http://orthanc.osimis.io/ThirdPartyDownloads/jsoncpp-0.10.7.tar.gz") + set(JSONCPP_MD5 "3a8072ca6a1fa9cbaf7715ae625f134f") + add_definitions(-DORTHANC_LEGACY_JSONCPP=1) + else() + set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-1.8.4) + set(JSONCPP_URL "http://orthanc.osimis.io/ThirdPartyDownloads/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 + ) + + if (NOT ENABLE_LOCALE) + add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT=1) + endif() + + 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) + message("Switching to C++11 standard in gcc, as version of JsonCpp is >= 1.0.0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wno-deprecated-declarations") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + message("Switching to C++11 standard in clang, as version of JsonCpp is >= 1.0.0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations") + endif() +endif() diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/LinuxStandardBaseToolchain.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/LinuxStandardBaseToolchain.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,71 @@ +# 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 -DUSE_LEGACY_LIBICU=ON -DBOOST_LOCALE_BACKEND=icu -G Ninja + +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) + +if (${CMAKE_VERSION} VERSION_LESS "3.6.0") + CMAKE_FORCE_CXX_COMPILER(${LSB_PATH}/bin/lsbc++ GNU) +else() + SET(CMAKE_CXX_COMPILER ${LSB_PATH}/bin/lsbc++) +endif() + +# 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() + diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/MinGW-W64-Toolchain32.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/MinGW-W64-Toolchain32.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -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) diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/MinGW-W64-Toolchain64.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/MinGW-W64-Toolchain64.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -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) diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/MinGWToolchain.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/MinGWToolchain.cmake Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,20 @@ +# 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) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTACK_SIZE_PARAM_IS_A_RESERVATION=0x10000" CACHE INTERNAL "" FORCE) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTACK_SIZE_PARAM_IS_A_RESERVATION=0x10000" CACHE INTERNAL "" FORCE) diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Resources/Patches/boost-1.69.0-linux-standard-base.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Resources/Patches/boost-1.69.0-linux-standard-base.patch Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,123 @@ +diff -urEb boost_1_69_0.orig/boost/move/adl_move_swap.hpp boost_1_69_0/boost/move/adl_move_swap.hpp +--- boost_1_69_0.orig/boost/move/adl_move_swap.hpp 2019-02-22 15:05:32.682359994 +0100 ++++ boost_1_69_0/boost/move/adl_move_swap.hpp 2019-02-22 15:05:48.426358034 +0100 +@@ -28,6 +28,8 @@ + //Try to avoid including , as it's quite big + #if defined(_MSC_VER) && defined(BOOST_DINKUMWARE_STDLIB) + #include //Dinkum libraries define std::swap in utility which is lighter than algorithm ++#elif defined(__LSB_VERSION__) ++# include + #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 +diff -urEb boost_1_69_0.orig/boost/system/detail/system_category_win32.hpp boost_1_69_0/boost/system/detail/system_category_win32.hpp +--- boost_1_69_0.orig/boost/system/detail/system_category_win32.hpp 2019-02-22 15:05:32.722359989 +0100 ++++ boost_1_69_0/boost/system/detail/system_category_win32.hpp 2019-02-22 15:06:31.922352713 +0100 +@@ -26,7 +26,7 @@ + namespace detail + { + +-#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) ++#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) || 1 /* std::snprintf() does not seem to exist on Visual Studio 2015 */ + + inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len ) + { +diff -urEb boost_1_69_0.orig/boost/thread/detail/config.hpp boost_1_69_0/boost/thread/detail/config.hpp +--- boost_1_69_0.orig/boost/thread/detail/config.hpp 2019-02-22 15:05:32.598360004 +0100 ++++ boost_1_69_0/boost/thread/detail/config.hpp 2019-02-22 15:05:48.426358034 +0100 +@@ -418,7 +418,7 @@ + #define BOOST_THREAD_INTERNAL_CLOCK_IS_MONO + #elif defined(BOOST_THREAD_CHRONO_MAC_API) + #define BOOST_THREAD_HAS_MONO_CLOCK +-#elif defined(__ANDROID__) ++#elif defined(__ANDROID__) || defined(__LSB_VERSION__) + #define BOOST_THREAD_HAS_MONO_CLOCK + #if defined(__ANDROID_API__) && __ANDROID_API__ >= 21 + #define BOOST_THREAD_INTERNAL_CLOCK_IS_MONO +diff -urEb boost_1_69_0.orig/boost/type_traits/detail/has_postfix_operator.hpp boost_1_69_0/boost/type_traits/detail/has_postfix_operator.hpp +--- boost_1_69_0.orig/boost/type_traits/detail/has_postfix_operator.hpp 2019-02-22 15:05:32.650359998 +0100 ++++ boost_1_69_0/boost/type_traits/detail/has_postfix_operator.hpp 2019-02-22 15:05:48.426358034 +0100 +@@ -85,8 +85,11 @@ + namespace boost { + namespace detail { + ++// https://stackoverflow.com/a/15474269 ++#ifndef Q_MOC_RUN + // This namespace ensures that argument-dependent name lookup does not mess things up. + namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) { ++#endif + + // 1. a function to have an instance of type T without requiring T to be default + // constructible +@@ -234,7 +237,9 @@ + BOOST_STATIC_CONSTANT(bool, value = (trait_impl1 < Lhs_noref, Ret, BOOST_TT_FORBIDDEN_IF >::value)); + }; + ++#ifndef Q_MOC_RUN + } // namespace impl ++#endif + } // namespace detail + + // this is the accessible definition of the trait to end user +diff -urEb boost_1_69_0.orig/boost/type_traits/detail/has_prefix_operator.hpp boost_1_69_0/boost/type_traits/detail/has_prefix_operator.hpp +--- boost_1_69_0.orig/boost/type_traits/detail/has_prefix_operator.hpp 2019-02-22 15:05:32.650359998 +0100 ++++ boost_1_69_0/boost/type_traits/detail/has_prefix_operator.hpp 2019-02-22 15:05:48.426358034 +0100 +@@ -114,8 +114,11 @@ + namespace boost { + namespace detail { + ++// https://stackoverflow.com/a/15474269 ++#ifndef Q_MOC_RUN + // This namespace ensures that argument-dependent name lookup does not mess things up. + namespace BOOST_JOIN(BOOST_TT_TRAIT_NAME,_impl) { ++#endif + + // 1. a function to have an instance of type T without requiring T to be default + // constructible +@@ -263,7 +266,9 @@ + BOOST_STATIC_CONSTANT(bool, value = (trait_impl1 < Rhs_noref, Ret, BOOST_TT_FORBIDDEN_IF >::value)); + }; + ++#ifndef Q_MOC_RUN + } // namespace impl ++#endif + } // namespace detail + + // this is the accessible definition of the trait to end user +diff -urEb boost_1_69_0.orig/libs/filesystem/src/operations.cpp boost_1_69_0/libs/filesystem/src/operations.cpp +--- boost_1_69_0.orig/libs/filesystem/src/operations.cpp 2019-02-22 15:05:32.566360008 +0100 ++++ boost_1_69_0/libs/filesystem/src/operations.cpp 2019-02-22 18:04:17.346573047 +0100 +@@ -2111,9 +2111,16 @@ + std::size_t path_size (0); // initialization quiets gcc warning (ticket #3509) + error_code ec = path_max(path_size); + if (ec)return ec; +- dirent de; +- buffer = std::malloc((sizeof(dirent) - sizeof(de.d_name)) +- + path_size + 1); // + 1 for "/0" ++ ++ // Fixed possible use of uninitialized dirent::d_type in dir_iterator ++ // https://github.com/boostorg/filesystem/commit/bbe9d1771e5d679b3f10c42a58fc81f7e8c024a9 ++ const std::size_t buffer_size = (sizeof(dirent) - sizeof(dirent().d_name)) ++ + path_size + 1; // + 1 for "\0" ++ buffer = std::malloc(buffer_size); ++ if (BOOST_UNLIKELY(!buffer)) ++ return make_error_code(boost::system::errc::not_enough_memory); ++ std::memset(buffer, 0, buffer_size); ++ + return ok; + } + +@@ -2142,6 +2149,13 @@ + *result = 0; + if ((p = ::readdir(dirp))== 0) + return errno; ++ ++ // Fixed possible use of uninitialized dirent::d_type in dir_iterator ++ // https://github.com/boostorg/filesystem/commit/bbe9d1771e5d679b3f10c42a58fc81f7e8c024a9 ++# ifdef BOOST_FILESYSTEM_STATUS_CACHE ++ entry->d_type = p->d_type; ++# endif ++ + std::strcpy(entry->d_name, p->d_name); + *result = entry; + return 0; diff -r 7ed502b17b8f -r fef9a239df5c Resources/Orthanc/Sdk-1.5.7/orthanc/OrthancCPlugin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Orthanc/Sdk-1.5.7/orthanc/OrthancCPlugin.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,7260 @@ +/** + * \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: + * + * -# int32_t OrthancPluginInitialize(const OrthancPluginContext* context): + * 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 using OrthancPluginRegisterFindCallback(). + * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback(). + * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback(). + * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback(). + * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2(). + * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer(). + * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback(). + * - Possibly register a callback to answer chunked HTTP transfers using ::OrthancPluginRegisterChunkedRestCallback(). + * -# void OrthancPluginFinalize(): + * This function is invoked by Orthanc during its shutdown. The plugin + * must free all its memory. + * -# const char* OrthancPluginGetName(): + * The plugin must return a short string to identify itself. + * -# const char* OrthancPluginGetVersion(): + * 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 extern "C" 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 DicomCallbacks DicomCallbacks + * @brief Functions to register and manage DICOM callbacks (worklists, C-Find, C-MOVE). + * + * @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-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 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 . + **/ + + + +#pragma once + + +#include +#include + +#ifdef WIN32 +# define ORTHANC_PLUGINS_API __declspec(dllexport) +#elif __GNUC__ >= 4 +# define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default"))) +#else +# define ORTHANC_PLUGINS_API +#endif + +#define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 +#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 5 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 7 + + +#if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) +#define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ + (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ + (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) +#endif + + + +/******************************************************************** + ** 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://bitbucket.org/sjodogne/orthanc/raw/default/Resources/ThirdParty/VisualStudio/stdint.h + **/ +#include + +#include + + + +/******************************************************************** + ** 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 /*!< The server hosting Orthanc is running out of 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_NullPointer = 35 /*!< Cannot handle a NULL pointer */, + OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */, + OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */, + OrthancPluginErrorCode_BadGeometry = 38 /*!< Geometry error encountered in Stone */, + 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 privileged or already in use */, + OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or 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_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */, + OrthancPluginErrorCode_UnsupportedMediaType = 3000 /*!< Unsupported media type */, + + _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 void* 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, + _OrthancPluginService_CallHttpClient2 = 27, + _OrthancPluginService_GenerateUuid = 28, + _OrthancPluginService_RegisterPrivateDictionaryTag = 29, + _OrthancPluginService_AutodetectMimeType = 30, + _OrthancPluginService_SetMetricsValue = 31, + _OrthancPluginService_EncodeDicomWebJson = 32, + _OrthancPluginService_EncodeDicomWebXml = 33, + _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */ + _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */ + + /* Registration of callbacks */ + _OrthancPluginService_RegisterRestCallback = 1000, + _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001, + _OrthancPluginService_RegisterStorageArea = 1002, + _OrthancPluginService_RegisterOnChangeCallback = 1003, + _OrthancPluginService_RegisterRestCallbackNoLock = 1004, + _OrthancPluginService_RegisterWorklistCallback = 1005, + _OrthancPluginService_RegisterDecodeImageCallback = 1006, + _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007, + _OrthancPluginService_RegisterFindCallback = 1008, + _OrthancPluginService_RegisterMoveCallback = 1009, + _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010, + _OrthancPluginService_RegisterRefreshMetricsCallback = 1011, + _OrthancPluginService_RegisterChunkedRestCallback = 1012, /* New in Orthanc 1.5.7 */ + + /* 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, + _OrthancPluginService_SendMultipartItem2 = 2012, + _OrthancPluginService_SetHttpErrorDetails = 2013, + + /* 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 C-Find, C-Move and worklists */ + _OrthancPluginService_WorklistAddAnswer = 7000, + _OrthancPluginService_WorklistMarkIncomplete = 7001, + _OrthancPluginService_WorklistIsMatch = 7002, + _OrthancPluginService_WorklistGetDicomQuery = 7003, + _OrthancPluginService_FindAddAnswer = 7004, + _OrthancPluginService_FindMarkIncomplete = 7005, + _OrthancPluginService_GetFindQuerySize = 7006, + _OrthancPluginService_GetFindQueryTag = 7007, + _OrthancPluginService_GetFindQueryTagName = 7008, + _OrthancPluginService_GetFindQueryValue = 7009, + _OrthancPluginService_CreateFindMatcher = 7010, + _OrthancPluginService_FreeFindMatcher = 7011, + _OrthancPluginService_FindMatcherIsMatch = 7012, + + /* Primitives for accessing Orthanc Peers (new in 1.4.2) */ + _OrthancPluginService_GetPeers = 8000, + _OrthancPluginService_FreePeers = 8001, + _OrthancPluginService_GetPeersCount = 8003, + _OrthancPluginService_GetPeerName = 8004, + _OrthancPluginService_GetPeerUrl = 8005, + _OrthancPluginService_CallPeerApi = 8006, + _OrthancPluginService_GetPeerUserProperty = 8007, + + /* Primitives for handling jobs (new in 1.4.2) */ + _OrthancPluginService_CreateJob = 9000, + _OrthancPluginService_FreeJob = 9001, + _OrthancPluginService_SubmitJob = 9002, + _OrthancPluginService_RegisterJobsUnserializer = 9003, + + _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 */ + + /** + * @brief Color image in RGB48 format. + * + * This format describes a color image. The pixels are stored in 6 + * consecutive bytes. The memory layout is RRGGBB. + **/ + OrthancPluginPixelFormat_RGB48 = 7, + + /** + * @brief Graylevel, unsigned 32bpp image. + * + * The image is graylevel. Each pixel is unsigned and stored in + * four bytes. + **/ + OrthancPluginPixelFormat_Grayscale32 = 8, + + /** + * @brief Graylevel, floating-point 32bpp image. + * + * The image is graylevel. Each pixel is floating-point and stored + * in four bytes. + **/ + OrthancPluginPixelFormat_Float32 = 9, + + /** + * @brief Color image in BGRA32 format. + * + * This format describes a color image. The pixels are stored in 4 + * consecutive bytes. The memory layout is BGRA. + **/ + OrthancPluginPixelFormat_BGRA32 = 10, + + /** + * @brief Graylevel, unsigned 64bpp image. + * + * The image is graylevel. Each pixel is unsigned and stored in + * eight bytes. + **/ + OrthancPluginPixelFormat_Grayscale64 = 11, + + _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_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */ + OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */ + + _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_None = 0, + 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_None = 0, + 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. + * @deprecated Plugins using OrthancPluginConstraintType will be faster + **/ + 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 constraints on the tags (main DICOM tags and identifier tags) + * that must be supported by the database plugins. + **/ + typedef enum + { + OrthancPluginConstraintType_Equal = 1, /*!< Equal */ + OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */ + OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */ + OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */ + OrthancPluginConstraintType_List = 5, /*!< List of values */ + + _OrthancPluginConstraintType_INTERNAL = 0x7fffffff + } OrthancPluginConstraintType; + + + /** + * 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; + + + /** + * The possible status for one single step of a job. + **/ + typedef enum + { + OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */ + OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */ + OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */ + } OrthancPluginJobStepStatus; + + + /** + * Explains why the job should stop and release the resources it has + * allocated. This is especially important to disambiguate between + * the "paused" condition and the "final" conditions (success, + * failure, or canceled). + **/ + typedef enum + { + OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */ + OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */ + OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */ + OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */ + } OrthancPluginJobStopReason; + + + /** + * The available types of metrics. + **/ + typedef enum + { + OrthancPluginMetricsType_Default = 0, /*!< Default metrics */ + + /** + * This metrics represents a time duration. Orthanc will keep the + * maximum value of the metrics over a sliding window of ten + * seconds, which is useful if the metrics is sampled frequently. + **/ + OrthancPluginMetricsType_Timer = 1 + } OrthancPluginMetricsType; + + + /** + * The available modes to export a binary DICOM tag into a DICOMweb + * JSON or XML document. + **/ + typedef enum + { + OrthancPluginDicomWebBinaryMode_Ignore = 0, /*!< Don't include binary tags */ + OrthancPluginDicomWebBinaryMode_InlineBinary = 1, /*!< Inline encoding using Base64 */ + OrthancPluginDicomWebBinaryMode_BulkDataUri = 2 /*!< Use a bulk data URI field */ + } OrthancPluginDicomWebBinaryMode; + + + + /** + * @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 for worklists. + * @ingroup DicomCallbacks + **/ + typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery; + + + + /** + * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. + * @ingroup DicomCallbacks + **/ + typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers; + + + + /** + * @brief Opaque structure to an object that represents a C-Find query. + * @ingroup DicomCallbacks + **/ + typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery; + + + + /** + * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists. + * @ingroup DicomCallbacks + **/ + typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers; + + + + /** + * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query. + * @ingroup Toolbox + **/ + typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindMatcher; + + + + /** + * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server. + * @ingroup Toolbox + **/ + typedef struct _OrthancPluginPeers_t OrthancPluginPeers; + + + + /** + * @brief Opaque structure to a job to be executed by Orthanc. + * @ingroup Toolbox + **/ + typedef struct _OrthancPluginJob_t OrthancPluginJob; + + + + /** + * @brief Opaque structure that represents a node in a JSON or XML + * document used in DICOMweb. + * @ingroup Toolbox + **/ + typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode; + + + + /** + * @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. + * @ingroup Callbacks + **/ + typedef void (*OrthancPluginFree) (void* buffer); + + + + /** + * @brief Signature of a function to set the content of a node + * encoding a binary DICOM tag, into a JSON or XML document + * generated for DICOMweb. + * @ingroup Callbacks + **/ + typedef void (*OrthancPluginDicomWebSetBinaryNode) ( + OrthancPluginDicomWebNode* node, + OrthancPluginDicomWebBinaryMode mode, + const char* bulkDataUri); + + + + /** + * @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 for worklists. + * + * 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 issuerAet 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 DicomCallbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) ( + OrthancPluginWorklistAnswers* answers, + const OrthancPluginWorklistQuery* query, + const char* issuerAet, + const char* calledAet); + + + + /** + * @brief Callback to filter incoming HTTP requests received by Orthanc. + * + * Signature of a callback function that is triggered whenever + * Orthanc receives an HTTP/REST request, and that answers whether + * this request should be allowed. If the callback returns "0" + * ("false"), the server answers with HTTP status code 403 + * (Forbidden). + * + * @param method The HTTP method used by the request. + * @param uri The URI of interest. + * @param ip The IP address of the HTTP client. + * @param headersCount The number of HTTP headers. + * @param headersKeys The keys of the HTTP headers (always converted to low-case). + * @param headersValues The values of the HTTP headers. + * @return 0 if forbidden access, 1 if allowed access, -1 if error. + * @ingroup Callback + * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2() + **/ + typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) ( + OrthancPluginHttpMethod method, + const char* uri, + const char* ip, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues); + + + + /** + * @brief Callback to filter incoming HTTP requests received by Orthanc. + * + * Signature of a callback function that is triggered whenever + * Orthanc receives an HTTP/REST request, and that answers whether + * this request should be allowed. If the callback returns "0" + * ("false"), the server answers with HTTP status code 403 + * (Forbidden). + * + * @param method The HTTP method used by the request. + * @param uri The URI of interest. + * @param ip The IP address of the HTTP client. + * @param headersCount The number of HTTP headers. + * @param headersKeys The keys of the HTTP headers (always converted to low-case). + * @param headersValues The values of the HTTP headers. + * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method). + * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method). + * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method). + * @return 0 if forbidden access, 1 if allowed access, -1 if error. + * @ingroup Callback + **/ + typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) ( + OrthancPluginHttpMethod method, + const char* uri, + const char* ip, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues, + uint32_t getArgumentsCount, + const char* const* getArgumentsKeys, + const char* const* getArgumentsValues); + + + + /** + * @brief Callback to handle incoming C-Find SCP requests. + * + * Signature of a callback function that is triggered whenever + * Orthanc receives a C-Find SCP request not concerning modality + * worklists. + * + * @param answers The target structure where answers must be stored. + * @param query The worklist query. + * @param issuerAet 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 DicomCallbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) ( + OrthancPluginFindAnswers* answers, + const OrthancPluginFindQuery* query, + const char* issuerAet, + const char* calledAet); + + + + /** + * @brief Callback to handle incoming C-Move SCP requests. + * + * Signature of a callback function that is triggered whenever + * Orthanc receives a C-Move SCP request. The callback receives the + * type of the resource of interest (study, series, instance...) + * together with the DICOM tags containing its identifiers. In turn, + * the plugin must create a driver object that will be responsible + * for driving the successive move suboperations. + * + * @param resourceType The type of the resource of interest. Note + * that this might be set to ResourceType_None if the + * QueryRetrieveLevel (0008,0052) tag was not provided by the + * issuer (i.e. the originator modality). + * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL. + * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL. + * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL. + * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL. + * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL. + * @param originatorAet The Application Entity Title (AET) of the + * modality from which the request originates. + * @param sourceAet The Application Entity Title (AET) of the + * modality that should send its DICOM files to another modality. + * @param targetAet The Application Entity Title (AET) of the + * modality that should receive the DICOM files. + * @param originatorId The Message ID issued by the originator modality, + * as found in tag (0000,0110) of the DICOM query emitted by the issuer. + * + * @return The NULL value if the plugin cannot deal with this query, + * or a pointer to the driver object that is responsible for + * handling the successive move suboperations. + * + * @note If targetAet equals sourceAet, this is actually a query/retrieve operation. + * @ingroup DicomCallbacks + **/ + typedef void* (*OrthancPluginMoveCallback) ( + OrthancPluginResourceType resourceType, + const char* patientId, + const char* accessionNumber, + const char* studyInstanceUid, + const char* seriesInstanceUid, + const char* sopInstanceUid, + const char* originatorAet, + const char* sourceAet, + const char* targetAet, + uint16_t originatorId); + + + /** + * @brief Callback to read the size of a C-Move driver. + * + * Signature of a callback function that returns the number of + * C-Move suboperations that are to be achieved by the given C-Move + * driver. This driver is the return value of a previous call to the + * OrthancPluginMoveCallback() callback. + * + * @param moveDriver The C-Move driver of interest. + * @return The number of suboperations. + * @ingroup DicomCallbacks + **/ + typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver); + + + /** + * @brief Callback to apply one C-Move suboperation. + * + * Signature of a callback function that applies the next C-Move + * suboperation that os to be achieved by the given C-Move + * driver. This driver is the return value of a previous call to the + * OrthancPluginMoveCallback() callback. + * + * @param moveDriver The C-Move driver of interest. + * @return 0 if success, or the error code if failure. + * @ingroup DicomCallbacks + **/ + typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver); + + + /** + * @brief Callback to free one C-Move driver. + * + * Signature of a callback function that releases the resources + * allocated by the given C-Move driver. This driver is the return + * value of a previous call to the OrthancPluginMoveCallback() + * callback. + * + * @param moveDriver The C-Move driver of interest. + * @ingroup DicomCallbacks + **/ + typedef void (*OrthancPluginFreeMove) (void* moveDriver); + + + /** + * @brief Callback to finalize one custom job. + * + * Signature of a callback function that releases all the resources + * allocated by the given job. This job is the argument provided to + * OrthancPluginCreateJob(). + * + * @param job The job of interest. + * @ingroup Toolbox + **/ + typedef void (*OrthancPluginJobFinalize) (void* job); + + + /** + * @brief Callback to check the progress of one custom job. + * + * Signature of a callback function that returns the progress of the + * job. + * + * @param job The job of interest. + * @return The progress, as a floating-point number ranging from 0 to 1. + * @ingroup Toolbox + **/ + typedef float (*OrthancPluginJobGetProgress) (void* job); + + + /** + * @brief Callback to retrieve the content of one custom job. + * + * Signature of a callback function that returns human-readable + * statistics about the job. This statistics must be formatted as a + * JSON object. This information is notably displayed in the "Jobs" + * tab of "Orthanc Explorer". + * + * @param job The job of interest. + * @return The statistics, as a JSON object encoded as a string. + * @ingroup Toolbox + **/ + typedef const char* (*OrthancPluginJobGetContent) (void* job); + + + /** + * @brief Callback to serialize one custom job. + * + * Signature of a callback function that returns a serialized + * version of the job, formatted as a JSON object. This + * serialization is stored in the Orthanc database, and is used to + * reload the job on the restart of Orthanc. The "unserialization" + * callback (with OrthancPluginJobsUnserializer signature) will + * receive this serialized object. + * + * @param job The job of interest. + * @return The serialized job, as a JSON object encoded as a string. + * @see OrthancPluginRegisterJobsUnserializer() + * @ingroup Toolbox + **/ + typedef const char* (*OrthancPluginJobGetSerialized) (void* job); + + + /** + * @brief Callback to execute one step of a custom job. + * + * Signature of a callback function that executes one step in the + * job. The jobs engine of Orthanc will make successive calls to + * this method, as long as it returns + * OrthancPluginJobStepStatus_Continue. + * + * @param job The job of interest. + * @return The status of execution. + * @ingroup Toolbox + **/ + typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job); + + + /** + * @brief Callback executed once one custom job leaves the "running" state. + * + * Signature of a callback function that is invoked once a job + * leaves the "running" state. This can happen if the previous call + * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc + * server is being stopped, or if the user manually tags the job as + * paused/canceled. This callback allows the plugin to free + * resources allocated for running this custom job (e.g. to stop + * threads, or to remove temporary files). + * + * Note that handling pauses might involves a specific treatment + * (such a stopping threads, but keeping temporary files on the + * disk). This "paused" situation can be checked by looking at the + * "reason" parameter. + * + * @param job The job of interest. + * @param reason The reason for leaving the "running" state. + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job, + OrthancPluginJobStopReason reason); + + + /** + * @brief Callback executed once one stopped custom job is started again. + * + * Signature of a callback function that is invoked once a job + * leaves the "failure/canceled" state, to be started again. This + * function will typically reset the progress to zero. Note that + * before being actually executed, the job would first be tagged as + * "pending" in the Orthanc jobs engine. + * + * @param job The job of interest. + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job); + + + /** + * @brief Callback executed to unserialize a custom job. + * + * Signature of a callback function that unserializes a job that was + * saved in the Orthanc database. + * + * @param jobType The type of the job, as provided to OrthancPluginCreateJob(). + * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized. + * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL + * if this unserializer cannot handle this job type. + * @see OrthancPluginRegisterJobsUnserializer() + * @ingroup Callbacks + **/ + typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType, + const char* serialized); + + + + /** + * @brief Callback executed to update the metrics of the plugin. + * + * Signature of a callback function that is called by Orthanc + * whenever a monitoring tool (such as Prometheus) asks the current + * values of the metrics. This callback gives the plugin a chance to + * update its metrics, by calling OrthancPluginSetMetricsValue(). + * This is typically useful for metrics that are expensive to + * acquire. + * + * @see OrthancPluginRegisterRefreshMetrics() + * @ingroup Callbacks + **/ + typedef void (*OrthancPluginRefreshMetricsCallback) (); + + + + /** + * @brief Callback executed to encode a binary tag in DICOMweb. + * + * Signature of a callback function that is called by Orthanc + * whenever a DICOM tag that contains a binary value must be written + * to a JSON or XML node, while a DICOMweb document is being + * generated. The value representation (VR) of the DICOM tag can be + * OB, OD, OF, OL, OW, or UN. + * + * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml() + * @param node The node being generated, as provided by Orthanc. + * @param setter The setter to be used to encode the content of the node. If + * the setter is not called, the binary tag is not written to the output document. + * @param levelDepth The depth of the node in the DICOM hierarchy of sequences. + * This parameter gives the number of elements in the "levelTagGroup", + * "levelTagElement", and "levelIndex" arrays. + * @param levelTagGroup The group of the parent DICOM tags in the hierarchy. + * @param levelTagElement The element of the parent DICOM tags in the hierarchy. + * @param levelIndex The index of the node in the parent sequences of the hiearchy. + * @param tagGroup The group of the DICOM tag of interest. + * @param tagElement The element of the DICOM tag of interest. + * @param vr The value representation of the binary DICOM node. + * @ingroup Callbacks + **/ + typedef void (*OrthancPluginDicomWebBinaryCallback) ( + OrthancPluginDicomWebNode* node, + OrthancPluginDicomWebSetBinaryNode setter, + uint32_t levelDepth, + const uint16_t* levelTagGroup, + const uint16_t* levelTagElement, + const uint32_t* levelIndex, + uint16_t tagGroup, + uint16_t tagElement, + OrthancPluginValueRepresentation vr); + + + + /** + * @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 that the version of the hosting Orthanc is above a given version. + * + * This function checks whether the version of the Orthanc server + * running this plugin, is above the given version. Contrarily to + * OrthancPluginCheckVersion(), it is up to the developer of the + * plugin to make sure that all the Orthanc SDK services called by + * the plugin are actually implemented in the given version of + * Orthanc. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param expectedMajor Expected major version. + * @param expectedMinor Expected minor version. + * @param expectedRevision Expected revision. + * @return 1 if and only if the versions are compatible. If the + * result is 0, the initialization of the plugin should fail. + * @see OrthancPluginCheckVersion + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersionAdvanced( + OrthancPluginContext* context, + int expectedMajor, + int expectedMinor, + int expectedRevision) + { + 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) || + sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) || + sizeof(int32_t) != sizeof(OrthancPluginConstraintType) || + sizeof(int32_t) != sizeof(OrthancPluginMetricsType) || + sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode)) + { + /* 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 > expectedMajor) + { + return 1; + } + + if (major < expectedMajor) + { + return 0; + } + + /* Check the minor number of the version */ + + if (minor > expectedMinor) + { + return 1; + } + + if (minor < expectedMinor) + { + return 0; + } + + /* Check the revision number of the version */ + + if (revision >= expectedRevision) + { + return 1; + } + else + { + return 0; + } + } + + + /** + * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc. + * + * This function checks whether the version of the Orthanc server + * running this plugin, is above the version of the current Orthanc + * SDK header. This guarantees that the plugin is compatible with + * the hosting Orthanc (i.e. it will not call unavailable services). + * 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. + * @see OrthancPluginCheckVersionAdvanced + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE int OrthancPluginCheckVersion( + OrthancPluginContext* context) + { + return OrthancPluginCheckVersionAdvanced( + context, + ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); + } + + + /** + * @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() + * + * @note + * The regular expression is case sensitive and must follow the + * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). + * + * @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, if using this function, + * 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() + * + * @note + * The regular expression is case sensitive and must follow the + * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). + * + * @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 void* 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 void* 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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @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 void* 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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @see OrthancPluginRestApiPostAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const void* 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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @see OrthancPluginRestApiPost + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const void* 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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @see OrthancPluginRestApiPutAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const void* 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. + * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource. + * @see OrthancPluginRestApiPut + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + const void* 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 void* 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 + * scripts. + * + * @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 + **/ + 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(), OrthancPluginSendMultipartItem2() + * @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). + * @see OrthancPluginSendMultipartItem2() + * @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 void* 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 NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + 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 NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* url, + const void* 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 NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* url, + const void* 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 NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + 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 public 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 ("n"). + * @return 0 if success, other value if error. + * @see OrthancPluginRegisterPrivateDictionaryTag() + * @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 + { + uint16_t group; + uint16_t element; + OrthancPluginValueRepresentation vr; + const char* name; + uint32_t minMultiplicity; + uint32_t maxMultiplicity; + const char* privateCreator; + } _OrthancPluginRegisterPrivateDictionaryTag; + + /** + * @brief Register a new private tag into the DICOM dictionary. + * + * This function declares a new private 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 ("n"). + * @param privateCreator The private creator of this private tag. + * @return 0 if success, other value if error. + * @see OrthancPluginRegisterDictionaryTag() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag( + OrthancPluginContext* context, + uint16_t group, + uint16_t element, + OrthancPluginValueRepresentation vr, + const char* name, + uint32_t minMultiplicity, + uint32_t maxMultiplicity, + const char* privateCreator) + { + _OrthancPluginRegisterPrivateDictionaryTag params; + params.group = group; + params.element = element; + params.vr = vr; + params.name = name; + params.minMultiplicity = minMultiplicity; + params.maxMultiplicity = maxMultiplicity; + params.privateCreator = privateCreator; + + return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, ¶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. 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 void* 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 void* 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 (can be NULL if no header). + * @param headersValues Array containing the values of the HTTP headers (can be NULL if no header). + * @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 DicomCallbacks + **/ + 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 DicomCallbacks + * @see OrthancPluginCreateDicom() + **/ + 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 DicomCallbacks + **/ + 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 DicomCallbacks + **/ + 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 DicomCallbacks + **/ + 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); + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* answer; + uint32_t answerSize; + uint32_t headersCount; + const char* const* headersKeys; + const char* const* headersValues; + } _OrthancPluginSendMultipartItem2; + + /** + * @brief Send an item as a part of some HTTP multipart answer, with custom headers. + * + * This function sends an item as a part of some HTTP multipart + * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to + * OrthancPluginSendMultipartItem(), this function will set HTTP header associated + * with the item. + * + * @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. + * @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. + * @return 0 if success, or the error code if failure (this notably happens + * if the connection is closed by the client). + * @see OrthancPluginSendMultipartItem() + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* answer, + uint32_t answerSize, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues) + { + _OrthancPluginSendMultipartItem2 params; + params.output = output; + params.answer = answer; + params.answerSize = answerSize; + params.headersCount = headersCount; + params.headersKeys = headersKeys; + params.headersValues = headersValues; + + return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, ¶ms); + } + + + typedef struct + { + OrthancPluginIncomingHttpRequestFilter callback; + } _OrthancPluginIncomingHttpRequestFilter; + + /** + * @brief Register a callback to filter incoming HTTP requests. + * + * This function registers a custom callback to filter incoming HTTP/REST + * requests received by the HTTP server 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 + * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2() + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter( + OrthancPluginContext* context, + OrthancPluginIncomingHttpRequestFilter callback) + { + _OrthancPluginIncomingHttpRequestFilter params; + params.callback = callback; + + return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, ¶ms); + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* answerBody; + OrthancPluginMemoryBuffer* answerHeaders; + uint16_t* httpStatus; + OrthancPluginHttpMethod method; + const char* url; + uint32_t headersCount; + const char* const* headersKeys; + const char* const* headersValues; + const void* body; + uint32_t bodySize; + const char* username; + const char* password; + uint32_t timeout; + const char* certificateFile; + const char* certificateKeyFile; + const char* certificateKeyPassword; + uint8_t pkcs11; + } _OrthancPluginCallHttpClient2; + + + + /** + * @brief Issue a HTTP call with full flexibility. + * + * Make a HTTP call to the given URL. The result to the query is + * stored into a newly allocated memory buffer. The HTTP request + * will be done accordingly to the global configuration of Orthanc + * (in particular, the options "HttpProxy", "HttpTimeout", + * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be + * taken into account). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answerBody The target memory buffer (out argument). + * It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). + * The answer headers are formatted as a JSON object (associative array). + * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). + * This argument can be set to NULL if the plugin has no interest in the HTTP headers. + * @param httpStatus The HTTP status after the execution of the request (out argument). + * @param method HTTP method to be used. + * @param url The URL of interest. + * @param headersCount The number of HTTP headers. + * @param headersKeys Array containing the keys of the HTTP headers (can be NULL if no header). + * @param headersValues Array containing the values of the HTTP headers (can be NULL if no header). + * @param username The username (can be NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @param body The HTTP body for a POST or PUT request. + * @param bodySize The size of the body. + * @param timeout Timeout in seconds (0 for default timeout). + * @param certificateFile Path to the client certificate for HTTPS, in PEM format + * (can be NULL if no client certificate or if not using HTTPS). + * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format + * (can be NULL if no client certificate or if not using HTTPS). + * @param certificateKeyPassword Password to unlock the key of the client certificate + * (can be NULL if no client certificate or if not using HTTPS). + * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginCallPeerApi() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* answerBody, + OrthancPluginMemoryBuffer* answerHeaders, + uint16_t* httpStatus, + OrthancPluginHttpMethod method, + const char* url, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues, + const void* body, + uint32_t bodySize, + const char* username, + const char* password, + uint32_t timeout, + const char* certificateFile, + const char* certificateKeyFile, + const char* certificateKeyPassword, + uint8_t pkcs11) + { + _OrthancPluginCallHttpClient2 params; + memset(¶ms, 0, sizeof(params)); + + params.answerBody = answerBody; + params.answerHeaders = answerHeaders; + params.httpStatus = httpStatus; + params.method = method; + params.url = url; + params.headersCount = headersCount; + params.headersKeys = headersKeys; + params.headersValues = headersValues; + params.body = body; + params.bodySize = bodySize; + params.username = username; + params.password = password; + params.timeout = timeout; + params.certificateFile = certificateFile; + params.certificateKeyFile = certificateKeyFile; + params.certificateKeyPassword = certificateKeyPassword; + params.pkcs11 = pkcs11; + + return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, ¶ms); + } + + + /** + * @brief Generate an UUID. + * + * Generate a random GUID/UUID (globally unique identifier). + * + * @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 UUID. This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid( + OrthancPluginContext* context) + { + char* result; + + _OrthancPluginRetrieveDynamicString params; + params.result = &result; + params.argument = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + + typedef struct + { + OrthancPluginFindCallback callback; + } _OrthancPluginFindCallback; + + /** + * @brief Register a callback to handle C-Find requests. + * + * This function registers a callback to handle C-Find SCP requests + * that are not related to 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 DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback( + OrthancPluginContext* context, + OrthancPluginFindCallback callback) + { + _OrthancPluginFindCallback params; + params.callback = callback; + + return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, ¶ms); + } + + + typedef struct + { + OrthancPluginFindAnswers *answers; + const OrthancPluginFindQuery *query; + const void *dicom; + uint32_t size; + uint32_t index; + uint32_t *resultUint32; + uint16_t *resultGroup; + uint16_t *resultElement; + char **resultString; + } _OrthancPluginFindOperation; + + /** + * @brief Add one answer to some C-Find request. + * + * This function adds one answer (encoded as a DICOM file) to the + * set of answers corresponding to some C-Find SCP request that is + * not related to modality worklists. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answers The set of answers. + * @param dicom The answer to be added, encoded as a DICOM file. + * @param size The size of the DICOM file. + * @return 0 if success, other value if error. + * @ingroup DicomCallbacks + * @see OrthancPluginCreateDicom() + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer( + OrthancPluginContext* context, + OrthancPluginFindAnswers* answers, + const void* dicom, + uint32_t size) + { + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.answers = answers; + params.dicom = dicom; + params.size = size; + + return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, ¶ms); + } + + + /** + * @brief Mark the set of C-Find answers as incomplete. + * + * This function marks as incomplete the set of answers + * corresponding to some C-Find SCP request that is not related to + * 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 DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete( + OrthancPluginContext* context, + OrthancPluginFindAnswers* answers) + { + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.answers = answers; + + return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, ¶ms); + } + + + + /** + * @brief Get the number of tags in a C-Find query. + * + * This function returns the number of tags that are contained in + * the given C-Find query. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The C-Find query. + * @return The number of tags. + * @ingroup DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize( + OrthancPluginContext* context, + const OrthancPluginFindQuery* query) + { + uint32_t count = 0; + + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.query = query; + params.resultUint32 = &count; + + if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return 0; + } + else + { + return count; + } + } + + + /** + * @brief Get one tag in a C-Find query. + * + * This function returns the group and the element of one DICOM tag + * in the given C-Find query. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param group The group of the tag (output). + * @param element The element of the tag (output). + * @param query The C-Find query. + * @param index The index of the tag of interest. + * @return 0 if success, other value if error. + * @ingroup DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag( + OrthancPluginContext* context, + uint16_t* group, + uint16_t* element, + const OrthancPluginFindQuery* query, + uint32_t index) + { + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.query = query; + params.index = index; + params.resultGroup = group; + params.resultElement = element; + + return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, ¶ms); + } + + + /** + * @brief Get the symbolic name of one tag in a C-Find query. + * + * This function returns the symbolic name of one DICOM tag in the + * given C-Find query. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The C-Find query. + * @param index The index of the tag of interest. + * @return The NULL value in case of error, or a string containing the name of the tag. + * @return 0 if success, other value if error. + * @ingroup DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName( + OrthancPluginContext* context, + const OrthancPluginFindQuery* query, + uint32_t index) + { + char* result; + + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.query = query; + params.index = index; + params.resultString = &result; + + if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + /** + * @brief Get the value associated with one tag in a C-Find query. + * + * This function returns the value associated with one tag in the + * given C-Find query. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The C-Find query. + * @param index The index of the tag of interest. + * @return The NULL value in case of error, or a string containing the value of the tag. + * @return 0 if success, other value if error. + * @ingroup DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue( + OrthancPluginContext* context, + const OrthancPluginFindQuery* query, + uint32_t index) + { + char* result; + + _OrthancPluginFindOperation params; + memset(¶ms, 0, sizeof(params)); + params.query = query; + params.index = index; + params.resultString = &result; + + if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + + typedef struct + { + OrthancPluginMoveCallback callback; + OrthancPluginGetMoveSize getMoveSize; + OrthancPluginApplyMove applyMove; + OrthancPluginFreeMove freeMove; + } _OrthancPluginMoveCallback; + + /** + * @brief Register a callback to handle C-Move requests. + * + * This function registers a callback to handle C-Move SCP requests. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The main callback. + * @param getMoveSize Callback to read the number of C-Move suboperations. + * @param applyMove Callback to apply one C-Move suboperation. + * @param freeMove Callback to free the C-Move driver. + * @return 0 if success, other value if error. + * @ingroup DicomCallbacks + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback( + OrthancPluginContext* context, + OrthancPluginMoveCallback callback, + OrthancPluginGetMoveSize getMoveSize, + OrthancPluginApplyMove applyMove, + OrthancPluginFreeMove freeMove) + { + _OrthancPluginMoveCallback params; + params.callback = callback; + params.getMoveSize = getMoveSize; + params.applyMove = applyMove; + params.freeMove = freeMove; + + return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, ¶ms); + } + + + + typedef struct + { + OrthancPluginFindMatcher** target; + const void* query; + uint32_t size; + } _OrthancPluginCreateFindMatcher; + + + /** + * @brief Create a C-Find matcher. + * + * This function creates a "matcher" object that can be used to + * check whether a DICOM instance matches a C-Find query. The C-Find + * query must be expressed as a DICOM buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param query The C-Find DICOM query. + * @param size The size of the DICOM query. + * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher( + OrthancPluginContext* context, + const void* query, + uint32_t size) + { + OrthancPluginFindMatcher* target = NULL; + + _OrthancPluginCreateFindMatcher params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.query = query; + params.size = size; + + if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return target; + } + } + + + typedef struct + { + OrthancPluginFindMatcher* matcher; + } _OrthancPluginFreeFindMatcher; + + /** + * @brief Free a C-Find matcher. + * + * This function frees a matcher that was created using OrthancPluginCreateFindMatcher(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param matcher The matcher of interest. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher( + OrthancPluginContext* context, + OrthancPluginFindMatcher* matcher) + { + _OrthancPluginFreeFindMatcher params; + params.matcher = matcher; + + context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, ¶ms); + } + + + typedef struct + { + const OrthancPluginFindMatcher* matcher; + const void* dicom; + uint32_t size; + int32_t* isMatch; + } _OrthancPluginFindMatcherIsMatch; + + /** + * @brief Test whether a DICOM instance matches a C-Find query. + * + * This function checks whether one DICOM instance matches C-Find + * matcher that was previously allocated using + * OrthancPluginCreateFindMatcher(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param matcher The matcher of interest. + * @param dicom The DICOM instance to be matched. + * @param size The size of the DICOM instance. + * @return 1 if the DICOM instance matches the query, 0 otherwise. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch( + OrthancPluginContext* context, + const OrthancPluginFindMatcher* matcher, + const void* dicom, + uint32_t size) + { + int32_t isMatch = 0; + + _OrthancPluginFindMatcherIsMatch params; + params.matcher = matcher; + params.dicom = dicom; + params.size = size; + params.isMatch = &isMatch; + + if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, ¶ms) == OrthancPluginErrorCode_Success) + { + return isMatch; + } + else + { + /* Error: Assume non-match */ + return 0; + } + } + + + typedef struct + { + OrthancPluginIncomingHttpRequestFilter2 callback; + } _OrthancPluginIncomingHttpRequestFilter2; + + /** + * @brief Register a callback to filter incoming HTTP requests. + * + * This function registers a custom callback to filter incoming HTTP/REST + * requests received by the HTTP server 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 OrthancPluginRegisterIncomingHttpRequestFilter2( + OrthancPluginContext* context, + OrthancPluginIncomingHttpRequestFilter2 callback) + { + _OrthancPluginIncomingHttpRequestFilter2 params; + params.callback = callback; + + return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, ¶ms); + } + + + + typedef struct + { + OrthancPluginPeers** peers; + } _OrthancPluginGetPeers; + + /** + * @brief Return the list of available Orthanc peers. + * + * This function returns the parameters of the Orthanc peers that are known to + * the Orthanc server hosting the plugin. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @return NULL if error, or a newly allocated opaque data structure containing the peers. + * This structure must be freed with OrthancPluginFreePeers(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers( + OrthancPluginContext* context) + { + OrthancPluginPeers* peers = NULL; + + _OrthancPluginGetPeers params; + memset(¶ms, 0, sizeof(params)); + params.peers = &peers; + + if (context->InvokeService(context, _OrthancPluginService_GetPeers, ¶ms) != OrthancPluginErrorCode_Success) + { + return NULL; + } + else + { + return peers; + } + } + + + typedef struct + { + OrthancPluginPeers* peers; + } _OrthancPluginFreePeers; + + /** + * @brief Free the list of available Orthanc peers. + * + * This function frees the data structure returned by OrthancPluginGetPeers(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param peers The data structure describing the Orthanc peers. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers( + OrthancPluginContext* context, + OrthancPluginPeers* peers) + { + _OrthancPluginFreePeers params; + params.peers = peers; + + context->InvokeService(context, _OrthancPluginService_FreePeers, ¶ms); + } + + + typedef struct + { + uint32_t* target; + const OrthancPluginPeers* peers; + } _OrthancPluginGetPeersCount; + + /** + * @brief Get the number of Orthanc peers. + * + * This function returns the number of Orthanc peers. + * + * This function is thread-safe: Several threads sharing the same + * OrthancPluginPeers object can simultaneously call this function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param peers The data structure describing the Orthanc peers. + * @result The number of peers. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount( + OrthancPluginContext* context, + const OrthancPluginPeers* peers) + { + uint32_t target = 0; + + _OrthancPluginGetPeersCount params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.peers = peers; + + if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return 0; + } + else + { + return target; + } + } + + + typedef struct + { + const char** target; + const OrthancPluginPeers* peers; + uint32_t peerIndex; + const char* userProperty; + } _OrthancPluginGetPeerProperty; + + /** + * @brief Get the symbolic name of an Orthanc peer. + * + * This function returns the symbolic name of the Orthanc peer, + * which corresponds to the key of the "OrthancPeers" configuration + * option of Orthanc. + * + * This function is thread-safe: Several threads sharing the same + * OrthancPluginPeers object can simultaneously call this function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param peers The data structure describing the Orthanc peers. + * @param peerIndex The index of the peer of interest. + * This value must be lower than OrthancPluginGetPeersCount(). + * @result The symbolic name, or NULL in the case of an error. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName( + OrthancPluginContext* context, + const OrthancPluginPeers* peers, + uint32_t peerIndex) + { + const char* target = NULL; + + _OrthancPluginGetPeerProperty params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.peers = peers; + params.peerIndex = peerIndex; + params.userProperty = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetPeerName, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + /** + * @brief Get the base URL of an Orthanc peer. + * + * This function returns the base URL to the REST API of some Orthanc peer. + * + * This function is thread-safe: Several threads sharing the same + * OrthancPluginPeers object can simultaneously call this function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param peers The data structure describing the Orthanc peers. + * @param peerIndex The index of the peer of interest. + * This value must be lower than OrthancPluginGetPeersCount(). + * @result The URL, or NULL in the case of an error. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl( + OrthancPluginContext* context, + const OrthancPluginPeers* peers, + uint32_t peerIndex) + { + const char* target = NULL; + + _OrthancPluginGetPeerProperty params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.peers = peers; + params.peerIndex = peerIndex; + params.userProperty = NULL; + + if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + + /** + * @brief Get some user-defined property of an Orthanc peer. + * + * This function returns some user-defined property of some Orthanc + * peer. An user-defined property is a property that is associated + * with the peer in the Orthanc configuration file, but that is not + * recognized by the Orthanc core. + * + * This function is thread-safe: Several threads sharing the same + * OrthancPluginPeers object can simultaneously call this function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param peers The data structure describing the Orthanc peers. + * @param peerIndex The index of the peer of interest. + * This value must be lower than OrthancPluginGetPeersCount(). + * @param userProperty The user property of interest. + * @result The value of the user property, or NULL if it is not defined. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty( + OrthancPluginContext* context, + const OrthancPluginPeers* peers, + uint32_t peerIndex, + const char* userProperty) + { + const char* target = NULL; + + _OrthancPluginGetPeerProperty params; + memset(¶ms, 0, sizeof(params)); + params.target = ⌖ + params.peers = peers; + params.peerIndex = peerIndex; + params.userProperty = userProperty; + + if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, ¶ms) != OrthancPluginErrorCode_Success) + { + /* No such user property */ + return NULL; + } + else + { + return target; + } + } + + + + typedef struct + { + OrthancPluginMemoryBuffer* answerBody; + OrthancPluginMemoryBuffer* answerHeaders; + uint16_t* httpStatus; + const OrthancPluginPeers* peers; + uint32_t peerIndex; + OrthancPluginHttpMethod method; + const char* uri; + uint32_t additionalHeadersCount; + const char* const* additionalHeadersKeys; + const char* const* additionalHeadersValues; + const void* body; + uint32_t bodySize; + uint32_t timeout; + } _OrthancPluginCallPeerApi; + + /** + * @brief Call the REST API of an Orthanc peer. + * + * Make a REST call to the given URI in the REST API of a remote + * Orthanc peer. The result to the query is stored into a newly + * allocated memory buffer. The HTTP request will be done according + * to the "OrthancPeers" configuration option of Orthanc. + * + * This function is thread-safe: Several threads sharing the same + * OrthancPluginPeers object can simultaneously call this function. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answerBody The target memory buffer (out argument). + * It must be freed with OrthancPluginFreeMemoryBuffer(). + * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument). + * The answer headers are formatted as a JSON object (associative array). + * The buffer must be freed with OrthancPluginFreeMemoryBuffer(). + * This argument can be set to NULL if the plugin has no interest in the HTTP headers. + * @param httpStatus The HTTP status after the execution of the request (out argument). + * @param peers The data structure describing the Orthanc peers. + * @param peerIndex The index of the peer of interest. + * This value must be lower than OrthancPluginGetPeersCount(). + * @param method HTTP method to be used. + * @param uri The URI of interest in the REST API. + * @param additionalHeadersCount The number of HTTP headers to be added to the + * HTTP headers provided in the global configuration of Orthanc. + * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be NULL if no header). + * @param additionalHeadersValues Array containing the values of the HTTP headers (can be NULL if no header). + * @param body The HTTP body for a POST or PUT request. + * @param bodySize The size of the body. + * @param timeout Timeout in seconds (0 for default timeout). + * @return 0 if success, or the error code if failure. + * @see OrthancPluginHttpClient() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* answerBody, + OrthancPluginMemoryBuffer* answerHeaders, + uint16_t* httpStatus, + const OrthancPluginPeers* peers, + uint32_t peerIndex, + OrthancPluginHttpMethod method, + const char* uri, + uint32_t additionalHeadersCount, + const char* const* additionalHeadersKeys, + const char* const* additionalHeadersValues, + const void* body, + uint32_t bodySize, + uint32_t timeout) + { + _OrthancPluginCallPeerApi params; + memset(¶ms, 0, sizeof(params)); + + params.answerBody = answerBody; + params.answerHeaders = answerHeaders; + params.httpStatus = httpStatus; + params.peers = peers; + params.peerIndex = peerIndex; + params.method = method; + params.uri = uri; + params.additionalHeadersCount = additionalHeadersCount; + params.additionalHeadersKeys = additionalHeadersKeys; + params.additionalHeadersValues = additionalHeadersValues; + params.body = body; + params.bodySize = bodySize; + params.timeout = timeout; + + return context->InvokeService(context, _OrthancPluginService_CallPeerApi, ¶ms); + } + + + + + + typedef struct + { + OrthancPluginJob** target; + void *job; + OrthancPluginJobFinalize finalize; + const char *type; + OrthancPluginJobGetProgress getProgress; + OrthancPluginJobGetContent getContent; + OrthancPluginJobGetSerialized getSerialized; + OrthancPluginJobStep step; + OrthancPluginJobStop stop; + OrthancPluginJobReset reset; + } _OrthancPluginCreateJob; + + /** + * @brief Create a custom job. + * + * This function creates a custom job to be run by the jobs engine + * of Orthanc. + * + * Orthanc starts one dedicated thread per custom job that is + * running. It is guaranteed that all the callbacks will only be + * called from this single dedicated thread, in mutual exclusion: As + * a consequence, it is *not* mandatory to protect the various + * callbacks by mutexes. + * + * The custom job can nonetheless launch its own processing threads + * on the first call to the "step()" callback, and stop them once + * the "stop()" callback is called. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param job The job to be executed. + * @param finalize The finalization callback. + * @param type The type of the job, provided to the job unserializer. + * See OrthancPluginRegisterJobsUnserializer(). + * @param getProgress The progress callback. + * @param getContent The content callback. + * @param getSerialized The serialization callback. + * @param step The callback to execute the individual steps of the job. + * @param stop The callback that is invoked once the job leaves the "running" state. + * @param reset The callback that is invoked if a stopped job is started again. + * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(), + * as long as it is not submitted with OrthancPluginSubmitJob(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob( + OrthancPluginContext *context, + void *job, + OrthancPluginJobFinalize finalize, + const char *type, + OrthancPluginJobGetProgress getProgress, + OrthancPluginJobGetContent getContent, + OrthancPluginJobGetSerialized getSerialized, + OrthancPluginJobStep step, + OrthancPluginJobStop stop, + OrthancPluginJobReset reset) + { + OrthancPluginJob* target = NULL; + + _OrthancPluginCreateJob params; + memset(¶ms, 0, sizeof(params)); + + params.target = ⌖ + params.job = job; + params.finalize = finalize; + params.type = type; + params.getProgress = getProgress; + params.getContent = getContent; + params.getSerialized = getSerialized; + params.step = step; + params.stop = stop; + params.reset = reset; + + if (context->InvokeService(context, _OrthancPluginService_CreateJob, ¶ms) != OrthancPluginErrorCode_Success || + target == NULL) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + typedef struct + { + OrthancPluginJob* job; + } _OrthancPluginFreeJob; + + /** + * @brief Free a custom job. + * + * This function frees an image that was created with OrthancPluginCreateJob(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param job The job. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob( + OrthancPluginContext* context, + OrthancPluginJob* job) + { + _OrthancPluginFreeJob params; + params.job = job; + + context->InvokeService(context, _OrthancPluginService_FreeJob, ¶ms); + } + + + + typedef struct + { + char** resultId; + OrthancPluginJob *job; + int priority; + } _OrthancPluginSubmitJob; + + /** + * @brief Submit a new job to the jobs engine of Orthanc. + * + * This function adds the given job to the pending jobs of + * Orthanc. Orthanc will take take of freeing it by invoking the + * finalization callback provided to OrthancPluginCreateJob(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param job The job, as received by OrthancPluginCreateJob(). + * @param priority The priority of the job. + * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob( + OrthancPluginContext *context, + OrthancPluginJob *job, + int priority) + { + char* resultId = NULL; + + _OrthancPluginSubmitJob params; + memset(¶ms, 0, sizeof(params)); + + params.resultId = &resultId; + params.job = job; + params.priority = priority; + + if (context->InvokeService(context, _OrthancPluginService_SubmitJob, ¶ms) != OrthancPluginErrorCode_Success || + resultId == NULL) + { + /* Error */ + return NULL; + } + else + { + return resultId; + } + } + + + + typedef struct + { + OrthancPluginJobsUnserializer unserializer; + } _OrthancPluginJobsUnserializer; + + /** + * @brief Register an unserializer for custom jobs. + * + * This function registers an unserializer that decodes custom jobs + * from a JSON string. This callback is invoked when the jobs engine + * of Orthanc is started (on Orthanc initialization), for each job + * that is stored in the Orthanc database. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param unserializer The job unserializer. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer( + OrthancPluginContext* context, + OrthancPluginJobsUnserializer unserializer) + { + _OrthancPluginJobsUnserializer params; + params.unserializer = unserializer; + + context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, ¶ms); + } + + + + typedef struct + { + OrthancPluginRestOutput* output; + const char* details; + uint8_t log; + } _OrthancPluginSetHttpErrorDetails; + + /** + * @brief Provide a detailed description for an HTTP error. + * + * This function sets the detailed description associated with an + * HTTP error. This description will be displayed in the "Details" + * field of the JSON body of the HTTP answer. It is only taken into + * consideration if the REST callback returns an error code that is + * different from "OrthancPluginErrorCode_Success", and if the + * "HttpDescribeErrors" configuration option of Orthanc is set to + * "true". + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param output The HTTP connection to the client application. + * @param details The details of the error message. + * @param log Whether to also write the detailed error to the Orthanc logs. + * @ingroup REST + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails( + OrthancPluginContext* context, + OrthancPluginRestOutput* output, + const char* details, + uint8_t log) + { + _OrthancPluginSetHttpErrorDetails params; + params.output = output; + params.details = details; + params.log = log; + context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, ¶ms); + } + + + + typedef struct + { + const char** result; + const char* argument; + } _OrthancPluginRetrieveStaticString; + + /** + * @brief Detect the MIME type of a file. + * + * This function returns the MIME type of a file by inspecting its extension. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param path Path to the file. + * @return The MIME type. This is a statically-allocated + * string, do not free it. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType( + OrthancPluginContext* context, + const char* path) + { + const char* result = NULL; + + _OrthancPluginRetrieveStaticString params; + params.result = &result; + params.argument = path; + + if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + + typedef struct + { + const char* name; + float value; + OrthancPluginMetricsType type; + } _OrthancPluginSetMetricsValue; + + /** + * @brief Set the value of a metrics. + * + * This function sets the value of a metrics to monitor the behavior + * of the plugin through tools such as Prometheus. The values of all + * the metrics are stored within the Orthanc context. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param name The name of the metrics to be set. + * @param value The value of the metrics. + * @param type The type of the metrics. This parameter is only taken into consideration + * the first time this metrics is set. + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue( + OrthancPluginContext* context, + const char* name, + float value, + OrthancPluginMetricsType type) + { + _OrthancPluginSetMetricsValue params; + params.name = name; + params.value = value; + params.type = type; + context->InvokeService(context, _OrthancPluginService_SetMetricsValue, ¶ms); + } + + + + typedef struct + { + OrthancPluginRefreshMetricsCallback callback; + } _OrthancPluginRegisterRefreshMetricsCallback; + + /** + * @brief Register a callback to refresh the metrics. + * + * This function registers a callback to refresh the metrics. The + * callback must make calls to OrthancPluginSetMetricsValue(). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param callback The callback function to handle the refresh. + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback( + OrthancPluginContext* context, + OrthancPluginRefreshMetricsCallback callback) + { + _OrthancPluginRegisterRefreshMetricsCallback params; + params.callback = callback; + context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, ¶ms); + } + + + + + typedef struct + { + char** target; + const void* dicom; + uint32_t dicomSize; + OrthancPluginDicomWebBinaryCallback callback; + } _OrthancPluginEncodeDicomWeb; + + /** + * @brief Convert a DICOM instance to DICOMweb JSON. + * + * This function converts a memory buffer containing a DICOM instance, + * into its DICOMweb JSON representation. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param dicom Pointer to the DICOM instance. + * @param dicomSize Size of the DICOM instance. + * @param callback Callback to set the value of the binary tags. + * @see OrthancPluginCreateDicom() + * @return The NULL value in case of error, or the JSON document. This string must + * be freed by OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson( + OrthancPluginContext* context, + const void* dicom, + uint32_t dicomSize, + OrthancPluginDicomWebBinaryCallback callback) + { + char* target = NULL; + + _OrthancPluginEncodeDicomWeb params; + params.target = ⌖ + params.dicom = dicom; + params.dicomSize = dicomSize; + params.callback = callback; + + if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + /** + * @brief Convert a DICOM instance to DICOMweb XML. + * + * This function converts a memory buffer containing a DICOM instance, + * into its DICOMweb XML representation. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param dicom Pointer to the DICOM instance. + * @param dicomSize Size of the DICOM instance. + * @param callback Callback to set the value of the binary tags. + * @return The NULL value in case of error, or the JSON document. This string must + * be freed by OrthancPluginFreeString(). + * @see OrthancPluginCreateDicom() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml( + OrthancPluginContext* context, + const void* dicom, + uint32_t dicomSize, + OrthancPluginDicomWebBinaryCallback callback) + { + char* target = NULL; + + _OrthancPluginEncodeDicomWeb params; + params.target = ⌖ + params.dicom = dicom; + params.dicomSize = dicomSize; + params.callback = callback; + + if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return target; + } + } + + + + /** + * @brief Callback executed when a HTTP header is received during a chunked transfer. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, as soon as it + * receives one HTTP header from the answer of the remote HTTP + * server. + * + * @see OrthancPluginChunkedHttpClient() + * @param answer The user payload, as provided by the calling plugin. + * @param key The key of the HTTP header. + * @param value The value of the HTTP header. + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddHeader) ( + void* answer, + const char* key, + const char* value); + + + /** + * @brief Callback executed when an answer chunk is received during a chunked transfer. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, as soon as it + * receives one data chunk from the answer of the remote HTTP + * server. + * + * @see OrthancPluginChunkedHttpClient() + * @param answer The user payload, as provided by the calling plugin. + * @param data The content of the data chunk. + * @param size The size of the data chunk. + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddChunk) ( + void* answer, + const void* data, + uint32_t size); + + + /** + * @brief Callback to know whether the request body is entirely read during a chunked transfer + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, while reading + * the body of a POST or PUT request. The plugin must answer "1" as + * soon as the body is entirely read: The "request" data structure + * must act as an iterator. + * + * @see OrthancPluginChunkedHttpClient() + * @param request The user payload, as provided by the calling plugin. + * @return "1" if the body is over, or "0" if there is still data to be read. + * @ingroup Toolbox + **/ + typedef uint8_t (*OrthancPluginChunkedClientRequestIsDone) (void* request); + + + /** + * @brief Callback to advance in the request body during a chunked transfer + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, while reading + * the body of a POST or PUT request. This function asks the plugin + * to advance to the next chunk of data of the request body: The + * "request" data structure must act as an iterator. + * + * @see OrthancPluginChunkedHttpClient() + * @param request The user payload, as provided by the calling plugin. + * @return 0 if success, or the error code if failure. + * @ingroup Toolbox + **/ + typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientRequestNext) (void* request); + + + /** + * @brief Callback to read the current chunk of the request body during a chunked transfer + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, while reading + * the body of a POST or PUT request. The plugin must provide the + * content of the current chunk of data of the request body. + * + * @see OrthancPluginChunkedHttpClient() + * @param request The user payload, as provided by the calling plugin. + * @return The content of the current request chunk. + * @ingroup Toolbox + **/ + typedef const void* (*OrthancPluginChunkedClientRequestGetChunkData) (void* request); + + + /** + * @brief Callback to read the size of the current request chunk during a chunked transfer + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP client during a chunked HTTP transfer, while reading + * the body of a POST or PUT request. The plugin must provide the + * size of the current chunk of data of the request body. + * + * @see OrthancPluginChunkedHttpClient() + * @param request The user payload, as provided by the calling plugin. + * @return The size of the current request chunk. + * @ingroup Toolbox + **/ + typedef uint32_t (*OrthancPluginChunkedClientRequestGetChunkSize) (void* request); + + + typedef struct + { + void* answer; + OrthancPluginChunkedClientAnswerAddChunk answerAddChunk; + OrthancPluginChunkedClientAnswerAddHeader answerAddHeader; + uint16_t* httpStatus; + OrthancPluginHttpMethod method; + const char* url; + uint32_t headersCount; + const char* const* headersKeys; + const char* const* headersValues; + void* request; + OrthancPluginChunkedClientRequestIsDone requestIsDone; + OrthancPluginChunkedClientRequestGetChunkData requestChunkData; + OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize; + OrthancPluginChunkedClientRequestNext requestNext; + const char* username; + const char* password; + uint32_t timeout; + const char* certificateFile; + const char* certificateKeyFile; + const char* certificateKeyPassword; + uint8_t pkcs11; + } _OrthancPluginChunkedHttpClient; + + + /** + * @brief Issue a HTTP call, using chunked HTTP transfers. + * + * Make a HTTP call to the given URL using chunked HTTP + * transfers. The request body is provided as an iterator over data + * chunks. The answer is provided as a sequence of function calls + * with the individual HTTP headers and answer chunks. + * + * Contrarily to OrthancPluginHttpClient() that entirely stores the + * request body and the answer body in memory buffers, this function + * uses chunked HTTP transfers. This results in a lower memory + * consumption. Pay attention to the fact that Orthanc servers with + * version <= 1.5.6 do not support chunked transfers: You must use + * OrthancPluginHttpClient() if contacting such older servers. + * + * The HTTP request will be done accordingly to the global + * configuration of Orthanc (in particular, the options "HttpProxy", + * "HttpTimeout", "HttpsVerifyPeers", "HttpsCACertificates", and + * "Pkcs11" will be taken into account). + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param answer The user payload for the answer body. It will be provided to the callbacks for the answer. + * @param answerAddChunk Callback function to report a data chunk from the answer body. + * @param answerAddHeader Callback function to report an HTTP header sent by the remote server. + * @param httpStatus The HTTP status after the execution of the request (out argument). + * @param method HTTP method to be used. + * @param url The URL of interest. + * @param headersCount The number of HTTP headers. + * @param headersKeys Array containing the keys of the HTTP headers (can be NULL if no header). + * @param headersValues Array containing the values of the HTTP headers (can be NULL if no header). + * @param request The user payload containing the request body, and acting as an iterator. + * It will be provided to the callbacks for the request. + * @param requestIsDone Callback function to tell whether the request body is entirely read. + * @param requestChunkData Callback function to get the content of the current data chunk of the request body. + * @param requestChunkSize Callback function to get the size of the current data chunk of the request body. + * @param requestNext Callback function to advance to the next data chunk of the request body. + * @param username The username (can be NULL if no password protection). + * @param password The password (can be NULL if no password protection). + * @param timeout Timeout in seconds (0 for default timeout). + * @param certificateFile Path to the client certificate for HTTPS, in PEM format + * (can be NULL if no client certificate or if not using HTTPS). + * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format + * (can be NULL if no client certificate or if not using HTTPS). + * @param certificateKeyPassword Password to unlock the key of the client certificate + * (can be NULL if no client certificate or if not using HTTPS). + * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginHttpClient() + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginChunkedHttpClient( + OrthancPluginContext* context, + void* answer, + OrthancPluginChunkedClientAnswerAddChunk answerAddChunk, + OrthancPluginChunkedClientAnswerAddHeader answerAddHeader, + uint16_t* httpStatus, + OrthancPluginHttpMethod method, + const char* url, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues, + void* request, + OrthancPluginChunkedClientRequestIsDone requestIsDone, + OrthancPluginChunkedClientRequestGetChunkData requestChunkData, + OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize, + OrthancPluginChunkedClientRequestNext requestNext, + const char* username, + const char* password, + uint32_t timeout, + const char* certificateFile, + const char* certificateKeyFile, + const char* certificateKeyPassword, + uint8_t pkcs11) + { + _OrthancPluginChunkedHttpClient params; + memset(¶ms, 0, sizeof(params)); + + /* In common with OrthancPluginHttpClient() */ + params.httpStatus = httpStatus; + params.method = method; + params.url = url; + params.headersCount = headersCount; + params.headersKeys = headersKeys; + params.headersValues = headersValues; + params.username = username; + params.password = password; + params.timeout = timeout; + params.certificateFile = certificateFile; + params.certificateKeyFile = certificateKeyFile; + params.certificateKeyPassword = certificateKeyPassword; + params.pkcs11 = pkcs11; + + /* For chunked body/answer */ + params.answer = answer; + params.answerAddChunk = answerAddChunk; + params.answerAddHeader = answerAddHeader; + params.request = request; + params.requestIsDone = requestIsDone; + params.requestChunkData = requestChunkData; + params.requestChunkSize = requestChunkSize; + params.requestNext = requestNext; + + return context->InvokeService(context, _OrthancPluginService_ChunkedHttpClient, ¶ms); + } + + + + /** + * @brief Opaque structure that reads the content of a HTTP request body during a chunked HTTP transfer. + * @ingroup Callback + **/ + typedef struct _OrthancPluginServerChunkedRequestReader_t OrthancPluginServerChunkedRequestReader; + + + + /** + * @brief Callback to create a reader to handle incoming chunked HTTP transfers. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP server that supports chunked HTTP transfers. This + * callback is only invoked if the HTTP method is POST or PUT. The + * callback must create an user-specific "reader" object that will + * be fed with the body of the incoming body. + * + * @see OrthancPluginRegisterChunkedRestCallback() + * @param reader Memory location that must be filled with the newly-created reader. + * @param url The URI that is accessed. + * @param request The body of the HTTP request. Note that "body" and "bodySize" are not used. + * @return 0 if success, or the error code if failure. + **/ + typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderFactory) ( + OrthancPluginServerChunkedRequestReader** reader, + const char* url, + const OrthancPluginHttpRequest* request); + + + /** + * @brief Callback invoked whenever a new data chunk is available during a chunked transfer. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP server that supports chunked HTTP transfers. This callback + * is invoked as soon as a new data chunk is available for the request body. + * + * @see OrthancPluginRegisterChunkedRestCallback() + * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. + * @param data The content of the data chunk. + * @param size The size of the data chunk. + * @return 0 if success, or the error code if failure. + **/ + typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderAddChunk) ( + OrthancPluginServerChunkedRequestReader* reader, + const void* data, + uint32_t size); + + + /** + * @brief Callback invoked whenever the request body is entirely received. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP server that supports chunked HTTP transfers. This + * callback is invoked as soon as the full body of the HTTP request + * is available. The plugin can then send its answer thanks to the + * provided "output" object. + * + * @see OrthancPluginRegisterChunkedRestCallback() + * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. + * @param output The HTTP connection to the client application. + * @return 0 if success, or the error code if failure. + **/ + typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderExecute) ( + OrthancPluginServerChunkedRequestReader* reader, + OrthancPluginRestOutput* output); + + + /** + * @brief Callback invoked to release the resources associated with an incoming HTTP chunked transfer. + * + * Signature of a callback function that is called by Orthanc acting + * as a HTTP server that supports chunked HTTP transfers. This + * callback is invoked to release all the resources allocated by the + * given reader. Note that this function might be invoked even if + * the entire body was not read, to deal with client error or + * disconnection. + * + * @see OrthancPluginRegisterChunkedRestCallback() + * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback. + **/ + typedef void (*OrthancPluginServerChunkedRequestReaderFinalize) ( + OrthancPluginServerChunkedRequestReader* reader); + + typedef struct + { + const char* pathRegularExpression; + OrthancPluginRestCallback getHandler; + OrthancPluginServerChunkedRequestReaderFactory postHandler; + OrthancPluginRestCallback deleteHandler; + OrthancPluginServerChunkedRequestReaderFactory putHandler; + OrthancPluginServerChunkedRequestReaderAddChunk addChunk; + OrthancPluginServerChunkedRequestReaderExecute execute; + OrthancPluginServerChunkedRequestReaderFinalize finalize; + } _OrthancPluginChunkedRestCallback; + + + /** + * @brief Register a REST callback to handle chunked HTTP transfers. + * + * 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 callbacks + * will NOT be invoked in mutual exclusion, so 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 getHandler The callback function to handle REST calls using the GET HTTP method. + * @param postHandler The callback function to handle REST calls using the GET POST method. + * @param deleteHandler The callback function to handle REST calls using the GET DELETE method. + * @param putHandler The callback function to handle REST calls using the GET PUT method. + * @param addChunk The callback invoked when a new chunk is available for the request body of a POST or PUT call. + * @param execute The callback invoked once the entire body of a POST or PUT call is read. + * @param finalize The callback invoked to release the resources associated with a POST or PUT call. + * @see OrthancPluginRegisterRestCallbackNoLock() + * + * @note + * The regular expression is case sensitive and must follow the + * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html). + * + * @ingroup Callbacks + **/ + ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterChunkedRestCallback( + OrthancPluginContext* context, + const char* pathRegularExpression, + OrthancPluginRestCallback getHandler, + OrthancPluginServerChunkedRequestReaderFactory postHandler, + OrthancPluginRestCallback deleteHandler, + OrthancPluginServerChunkedRequestReaderFactory putHandler, + OrthancPluginServerChunkedRequestReaderAddChunk addChunk, + OrthancPluginServerChunkedRequestReaderExecute execute, + OrthancPluginServerChunkedRequestReaderFinalize finalize) + { + _OrthancPluginChunkedRestCallback params; + params.pathRegularExpression = pathRegularExpression; + params.getHandler = getHandler; + params.postHandler = postHandler; + params.deleteHandler = deleteHandler; + params.putHandler = putHandler; + params.addChunk = addChunk; + params.execute = execute; + params.finalize = finalize; + + context->InvokeService(context, _OrthancPluginService_RegisterChunkedRestCallback, ¶ms); + } + + + + + + typedef struct + { + char** result; + uint16_t group; + uint16_t element; + const char* privateCreator; + } _OrthancPluginGetTagName; + + /** + * @brief Returns the symbolic name of a DICOM tag. + * + * This function makes a lookup to the dictionary of DICOM tags that + * are known to Orthanc, and returns the symbolic name of a DICOM tag. + * + * @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 privateCreator For private tags, the name of the private creator (can be NULL). + * @return NULL in the case of an error, or a newly allocated string + * containing the path. This string must be freed by + * OrthancPluginFreeString(). + * @ingroup Toolbox + **/ + ORTHANC_PLUGIN_INLINE char* OrthancPluginGetTagName( + OrthancPluginContext* context, + uint16_t group, + uint16_t element, + const char* privateCreator) + { + char* result; + + _OrthancPluginGetTagName params; + params.result = &result; + params.group = group; + params.element = element; + params.privateCreator = privateCreator; + + if (context->InvokeService(context, _OrthancPluginService_GetTagName, ¶ms) != OrthancPluginErrorCode_Success) + { + /* Error */ + return NULL; + } + else + { + return result; + } + } + + + +#ifdef __cplusplus +} +#endif + + +/** @} */ + diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk.cpp Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,93 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#include "sdk.h" + +#include + +#include "./sdk_OrthancPluginInstanceOrigin.impl.h" +#include "./sdk_OrthancPluginJobStepStatus.impl.h" +#include "./sdk_OrthancPluginDicomWebBinaryMode.impl.h" +#include "./sdk_OrthancPluginHttpMethod.impl.h" +#include "./sdk_OrthancPluginResourceType.impl.h" +#include "./sdk_OrthancPluginConstraintType.impl.h" +#include "./sdk_OrthancPluginPixelFormat.impl.h" +#include "./sdk_OrthancPluginCompressionType.impl.h" +#include "./sdk_OrthancPluginJobStopReason.impl.h" +#include "./sdk_OrthancPluginIdentifierConstraint.impl.h" +#include "./sdk_OrthancPluginContentType.impl.h" +#include "./sdk_OrthancPluginDicomToJsonFlags.impl.h" +#include "./sdk_OrthancPluginErrorCode.impl.h" +#include "./sdk_OrthancPluginCreateDicomFlags.impl.h" +#include "./sdk_OrthancPluginDicomToJsonFormat.impl.h" +#include "./sdk_OrthancPluginMetricsType.impl.h" +#include "./sdk_OrthancPluginValueRepresentation.impl.h" +#include "./sdk_OrthancPluginImageFormat.impl.h" +#include "./sdk_OrthancPluginChangeType.impl.h" + +#include "./sdk_OrthancPluginRestOutput.impl.h" +#include "./sdk_OrthancPluginServerChunkedRequestReader.impl.h" +#include "./sdk_OrthancPluginImage.impl.h" +#include "./sdk_OrthancPluginWorklistQuery.impl.h" +#include "./sdk_OrthancPluginStorageArea.impl.h" +#include "./sdk_OrthancPluginJob.impl.h" +#include "./sdk_OrthancPluginDicomWebNode.impl.h" +#include "./sdk_OrthancPluginWorklistAnswers.impl.h" +#include "./sdk_OrthancPluginFindAnswers.impl.h" +#include "./sdk_OrthancPluginPeers.impl.h" +#include "./sdk_OrthancPluginDicomInstance.impl.h" +#include "./sdk_OrthancPluginFindQuery.impl.h" + +#include "./sdk_GlobalFunctions.impl.h" + +void RegisterOrthancSdk(PyObject* module) +{ + RegisterOrthancPluginInstanceOriginEnumeration(module); + RegisterOrthancPluginJobStepStatusEnumeration(module); + RegisterOrthancPluginDicomWebBinaryModeEnumeration(module); + RegisterOrthancPluginHttpMethodEnumeration(module); + RegisterOrthancPluginResourceTypeEnumeration(module); + RegisterOrthancPluginConstraintTypeEnumeration(module); + RegisterOrthancPluginPixelFormatEnumeration(module); + RegisterOrthancPluginCompressionTypeEnumeration(module); + RegisterOrthancPluginJobStopReasonEnumeration(module); + RegisterOrthancPluginIdentifierConstraintEnumeration(module); + RegisterOrthancPluginContentTypeEnumeration(module); + RegisterOrthancPluginDicomToJsonFlagsEnumeration(module); + RegisterOrthancPluginErrorCodeEnumeration(module); + RegisterOrthancPluginCreateDicomFlagsEnumeration(module); + RegisterOrthancPluginDicomToJsonFormatEnumeration(module); + RegisterOrthancPluginMetricsTypeEnumeration(module); + RegisterOrthancPluginValueRepresentationEnumeration(module); + RegisterOrthancPluginImageFormatEnumeration(module); + RegisterOrthancPluginChangeTypeEnumeration(module); + + RegisterOrthancPluginRestOutputClass(module); + RegisterOrthancPluginServerChunkedRequestReaderClass(module); + RegisterOrthancPluginImageClass(module); + RegisterOrthancPluginWorklistQueryClass(module); + RegisterOrthancPluginStorageAreaClass(module); + RegisterOrthancPluginJobClass(module); + RegisterOrthancPluginDicomWebNodeClass(module); + RegisterOrthancPluginWorklistAnswersClass(module); + RegisterOrthancPluginFindAnswersClass(module); + RegisterOrthancPluginPeersClass(module); + RegisterOrthancPluginDicomInstanceClass(module); + RegisterOrthancPluginFindQueryClass(module); +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,38 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include + +void RegisterOrthancSdk(PyObject* module); +PyMethodDef* GetOrthancSdkFunctions(); + +PyObject* GetOrthancPluginRestOutputType(); +PyObject* GetOrthancPluginServerChunkedRequestReaderType(); +PyObject* GetOrthancPluginImageType(); +PyObject* GetOrthancPluginWorklistQueryType(); +PyObject* GetOrthancPluginStorageAreaType(); +PyObject* GetOrthancPluginJobType(); +PyObject* GetOrthancPluginDicomWebNodeType(); +PyObject* GetOrthancPluginWorklistAnswersType(); +PyObject* GetOrthancPluginFindAnswersType(); +PyObject* GetOrthancPluginPeersType(); +PyObject* GetOrthancPluginDicomInstanceType(); +PyObject* GetOrthancPluginFindQueryType(); diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_GlobalFunctions.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_GlobalFunctions.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,1669 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +static PyObject* sdk_OrthancPluginCheckVersionAdvanced(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginCheckVersionAdvanced()"); + + int arg0 = 0; + int arg1 = 0; + int arg2 = 0; + + if (!PyArg_ParseTuple(args, "iii", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + long value = OrthancPluginCheckVersionAdvanced(OrthancPlugins::GetGlobalContext(), arg0, arg1, arg2); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginCheckVersion(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginCheckVersion()"); + + + long value = OrthancPluginCheckVersion(OrthancPlugins::GetGlobalContext()); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginLogError(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLogError()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginLogError(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginLogWarning(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLogWarning()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginLogInfo(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLogInfo()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginLogInfo(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginGetDicomForInstance(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetDicomForInstance()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginGetDicomForInstance(OrthancPlugins::GetGlobalContext(), *buffer, arg0); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiGet(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiGet()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiGet(OrthancPlugins::GetGlobalContext(), *buffer, arg0); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiGetAfterPlugins(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiGetAfterPlugins()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiGetAfterPlugins(OrthancPlugins::GetGlobalContext(), *buffer, arg0); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiPost(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiPost()"); + + const char* arg0 = NULL; + Py_buffer arg1; + + if (!PyArg_ParseTuple(args, "ss*", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiPost(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiPostAfterPlugins(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiPostAfterPlugins()"); + + const char* arg0 = NULL; + Py_buffer arg1; + + if (!PyArg_ParseTuple(args, "ss*", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiPostAfterPlugins(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiDelete(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiDelete()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginRestApiDelete(OrthancPlugins::GetGlobalContext(), arg0); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiDeleteAfterPlugins(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiDeleteAfterPlugins()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginRestApiDeleteAfterPlugins(OrthancPlugins::GetGlobalContext(), arg0); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiPut(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiPut()"); + + const char* arg0 = NULL; + Py_buffer arg1; + + if (!PyArg_ParseTuple(args, "ss*", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiPut(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRestApiPutAfterPlugins(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRestApiPutAfterPlugins()"); + + const char* arg0 = NULL; + Py_buffer arg1; + + if (!PyArg_ParseTuple(args, "ss*", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginRestApiPutAfterPlugins(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginLookupPatient(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLookupPatient()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginLookupPatient(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginLookupStudy(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLookupStudy()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginLookupStudy(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginLookupStudyWithAccessionNumber(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLookupStudyWithAccessionNumber()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginLookupStudyWithAccessionNumber(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginLookupSeries(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLookupSeries()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginLookupSeries(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginLookupInstance(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginLookupInstance()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginLookupInstance(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGetOrthancPath(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetOrthancPath()"); + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetOrthancPath(OrthancPlugins::GetGlobalContext())); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGetOrthancDirectory(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetOrthancDirectory()"); + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetOrthancDirectory(OrthancPlugins::GetGlobalContext())); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGetConfigurationPath(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetConfigurationPath()"); + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetConfigurationPath(OrthancPlugins::GetGlobalContext())); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginSetRootUri(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginSetRootUri()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginSetRootUri(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginSetDescription(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginSetDescription()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginSetDescription(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginExtendOrthancExplorer(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginExtendOrthancExplorer()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginGetGlobalProperty(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetGlobalProperty()"); + + long int arg0 = 0; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ls", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetGlobalProperty(OrthancPlugins::GetGlobalContext(), arg0, arg1)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginSetGlobalProperty(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginSetGlobalProperty()"); + + long int arg0 = 0; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ls", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginSetGlobalProperty(OrthancPlugins::GetGlobalContext(), arg0, arg1); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginGetCommandLineArgumentsCount(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetCommandLineArgumentsCount()"); + + + long value = OrthancPluginGetCommandLineArgumentsCount(OrthancPlugins::GetGlobalContext()); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginGetCommandLineArgument(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetCommandLineArgument()"); + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetCommandLineArgument(OrthancPlugins::GetGlobalContext(), arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGetExpectedDatabaseVersion(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetExpectedDatabaseVersion()"); + + + long value = OrthancPluginGetExpectedDatabaseVersion(OrthancPlugins::GetGlobalContext()); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginGetConfiguration(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetConfiguration()"); + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetConfiguration(OrthancPlugins::GetGlobalContext())); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginBufferCompression(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginBufferCompression()"); + + Py_buffer arg0; + long int arg2 = 0; + unsigned char arg3 = 0; + + if (!PyArg_ParseTuple(args, "s*lb", &arg0, &arg2, &arg3)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginBufferCompression(OrthancPlugins::GetGlobalContext(), *buffer, arg0.buf, arg0.len, static_cast(arg2), arg3); + PyBuffer_Release(&arg0); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginReadFile(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginReadFile()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginReadFile(OrthancPlugins::GetGlobalContext(), *buffer, arg0); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginWriteFile(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginWriteFile()"); + + const char* arg0 = NULL; + Py_buffer arg1; + + if (!PyArg_ParseTuple(args, "ss*", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginWriteFile(OrthancPlugins::GetGlobalContext(), arg0, arg1.buf, arg1.len); + PyBuffer_Release(&arg1); + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginGetErrorDescription(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetErrorDescription()"); + + long int arg0 = 0; + + if (!PyArg_ParseTuple(args, "l", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetErrorDescription(OrthancPlugins::GetGlobalContext(), static_cast(arg0)); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject* sdk_OrthancPluginUncompressImage(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginUncompressImage()"); + + Py_buffer arg0; + long int arg2 = 0; + + if (!PyArg_ParseTuple(args, "s*l", &arg0, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + // This is the case of a constructor + OrthancPluginImage* obj = OrthancPluginUncompressImage(OrthancPlugins::GetGlobalContext(), arg0.buf, arg0.len, static_cast(arg2)); + PyBuffer_Release(&arg0); + if (obj == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); + PyObject *python = PyObject_CallObject((PyObject *) &sdk_OrthancPluginImage_Type, argList); + Py_DECREF(argList); + return python; + } +} + +static PyObject* sdk_OrthancPluginCompressPngImage(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginCompressPngImage()"); + + long int arg0 = 0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; + unsigned long arg3 = 0; + Py_buffer arg4; + + if (!PyArg_ParseTuple(args, "lkkks*", &arg0, &arg1, &arg2, &arg3, &arg4)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (5 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginCompressPngImage(OrthancPlugins::GetGlobalContext(), *buffer, static_cast(arg0), arg1, arg2, arg3, arg4.buf); + PyBuffer_Release(&arg4); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginCompressJpegImage(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginCompressJpegImage()"); + + long int arg0 = 0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; + unsigned long arg3 = 0; + Py_buffer arg4; + unsigned char arg5 = 0; + + if (!PyArg_ParseTuple(args, "lkkks*b", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (6 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginCompressJpegImage(OrthancPlugins::GetGlobalContext(), *buffer, static_cast(arg0), arg1, arg2, arg3, arg4.buf, arg5); + PyBuffer_Release(&arg4); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginHttpGet(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginHttpGet()"); + + const char* arg0 = NULL; + const char* arg1 = NULL; + const char* arg2 = NULL; + + if (!PyArg_ParseTuple(args, "sss", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginHttpGet(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1, arg2); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginHttpPost(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginHttpPost()"); + + const char* arg0 = NULL; + Py_buffer arg1; + const char* arg3 = NULL; + const char* arg4 = NULL; + + if (!PyArg_ParseTuple(args, "ss*ss", &arg0, &arg1, &arg3, &arg4)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (4 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginHttpPost(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len, arg3, arg4); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginHttpPut(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginHttpPut()"); + + const char* arg0 = NULL; + Py_buffer arg1; + const char* arg3 = NULL; + const char* arg4 = NULL; + + if (!PyArg_ParseTuple(args, "ss*ss", &arg0, &arg1, &arg3, &arg4)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (4 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginHttpPut(OrthancPlugins::GetGlobalContext(), *buffer, arg0, arg1.buf, arg1.len, arg3, arg4); + PyBuffer_Release(&arg1); + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginHttpDelete(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginHttpDelete()"); + + const char* arg0 = NULL; + const char* arg1 = NULL; + const char* arg2 = NULL; + + if (!PyArg_ParseTuple(args, "sss", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginHttpDelete(OrthancPlugins::GetGlobalContext(), arg0, arg1, arg2); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginGetFontsCount(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetFontsCount()"); + + + long value = OrthancPluginGetFontsCount(OrthancPlugins::GetGlobalContext()); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginGetFontName(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetFontName()"); + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetFontName(OrthancPlugins::GetGlobalContext(), arg0); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject* sdk_OrthancPluginGetFontSize(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetFontSize()"); + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + long value = OrthancPluginGetFontSize(OrthancPlugins::GetGlobalContext(), arg0); + + return PyLong_FromLong(value); +} + +static PyObject* sdk_OrthancPluginRegisterErrorCode(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRegisterErrorCode()"); + + long int arg0 = 0; + unsigned short arg1 = 0; + const char* arg2 = NULL; + + if (!PyArg_ParseTuple(args, "lHs", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginRegisterErrorCode(OrthancPlugins::GetGlobalContext(), arg0, arg1, arg2); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRegisterDictionaryTag(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRegisterDictionaryTag()"); + + unsigned short arg0 = 0; + unsigned short arg1 = 0; + long int arg2 = 0; + const char* arg3 = NULL; + unsigned long arg4 = 0; + unsigned long arg5 = 0; + + if (!PyArg_ParseTuple(args, "HHlskk", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (6 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginRegisterDictionaryTag(OrthancPlugins::GetGlobalContext(), arg0, arg1, static_cast(arg2), arg3, arg4, arg5); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginRegisterPrivateDictionaryTag(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginRegisterPrivateDictionaryTag()"); + + unsigned short arg0 = 0; + unsigned short arg1 = 0; + long int arg2 = 0; + const char* arg3 = NULL; + unsigned long arg4 = 0; + unsigned long arg5 = 0; + const char* arg6 = NULL; + + if (!PyArg_ParseTuple(args, "HHlskks", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (7 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginRegisterPrivateDictionaryTag(OrthancPlugins::GetGlobalContext(), arg0, arg1, static_cast(arg2), arg3, arg4, arg5, arg6); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject* sdk_OrthancPluginDicomBufferToJson(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginDicomBufferToJson()"); + + Py_buffer arg0; + long int arg2 = 0; + long int arg3 = 0; + unsigned long arg4 = 0; + + if (!PyArg_ParseTuple(args, "s*llk", &arg0, &arg2, &arg3, &arg4)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (4 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginDicomBufferToJson(OrthancPlugins::GetGlobalContext(), arg0.buf, arg0.len, static_cast(arg2), static_cast(arg3), arg4)); + PyBuffer_Release(&arg0); + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginDicomInstanceToJson(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginDicomInstanceToJson()"); + + const char* arg0 = NULL; + long int arg1 = 0; + long int arg2 = 0; + unsigned long arg3 = 0; + + if (!PyArg_ParseTuple(args, "sllk", &arg0, &arg1, &arg2, &arg3)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (4 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginDicomInstanceToJson(OrthancPlugins::GetGlobalContext(), arg0, static_cast(arg1), static_cast(arg2), arg3)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginCreateImage(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginCreateImage()"); + + long int arg0 = 0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; + + if (!PyArg_ParseTuple(args, "lkk", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + // This is the case of a constructor + OrthancPluginImage* obj = OrthancPluginCreateImage(OrthancPlugins::GetGlobalContext(), static_cast(arg0), arg1, arg2); + + if (obj == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); + PyObject *python = PyObject_CallObject((PyObject *) &sdk_OrthancPluginImage_Type, argList); + Py_DECREF(argList); + return python; + } +} + +static PyObject* sdk_OrthancPluginDecodeDicomImage(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginDecodeDicomImage()"); + + Py_buffer arg0; + unsigned long arg2 = 0; + + if (!PyArg_ParseTuple(args, "s*k", &arg0, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + // This is the case of a constructor + OrthancPluginImage* obj = OrthancPluginDecodeDicomImage(OrthancPlugins::GetGlobalContext(), arg0.buf, arg0.len, arg2); + PyBuffer_Release(&arg0); + if (obj == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); + PyObject *python = PyObject_CallObject((PyObject *) &sdk_OrthancPluginImage_Type, argList); + Py_DECREF(argList); + return python; + } +} + +static PyObject* sdk_OrthancPluginComputeMd5(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginComputeMd5()"); + + Py_buffer arg0; + + if (!PyArg_ParseTuple(args, "s*", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginComputeMd5(OrthancPlugins::GetGlobalContext(), arg0.buf, arg0.len)); + PyBuffer_Release(&arg0); + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginComputeSha1(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginComputeSha1()"); + + Py_buffer arg0; + + if (!PyArg_ParseTuple(args, "s*", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginComputeSha1(OrthancPlugins::GetGlobalContext(), arg0.buf, arg0.len)); + PyBuffer_Release(&arg0); + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGenerateUuid(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGenerateUuid()"); + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGenerateUuid(OrthancPlugins::GetGlobalContext())); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject* sdk_OrthancPluginGetPeers(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetPeers()"); + + + // This is the case of a constructor + OrthancPluginPeers* obj = OrthancPluginGetPeers(OrthancPlugins::GetGlobalContext()); + + if (obj == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); + PyObject *python = PyObject_CallObject((PyObject *) &sdk_OrthancPluginPeers_Type, argList); + Py_DECREF(argList); + return python; + } +} + +static PyObject* sdk_OrthancPluginAutodetectMimeType(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginAutodetectMimeType()"); + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginAutodetectMimeType(OrthancPlugins::GetGlobalContext(), arg0); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject* sdk_OrthancPluginSetMetricsValue(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginSetMetricsValue()"); + + const char* arg0 = NULL; + float arg1 = 0; + long int arg2 = 0; + + if (!PyArg_ParseTuple(args, "sfl", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPluginSetMetricsValue(OrthancPlugins::GetGlobalContext(), arg0, arg1, static_cast(arg2)); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* sdk_OrthancPluginGetTagName(PyObject* module, PyObject* args) +{ + OrthancPlugins::LogInfo("Calling Python global function: OrthancPluginGetTagName()"); + + unsigned short arg0 = 0; + unsigned short arg1 = 0; + const char* arg2 = NULL; + + if (!PyArg_ParseTuple(args, "HHs", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetTagName(OrthancPlugins::GetGlobalContext(), arg0, arg1, arg2)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + + +static PyMethodDef ORTHANC_SDK_FUNCTIONS[] = +{ + { "CheckVersionAdvanced", sdk_OrthancPluginCheckVersionAdvanced, METH_VARARGS, + "Generated from C function OrthancPluginCheckVersionAdvanced()" }, + { "CheckVersion", sdk_OrthancPluginCheckVersion, METH_VARARGS, + "Generated from C function OrthancPluginCheckVersion()" }, + { "LogError", sdk_OrthancPluginLogError, METH_VARARGS, + "Generated from C function OrthancPluginLogError()" }, + { "LogWarning", sdk_OrthancPluginLogWarning, METH_VARARGS, + "Generated from C function OrthancPluginLogWarning()" }, + { "LogInfo", sdk_OrthancPluginLogInfo, METH_VARARGS, + "Generated from C function OrthancPluginLogInfo()" }, + { "GetDicomForInstance", sdk_OrthancPluginGetDicomForInstance, METH_VARARGS, + "Generated from C function OrthancPluginGetDicomForInstance()" }, + { "RestApiGet", sdk_OrthancPluginRestApiGet, METH_VARARGS, + "Generated from C function OrthancPluginRestApiGet()" }, + { "RestApiGetAfterPlugins", sdk_OrthancPluginRestApiGetAfterPlugins, METH_VARARGS, + "Generated from C function OrthancPluginRestApiGetAfterPlugins()" }, + { "RestApiPost", sdk_OrthancPluginRestApiPost, METH_VARARGS, + "Generated from C function OrthancPluginRestApiPost()" }, + { "RestApiPostAfterPlugins", sdk_OrthancPluginRestApiPostAfterPlugins, METH_VARARGS, + "Generated from C function OrthancPluginRestApiPostAfterPlugins()" }, + { "RestApiDelete", sdk_OrthancPluginRestApiDelete, METH_VARARGS, + "Generated from C function OrthancPluginRestApiDelete()" }, + { "RestApiDeleteAfterPlugins", sdk_OrthancPluginRestApiDeleteAfterPlugins, METH_VARARGS, + "Generated from C function OrthancPluginRestApiDeleteAfterPlugins()" }, + { "RestApiPut", sdk_OrthancPluginRestApiPut, METH_VARARGS, + "Generated from C function OrthancPluginRestApiPut()" }, + { "RestApiPutAfterPlugins", sdk_OrthancPluginRestApiPutAfterPlugins, METH_VARARGS, + "Generated from C function OrthancPluginRestApiPutAfterPlugins()" }, + { "LookupPatient", sdk_OrthancPluginLookupPatient, METH_VARARGS, + "Generated from C function OrthancPluginLookupPatient()" }, + { "LookupStudy", sdk_OrthancPluginLookupStudy, METH_VARARGS, + "Generated from C function OrthancPluginLookupStudy()" }, + { "LookupStudyWithAccessionNumber", sdk_OrthancPluginLookupStudyWithAccessionNumber, METH_VARARGS, + "Generated from C function OrthancPluginLookupStudyWithAccessionNumber()" }, + { "LookupSeries", sdk_OrthancPluginLookupSeries, METH_VARARGS, + "Generated from C function OrthancPluginLookupSeries()" }, + { "LookupInstance", sdk_OrthancPluginLookupInstance, METH_VARARGS, + "Generated from C function OrthancPluginLookupInstance()" }, + { "GetOrthancPath", sdk_OrthancPluginGetOrthancPath, METH_VARARGS, + "Generated from C function OrthancPluginGetOrthancPath()" }, + { "GetOrthancDirectory", sdk_OrthancPluginGetOrthancDirectory, METH_VARARGS, + "Generated from C function OrthancPluginGetOrthancDirectory()" }, + { "GetConfigurationPath", sdk_OrthancPluginGetConfigurationPath, METH_VARARGS, + "Generated from C function OrthancPluginGetConfigurationPath()" }, + { "SetRootUri", sdk_OrthancPluginSetRootUri, METH_VARARGS, + "Generated from C function OrthancPluginSetRootUri()" }, + { "SetDescription", sdk_OrthancPluginSetDescription, METH_VARARGS, + "Generated from C function OrthancPluginSetDescription()" }, + { "ExtendOrthancExplorer", sdk_OrthancPluginExtendOrthancExplorer, METH_VARARGS, + "Generated from C function OrthancPluginExtendOrthancExplorer()" }, + { "GetGlobalProperty", sdk_OrthancPluginGetGlobalProperty, METH_VARARGS, + "Generated from C function OrthancPluginGetGlobalProperty()" }, + { "SetGlobalProperty", sdk_OrthancPluginSetGlobalProperty, METH_VARARGS, + "Generated from C function OrthancPluginSetGlobalProperty()" }, + { "GetCommandLineArgumentsCount", sdk_OrthancPluginGetCommandLineArgumentsCount, METH_VARARGS, + "Generated from C function OrthancPluginGetCommandLineArgumentsCount()" }, + { "GetCommandLineArgument", sdk_OrthancPluginGetCommandLineArgument, METH_VARARGS, + "Generated from C function OrthancPluginGetCommandLineArgument()" }, + { "GetExpectedDatabaseVersion", sdk_OrthancPluginGetExpectedDatabaseVersion, METH_VARARGS, + "Generated from C function OrthancPluginGetExpectedDatabaseVersion()" }, + { "GetConfiguration", sdk_OrthancPluginGetConfiguration, METH_VARARGS, + "Generated from C function OrthancPluginGetConfiguration()" }, + { "BufferCompression", sdk_OrthancPluginBufferCompression, METH_VARARGS, + "Generated from C function OrthancPluginBufferCompression()" }, + { "ReadFile", sdk_OrthancPluginReadFile, METH_VARARGS, + "Generated from C function OrthancPluginReadFile()" }, + { "WriteFile", sdk_OrthancPluginWriteFile, METH_VARARGS, + "Generated from C function OrthancPluginWriteFile()" }, + { "GetErrorDescription", sdk_OrthancPluginGetErrorDescription, METH_VARARGS, + "Generated from C function OrthancPluginGetErrorDescription()" }, + { "UncompressImage", sdk_OrthancPluginUncompressImage, METH_VARARGS, + "Generated from C function OrthancPluginUncompressImage()" }, + { "CompressPngImage", sdk_OrthancPluginCompressPngImage, METH_VARARGS, + "Generated from C function OrthancPluginCompressPngImage()" }, + { "CompressJpegImage", sdk_OrthancPluginCompressJpegImage, METH_VARARGS, + "Generated from C function OrthancPluginCompressJpegImage()" }, + { "HttpGet", sdk_OrthancPluginHttpGet, METH_VARARGS, + "Generated from C function OrthancPluginHttpGet()" }, + { "HttpPost", sdk_OrthancPluginHttpPost, METH_VARARGS, + "Generated from C function OrthancPluginHttpPost()" }, + { "HttpPut", sdk_OrthancPluginHttpPut, METH_VARARGS, + "Generated from C function OrthancPluginHttpPut()" }, + { "HttpDelete", sdk_OrthancPluginHttpDelete, METH_VARARGS, + "Generated from C function OrthancPluginHttpDelete()" }, + { "GetFontsCount", sdk_OrthancPluginGetFontsCount, METH_VARARGS, + "Generated from C function OrthancPluginGetFontsCount()" }, + { "GetFontName", sdk_OrthancPluginGetFontName, METH_VARARGS, + "Generated from C function OrthancPluginGetFontName()" }, + { "GetFontSize", sdk_OrthancPluginGetFontSize, METH_VARARGS, + "Generated from C function OrthancPluginGetFontSize()" }, + { "RegisterErrorCode", sdk_OrthancPluginRegisterErrorCode, METH_VARARGS, + "Generated from C function OrthancPluginRegisterErrorCode()" }, + { "RegisterDictionaryTag", sdk_OrthancPluginRegisterDictionaryTag, METH_VARARGS, + "Generated from C function OrthancPluginRegisterDictionaryTag()" }, + { "RegisterPrivateDictionaryTag", sdk_OrthancPluginRegisterPrivateDictionaryTag, METH_VARARGS, + "Generated from C function OrthancPluginRegisterPrivateDictionaryTag()" }, + { "DicomBufferToJson", sdk_OrthancPluginDicomBufferToJson, METH_VARARGS, + "Generated from C function OrthancPluginDicomBufferToJson()" }, + { "DicomInstanceToJson", sdk_OrthancPluginDicomInstanceToJson, METH_VARARGS, + "Generated from C function OrthancPluginDicomInstanceToJson()" }, + { "CreateImage", sdk_OrthancPluginCreateImage, METH_VARARGS, + "Generated from C function OrthancPluginCreateImage()" }, + { "DecodeDicomImage", sdk_OrthancPluginDecodeDicomImage, METH_VARARGS, + "Generated from C function OrthancPluginDecodeDicomImage()" }, + { "ComputeMd5", sdk_OrthancPluginComputeMd5, METH_VARARGS, + "Generated from C function OrthancPluginComputeMd5()" }, + { "ComputeSha1", sdk_OrthancPluginComputeSha1, METH_VARARGS, + "Generated from C function OrthancPluginComputeSha1()" }, + { "GenerateUuid", sdk_OrthancPluginGenerateUuid, METH_VARARGS, + "Generated from C function OrthancPluginGenerateUuid()" }, + { "GetPeers", sdk_OrthancPluginGetPeers, METH_VARARGS, + "Generated from C function OrthancPluginGetPeers()" }, + { "AutodetectMimeType", sdk_OrthancPluginAutodetectMimeType, METH_VARARGS, + "Generated from C function OrthancPluginAutodetectMimeType()" }, + { "SetMetricsValue", sdk_OrthancPluginSetMetricsValue, METH_VARARGS, + "Generated from C function OrthancPluginSetMetricsValue()" }, + { "GetTagName", sdk_OrthancPluginGetTagName, METH_VARARGS, + "Generated from C function OrthancPluginGetTagName()" }, + { NULL, NULL } +}; + + +PyMethodDef* GetOrthancSdkFunctions() +{ + return ORTHANC_SDK_FUNCTIONS; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginChangeType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginChangeType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,90 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginChangeType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginChangeType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ChangeType", /* tp_name */ + sizeof(sdk_OrthancPluginChangeType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginChangeTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginChangeType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginChangeType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginChangeType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginChangeType"; + + sdk_OrthancPluginChangeType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginChangeType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginChangeType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "COMPLETED_SERIES", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "DELETED", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "NEW_CHILD_INSTANCE", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "NEW_INSTANCE", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "NEW_PATIENT", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "NEW_SERIES", PyLong_FromLong(5)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "NEW_STUDY", PyLong_FromLong(6)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "STABLE_PATIENT", PyLong_FromLong(7)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "STABLE_SERIES", PyLong_FromLong(8)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "STABLE_STUDY", PyLong_FromLong(9)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "ORTHANC_STARTED", PyLong_FromLong(10)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "ORTHANC_STOPPED", PyLong_FromLong(11)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "UPDATED_ATTACHMENT", PyLong_FromLong(12)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "UPDATED_METADATA", PyLong_FromLong(13)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "UPDATED_PEERS", PyLong_FromLong(14)); + PyDict_SetItemString(sdk_OrthancPluginChangeType_Type.tp_dict, "UPDATED_MODALITIES", PyLong_FromLong(15)); + + Py_INCREF(&sdk_OrthancPluginChangeType_Type); + if (PyModule_AddObject(module, "ChangeType", (PyObject *)&sdk_OrthancPluginChangeType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginChangeType"); + Py_DECREF(&sdk_OrthancPluginChangeType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginCompressionType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginCompressionType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,78 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginCompressionType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginCompressionType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.CompressionType", /* tp_name */ + sizeof(sdk_OrthancPluginCompressionType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginCompressionTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginCompressionType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginCompressionType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginCompressionType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginCompressionType"; + + sdk_OrthancPluginCompressionType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginCompressionType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginCompressionType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginCompressionType_Type.tp_dict, "ZLIB", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginCompressionType_Type.tp_dict, "ZLIB_WITH_SIZE", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginCompressionType_Type.tp_dict, "GZIP", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginCompressionType_Type.tp_dict, "GZIP_WITH_SIZE", PyLong_FromLong(3)); + + Py_INCREF(&sdk_OrthancPluginCompressionType_Type); + if (PyModule_AddObject(module, "CompressionType", (PyObject *)&sdk_OrthancPluginCompressionType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginCompressionType"); + Py_DECREF(&sdk_OrthancPluginCompressionType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginConstraintType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginConstraintType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,79 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginConstraintType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginConstraintType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ConstraintType", /* tp_name */ + sizeof(sdk_OrthancPluginConstraintType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginConstraintTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginConstraintType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginConstraintType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginConstraintType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginConstraintType"; + + sdk_OrthancPluginConstraintType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginConstraintType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginConstraintType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginConstraintType_Type.tp_dict, "EQUAL", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginConstraintType_Type.tp_dict, "SMALLER_OR_EQUAL", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginConstraintType_Type.tp_dict, "GREATER_OR_EQUAL", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginConstraintType_Type.tp_dict, "WILDCARD", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginConstraintType_Type.tp_dict, "LIST", PyLong_FromLong(5)); + + Py_INCREF(&sdk_OrthancPluginConstraintType_Type); + if (PyModule_AddObject(module, "ConstraintType", (PyObject *)&sdk_OrthancPluginConstraintType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginConstraintType"); + Py_DECREF(&sdk_OrthancPluginConstraintType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginContentType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginContentType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginContentType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginContentType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ContentType", /* tp_name */ + sizeof(sdk_OrthancPluginContentType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginContentTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginContentType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginContentType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginContentType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginContentType"; + + sdk_OrthancPluginContentType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginContentType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginContentType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginContentType_Type.tp_dict, "UNKNOWN", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginContentType_Type.tp_dict, "DICOM", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginContentType_Type.tp_dict, "DICOM_AS_JSON", PyLong_FromLong(2)); + + Py_INCREF(&sdk_OrthancPluginContentType_Type); + if (PyModule_AddObject(module, "ContentType", (PyObject *)&sdk_OrthancPluginContentType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginContentType"); + Py_DECREF(&sdk_OrthancPluginContentType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginCreateDicomFlags.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginCreateDicomFlags.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginCreateDicomFlags_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginCreateDicomFlags_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.CreateDicomFlags", /* tp_name */ + sizeof(sdk_OrthancPluginCreateDicomFlags_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginCreateDicomFlagsEnumeration(PyObject* module) +{ + sdk_OrthancPluginCreateDicomFlags_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginCreateDicomFlags_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginCreateDicomFlags_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginCreateDicomFlags"; + + sdk_OrthancPluginCreateDicomFlags_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginCreateDicomFlags_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginCreateDicomFlags"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginCreateDicomFlags_Type.tp_dict, "NONE", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginCreateDicomFlags_Type.tp_dict, "DECODE_DATA_URI_SCHEME", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginCreateDicomFlags_Type.tp_dict, "GENERATE_IDENTIFIERS", PyLong_FromLong(2)); + + Py_INCREF(&sdk_OrthancPluginCreateDicomFlags_Type); + if (PyModule_AddObject(module, "CreateDicomFlags", (PyObject *)&sdk_OrthancPluginCreateDicomFlags_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginCreateDicomFlags"); + Py_DECREF(&sdk_OrthancPluginCreateDicomFlags_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginDicomInstance.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginDicomInstance.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,329 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginDicomInstance* object_; + bool borrowed_; +} sdk_OrthancPluginDicomInstance_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceRemoteAet( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSize( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceJson( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSimplifiedJson( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginHasInstanceMetadata( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceMetadata( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceOrigin( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginDicomInstance_Methods[] = { + { "GetInstanceRemoteAet", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceRemoteAet, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceRemoteAet()" }, + { "GetInstanceSize", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSize, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceSize()" }, + { "GetInstanceJson", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceJson, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceJson()" }, + { "GetInstanceSimplifiedJson", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSimplifiedJson, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceSimplifiedJson()" }, + { "HasInstanceMetadata", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginHasInstanceMetadata, METH_VARARGS, + "Generated from C function OrthancPluginHasInstanceMetadata()" }, + { "GetInstanceMetadata", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceMetadata, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceMetadata()" }, + { "GetInstanceOrigin", + (PyCFunction) sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceOrigin, METH_VARARGS, + "Generated from C function OrthancPluginGetInstanceOrigin()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginDicomInstance_Constructor( + sdk_OrthancPluginDicomInstance_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginDicomInstance"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginDicomInstance_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.DicomInstance", /* tp_name */ + sizeof(sdk_OrthancPluginDicomInstance_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceRemoteAet( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceRemoteAet() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + const char* s = OrthancPluginGetInstanceRemoteAet(OrthancPlugins::GetGlobalContext(), self->object_); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSize( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceSize() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetInstanceSize(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceJson( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceJson() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetInstanceJson(OrthancPlugins::GetGlobalContext(), self->object_)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceSimplifiedJson( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceSimplifiedJson() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetInstanceSimplifiedJson(OrthancPlugins::GetGlobalContext(), self->object_)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginHasInstanceMetadata( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginHasInstanceMetadata() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + long value = OrthancPluginHasInstanceMetadata(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceMetadata( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceMetadata() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetInstanceMetadata(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject *sdk_OrthancPluginDicomInstance_OrthancPluginGetInstanceOrigin( + sdk_OrthancPluginDicomInstance_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetInstanceOrigin() on object of class OrthancPluginDicomInstance"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPluginInstanceOrigin value = OrthancPluginGetInstanceOrigin(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + + + +static void RegisterOrthancPluginDicomInstanceClass(PyObject* module) +{ + sdk_OrthancPluginDicomInstance_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginDicomInstance_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginDicomInstance_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginDicomInstance"; + sdk_OrthancPluginDicomInstance_Type.tp_methods = sdk_OrthancPluginDicomInstance_Methods; + sdk_OrthancPluginDicomInstance_Type.tp_init = (initproc) sdk_OrthancPluginDicomInstance_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginDicomInstance_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginDicomInstance"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginDicomInstance_Type); + if (PyModule_AddObject(module, "DicomInstance", (PyObject *)&sdk_OrthancPluginDicomInstance_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginDicomInstance"); + Py_DECREF(&sdk_OrthancPluginDicomInstance_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginDicomInstanceType() +{ + return (PyObject*) &sdk_OrthancPluginDicomInstance_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginDicomToJsonFlags.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginDicomToJsonFlags.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,81 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginDicomToJsonFlags_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginDicomToJsonFlags_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.DicomToJsonFlags", /* tp_name */ + sizeof(sdk_OrthancPluginDicomToJsonFlags_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginDicomToJsonFlagsEnumeration(PyObject* module) +{ + sdk_OrthancPluginDicomToJsonFlags_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginDicomToJsonFlags_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginDicomToJsonFlags_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginDicomToJsonFlags"; + + sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginDicomToJsonFlags_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomToJsonFlags"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "NONE", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "INCLUDE_BINARY", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "INCLUDE_PRIVATE_TAGS", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "INCLUDE_UNKNOWN_TAGS", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "INCLUDE_PIXEL_DATA", PyLong_FromLong(8)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "CONVERT_BINARY_TO_ASCII", PyLong_FromLong(16)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFlags_Type.tp_dict, "CONVERT_BINARY_TO_NULL", PyLong_FromLong(32)); + + Py_INCREF(&sdk_OrthancPluginDicomToJsonFlags_Type); + if (PyModule_AddObject(module, "DicomToJsonFlags", (PyObject *)&sdk_OrthancPluginDicomToJsonFlags_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomToJsonFlags"); + Py_DECREF(&sdk_OrthancPluginDicomToJsonFlags_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginDicomToJsonFormat.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginDicomToJsonFormat.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginDicomToJsonFormat_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginDicomToJsonFormat_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.DicomToJsonFormat", /* tp_name */ + sizeof(sdk_OrthancPluginDicomToJsonFormat_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginDicomToJsonFormatEnumeration(PyObject* module) +{ + sdk_OrthancPluginDicomToJsonFormat_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginDicomToJsonFormat_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginDicomToJsonFormat_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginDicomToJsonFormat"; + + sdk_OrthancPluginDicomToJsonFormat_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginDicomToJsonFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomToJsonFormat"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFormat_Type.tp_dict, "FULL", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFormat_Type.tp_dict, "SHORT", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginDicomToJsonFormat_Type.tp_dict, "HUMAN", PyLong_FromLong(3)); + + Py_INCREF(&sdk_OrthancPluginDicomToJsonFormat_Type); + if (PyModule_AddObject(module, "DicomToJsonFormat", (PyObject *)&sdk_OrthancPluginDicomToJsonFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomToJsonFormat"); + Py_DECREF(&sdk_OrthancPluginDicomToJsonFormat_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginDicomWebBinaryMode.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginDicomWebBinaryMode.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginDicomWebBinaryMode_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginDicomWebBinaryMode_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.DicomWebBinaryMode", /* tp_name */ + sizeof(sdk_OrthancPluginDicomWebBinaryMode_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginDicomWebBinaryModeEnumeration(PyObject* module) +{ + sdk_OrthancPluginDicomWebBinaryMode_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginDicomWebBinaryMode_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginDicomWebBinaryMode_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginDicomWebBinaryMode"; + + sdk_OrthancPluginDicomWebBinaryMode_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginDicomWebBinaryMode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomWebBinaryMode"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginDicomWebBinaryMode_Type.tp_dict, "IGNORE", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginDicomWebBinaryMode_Type.tp_dict, "INLINE_BINARY", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginDicomWebBinaryMode_Type.tp_dict, "BULK_DATA_URI", PyLong_FromLong(2)); + + Py_INCREF(&sdk_OrthancPluginDicomWebBinaryMode_Type); + if (PyModule_AddObject(module, "DicomWebBinaryMode", (PyObject *)&sdk_OrthancPluginDicomWebBinaryMode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginDicomWebBinaryMode"); + Py_DECREF(&sdk_OrthancPluginDicomWebBinaryMode_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginDicomWebNode.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginDicomWebNode.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,109 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginDicomWebNode* object_; + bool borrowed_; +} sdk_OrthancPluginDicomWebNode_Object; + + + +// Forward declaration of the methods + + +static PyMethodDef sdk_OrthancPluginDicomWebNode_Methods[] = { + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginDicomWebNode_Constructor( + sdk_OrthancPluginDicomWebNode_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginDicomWebNode"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginDicomWebNode_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.DicomWebNode", /* tp_name */ + sizeof(sdk_OrthancPluginDicomWebNode_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods + + +static void RegisterOrthancPluginDicomWebNodeClass(PyObject* module) +{ + sdk_OrthancPluginDicomWebNode_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginDicomWebNode_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginDicomWebNode_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginDicomWebNode"; + sdk_OrthancPluginDicomWebNode_Type.tp_methods = sdk_OrthancPluginDicomWebNode_Methods; + sdk_OrthancPluginDicomWebNode_Type.tp_init = (initproc) sdk_OrthancPluginDicomWebNode_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginDicomWebNode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginDicomWebNode"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginDicomWebNode_Type); + if (PyModule_AddObject(module, "DicomWebNode", (PyObject *)&sdk_OrthancPluginDicomWebNode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginDicomWebNode"); + Py_DECREF(&sdk_OrthancPluginDicomWebNode_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginDicomWebNodeType() +{ + return (PyObject*) &sdk_OrthancPluginDicomWebNode_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginErrorCode.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginErrorCode.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,174 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginErrorCode_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginErrorCode_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ErrorCode", /* tp_name */ + sizeof(sdk_OrthancPluginErrorCode_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginErrorCodeEnumeration(PyObject* module) +{ + sdk_OrthancPluginErrorCode_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginErrorCode_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginErrorCode_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginErrorCode"; + + sdk_OrthancPluginErrorCode_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginErrorCode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginErrorCode"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INTERNAL_ERROR", PyLong_FromLong(-1)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SUCCESS", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "PLUGIN", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NOT_IMPLEMENTED", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "PARAMETER_OUT_OF_RANGE", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NOT_ENOUGH_MEMORY", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_PARAMETER_TYPE", PyLong_FromLong(5)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_SEQUENCE_OF_CALLS", PyLong_FromLong(6)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INEXISTENT_ITEM", PyLong_FromLong(7)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_REQUEST", PyLong_FromLong(8)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NETWORK_PROTOCOL", PyLong_FromLong(9)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SYSTEM_COMMAND", PyLong_FromLong(10)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DATABASE", PyLong_FromLong(11)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "URI_SYNTAX", PyLong_FromLong(12)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INEXISTENT_FILE", PyLong_FromLong(13)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANNOT_WRITE_FILE", PyLong_FromLong(14)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_FILE_FORMAT", PyLong_FromLong(15)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "TIMEOUT", PyLong_FromLong(16)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNKNOWN_RESOURCE", PyLong_FromLong(17)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INCOMPATIBLE_DATABASE_VERSION", PyLong_FromLong(18)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "FULL_STORAGE", PyLong_FromLong(19)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CORRUPTED_FILE", PyLong_FromLong(20)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INEXISTENT_TAG", PyLong_FromLong(21)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "READ_ONLY", PyLong_FromLong(22)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INCOMPATIBLE_IMAGE_FORMAT", PyLong_FromLong(23)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "INCOMPATIBLE_IMAGE_SIZE", PyLong_FromLong(24)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SHARED_LIBRARY", PyLong_FromLong(25)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNKNOWN_PLUGIN_SERVICE", PyLong_FromLong(26)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNKNOWN_DICOM_TAG", PyLong_FromLong(27)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_JSON", PyLong_FromLong(28)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNAUTHORIZED", PyLong_FromLong(29)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_FONT", PyLong_FromLong(30)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DATABASE_PLUGIN", PyLong_FromLong(31)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "STORAGE_AREA_PLUGIN", PyLong_FromLong(32)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "EMPTY_REQUEST", PyLong_FromLong(33)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NOT_ACCEPTABLE", PyLong_FromLong(34)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NULL_POINTER", PyLong_FromLong(35)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DATABASE_UNAVAILABLE", PyLong_FromLong(36)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANCELED_JOB", PyLong_FromLong(37)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_GEOMETRY", PyLong_FromLong(38)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_NOT_OPENED", PyLong_FromLong(1000)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_ALREADY_OPENED", PyLong_FromLong(1001)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_CANNOT_OPEN", PyLong_FromLong(1002)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_STATEMENT_ALREADY_USED", PyLong_FromLong(1003)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_EXECUTE", PyLong_FromLong(1004)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_ROLLBACK_WITHOUT_TRANSACTION", PyLong_FromLong(1005)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_COMMIT_WITHOUT_TRANSACTION", PyLong_FromLong(1006)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_REGISTER_FUNCTION", PyLong_FromLong(1007)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_FLUSH", PyLong_FromLong(1008)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_CANNOT_RUN", PyLong_FromLong(1009)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_CANNOT_STEP", PyLong_FromLong(1010)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_BIND_OUT_OF_RANGE", PyLong_FromLong(1011)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_PREPARE_STATEMENT", PyLong_FromLong(1012)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_TRANSACTION_ALREADY_STARTED", PyLong_FromLong(1013)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_TRANSACTION_COMMIT", PyLong_FromLong(1014)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SQLITE_TRANSACTION_BEGIN", PyLong_FromLong(1015)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DIRECTORY_OVER_FILE", PyLong_FromLong(2000)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "FILE_STORAGE_CANNOT_WRITE", PyLong_FromLong(2001)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DIRECTORY_EXPECTED", PyLong_FromLong(2002)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "HTTP_PORT_IN_USE", PyLong_FromLong(2003)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DICOM_PORT_IN_USE", PyLong_FromLong(2004)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_HTTP_STATUS_IN_REST", PyLong_FromLong(2005)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "REGULAR_FILE_EXPECTED", PyLong_FromLong(2006)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "PATH_TO_EXECUTABLE", PyLong_FromLong(2007)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "MAKE_DIRECTORY", PyLong_FromLong(2008)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_APPLICATION_ENTITY_TITLE", PyLong_FromLong(2009)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_CFIND_HANDLER", PyLong_FromLong(2010)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_CMOVE_HANDLER", PyLong_FromLong(2011)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_CSTORE_HANDLER", PyLong_FromLong(2012)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_APPLICATION_ENTITY_FILTER", PyLong_FromLong(2013)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_SOP_CLASS_OR_INSTANCE", PyLong_FromLong(2014)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_PRESENTATION_CONTEXT", PyLong_FromLong(2015)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DICOM_FIND_UNAVAILABLE", PyLong_FromLong(2016)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DICOM_MOVE_UNAVAILABLE", PyLong_FromLong(2017)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANNOT_STORE_INSTANCE", PyLong_FromLong(2018)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_NOT_STRING", PyLong_FromLong(2019)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_OVERRIDE_TAG", PyLong_FromLong(2020)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_USE_CONTENT", PyLong_FromLong(2021)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_NO_PAYLOAD", PyLong_FromLong(2022)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_USE_DATA_URI_SCHEME", PyLong_FromLong(2023)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_BAD_PARENT", PyLong_FromLong(2024)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_PARENT_IS_INSTANCE", PyLong_FromLong(2025)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CREATE_DICOM_PARENT_ENCODING", PyLong_FromLong(2026)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNKNOWN_MODALITY", PyLong_FromLong(2027)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "BAD_JOB_ORDERING", PyLong_FromLong(2028)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "JSON_TO_LUA_TABLE", PyLong_FromLong(2029)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANNOT_CREATE_LUA", PyLong_FromLong(2030)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANNOT_EXECUTE_LUA", PyLong_FromLong(2031)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "LUA_ALREADY_EXECUTED", PyLong_FromLong(2032)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "LUA_BAD_OUTPUT", PyLong_FromLong(2033)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NOT_LUA_PREDICATE", PyLong_FromLong(2034)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "LUA_RETURNS_NO_STRING", PyLong_FromLong(2035)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "STORAGE_AREA_ALREADY_REGISTERED", PyLong_FromLong(2036)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DATABASE_BACKEND_ALREADY_REGISTERED", PyLong_FromLong(2037)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "DATABASE_NOT_INITIALIZED", PyLong_FromLong(2038)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "SSL_DISABLED", PyLong_FromLong(2039)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "CANNOT_ORDER_SLICES", PyLong_FromLong(2040)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "NO_WORKLIST_HANDLER", PyLong_FromLong(2041)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "ALREADY_EXISTING_TAG", PyLong_FromLong(2042)); + PyDict_SetItemString(sdk_OrthancPluginErrorCode_Type.tp_dict, "UNSUPPORTED_MEDIA_TYPE", PyLong_FromLong(3000)); + + Py_INCREF(&sdk_OrthancPluginErrorCode_Type); + if (PyModule_AddObject(module, "ErrorCode", (PyObject *)&sdk_OrthancPluginErrorCode_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginErrorCode"); + Py_DECREF(&sdk_OrthancPluginErrorCode_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginFindAnswers.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginFindAnswers.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,188 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginFindAnswers* object_; + bool borrowed_; +} sdk_OrthancPluginFindAnswers_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginFindAnswers_OrthancPluginFindAddAnswer( + sdk_OrthancPluginFindAnswers_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginFindAnswers_OrthancPluginFindMarkIncomplete( + sdk_OrthancPluginFindAnswers_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginFindAnswers_Methods[] = { + { "FindAddAnswer", + (PyCFunction) sdk_OrthancPluginFindAnswers_OrthancPluginFindAddAnswer, METH_VARARGS, + "Generated from C function OrthancPluginFindAddAnswer()" }, + { "FindMarkIncomplete", + (PyCFunction) sdk_OrthancPluginFindAnswers_OrthancPluginFindMarkIncomplete, METH_VARARGS, + "Generated from C function OrthancPluginFindMarkIncomplete()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginFindAnswers_Constructor( + sdk_OrthancPluginFindAnswers_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginFindAnswers"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginFindAnswers_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.FindAnswers", /* tp_name */ + sizeof(sdk_OrthancPluginFindAnswers_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginFindAnswers_OrthancPluginFindAddAnswer( + sdk_OrthancPluginFindAnswers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginFindAddAnswer() on object of class OrthancPluginFindAnswers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + Py_buffer arg0; + + if (!PyArg_ParseTuple(args, "s*", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginFindAddAnswer(OrthancPlugins::GetGlobalContext(), self->object_, arg0.buf, arg0.len); + PyBuffer_Release(&arg0); + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginFindAnswers_OrthancPluginFindMarkIncomplete( + sdk_OrthancPluginFindAnswers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginFindMarkIncomplete() on object of class OrthancPluginFindAnswers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPluginErrorCode code = OrthancPluginFindMarkIncomplete(OrthancPlugins::GetGlobalContext(), self->object_); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + + + +static void RegisterOrthancPluginFindAnswersClass(PyObject* module) +{ + sdk_OrthancPluginFindAnswers_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginFindAnswers_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginFindAnswers_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginFindAnswers"; + sdk_OrthancPluginFindAnswers_Type.tp_methods = sdk_OrthancPluginFindAnswers_Methods; + sdk_OrthancPluginFindAnswers_Type.tp_init = (initproc) sdk_OrthancPluginFindAnswers_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginFindAnswers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginFindAnswers"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginFindAnswers_Type); + if (PyModule_AddObject(module, "FindAnswers", (PyObject *)&sdk_OrthancPluginFindAnswers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginFindAnswers"); + Py_DECREF(&sdk_OrthancPluginFindAnswers_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginFindAnswersType() +{ + return (PyObject*) &sdk_OrthancPluginFindAnswers_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginFindQuery.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginFindQuery.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,217 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginFindQuery* object_; + bool borrowed_; +} sdk_OrthancPluginFindQuery_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQuerySize( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryTagName( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryValue( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginFindQuery_Methods[] = { + { "GetFindQuerySize", + (PyCFunction) sdk_OrthancPluginFindQuery_OrthancPluginGetFindQuerySize, METH_VARARGS, + "Generated from C function OrthancPluginGetFindQuerySize()" }, + { "GetFindQueryTagName", + (PyCFunction) sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryTagName, METH_VARARGS, + "Generated from C function OrthancPluginGetFindQueryTagName()" }, + { "GetFindQueryValue", + (PyCFunction) sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryValue, METH_VARARGS, + "Generated from C function OrthancPluginGetFindQueryValue()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginFindQuery_Constructor( + sdk_OrthancPluginFindQuery_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginFindQuery"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginFindQuery_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.FindQuery", /* tp_name */ + sizeof(sdk_OrthancPluginFindQuery_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQuerySize( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetFindQuerySize() on object of class OrthancPluginFindQuery"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetFindQuerySize(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryTagName( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetFindQueryTagName() on object of class OrthancPluginFindQuery"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetFindQueryTagName(OrthancPlugins::GetGlobalContext(), self->object_, arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + +static PyObject *sdk_OrthancPluginFindQuery_OrthancPluginGetFindQueryValue( + sdk_OrthancPluginFindQuery_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetFindQueryValue() on object of class OrthancPluginFindQuery"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginGetFindQueryValue(OrthancPlugins::GetGlobalContext(), self->object_, arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + + + +static void RegisterOrthancPluginFindQueryClass(PyObject* module) +{ + sdk_OrthancPluginFindQuery_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginFindQuery_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginFindQuery_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginFindQuery"; + sdk_OrthancPluginFindQuery_Type.tp_methods = sdk_OrthancPluginFindQuery_Methods; + sdk_OrthancPluginFindQuery_Type.tp_init = (initproc) sdk_OrthancPluginFindQuery_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginFindQuery_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginFindQuery"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginFindQuery_Type); + if (PyModule_AddObject(module, "FindQuery", (PyObject *)&sdk_OrthancPluginFindQuery_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginFindQuery"); + Py_DECREF(&sdk_OrthancPluginFindQuery_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginFindQueryType() +{ + return (PyObject*) &sdk_OrthancPluginFindQuery_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginHttpMethod.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginHttpMethod.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,78 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginHttpMethod_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginHttpMethod_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.HttpMethod", /* tp_name */ + sizeof(sdk_OrthancPluginHttpMethod_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginHttpMethodEnumeration(PyObject* module) +{ + sdk_OrthancPluginHttpMethod_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginHttpMethod_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginHttpMethod_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginHttpMethod"; + + sdk_OrthancPluginHttpMethod_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginHttpMethod_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginHttpMethod"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginHttpMethod_Type.tp_dict, "GET", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginHttpMethod_Type.tp_dict, "POST", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginHttpMethod_Type.tp_dict, "PUT", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginHttpMethod_Type.tp_dict, "DELETE", PyLong_FromLong(4)); + + Py_INCREF(&sdk_OrthancPluginHttpMethod_Type); + if (PyModule_AddObject(module, "HttpMethod", (PyObject *)&sdk_OrthancPluginHttpMethod_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginHttpMethod"); + Py_DECREF(&sdk_OrthancPluginHttpMethod_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginIdentifierConstraint.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginIdentifierConstraint.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,78 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginIdentifierConstraint_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginIdentifierConstraint_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.IdentifierConstraint", /* tp_name */ + sizeof(sdk_OrthancPluginIdentifierConstraint_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginIdentifierConstraintEnumeration(PyObject* module) +{ + sdk_OrthancPluginIdentifierConstraint_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginIdentifierConstraint_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginIdentifierConstraint_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginIdentifierConstraint"; + + sdk_OrthancPluginIdentifierConstraint_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginIdentifierConstraint_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginIdentifierConstraint"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginIdentifierConstraint_Type.tp_dict, "EQUAL", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginIdentifierConstraint_Type.tp_dict, "SMALLER_OR_EQUAL", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginIdentifierConstraint_Type.tp_dict, "GREATER_OR_EQUAL", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginIdentifierConstraint_Type.tp_dict, "WILDCARD", PyLong_FromLong(4)); + + Py_INCREF(&sdk_OrthancPluginIdentifierConstraint_Type); + if (PyModule_AddObject(module, "IdentifierConstraint", (PyObject *)&sdk_OrthancPluginIdentifierConstraint_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginIdentifierConstraint"); + Py_DECREF(&sdk_OrthancPluginIdentifierConstraint_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginImage.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginImage.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,322 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginImage* object_; + bool borrowed_; +} sdk_OrthancPluginImage_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImagePixelFormat( + sdk_OrthancPluginImage_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImageWidth( + sdk_OrthancPluginImage_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImageHeight( + sdk_OrthancPluginImage_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImagePitch( + sdk_OrthancPluginImage_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginImage_OrthancPluginConvertPixelFormat( + sdk_OrthancPluginImage_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginImage_OrthancPluginDrawText( + sdk_OrthancPluginImage_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginImage_Methods[] = { + { "GetImagePixelFormat", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginGetImagePixelFormat, METH_VARARGS, + "Generated from C function OrthancPluginGetImagePixelFormat()" }, + { "GetImageWidth", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginGetImageWidth, METH_VARARGS, + "Generated from C function OrthancPluginGetImageWidth()" }, + { "GetImageHeight", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginGetImageHeight, METH_VARARGS, + "Generated from C function OrthancPluginGetImageHeight()" }, + { "GetImagePitch", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginGetImagePitch, METH_VARARGS, + "Generated from C function OrthancPluginGetImagePitch()" }, + { "ConvertPixelFormat", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginConvertPixelFormat, METH_VARARGS, + "Generated from C function OrthancPluginConvertPixelFormat()" }, + { "DrawText", + (PyCFunction) sdk_OrthancPluginImage_OrthancPluginDrawText, METH_VARARGS, + "Generated from C function OrthancPluginDrawText()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginImage_Constructor( + sdk_OrthancPluginImage_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginImage"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginImage_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.Image", /* tp_name */ + sizeof(sdk_OrthancPluginImage_Object), /* tp_basicsize */ +}; + + +static void sdk_OrthancPluginImage_Destructor(PyObject *self) +{ + OrthancPlugins::LogInfo("Destroying Python object of class OrthancPluginImage"); + + sdk_OrthancPluginImage_Object& tmp = *((sdk_OrthancPluginImage_Object*) self); + + if (tmp.object_ != NULL && + !tmp.borrowed_) + { + OrthancPluginFreeImage(OrthancPlugins::GetGlobalContext(), tmp.object_); + tmp.object_ = NULL; + } + + Py_TYPE(self)->tp_free((PyObject *)self); +} + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImagePixelFormat( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetImagePixelFormat() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPluginPixelFormat value = OrthancPluginGetImagePixelFormat(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImageWidth( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetImageWidth() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetImageWidth(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImageHeight( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetImageHeight() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetImageHeight(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginImage_OrthancPluginGetImagePitch( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetImagePitch() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginImage_OrthancPluginConvertPixelFormat( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginConvertPixelFormat() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + long int arg0 = 0; + + if (!PyArg_ParseTuple(args, "l", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + // This is the case of a constructor + OrthancPluginImage* obj = OrthancPluginConvertPixelFormat(OrthancPlugins::GetGlobalContext(), self->object_, static_cast(arg0)); + + if (obj == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); + PyObject *python = PyObject_CallObject((PyObject *) &sdk_OrthancPluginImage_Type, argList); + Py_DECREF(argList); + return python; + } +} + +static PyObject *sdk_OrthancPluginImage_OrthancPluginDrawText( + sdk_OrthancPluginImage_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginDrawText() on object of class OrthancPluginImage"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + const char* arg1 = NULL; + long int arg2 = 0; + long int arg3 = 0; + unsigned char arg4 = 0; + unsigned char arg5 = 0; + unsigned char arg6 = 0; + + if (!PyArg_ParseTuple(args, "ksllbbb", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (7 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginDrawText(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1, arg2, arg3, arg4, arg5, arg6); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + + + +static void RegisterOrthancPluginImageClass(PyObject* module) +{ + sdk_OrthancPluginImage_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginImage_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginImage_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginImage"; + sdk_OrthancPluginImage_Type.tp_methods = sdk_OrthancPluginImage_Methods; + sdk_OrthancPluginImage_Type.tp_init = (initproc) sdk_OrthancPluginImage_Constructor; + + /** + * "tp_dealloc is called when the reference count of the object goes + * down to zero. This is where you destroy the object and its + * members. It should then free the memory occupied by the object by + * calling tp_free." + * https://stackoverflow.com/a/24863227/881731 + **/ + sdk_OrthancPluginImage_Type.tp_dealloc = sdk_OrthancPluginImage_Destructor; + + if (PyType_Ready(&sdk_OrthancPluginImage_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginImage"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginImage_Type); + if (PyModule_AddObject(module, "Image", (PyObject *)&sdk_OrthancPluginImage_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginImage"); + Py_DECREF(&sdk_OrthancPluginImage_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginImageType() +{ + return (PyObject*) &sdk_OrthancPluginImage_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginImageFormat.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginImageFormat.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginImageFormat_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginImageFormat_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ImageFormat", /* tp_name */ + sizeof(sdk_OrthancPluginImageFormat_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginImageFormatEnumeration(PyObject* module) +{ + sdk_OrthancPluginImageFormat_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginImageFormat_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginImageFormat_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginImageFormat"; + + sdk_OrthancPluginImageFormat_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginImageFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginImageFormat"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginImageFormat_Type.tp_dict, "PNG", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginImageFormat_Type.tp_dict, "JPEG", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginImageFormat_Type.tp_dict, "DICOM", PyLong_FromLong(2)); + + Py_INCREF(&sdk_OrthancPluginImageFormat_Type); + if (PyModule_AddObject(module, "ImageFormat", (PyObject *)&sdk_OrthancPluginImageFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginImageFormat"); + Py_DECREF(&sdk_OrthancPluginImageFormat_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginInstanceOrigin.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginInstanceOrigin.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,79 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginInstanceOrigin_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginInstanceOrigin_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.InstanceOrigin", /* tp_name */ + sizeof(sdk_OrthancPluginInstanceOrigin_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginInstanceOriginEnumeration(PyObject* module) +{ + sdk_OrthancPluginInstanceOrigin_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginInstanceOrigin_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginInstanceOrigin_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginInstanceOrigin"; + + sdk_OrthancPluginInstanceOrigin_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginInstanceOrigin_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginInstanceOrigin"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginInstanceOrigin_Type.tp_dict, "UNKNOWN", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginInstanceOrigin_Type.tp_dict, "DICOM_PROTOCOL", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginInstanceOrigin_Type.tp_dict, "REST_API", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginInstanceOrigin_Type.tp_dict, "PLUGIN", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginInstanceOrigin_Type.tp_dict, "LUA", PyLong_FromLong(5)); + + Py_INCREF(&sdk_OrthancPluginInstanceOrigin_Type); + if (PyModule_AddObject(module, "InstanceOrigin", (PyObject *)&sdk_OrthancPluginInstanceOrigin_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginInstanceOrigin"); + Py_DECREF(&sdk_OrthancPluginInstanceOrigin_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginJob.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginJob.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,174 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginJob* object_; + bool borrowed_; +} sdk_OrthancPluginJob_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginJob_OrthancPluginSubmitJob( + sdk_OrthancPluginJob_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginJob_Methods[] = { + { "SubmitJob", + (PyCFunction) sdk_OrthancPluginJob_OrthancPluginSubmitJob, METH_VARARGS, + "Generated from C function OrthancPluginSubmitJob()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginJob_Constructor( + sdk_OrthancPluginJob_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginJob"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginJob_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.Job", /* tp_name */ + sizeof(sdk_OrthancPluginJob_Object), /* tp_basicsize */ +}; + + +static void sdk_OrthancPluginJob_Destructor(PyObject *self) +{ + OrthancPlugins::LogInfo("Destroying Python object of class OrthancPluginJob"); + + sdk_OrthancPluginJob_Object& tmp = *((sdk_OrthancPluginJob_Object*) self); + + if (tmp.object_ != NULL && + !tmp.borrowed_) + { + OrthancPluginFreeJob(OrthancPlugins::GetGlobalContext(), tmp.object_); + tmp.object_ = NULL; + } + + Py_TYPE(self)->tp_free((PyObject *)self); +} + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginJob_OrthancPluginSubmitJob( + sdk_OrthancPluginJob_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSubmitJob() on object of class OrthancPluginJob"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + int arg0 = 0; + + if (!PyArg_ParseTuple(args, "i", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPlugins::OrthancString s; + s.Assign(OrthancPluginSubmitJob(OrthancPlugins::GetGlobalContext(), self->object_, arg0)); + + if (s.GetContent() == NULL) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } + else + { + return PyUnicode_FromString(s.GetContent()); + } +} + + + +static void RegisterOrthancPluginJobClass(PyObject* module) +{ + sdk_OrthancPluginJob_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginJob_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginJob_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginJob"; + sdk_OrthancPluginJob_Type.tp_methods = sdk_OrthancPluginJob_Methods; + sdk_OrthancPluginJob_Type.tp_init = (initproc) sdk_OrthancPluginJob_Constructor; + + /** + * "tp_dealloc is called when the reference count of the object goes + * down to zero. This is where you destroy the object and its + * members. It should then free the memory occupied by the object by + * calling tp_free." + * https://stackoverflow.com/a/24863227/881731 + **/ + sdk_OrthancPluginJob_Type.tp_dealloc = sdk_OrthancPluginJob_Destructor; + + if (PyType_Ready(&sdk_OrthancPluginJob_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginJob"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginJob_Type); + if (PyModule_AddObject(module, "Job", (PyObject *)&sdk_OrthancPluginJob_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginJob"); + Py_DECREF(&sdk_OrthancPluginJob_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginJobType() +{ + return (PyObject*) &sdk_OrthancPluginJob_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginJobStepStatus.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginJobStepStatus.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,77 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginJobStepStatus_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginJobStepStatus_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.JobStepStatus", /* tp_name */ + sizeof(sdk_OrthancPluginJobStepStatus_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginJobStepStatusEnumeration(PyObject* module) +{ + sdk_OrthancPluginJobStepStatus_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginJobStepStatus_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginJobStepStatus_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginJobStepStatus"; + + sdk_OrthancPluginJobStepStatus_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginJobStepStatus_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginJobStepStatus"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginJobStepStatus_Type.tp_dict, "SUCCESS", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginJobStepStatus_Type.tp_dict, "FAILURE", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginJobStepStatus_Type.tp_dict, "CONTINUE", PyLong_FromLong(3)); + + Py_INCREF(&sdk_OrthancPluginJobStepStatus_Type); + if (PyModule_AddObject(module, "JobStepStatus", (PyObject *)&sdk_OrthancPluginJobStepStatus_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginJobStepStatus"); + Py_DECREF(&sdk_OrthancPluginJobStepStatus_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginJobStopReason.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginJobStopReason.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,78 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginJobStopReason_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginJobStopReason_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.JobStopReason", /* tp_name */ + sizeof(sdk_OrthancPluginJobStopReason_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginJobStopReasonEnumeration(PyObject* module) +{ + sdk_OrthancPluginJobStopReason_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginJobStopReason_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginJobStopReason_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginJobStopReason"; + + sdk_OrthancPluginJobStopReason_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginJobStopReason_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginJobStopReason"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginJobStopReason_Type.tp_dict, "SUCCESS", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginJobStopReason_Type.tp_dict, "PAUSED", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginJobStopReason_Type.tp_dict, "FAILURE", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginJobStopReason_Type.tp_dict, "CANCELED", PyLong_FromLong(4)); + + Py_INCREF(&sdk_OrthancPluginJobStopReason_Type); + if (PyModule_AddObject(module, "JobStopReason", (PyObject *)&sdk_OrthancPluginJobStopReason_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginJobStopReason"); + Py_DECREF(&sdk_OrthancPluginJobStopReason_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginMetricsType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginMetricsType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,76 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginMetricsType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginMetricsType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.MetricsType", /* tp_name */ + sizeof(sdk_OrthancPluginMetricsType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginMetricsTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginMetricsType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginMetricsType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginMetricsType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginMetricsType"; + + sdk_OrthancPluginMetricsType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginMetricsType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginMetricsType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginMetricsType_Type.tp_dict, "DEFAULT", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginMetricsType_Type.tp_dict, "TIMER", PyLong_FromLong(1)); + + Py_INCREF(&sdk_OrthancPluginMetricsType_Type); + if (PyModule_AddObject(module, "MetricsType", (PyObject *)&sdk_OrthancPluginMetricsType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginMetricsType"); + Py_DECREF(&sdk_OrthancPluginMetricsType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginPeers.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginPeers.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,274 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginPeers* object_; + bool borrowed_; +} sdk_OrthancPluginPeers_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeersCount( + sdk_OrthancPluginPeers_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerName( + sdk_OrthancPluginPeers_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerUrl( + sdk_OrthancPluginPeers_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerUserProperty( + sdk_OrthancPluginPeers_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginPeers_Methods[] = { + { "GetPeersCount", + (PyCFunction) sdk_OrthancPluginPeers_OrthancPluginGetPeersCount, METH_VARARGS, + "Generated from C function OrthancPluginGetPeersCount()" }, + { "GetPeerName", + (PyCFunction) sdk_OrthancPluginPeers_OrthancPluginGetPeerName, METH_VARARGS, + "Generated from C function OrthancPluginGetPeerName()" }, + { "GetPeerUrl", + (PyCFunction) sdk_OrthancPluginPeers_OrthancPluginGetPeerUrl, METH_VARARGS, + "Generated from C function OrthancPluginGetPeerUrl()" }, + { "GetPeerUserProperty", + (PyCFunction) sdk_OrthancPluginPeers_OrthancPluginGetPeerUserProperty, METH_VARARGS, + "Generated from C function OrthancPluginGetPeerUserProperty()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginPeers_Constructor( + sdk_OrthancPluginPeers_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginPeers"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginPeers_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.Peers", /* tp_name */ + sizeof(sdk_OrthancPluginPeers_Object), /* tp_basicsize */ +}; + + +static void sdk_OrthancPluginPeers_Destructor(PyObject *self) +{ + OrthancPlugins::LogInfo("Destroying Python object of class OrthancPluginPeers"); + + sdk_OrthancPluginPeers_Object& tmp = *((sdk_OrthancPluginPeers_Object*) self); + + if (tmp.object_ != NULL && + !tmp.borrowed_) + { + OrthancPluginFreePeers(OrthancPlugins::GetGlobalContext(), tmp.object_); + tmp.object_ = NULL; + } + + Py_TYPE(self)->tp_free((PyObject *)self); +} + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeersCount( + sdk_OrthancPluginPeers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetPeersCount() on object of class OrthancPluginPeers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + long value = OrthancPluginGetPeersCount(OrthancPlugins::GetGlobalContext(), self->object_); + + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerName( + sdk_OrthancPluginPeers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetPeerName() on object of class OrthancPluginPeers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetPeerName(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerUrl( + sdk_OrthancPluginPeers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetPeerUrl() on object of class OrthancPluginPeers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + + if (!PyArg_ParseTuple(args, "k", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetPeerUrl(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + +static PyObject *sdk_OrthancPluginPeers_OrthancPluginGetPeerUserProperty( + sdk_OrthancPluginPeers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginGetPeerUserProperty() on object of class OrthancPluginPeers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned long arg0 = 0; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ks", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + const char* s = OrthancPluginGetPeerUserProperty(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + if (s == NULL) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + return PyUnicode_FromString(s); + } +} + + + +static void RegisterOrthancPluginPeersClass(PyObject* module) +{ + sdk_OrthancPluginPeers_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginPeers_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginPeers_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginPeers"; + sdk_OrthancPluginPeers_Type.tp_methods = sdk_OrthancPluginPeers_Methods; + sdk_OrthancPluginPeers_Type.tp_init = (initproc) sdk_OrthancPluginPeers_Constructor; + + /** + * "tp_dealloc is called when the reference count of the object goes + * down to zero. This is where you destroy the object and its + * members. It should then free the memory occupied by the object by + * calling tp_free." + * https://stackoverflow.com/a/24863227/881731 + **/ + sdk_OrthancPluginPeers_Type.tp_dealloc = sdk_OrthancPluginPeers_Destructor; + + if (PyType_Ready(&sdk_OrthancPluginPeers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginPeers"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginPeers_Type); + if (PyModule_AddObject(module, "Peers", (PyObject *)&sdk_OrthancPluginPeers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginPeers"); + Py_DECREF(&sdk_OrthancPluginPeers_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginPeersType() +{ + return (PyObject*) &sdk_OrthancPluginPeers_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginPixelFormat.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginPixelFormat.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,85 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginPixelFormat_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginPixelFormat_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.PixelFormat", /* tp_name */ + sizeof(sdk_OrthancPluginPixelFormat_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginPixelFormatEnumeration(PyObject* module) +{ + sdk_OrthancPluginPixelFormat_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginPixelFormat_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginPixelFormat_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginPixelFormat"; + + sdk_OrthancPluginPixelFormat_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginPixelFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginPixelFormat"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "GRAYSCALE8", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "GRAYSCALE16", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "SIGNED_GRAYSCALE16", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "RGB24", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "RGBA32", PyLong_FromLong(5)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "UNKNOWN", PyLong_FromLong(6)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "RGB48", PyLong_FromLong(7)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "GRAYSCALE32", PyLong_FromLong(8)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "FLOAT32", PyLong_FromLong(9)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "BGRA32", PyLong_FromLong(10)); + PyDict_SetItemString(sdk_OrthancPluginPixelFormat_Type.tp_dict, "GRAYSCALE64", PyLong_FromLong(11)); + + Py_INCREF(&sdk_OrthancPluginPixelFormat_Type); + if (PyModule_AddObject(module, "PixelFormat", (PyObject *)&sdk_OrthancPluginPixelFormat_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginPixelFormat"); + Py_DECREF(&sdk_OrthancPluginPixelFormat_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginResourceType.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginResourceType.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,79 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginResourceType_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginResourceType_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ResourceType", /* tp_name */ + sizeof(sdk_OrthancPluginResourceType_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginResourceTypeEnumeration(PyObject* module) +{ + sdk_OrthancPluginResourceType_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginResourceType_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginResourceType_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginResourceType"; + + sdk_OrthancPluginResourceType_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginResourceType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginResourceType"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginResourceType_Type.tp_dict, "PATIENT", PyLong_FromLong(0)); + PyDict_SetItemString(sdk_OrthancPluginResourceType_Type.tp_dict, "STUDY", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginResourceType_Type.tp_dict, "SERIES", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginResourceType_Type.tp_dict, "INSTANCE", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginResourceType_Type.tp_dict, "NONE", PyLong_FromLong(4)); + + Py_INCREF(&sdk_OrthancPluginResourceType_Type); + if (PyModule_AddObject(module, "ResourceType", (PyObject *)&sdk_OrthancPluginResourceType_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginResourceType"); + Py_DECREF(&sdk_OrthancPluginResourceType_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginRestOutput.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginRestOutput.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,575 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginRestOutput* object_; + bool borrowed_; +} sdk_OrthancPluginRestOutput_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginAnswerBuffer( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerPngImage( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginRedirect( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatusCode( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendUnauthorized( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendMethodNotAllowed( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetCookie( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetHttpHeader( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginStartMultipartAnswer( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendMultipartItem( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatus( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerJpegImage( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetHttpErrorDetails( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginRestOutput_Methods[] = { + { "AnswerBuffer", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginAnswerBuffer, METH_VARARGS, + "Generated from C function OrthancPluginAnswerBuffer()" }, + { "CompressAndAnswerPngImage", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerPngImage, METH_VARARGS, + "Generated from C function OrthancPluginCompressAndAnswerPngImage()" }, + { "Redirect", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginRedirect, METH_VARARGS, + "Generated from C function OrthancPluginRedirect()" }, + { "SendHttpStatusCode", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatusCode, METH_VARARGS, + "Generated from C function OrthancPluginSendHttpStatusCode()" }, + { "SendUnauthorized", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSendUnauthorized, METH_VARARGS, + "Generated from C function OrthancPluginSendUnauthorized()" }, + { "SendMethodNotAllowed", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSendMethodNotAllowed, METH_VARARGS, + "Generated from C function OrthancPluginSendMethodNotAllowed()" }, + { "SetCookie", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSetCookie, METH_VARARGS, + "Generated from C function OrthancPluginSetCookie()" }, + { "SetHttpHeader", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSetHttpHeader, METH_VARARGS, + "Generated from C function OrthancPluginSetHttpHeader()" }, + { "StartMultipartAnswer", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginStartMultipartAnswer, METH_VARARGS, + "Generated from C function OrthancPluginStartMultipartAnswer()" }, + { "SendMultipartItem", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSendMultipartItem, METH_VARARGS, + "Generated from C function OrthancPluginSendMultipartItem()" }, + { "SendHttpStatus", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatus, METH_VARARGS, + "Generated from C function OrthancPluginSendHttpStatus()" }, + { "CompressAndAnswerJpegImage", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerJpegImage, METH_VARARGS, + "Generated from C function OrthancPluginCompressAndAnswerJpegImage()" }, + { "SetHttpErrorDetails", + (PyCFunction) sdk_OrthancPluginRestOutput_OrthancPluginSetHttpErrorDetails, METH_VARARGS, + "Generated from C function OrthancPluginSetHttpErrorDetails()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginRestOutput_Constructor( + sdk_OrthancPluginRestOutput_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginRestOutput"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginRestOutput_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.RestOutput", /* tp_name */ + sizeof(sdk_OrthancPluginRestOutput_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginAnswerBuffer( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginAnswerBuffer() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + Py_buffer arg0; + const char* arg2 = NULL; + + if (!PyArg_ParseTuple(args, "s*s", &arg0, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), self->object_, arg0.buf, arg0.len, arg2); + PyBuffer_Release(&arg0); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerPngImage( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginCompressAndAnswerPngImage() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + long int arg0 = 0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; + unsigned long arg3 = 0; + Py_buffer arg4; + + if (!PyArg_ParseTuple(args, "lkkks*", &arg0, &arg1, &arg2, &arg3, &arg4)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (5 arguments expected)"); + return NULL; + } + OrthancPluginCompressAndAnswerPngImage(OrthancPlugins::GetGlobalContext(), self->object_, static_cast(arg0), arg1, arg2, arg3, arg4.buf); + PyBuffer_Release(&arg4); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginRedirect( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginRedirect() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginRedirect(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatusCode( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSendHttpStatusCode() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned short arg0 = 0; + + if (!PyArg_ParseTuple(args, "H", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginSendHttpStatusCode(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendUnauthorized( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSendUnauthorized() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginSendUnauthorized(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendMethodNotAllowed( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSendMethodNotAllowed() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + + if (!PyArg_ParseTuple(args, "s", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), self->object_, arg0); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetCookie( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSetCookie() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ss", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginSetCookie(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetHttpHeader( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSetHttpHeader() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ss", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginSetHttpHeader(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginStartMultipartAnswer( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginStartMultipartAnswer() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + const char* arg1 = NULL; + + if (!PyArg_ParseTuple(args, "ss", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginStartMultipartAnswer(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendMultipartItem( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSendMultipartItem() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + unsigned long arg1 = 0; + + if (!PyArg_ParseTuple(args, "sk", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginSendMultipartItem(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSendHttpStatus( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSendHttpStatus() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + unsigned short arg0 = 0; + const char* arg1 = NULL; + unsigned long arg2 = 0; + + if (!PyArg_ParseTuple(args, "Hsk", &arg0, &arg1, &arg2)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (3 arguments expected)"); + return NULL; + } + OrthancPluginSendHttpStatus(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1, arg2); + + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginCompressAndAnswerJpegImage( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginCompressAndAnswerJpegImage() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + long int arg0 = 0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; + unsigned long arg3 = 0; + Py_buffer arg4; + unsigned char arg5 = 0; + + if (!PyArg_ParseTuple(args, "lkkks*b", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (6 arguments expected)"); + return NULL; + } + OrthancPluginCompressAndAnswerJpegImage(OrthancPlugins::GetGlobalContext(), self->object_, static_cast(arg0), arg1, arg2, arg3, arg4.buf, arg5); + PyBuffer_Release(&arg4); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *sdk_OrthancPluginRestOutput_OrthancPluginSetHttpErrorDetails( + sdk_OrthancPluginRestOutput_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginSetHttpErrorDetails() on object of class OrthancPluginRestOutput"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + unsigned char arg1 = 0; + + if (!PyArg_ParseTuple(args, "sb", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginSetHttpErrorDetails(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1); + + + Py_INCREF(Py_None); + return Py_None; +} + + + +static void RegisterOrthancPluginRestOutputClass(PyObject* module) +{ + sdk_OrthancPluginRestOutput_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginRestOutput_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginRestOutput_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginRestOutput"; + sdk_OrthancPluginRestOutput_Type.tp_methods = sdk_OrthancPluginRestOutput_Methods; + sdk_OrthancPluginRestOutput_Type.tp_init = (initproc) sdk_OrthancPluginRestOutput_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginRestOutput_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginRestOutput"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginRestOutput_Type); + if (PyModule_AddObject(module, "RestOutput", (PyObject *)&sdk_OrthancPluginRestOutput_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginRestOutput"); + Py_DECREF(&sdk_OrthancPluginRestOutput_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginRestOutputType() +{ + return (PyObject*) &sdk_OrthancPluginRestOutput_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginServerChunkedRequestReader.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginServerChunkedRequestReader.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,109 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginServerChunkedRequestReader* object_; + bool borrowed_; +} sdk_OrthancPluginServerChunkedRequestReader_Object; + + + +// Forward declaration of the methods + + +static PyMethodDef sdk_OrthancPluginServerChunkedRequestReader_Methods[] = { + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginServerChunkedRequestReader_Constructor( + sdk_OrthancPluginServerChunkedRequestReader_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginServerChunkedRequestReader"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginServerChunkedRequestReader_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ServerChunkedRequestReader", /* tp_name */ + sizeof(sdk_OrthancPluginServerChunkedRequestReader_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods + + +static void RegisterOrthancPluginServerChunkedRequestReaderClass(PyObject* module) +{ + sdk_OrthancPluginServerChunkedRequestReader_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginServerChunkedRequestReader_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginServerChunkedRequestReader_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginServerChunkedRequestReader"; + sdk_OrthancPluginServerChunkedRequestReader_Type.tp_methods = sdk_OrthancPluginServerChunkedRequestReader_Methods; + sdk_OrthancPluginServerChunkedRequestReader_Type.tp_init = (initproc) sdk_OrthancPluginServerChunkedRequestReader_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginServerChunkedRequestReader_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginServerChunkedRequestReader"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginServerChunkedRequestReader_Type); + if (PyModule_AddObject(module, "ServerChunkedRequestReader", (PyObject *)&sdk_OrthancPluginServerChunkedRequestReader_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginServerChunkedRequestReader"); + Py_DECREF(&sdk_OrthancPluginServerChunkedRequestReader_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginServerChunkedRequestReaderType() +{ + return (PyObject*) &sdk_OrthancPluginServerChunkedRequestReader_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginStorageArea.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginStorageArea.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,285 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginStorageArea* object_; + bool borrowed_; +} sdk_OrthancPluginStorageArea_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaCreate( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRead( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRemove( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginReconstructMainDicomTags( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginStorageArea_Methods[] = { + { "StorageAreaCreate", + (PyCFunction) sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaCreate, METH_VARARGS, + "Generated from C function OrthancPluginStorageAreaCreate()" }, + { "StorageAreaRead", + (PyCFunction) sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRead, METH_VARARGS, + "Generated from C function OrthancPluginStorageAreaRead()" }, + { "StorageAreaRemove", + (PyCFunction) sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRemove, METH_VARARGS, + "Generated from C function OrthancPluginStorageAreaRemove()" }, + { "ReconstructMainDicomTags", + (PyCFunction) sdk_OrthancPluginStorageArea_OrthancPluginReconstructMainDicomTags, METH_VARARGS, + "Generated from C function OrthancPluginReconstructMainDicomTags()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginStorageArea_Constructor( + sdk_OrthancPluginStorageArea_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginStorageArea"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginStorageArea_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.StorageArea", /* tp_name */ + sizeof(sdk_OrthancPluginStorageArea_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaCreate( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginStorageAreaCreate() on object of class OrthancPluginStorageArea"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + Py_buffer arg1; + unsigned long long arg2 = 0; + long int arg3 = 0; + + if (!PyArg_ParseTuple(args, "ss*Kl", &arg0, &arg1, &arg2, &arg3)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (4 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginStorageAreaCreate(OrthancPlugins::GetGlobalContext(), self->object_, arg0, arg1.buf, arg2, static_cast(arg3)); + PyBuffer_Release(&arg1); + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRead( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginStorageAreaRead() on object of class OrthancPluginStorageArea"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + long int arg1 = 0; + + if (!PyArg_ParseTuple(args, "sl", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginStorageAreaRead(OrthancPlugins::GetGlobalContext(), *buffer, self->object_, arg0, static_cast(arg1)); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginStorageAreaRemove( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginStorageAreaRemove() on object of class OrthancPluginStorageArea"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + const char* arg0 = NULL; + long int arg1 = 0; + + if (!PyArg_ParseTuple(args, "sl", &arg0, &arg1)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (2 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginStorageAreaRemove(OrthancPlugins::GetGlobalContext(), self->object_, arg0, static_cast(arg1)); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + +static PyObject *sdk_OrthancPluginStorageArea_OrthancPluginReconstructMainDicomTags( + sdk_OrthancPluginStorageArea_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginReconstructMainDicomTags() on object of class OrthancPluginStorageArea"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + long int arg0 = 0; + + if (!PyArg_ParseTuple(args, "l", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + OrthancPluginErrorCode code = OrthancPluginReconstructMainDicomTags(OrthancPlugins::GetGlobalContext(), self->object_, static_cast(arg0)); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + + + +static void RegisterOrthancPluginStorageAreaClass(PyObject* module) +{ + sdk_OrthancPluginStorageArea_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginStorageArea_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginStorageArea_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginStorageArea"; + sdk_OrthancPluginStorageArea_Type.tp_methods = sdk_OrthancPluginStorageArea_Methods; + sdk_OrthancPluginStorageArea_Type.tp_init = (initproc) sdk_OrthancPluginStorageArea_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginStorageArea_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginStorageArea"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginStorageArea_Type); + if (PyModule_AddObject(module, "StorageArea", (PyObject *)&sdk_OrthancPluginStorageArea_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginStorageArea"); + Py_DECREF(&sdk_OrthancPluginStorageArea_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginStorageAreaType() +{ + return (PyObject*) &sdk_OrthancPluginStorageArea_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginValueRepresentation.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginValueRepresentation.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,101 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD +} sdk_OrthancPluginValueRepresentation_Object; + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginValueRepresentation_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.ValueRepresentation", /* tp_name */ + sizeof(sdk_OrthancPluginValueRepresentation_Object), /* tp_basicsize */ +}; + + +void RegisterOrthancPluginValueRepresentationEnumeration(PyObject* module) +{ + sdk_OrthancPluginValueRepresentation_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginValueRepresentation_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginValueRepresentation_Type.tp_doc = "Generated from C enumeration OrthancPluginOrthancPluginValueRepresentation"; + + sdk_OrthancPluginValueRepresentation_Type.tp_dict = PyDict_New(); + + if (PyType_Ready(&sdk_OrthancPluginValueRepresentation_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginValueRepresentation"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + /** + * Declare constants here (static members = class attributes) + * https://stackoverflow.com/a/8017906/881731 + * + * "Static and class methods can be defined in tp_methods by adding + * METH_STATIC or METH_CLASS to the ml_flags field of the + * PyMethodDef structure. This is equivalent to @staticmethod and + * @classmethod decorators." + * + * "Class attributes can be added by setting the tp_dict to a + * dictionary with these attributes before calling PyType_Ready() + * (in your module initialization function)." + **/ + + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "AE", PyLong_FromLong(1)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "AS", PyLong_FromLong(2)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "AT", PyLong_FromLong(3)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "CS", PyLong_FromLong(4)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "DA", PyLong_FromLong(5)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "DS", PyLong_FromLong(6)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "DT", PyLong_FromLong(7)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "FD", PyLong_FromLong(8)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "FL", PyLong_FromLong(9)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "IS", PyLong_FromLong(10)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "LO", PyLong_FromLong(11)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "LT", PyLong_FromLong(12)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "OB", PyLong_FromLong(13)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "OF", PyLong_FromLong(14)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "OW", PyLong_FromLong(15)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "PN", PyLong_FromLong(16)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "SH", PyLong_FromLong(17)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "SL", PyLong_FromLong(18)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "SQ", PyLong_FromLong(19)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "SS", PyLong_FromLong(20)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "ST", PyLong_FromLong(21)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "TM", PyLong_FromLong(22)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "UI", PyLong_FromLong(23)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "UL", PyLong_FromLong(24)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "UN", PyLong_FromLong(25)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "US", PyLong_FromLong(26)); + PyDict_SetItemString(sdk_OrthancPluginValueRepresentation_Type.tp_dict, "UT", PyLong_FromLong(27)); + + Py_INCREF(&sdk_OrthancPluginValueRepresentation_Type); + if (PyModule_AddObject(module, "ValueRepresentation", (PyObject *)&sdk_OrthancPluginValueRepresentation_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python enumeration: OrthancPluginValueRepresentation"); + Py_DECREF(&sdk_OrthancPluginValueRepresentation_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginWorklistAnswers.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginWorklistAnswers.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,145 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginWorklistAnswers* object_; + bool borrowed_; +} sdk_OrthancPluginWorklistAnswers_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginWorklistAnswers_OrthancPluginWorklistMarkIncomplete( + sdk_OrthancPluginWorklistAnswers_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginWorklistAnswers_Methods[] = { + { "WorklistMarkIncomplete", + (PyCFunction) sdk_OrthancPluginWorklistAnswers_OrthancPluginWorklistMarkIncomplete, METH_VARARGS, + "Generated from C function OrthancPluginWorklistMarkIncomplete()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginWorklistAnswers_Constructor( + sdk_OrthancPluginWorklistAnswers_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginWorklistAnswers"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginWorklistAnswers_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.WorklistAnswers", /* tp_name */ + sizeof(sdk_OrthancPluginWorklistAnswers_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginWorklistAnswers_OrthancPluginWorklistMarkIncomplete( + sdk_OrthancPluginWorklistAnswers_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginWorklistMarkIncomplete() on object of class OrthancPluginWorklistAnswers"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPluginErrorCode code = OrthancPluginWorklistMarkIncomplete(OrthancPlugins::GetGlobalContext(), self->object_); + + + if (code == OrthancPluginErrorCode_Success) + { + Py_INCREF(Py_None); + return Py_None; + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, code); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + + + +static void RegisterOrthancPluginWorklistAnswersClass(PyObject* module) +{ + sdk_OrthancPluginWorklistAnswers_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginWorklistAnswers_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginWorklistAnswers_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginWorklistAnswers"; + sdk_OrthancPluginWorklistAnswers_Type.tp_methods = sdk_OrthancPluginWorklistAnswers_Methods; + sdk_OrthancPluginWorklistAnswers_Type.tp_init = (initproc) sdk_OrthancPluginWorklistAnswers_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginWorklistAnswers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginWorklistAnswers"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginWorklistAnswers_Type); + if (PyModule_AddObject(module, "WorklistAnswers", (PyObject *)&sdk_OrthancPluginWorklistAnswers_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginWorklistAnswers"); + Py_DECREF(&sdk_OrthancPluginWorklistAnswers_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginWorklistAnswersType() +{ + return (PyObject*) &sdk_OrthancPluginWorklistAnswers_Type; +} diff -r 7ed502b17b8f -r fef9a239df5c Sources/Autogenerated/sdk_OrthancPluginWorklistQuery.impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sources/Autogenerated/sdk_OrthancPluginWorklistQuery.impl.h Thu Mar 26 18:50:10 2020 +0100 @@ -0,0 +1,175 @@ +/** + * Python plugin for Orthanc + * Copyright (C) 2017-2020 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * 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 + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + + +typedef struct +{ + PyObject_HEAD + + /* Type-specific fields go here. */ + OrthancPluginWorklistQuery* object_; + bool borrowed_; +} sdk_OrthancPluginWorklistQuery_Object; + + + +// Forward declaration of the methods +static PyObject *sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistIsMatch( + sdk_OrthancPluginWorklistQuery_Object* self, PyObject *args); +static PyObject *sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistGetDicomQuery( + sdk_OrthancPluginWorklistQuery_Object* self, PyObject *args); + + +static PyMethodDef sdk_OrthancPluginWorklistQuery_Methods[] = { + { "WorklistIsMatch", + (PyCFunction) sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistIsMatch, METH_VARARGS, + "Generated from C function OrthancPluginWorklistIsMatch()" }, + { "WorklistGetDicomQuery", + (PyCFunction) sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistGetDicomQuery, METH_VARARGS, + "Generated from C function OrthancPluginWorklistGetDicomQuery()" }, + { NULL } /* Sentinel */ +}; + + +static int sdk_OrthancPluginWorklistQuery_Constructor( + sdk_OrthancPluginWorklistQuery_Object *self, PyObject *args, PyObject *kwds) +{ + OrthancPlugins::LogInfo("Creating Python object of class OrthancPluginWorklistQuery"); + + self->object_ = NULL; + self->borrowed_ = false; + + long long object = 0; + unsigned char borrowed = false; + + if (PyArg_ParseTuple(args, "Lb", &object, &borrowed)) + { + self->object_ = reinterpret_cast(static_cast(object)); + self->borrowed_ = borrowed; + return 0; + } + else + { + PyErr_SetString(PyExc_ValueError, "Expected a pair (pointer, borrowed) in the constructor"); + return -1; + } +} + + +/** + * Static global structure => the fields that are beyond the last + * initialized field are set to zero. + * https://stackoverflow.com/a/11152199/881731 + **/ +static PyTypeObject sdk_OrthancPluginWorklistQuery_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "orthanc.WorklistQuery", /* tp_name */ + sizeof(sdk_OrthancPluginWorklistQuery_Object), /* tp_basicsize */ +}; + + + + +// Actual implementation of the methods +static PyObject *sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistIsMatch( + sdk_OrthancPluginWorklistQuery_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginWorklistIsMatch() on object of class OrthancPluginWorklistQuery"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + Py_buffer arg0; + + if (!PyArg_ParseTuple(args, "s*", &arg0)) + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + PyErr_SetString(PyExc_TypeError, "Bad types for the arguments (1 arguments expected)"); + return NULL; + } + long value = OrthancPluginWorklistIsMatch(OrthancPlugins::GetGlobalContext(), self->object_, arg0.buf, arg0.len); + PyBuffer_Release(&arg0); + return PyLong_FromLong(value); +} + +static PyObject *sdk_OrthancPluginWorklistQuery_OrthancPluginWorklistGetDicomQuery( + sdk_OrthancPluginWorklistQuery_Object* self, PyObject *args) +{ + OrthancPlugins::LogInfo("Calling method OrthancPluginWorklistGetDicomQuery() on object of class OrthancPluginWorklistQuery"); + + if (self->object_ == NULL) + { + // TODO: RAISE + //PythonLock::RaiseException(module, OrthancPluginErrorCode_NullPointer); + PyErr_SetString(PyExc_ValueError, "Invalid object"); + return NULL; + } + + + OrthancPlugins::MemoryBuffer buffer; + OrthancPluginErrorCode code = OrthancPluginWorklistGetDicomQuery(OrthancPlugins::GetGlobalContext(), *buffer, self->object_); + + if (code == OrthancPluginErrorCode_Success) + { + return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); + } + else + { + // TODO => RAISE : https://stackoverflow.com/questions/60832317 + //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); + PyErr_SetString(PyExc_ValueError, "Internal error"); + return NULL; + } +} + + + +static void RegisterOrthancPluginWorklistQueryClass(PyObject* module) +{ + sdk_OrthancPluginWorklistQuery_Type.tp_new = PyType_GenericNew; + sdk_OrthancPluginWorklistQuery_Type.tp_flags = Py_TPFLAGS_DEFAULT; + sdk_OrthancPluginWorklistQuery_Type.tp_doc = "Generated from Orthanc C class: OrthancPluginWorklistQuery"; + sdk_OrthancPluginWorklistQuery_Type.tp_methods = sdk_OrthancPluginWorklistQuery_Methods; + sdk_OrthancPluginWorklistQuery_Type.tp_init = (initproc) sdk_OrthancPluginWorklistQuery_Constructor; + + + if (PyType_Ready(&sdk_OrthancPluginWorklistQuery_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginWorklistQuery"); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } + + Py_INCREF(&sdk_OrthancPluginWorklistQuery_Type); + if (PyModule_AddObject(module, "WorklistQuery", (PyObject *)&sdk_OrthancPluginWorklistQuery_Type) < 0) + { + OrthancPlugins::LogError("Cannot register Python class: OrthancPluginWorklistQuery"); + Py_DECREF(&sdk_OrthancPluginWorklistQuery_Type); + ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); + } +} + + +PyObject* GetOrthancPluginWorklistQueryType() +{ + return (PyObject*) &sdk_OrthancPluginWorklistQuery_Type; +}