Mercurial > hg > orthanc
changeset 6179:6d442d7f3b6a
added PluginMemoryBuffer64
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jun 2025 11:46:20 +0200 |
parents | 8cfe9a74e771 |
children | b91b5759f8dc |
files | OrthancServer/CMakeLists.txt OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h |
diffstat | 6 files changed, 266 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/CMakeLists.txt Thu Jun 12 11:33:54 2025 +0200 +++ b/OrthancServer/CMakeLists.txt Thu Jun 12 11:46:20 2025 +0200 @@ -204,6 +204,7 @@ ${CMAKE_SOURCE_DIR}/Plugins/Engine/OrthancPluginDatabaseV4.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/OrthancPlugins.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginMemoryBuffer32.cpp + ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginMemoryBuffer64.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginsEnumerations.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginsErrorDictionary.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginsJob.cpp
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu Jun 12 11:33:54 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu Jun 12 11:46:20 2025 +0200 @@ -66,6 +66,7 @@ #include "OrthancPluginDatabaseV3.h" #include "OrthancPluginDatabaseV4.h" #include "PluginMemoryBuffer32.h" +#include "PluginMemoryBuffer64.h" #include "PluginsEnumerations.h" #include "PluginsJob.h" @@ -5467,19 +5468,9 @@ const _OrthancPluginCreateMemoryBuffer64& p = *reinterpret_cast<const _OrthancPluginCreateMemoryBuffer64*>(parameters); - p.target->data = NULL; - p.target->size = 0; - - if (p.size != 0) - { - p.target->data = malloc(p.size); - if (p.target->data == NULL) - { - throw OrthancException(ErrorCode_NotEnoughMemory); - } - - p.target->size = p.size; - } + PluginMemoryBuffer64 buffer; + buffer.Resize(p.size); + buffer.Release(p.target); return true; }
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp Thu Jun 12 11:33:54 2025 +0200 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp Thu Jun 12 11:46:20 2025 +0200 @@ -107,7 +107,26 @@ throw OrthancException(ErrorCode_NullPointer); } - *target = buffer_; + target->data = buffer_.data; + target->size = buffer_.size; + + buffer_.data = NULL; + buffer_.size = 0; + } + + + void PluginMemoryBuffer32::Release(OrthancPluginMemoryBuffer64* target) + { + SanityCheck(); + + if (target == NULL) + { + throw OrthancException(ErrorCode_NullPointer); + } + + target->data = buffer_.data; + target->size = buffer_.size; + buffer_.data = NULL; buffer_.size = 0; } @@ -129,6 +148,11 @@ else { buffer_.data = ::malloc(size); + + if (buffer_.data == NULL) + { + throw OrthancException(ErrorCode_NotEnoughMemory); + } } buffer_.size = size;
--- a/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h Thu Jun 12 11:33:54 2025 +0200 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h Thu Jun 12 11:46:20 2025 +0200 @@ -64,6 +64,8 @@ void Release(OrthancPluginMemoryBuffer* target); + void Release(OrthancPluginMemoryBuffer64* target); + void Resize(size_t size); void Assign(const void* data,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.cpp Thu Jun 12 11:46:20 2025 +0200 @@ -0,0 +1,160 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2024-2025 Orthanc Team SRL, Belgium + * Copyright (C) 2021-2025 Sebastien Jodogne, ICTEAM UCLouvain, 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. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../../Sources/PrecompiledHeadersServer.h" +#include "PluginMemoryBuffer64.h" + +#include "../../../OrthancFramework/Sources/OrthancException.h" + + +namespace Orthanc +{ + void PluginMemoryBuffer64::Clear() + { + if (buffer_.size != 0) + { + ::free(buffer_.data); + } + + buffer_.data = NULL; + buffer_.size = 0; + } + + + void PluginMemoryBuffer64::SanityCheck() const + { + if ((buffer_.data == NULL && buffer_.size != 0) || + (buffer_.data != NULL && buffer_.size == 0)) + { + throw OrthancException(ErrorCode_Plugin); + } + } + + + PluginMemoryBuffer64::PluginMemoryBuffer64() + { + buffer_.size = 0; + buffer_.data = NULL; + } + + + void PluginMemoryBuffer64::MoveToString(std::string& target) + { + SanityCheck(); + + target.resize(buffer_.size); + + if (buffer_.size != 0) + { + memcpy(&target[0], buffer_.data, buffer_.size); + } + + Clear(); + } + + + const void* PluginMemoryBuffer64::GetData() const + { + SanityCheck(); + + if (buffer_.size == 0) + { + return NULL; + } + else + { + return buffer_.data; + } + } + + + size_t PluginMemoryBuffer64::GetSize() const + { + SanityCheck(); + return buffer_.size; + } + + + void PluginMemoryBuffer64::Release(OrthancPluginMemoryBuffer64* target) + { + SanityCheck(); + + if (target == NULL) + { + throw OrthancException(ErrorCode_NullPointer); + } + + target->data = buffer_.data; + target->size = buffer_.size; + + buffer_.data = NULL; + buffer_.size = 0; + } + + + void PluginMemoryBuffer64::Resize(size_t size) + { + Clear(); + + if (size == 0) + { + buffer_.data = NULL; + } + else + { + buffer_.data = ::malloc(size); + + if (buffer_.data == NULL) + { + throw OrthancException(ErrorCode_NotEnoughMemory); + } + } + + buffer_.size = size; + } + + + void PluginMemoryBuffer64::Assign(const void* data, + size_t size) + { + Resize(size); + + if (size != 0) + { + memcpy(buffer_.data, data, size); + } + } + + + void PluginMemoryBuffer64::Assign(const std::string& data) + { + if (data.empty()) + { + Assign(NULL, 0); + } + else + { + Assign(data.c_str(), data.size()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer64.h Thu Jun 12 11:46:20 2025 +0200 @@ -0,0 +1,74 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2023 Osimis S.A., Belgium + * Copyright (C) 2024-2025 Orthanc Team SRL, Belgium + * Copyright (C) 2021-2025 Sebastien Jodogne, ICTEAM UCLouvain, 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. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#if ORTHANC_ENABLE_PLUGINS != 1 +# error The plugin support is disabled +#endif + +#include "../../../OrthancFramework/Sources/MallocMemoryBuffer.h" +#include "../Include/orthanc/OrthancCPlugin.h" + +#include <json/value.h> + +namespace Orthanc +{ + class PluginMemoryBuffer64 : public IMemoryBuffer + { + private: + OrthancPluginMemoryBuffer64 buffer_; + + void Clear(); + + void SanityCheck() const; + + public: + PluginMemoryBuffer64(); + + virtual ~PluginMemoryBuffer64() + { + Clear(); + } + + virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE; + + virtual const void* GetData() const ORTHANC_OVERRIDE; + + virtual size_t GetSize() const ORTHANC_OVERRIDE; + + OrthancPluginMemoryBuffer64* GetObject() + { + return &buffer_; + } + + void Release(OrthancPluginMemoryBuffer64* target); + + void Resize(size_t size); + + void Assign(const void* data, + size_t size); + + void Assign(const std::string& data); + }; +}