# HG changeset patch # User Sebastien Jodogne # Date 1581586950 -3600 # Node ID 4c1d2ff7ddd0870a7a4950d5b7be8a6b26abe1a7 # Parent 85acfcc15829fe2918d1098c5bddeb2f20568297 handling of errors in storage commitment plugin factory diff -r 85acfcc15829 -r 4c1d2ff7ddd0 OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp --- 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 diff -r 85acfcc15829 -r 4c1d2ff7ddd0 Plugins/Engine/OrthancPlugins.cpp --- 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(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(n), + remoteAet.c_str(), calledAet.c_str()); + + if (error != OrthancPluginErrorCode_Success) { + throw OrthancException(static_cast(error)); + } + else if (handler == NULL) + { + // This plugin won't handle this storage commitment request return NULL; } else diff -r 85acfcc15829 -r 4c1d2ff7ddd0 Plugins/Include/orthanc/OrthancCPlugin.h --- 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, diff -r 85acfcc15829 -r 4c1d2ff7ddd0 Plugins/Samples/StorageCommitmentScp/Plugin.cpp --- 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; }