# HG changeset patch # User Sebastien Jodogne # Date 1749714938 -7200 # Node ID 705343f27dab2a880571cc127678d0fbfbf7c168 # Parent 628edb487cec19649d45f9e8ebe53c131e5cada9 added PluginMemoryBuffer32 to share code between OrthancPlugins and PluginsJob diff -r 628edb487cec -r 705343f27dab OrthancServer/CMakeLists.txt --- a/OrthancServer/CMakeLists.txt Wed Jun 11 17:51:11 2025 +0200 +++ b/OrthancServer/CMakeLists.txt Thu Jun 12 09:55:38 2025 +0200 @@ -203,6 +203,7 @@ ${CMAKE_SOURCE_DIR}/Plugins/Engine/OrthancPluginDatabaseV3.cpp ${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/PluginsEnumerations.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginsErrorDictionary.cpp ${CMAKE_SOURCE_DIR}/Plugins/Engine/PluginsJob.cpp diff -r 628edb487cec -r 705343f27dab OrthancServer/Plugins/Engine/OrthancPlugins.cpp --- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Wed Jun 11 17:51:11 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Thu Jun 12 09:55:38 2025 +0200 @@ -65,6 +65,7 @@ #include "OrthancPluginDatabase.h" #include "OrthancPluginDatabaseV3.h" #include "OrthancPluginDatabaseV4.h" +#include "PluginMemoryBuffer32.h" #include "PluginsEnumerations.h" #include "PluginsJob.h" @@ -506,51 +507,6 @@ namespace { - class MemoryBufferRaii : public boost::noncopyable - { - private: - OrthancPluginMemoryBuffer buffer_; - - public: - MemoryBufferRaii() - { - buffer_.size = 0; - buffer_.data = NULL; - } - - ~MemoryBufferRaii() - { - if (buffer_.size != 0) - { - free(buffer_.data); - } - } - - OrthancPluginMemoryBuffer* GetObject() - { - return &buffer_; - } - - void ToString(std::string& target) const - { - if ((buffer_.data == NULL && buffer_.size != 0) || - (buffer_.data != NULL && buffer_.size == 0)) - { - throw OrthancException(ErrorCode_Plugin); - } - else - { - target.resize(buffer_.size); - - if (buffer_.size != 0) - { - memcpy(&target[0], buffer_.data, buffer_.size); - } - } - } - }; - - class StorageAreaBase : public IStorageArea { private: @@ -6499,13 +6455,13 @@ transcoder = pimpl_->transcoderCallbacks_.begin(); transcoder != pimpl_->transcoderCallbacks_.end(); ++transcoder) { - MemoryBufferRaii a; + PluginMemoryBuffer32 a; if ((*transcoder) (a.GetObject(), buffer, size, uids.empty() ? NULL : &uids[0], static_cast(uids.size()), allowNewSopInstanceUid) == OrthancPluginErrorCode_Success) { - a.ToString(target); + a.MoveToString(target); return true; } } diff -r 628edb487cec -r 705343f27dab OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.cpp Thu Jun 12 09:55:38 2025 +0200 @@ -0,0 +1,106 @@ +/** + * 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 . + **/ + + +#include "../../Sources/PrecompiledHeadersServer.h" +#include "PluginMemoryBuffer32.h" + +#include "../../../OrthancFramework/Sources/OrthancException.h" +#include "../../../OrthancFramework/Sources/Toolbox.h" + + +namespace Orthanc +{ + void PluginMemoryBuffer32::Clear() + { + if (buffer_.size != 0) + { + ::free(buffer_.data); + } + } + + + void PluginMemoryBuffer32::SanityCheck() const + { + if ((buffer_.data == NULL && buffer_.size != 0) || + (buffer_.data != NULL && buffer_.size == 0)) + { + throw OrthancException(ErrorCode_Plugin); + } + } + + + PluginMemoryBuffer32::PluginMemoryBuffer32() + { + buffer_.size = 0; + buffer_.data = NULL; + } + + + void PluginMemoryBuffer32::MoveToString(std::string& target) + { + SanityCheck(); + + target.resize(buffer_.size); + + if (buffer_.size != 0) + { + memcpy(&target[0], buffer_.data, buffer_.size); + } + + Clear(); + } + + + const void* PluginMemoryBuffer32::GetData() const + { + SanityCheck(); + + if (buffer_.size == 0) + { + return NULL; + } + else + { + return buffer_.data; + } + } + + + size_t PluginMemoryBuffer32::GetSize() const + { + SanityCheck(); + return buffer_.size; + } + + + void PluginMemoryBuffer32::ToJsonObject(Json::Value& target) const + { + SanityCheck(); + + if (!Toolbox::ReadJson(target, buffer_.data, buffer_.size) || + target.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_Plugin, "The plugin has not provided a valid JSON object"); + } + } +} diff -r 628edb487cec -r 705343f27dab OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/Plugins/Engine/PluginMemoryBuffer32.h Thu Jun 12 09:55:38 2025 +0200 @@ -0,0 +1,67 @@ +/** + * 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 . + **/ + + +#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 + +namespace Orthanc +{ + class PluginMemoryBuffer32 : public IMemoryBuffer + { + private: + OrthancPluginMemoryBuffer buffer_; + + void Clear(); + + void SanityCheck() const; + + public: + PluginMemoryBuffer32(); + + virtual ~PluginMemoryBuffer32() + { + Clear(); + } + + virtual void MoveToString(std::string& target) ORTHANC_OVERRIDE; + + virtual const void* GetData() const ORTHANC_OVERRIDE; + + virtual size_t GetSize() const ORTHANC_OVERRIDE; + + OrthancPluginMemoryBuffer* GetObject() + { + return &buffer_; + } + + void ToJsonObject(Json::Value& target) const; + }; +} diff -r 628edb487cec -r 705343f27dab OrthancServer/Plugins/Engine/PluginsJob.cpp --- a/OrthancServer/Plugins/Engine/PluginsJob.cpp Wed Jun 11 17:51:11 2025 +0200 +++ b/OrthancServer/Plugins/Engine/PluginsJob.cpp Thu Jun 12 09:55:38 2025 +0200 @@ -32,6 +32,7 @@ #include "../../../OrthancFramework/Sources/Logging.h" #include "../../../OrthancFramework/Sources/OrthancException.h" #include "../../../OrthancFramework/Sources/Toolbox.h" +#include "PluginMemoryBuffer32.h" #include @@ -152,53 +153,11 @@ return parameters_.getProgress(parameters_.job); } - - namespace - { - class MemoryBufferRaii : public boost::noncopyable - { - private: - OrthancPluginMemoryBuffer buffer_; - - public: - MemoryBufferRaii() - { - buffer_.size = 0; - buffer_.data = NULL; - } - - ~MemoryBufferRaii() - { - if (buffer_.size != 0) - { - free(buffer_.data); - } - } - - OrthancPluginMemoryBuffer* GetObject() - { - return &buffer_; - } - - void ToJsonObject(Json::Value& target) const - { - if ((buffer_.data == NULL && buffer_.size != 0) || - (buffer_.data != NULL && buffer_.size == 0) || - !Toolbox::ReadJson(target, buffer_.data, buffer_.size) || - target.type() != Json::objectValue) - { - throw OrthancException(ErrorCode_Plugin, - "A job plugin must provide a JSON object as its public content and as its serialization"); - } - } - }; - } - void PluginsJob::GetPublicContent(Json::Value& value) const { if (parameters_.getContent != NULL) { - MemoryBufferRaii target; + PluginMemoryBuffer32 target; OrthancPluginErrorCode code = parameters_.getContent(target.GetObject(), parameters_.job); @@ -236,7 +195,7 @@ { if (parameters_.getSerialized != NULL) { - MemoryBufferRaii target; + PluginMemoryBuffer32 target; int32_t code = parameters_.getContent(target.GetObject(), parameters_.job);