Mercurial > hg > orthanc
changeset 3665:4c1d2ff7ddd0 storage-commitment
handling of errors in storage commitment plugin factory
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Feb 2020 10:42:30 +0100 |
parents | 85acfcc15829 |
children | 6e5b3ae8825c |
files | OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Samples/StorageCommitmentScp/Plugin.cpp |
diffstat | 4 files changed, 37 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp Wed Feb 12 16:06:58 2020 +0100 +++ b/OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp Thu Feb 13 10:42:30 2020 +0100 @@ -118,16 +118,9 @@ virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE { - if (hasFailureReason_) - { - throw OrthancException(ErrorCode_BadSequenceOfCalls); - } - else - { - failureReason_ = that_.Lookup(index_); - hasFailureReason_ = true; - return true; - } + failureReason_ = that_.Lookup(index_); + hasFailureReason_ = true; + return true; } size_t GetIndex() const
--- a/Plugins/Engine/OrthancPlugins.cpp Wed Feb 12 16:06:58 2020 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Feb 13 10:42:30 2020 +0100 @@ -763,12 +763,19 @@ b[i] = sopInstanceUids[i].c_str(); } - void* handler = parameters_.factory(jobId.c_str(), transactionUid.c_str(), - a.empty() ? NULL : &a[0], b.empty() ? NULL : &b[0], - static_cast<uint32_t>(n), - remoteAet.c_str(), calledAet.c_str()); - if (handler == NULL) + void* handler = NULL; + OrthancPluginErrorCode error = parameters_.factory( + &handler, jobId.c_str(), transactionUid.c_str(), + a.empty() ? NULL : &a[0], b.empty() ? NULL : &b[0], static_cast<uint32_t>(n), + remoteAet.c_str(), calledAet.c_str()); + + if (error != OrthancPluginErrorCode_Success) { + throw OrthancException(static_cast<ErrorCode>(error)); + } + else if (handler == NULL) + { + // This plugin won't handle this storage commitment request return NULL; } else
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Wed Feb 12 16:06:58 2020 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Feb 13 10:42:30 2020 +0100 @@ -128,11 +128,11 @@ #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 && \ +#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 @@ -7300,7 +7300,8 @@ - typedef void* (*OrthancPluginStorageCommitmentFactory) ( + typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentFactory) ( + void** handler /* out */, const char* jobId, const char* transactionUid, const char* const* sopClassUids,
--- a/Plugins/Samples/StorageCommitmentScp/Plugin.cpp Wed Feb 12 16:06:58 2020 +0100 +++ b/Plugins/Samples/StorageCommitmentScp/Plugin.cpp Thu Feb 13 10:42:30 2020 +0100 @@ -48,13 +48,14 @@ }; -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) +static OrthancPluginErrorCode StorageCommitmentScp(void** handler /* out */, + 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); @@ -62,8 +63,9 @@ { printf("++ [%s] [%s]\n", sopClassUids[i], sopInstanceUids[i]); } - - return new StorageCommitmentSample; + + *handler = new StorageCommitmentSample; + return OrthancPluginErrorCode_Success; } @@ -84,9 +86,10 @@ OrthancPluginSetDescription(c, "Sample storage commitment SCP plugin."); - OrthancPluginRegisterStorageCommitmentScpCallback(c, StorageCommitmentScp, - OrthancPlugins::IStorageCommitmentScpHandler::Destructor, - OrthancPlugins::IStorageCommitmentScpHandler::Lookup); + OrthancPluginRegisterStorageCommitmentScpCallback( + c, StorageCommitmentScp, + OrthancPlugins::IStorageCommitmentScpHandler::Destructor, + OrthancPlugins::IStorageCommitmentScpHandler::Lookup); return 0; }