# HG changeset patch # User Sebastien Jodogne # Date 1581520018 -3600 # Node ID 85acfcc15829fe2918d1098c5bddeb2f20568297 # Parent d8371b4302ffd0e0e5e68ece6bf09a302acd10fc sample storage commitment plugin, C++ wrapper diff -r d8371b4302ff -r 85acfcc15829 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Tue Feb 11 19:59:53 2020 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Feb 12 16:06:58 2020 +0100 @@ -695,7 +695,8 @@ public: Handler(_OrthancPluginRegisterStorageCommitmentScpCallback parameters, void* handler) : - parameters_(parameters) + parameters_(parameters), + handler_(handler) { if (handler == NULL) { diff -r d8371b4302ff -r 85acfcc15829 Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue Feb 11 19:59:53 2020 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Wed Feb 12 16:06:58 2020 +0100 @@ -123,8 +123,8 @@ #endif #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1 -#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 5 -#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 7 +#define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 6 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 0 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) @@ -7304,7 +7304,7 @@ const char* jobId, const char* transactionUid, const char* const* sopClassUids, - const char* const* sopInstancesUids, + const char* const* sopInstanceUids, uint32_t countInstances, const char* remoteAet, const char* calledAet); diff -r d8371b4302ff -r 85acfcc15829 Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Tue Feb 11 19:59:53 2020 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Feb 12 16:06:58 2020 +0100 @@ -3036,4 +3036,41 @@ } #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 d8371b4302ff -r 85acfcc15829 Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Tue Feb 11 19:59:53 2020 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Feb 12 16:06:58 2020 +0100 @@ -103,6 +103,12 @@ # 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 @@ -1093,4 +1099,26 @@ #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 d8371b4302ff -r 85acfcc15829 Plugins/Samples/StorageCommitmentScp/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Samples/StorageCommitmentScp/CMakeLists.txt Wed Feb 12 16:06:58 2020 +0100 @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 2.8) + +project(StorageCommitmentScp) + +SET(PLUGIN_VERSION "0.0" CACHE STRING "Version of the plugin") +SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") +SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") + +SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") +SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of boost") + +set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..) +include(${SAMPLES_ROOT}/Common/OrthancPlugins.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) + +add_library(StorageCommitmentScp SHARED + Plugin.cpp + ../Common/OrthancPluginCppWrapper.cpp + ${JSONCPP_SOURCES} + ${BOOST_SOURCES} + ) + +message("Setting the version of the plugin to ${PLUGIN_VERSION}") +add_definitions( + -DPLUGIN_VERSION="${PLUGIN_VERSION}" + ) + +set_target_properties(StorageCommitmentScp PROPERTIES + VERSION ${PLUGIN_VERSION} + SOVERSION ${PLUGIN_VERSION}) + +install( + TARGETS StorageCommitmentScp + RUNTIME DESTINATION lib # Destination for Windows + LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux + ) diff -r d8371b4302ff -r 85acfcc15829 Plugins/Samples/StorageCommitmentScp/Plugin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Samples/StorageCommitmentScp/Plugin.cpp Wed Feb 12 16:06:58 2020 +0100 @@ -0,0 +1,110 @@ +/** + * 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. + * + * 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 "../Common/OrthancPluginCppWrapper.h" + +#include +#include + + + +class StorageCommitmentSample : public OrthancPlugins::IStorageCommitmentScpHandler +{ +private: + int count_; + +public: + StorageCommitmentSample() : count_(0) + { + } + + virtual OrthancPluginStorageCommitmentFailureReason Lookup(const std::string& sopClassUid, + const std::string& sopInstanceUid) + { + printf("?? [%s] [%s]\n", sopClassUid.c_str(), sopInstanceUid.c_str()); + if (count_++ % 2 == 0) + return OrthancPluginStorageCommitmentFailureReason_Success; + else + return OrthancPluginStorageCommitmentFailureReason_NoSuchObjectInstance; + } +}; + + +static void* StorageCommitmentScp(const char* jobId, + const char* transactionUid, + const char* const* sopClassUids, + const char* const* sopInstanceUids, + uint32_t countInstances, + const char* remoteAet, + const char* calledAet) +{ + printf("[%s] [%s] [%s] [%s]\n", jobId, transactionUid, remoteAet, calledAet); + + for (uint32_t i = 0; i < countInstances; i++) + { + printf("++ [%s] [%s]\n", sopClassUids[i], sopInstanceUids[i]); + } + + return new StorageCommitmentSample; +} + + +extern "C" +{ + ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) + { + OrthancPlugins::SetGlobalContext(c); + + /* Check the version of the Orthanc core */ + if (OrthancPluginCheckVersion(c) == 0) + { + OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); + return -1; + } + + OrthancPluginSetDescription(c, "Sample storage commitment SCP plugin."); + + OrthancPluginRegisterStorageCommitmentScpCallback(c, StorageCommitmentScp, + OrthancPlugins::IStorageCommitmentScpHandler::Destructor, + OrthancPlugins::IStorageCommitmentScpHandler::Lookup); + + return 0; + } + + + ORTHANC_PLUGINS_API void OrthancPluginFinalize() + { + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetName() + { + return "storage-commitment-scp"; + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() + { + return PLUGIN_VERSION; + } +}