Mercurial > hg > orthanc
changeset 1629:bad4772b605c
OrthancPluginErrorCode in database plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 17:45:59 +0200 |
parents | 77c4cc4def0f |
children | ffd23c0104af |
files | Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Include/orthanc/OrthancCDatabasePlugin.h Plugins/Include/orthanc/OrthancCPlugin.h Plugins/Include/orthanc/OrthancCppDatabasePlugin.h |
diffstat | 4 files changed, 697 insertions(+), 380 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Fri Sep 18 16:46:35 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Fri Sep 18 17:45:59 2015 +0200 @@ -35,6 +35,7 @@ #include "../../Core/OrthancException.h" #include "../../Core/Logging.h" +#include "PluginsEnumerations.h" #include <cassert> @@ -224,9 +225,11 @@ tmp.compressedSize = attachment.GetCompressedSize(); tmp.compressedHash = attachment.GetCompressedMD5().c_str(); - if (backend_.addAttachment(payload_, id, &tmp) != 0) + OrthancPluginErrorCode error = backend_.addAttachment(payload_, id, &tmp); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -234,27 +237,33 @@ void OrthancPluginDatabase::AttachChild(int64_t parent, int64_t child) { - if (backend_.attachChild(payload_, parent, child) != 0) + OrthancPluginErrorCode error = backend_.attachChild(payload_, parent, child); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } void OrthancPluginDatabase::ClearChanges() { - if (backend_.clearChanges(payload_) != 0) + OrthancPluginErrorCode error = backend_.clearChanges(payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } void OrthancPluginDatabase::ClearExportedResources() { - if (backend_.clearExportedResources(payload_) != 0) + OrthancPluginErrorCode error = backend_.clearExportedResources(payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -264,9 +273,11 @@ { int64_t id; - if (backend_.createResource(&id, payload_, publicId.c_str(), Convert(type)) != 0) + OrthancPluginErrorCode error = backend_.createResource(&id, payload_, publicId.c_str(), Convert(type)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return id; @@ -276,9 +287,11 @@ void OrthancPluginDatabase::DeleteAttachment(int64_t id, FileContentType attachment) { - if (backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment)) != 0) + OrthancPluginErrorCode error = backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -286,18 +299,22 @@ void OrthancPluginDatabase::DeleteMetadata(int64_t id, MetadataType type) { - if (backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type)) != 0) + OrthancPluginErrorCode error = backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } void OrthancPluginDatabase::DeleteResource(int64_t id) { - if (backend_.deleteResource(payload_, id) != 0) + OrthancPluginErrorCode error = backend_.deleteResource(payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -329,9 +346,11 @@ { ResetAnswers(); - if (backend_.getAllPublicIds(GetContext(), payload_, Convert(resourceType)) != 0) + OrthancPluginErrorCode error = backend_.getAllPublicIds(GetContext(), payload_, Convert(resourceType)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -348,9 +367,12 @@ // This extension is available since Orthanc 0.9.4 ResetAnswers(); - if (extensions_.getAllPublicIdsWithLimit(GetContext(), payload_, Convert(resourceType), since, limit) != 0) + OrthancPluginErrorCode error = extensions_.getAllPublicIdsWithLimit + (GetContext(), payload_, Convert(resourceType), since, limit); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -399,9 +421,11 @@ answerDone_ = &done; done = false; - if (backend_.getChanges(GetContext(), payload_, since, maxResults) != 0) + OrthancPluginErrorCode error = backend_.getChanges(GetContext(), payload_, since, maxResults); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -411,9 +435,11 @@ { ResetAnswers(); - if (backend_.getChildrenInternalId(GetContext(), payload_, id) != 0) + OrthancPluginErrorCode error = backend_.getChildrenInternalId(GetContext(), payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -425,9 +451,11 @@ { ResetAnswers(); - if (backend_.getChildrenPublicId(GetContext(), payload_, id) != 0) + OrthancPluginErrorCode error = backend_.getChildrenPublicId(GetContext(), payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -444,9 +472,11 @@ answerDone_ = &done; done = false; - if (backend_.getExportedResources(GetContext(), payload_, since, maxResults) != 0) + OrthancPluginErrorCode error = backend_.getExportedResources(GetContext(), payload_, since, maxResults); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -459,9 +489,11 @@ answerChanges_ = ⌖ answerDone_ = &ignored; - if (backend_.getLastChange(GetContext(), payload_) != 0) + OrthancPluginErrorCode error = backend_.getLastChange(GetContext(), payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -474,9 +506,11 @@ answerExportedResources_ = ⌖ answerDone_ = &ignored; - if (backend_.getLastExportedResource(GetContext(), payload_) != 0) + OrthancPluginErrorCode error = backend_.getLastExportedResource(GetContext(), payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -487,9 +521,11 @@ ResetAnswers(); answerDicomMap_ = ↦ - if (backend_.getMainDicomTags(GetContext(), payload_, id) != 0) + OrthancPluginErrorCode error = backend_.getMainDicomTags(GetContext(), payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -499,8 +535,14 @@ ResetAnswers(); std::string s; - if (backend_.getPublicId(GetContext(), payload_, resourceId) != 0 || - !ForwardSingleAnswer(s)) + OrthancPluginErrorCode error = backend_.getPublicId(GetContext(), payload_, resourceId); + + if (error != OrthancPluginErrorCode_Success) + { + throw OrthancException(Plugins::Convert(error)); + } + + if (!ForwardSingleAnswer(s)) { throw OrthancException(ErrorCode_Plugin); } @@ -513,9 +555,11 @@ { uint64_t count; - if (backend_.getResourceCount(&count, payload_, Convert(resourceType)) != 0) + OrthancPluginErrorCode error = backend_.getResourceCount(&count, payload_, Convert(resourceType)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return count; @@ -526,9 +570,11 @@ { OrthancPluginResourceType type; - if (backend_.getResourceType(&type, payload_, resourceId) != 0) + OrthancPluginErrorCode error = backend_.getResourceType(&type, payload_, resourceId); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return Convert(type); @@ -539,9 +585,11 @@ { uint64_t size; - if (backend_.getTotalCompressedSize(&size, payload_) != 0) + OrthancPluginErrorCode error = backend_.getTotalCompressedSize(&size, payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return size; @@ -552,9 +600,11 @@ { uint64_t size; - if (backend_.getTotalUncompressedSize(&size, payload_) != 0) + OrthancPluginErrorCode error = backend_.getTotalUncompressedSize(&size, payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return size; @@ -565,9 +615,11 @@ { int32_t existing; - if (backend_.isExistingResource(&existing, payload_, internalId) != 0) + OrthancPluginErrorCode error = backend_.isExistingResource(&existing, payload_, internalId); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return (existing != 0); @@ -578,9 +630,11 @@ { int32_t isProtected; - if (backend_.isProtectedPatient(&isProtected, payload_, internalId) != 0) + OrthancPluginErrorCode error = backend_.isProtectedPatient(&isProtected, payload_, internalId); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return (isProtected != 0); @@ -592,9 +646,11 @@ { ResetAnswers(); - if (backend_.listAvailableMetadata(GetContext(), payload_, id) != 0) + OrthancPluginErrorCode error = backend_.listAvailableMetadata(GetContext(), payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } if (type_ != _OrthancPluginDatabaseAnswerType_None && @@ -621,9 +677,11 @@ { ResetAnswers(); - if (backend_.listAvailableAttachments(GetContext(), payload_, id) != 0) + OrthancPluginErrorCode error = backend_.listAvailableAttachments(GetContext(), payload_, id); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } if (type_ != _OrthancPluginDatabaseAnswerType_None && @@ -655,9 +713,11 @@ tmp.publicId = change.GetPublicId().c_str(); tmp.date = change.GetDate().c_str(); - if (backend_.logChange(payload_, &tmp) != 0) + OrthancPluginErrorCode error = backend_.logChange(payload_, &tmp); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -675,9 +735,11 @@ tmp.seriesInstanceUid = resource.GetSeriesInstanceUid().c_str(); tmp.sopInstanceUid = resource.GetSopInstanceUid().c_str(); - if (backend_.logExportedResource(payload_, &tmp) != 0) + OrthancPluginErrorCode error = backend_.logExportedResource(payload_, &tmp); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -688,9 +750,12 @@ { ResetAnswers(); - if (backend_.lookupAttachment(GetContext(), payload_, id, static_cast<int32_t>(contentType))) + OrthancPluginErrorCode error = backend_.lookupAttachment + (GetContext(), payload_, id, static_cast<int32_t>(contentType)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } if (type_ == _OrthancPluginDatabaseAnswerType_None) @@ -715,10 +780,12 @@ { ResetAnswers(); - if (backend_.lookupGlobalProperty(GetContext(), payload_, - static_cast<int32_t>(property))) + OrthancPluginErrorCode error = backend_.lookupGlobalProperty + (GetContext(), payload_, static_cast<int32_t>(property)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return ForwardSingleAnswer(target); @@ -736,9 +803,11 @@ tmp.element = tag.GetElement(); tmp.value = value.c_str(); - if (backend_.lookupIdentifier(GetContext(), payload_, &tmp) != 0) + OrthancPluginErrorCode error = backend_.lookupIdentifier(GetContext(), payload_, &tmp); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -750,9 +819,11 @@ { ResetAnswers(); - if (backend_.lookupIdentifier2(GetContext(), payload_, value.c_str()) != 0) + OrthancPluginErrorCode error = backend_.lookupIdentifier2(GetContext(), payload_, value.c_str()); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } ForwardAnswers(target); @@ -765,9 +836,11 @@ { ResetAnswers(); - if (backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type))) + OrthancPluginErrorCode error = backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return ForwardSingleAnswer(target); @@ -779,9 +852,11 @@ { ResetAnswers(); - if (backend_.lookupParent(GetContext(), payload_, resourceId)) + OrthancPluginErrorCode error = backend_.lookupParent(GetContext(), payload_, resourceId); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return ForwardSingleAnswer(parentId); @@ -794,9 +869,11 @@ { ResetAnswers(); - if (backend_.lookupResource(GetContext(), payload_, publicId.c_str())) + OrthancPluginErrorCode error = backend_.lookupResource(GetContext(), payload_, publicId.c_str()); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } if (type_ == _OrthancPluginDatabaseAnswerType_None) @@ -821,9 +898,11 @@ { ResetAnswers(); - if (backend_.selectPatientToRecycle(GetContext(), payload_)) + OrthancPluginErrorCode error = backend_.selectPatientToRecycle(GetContext(), payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return ForwardSingleAnswer(internalId); @@ -835,9 +914,11 @@ { ResetAnswers(); - if (backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid)) + OrthancPluginErrorCode error = backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return ForwardSingleAnswer(internalId); @@ -847,10 +928,12 @@ void OrthancPluginDatabase::SetGlobalProperty(GlobalProperty property, const std::string& value) { - if (backend_.setGlobalProperty(payload_, static_cast<int32_t>(property), - value.c_str()) != 0) + OrthancPluginErrorCode error = backend_.setGlobalProperty + (payload_, static_cast<int32_t>(property), value.c_str()); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -859,24 +942,25 @@ const DicomTag& tag, const std::string& value) { - int32_t status; OrthancPluginDicomTag tmp; tmp.group = tag.GetGroup(); tmp.element = tag.GetElement(); tmp.value = value.c_str(); + OrthancPluginErrorCode error; + if (tag.IsIdentifier()) { - status = backend_.setIdentifierTag(payload_, id, &tmp); + error = backend_.setIdentifierTag(payload_, id, &tmp); } else { - status = backend_.setMainDicomTag(payload_, id, &tmp); + error = backend_.setMainDicomTag(payload_, id, &tmp); } - if (status != 0) + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -885,10 +969,12 @@ MetadataType type, const std::string& value) { - if (backend_.setMetadata(payload_, id, static_cast<int32_t>(type), - value.c_str()) != 0) + OrthancPluginErrorCode error = backend_.setMetadata + (payload_, id, static_cast<int32_t>(type), value.c_str()); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -896,9 +982,11 @@ void OrthancPluginDatabase::SetProtectedPatient(int64_t internalId, bool isProtected) { - if (backend_.setProtectedPatient(payload_, internalId, isProtected) != 0) + OrthancPluginErrorCode error = backend_.setProtectedPatient(payload_, internalId, isProtected); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } @@ -919,25 +1007,31 @@ virtual void Begin() { - if (backend_.startTransaction(payload_) != 0) + OrthancPluginErrorCode error = backend_.startTransaction(payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } virtual void Rollback() { - if (backend_.rollbackTransaction(payload_) != 0) + OrthancPluginErrorCode error = backend_.rollbackTransaction(payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } virtual void Commit() { - if (backend_.commitTransaction(payload_) != 0) + OrthancPluginErrorCode error = backend_.commitTransaction(payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } }; @@ -988,9 +1082,11 @@ if (extensions_.getDatabaseVersion != NULL) { uint32_t version; - if (extensions_.getDatabaseVersion(&version, payload_) != 0) + OrthancPluginErrorCode error = extensions_.getDatabaseVersion(&version, payload_); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } return version; @@ -1010,11 +1106,13 @@ { if (extensions_.upgradeDatabase != NULL) { - if (extensions_.upgradeDatabase( - payload_, targetVersion, - reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)) != 0) + OrthancPluginErrorCode error = extensions_.upgradeDatabase( + payload_, targetVersion, + reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); + + if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(ErrorCode_Plugin); + throw OrthancException(Plugins::Convert(error)); } } }
--- a/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Fri Sep 18 16:46:35 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCDatabasePlugin.h Fri Sep 18 17:45:59 2015 +0200 @@ -320,27 +320,27 @@ typedef struct { - int32_t (*addAttachment) ( + OrthancPluginErrorCode (*addAttachment) ( /* inputs */ void* payload, int64_t id, const OrthancPluginAttachment* attachment); - int32_t (*attachChild) ( + OrthancPluginErrorCode (*attachChild) ( /* inputs */ void* payload, int64_t parent, int64_t child); - int32_t (*clearChanges) ( + OrthancPluginErrorCode (*clearChanges) ( /* inputs */ void* payload); - int32_t (*clearExportedResources) ( + OrthancPluginErrorCode (*clearExportedResources) ( /* inputs */ void* payload); - int32_t (*createResource) ( + OrthancPluginErrorCode (*createResource) ( /* outputs */ int64_t* id, /* inputs */ @@ -348,25 +348,25 @@ const char* publicId, OrthancPluginResourceType resourceType); - int32_t (*deleteAttachment) ( + OrthancPluginErrorCode (*deleteAttachment) ( /* inputs */ void* payload, int64_t id, int32_t contentType); - int32_t (*deleteMetadata) ( + OrthancPluginErrorCode (*deleteMetadata) ( /* inputs */ void* payload, int64_t id, int32_t metadataType); - int32_t (*deleteResource) ( + OrthancPluginErrorCode (*deleteResource) ( /* inputs */ void* payload, int64_t id); /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*getAllPublicIds) ( + OrthancPluginErrorCode (*getAllPublicIds) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -375,7 +375,7 @@ /* Output: Use OrthancPluginDatabaseAnswerChange() and * OrthancPluginDatabaseAnswerChangesDone() */ - int32_t (*getChanges) ( + OrthancPluginErrorCode (*getChanges) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -384,7 +384,7 @@ uint32_t maxResult); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*getChildrenInternalId) ( + OrthancPluginErrorCode (*getChildrenInternalId) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -392,7 +392,7 @@ int64_t id); /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*getChildrenPublicId) ( + OrthancPluginErrorCode (*getChildrenPublicId) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -401,7 +401,7 @@ /* Output: Use OrthancPluginDatabaseAnswerExportedResource() and * OrthancPluginDatabaseAnswerExportedResourcesDone() */ - int32_t (*getExportedResources) ( + OrthancPluginErrorCode (*getExportedResources) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -410,21 +410,21 @@ uint32_t maxResult); /* Output: Use OrthancPluginDatabaseAnswerChange() */ - int32_t (*getLastChange) ( + OrthancPluginErrorCode (*getLastChange) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload); /* Output: Use OrthancPluginDatabaseAnswerExportedResource() */ - int32_t (*getLastExportedResource) ( + OrthancPluginErrorCode (*getLastExportedResource) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload); /* Output: Use OrthancPluginDatabaseAnswerDicomTag() */ - int32_t (*getMainDicomTags) ( + OrthancPluginErrorCode (*getMainDicomTags) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -432,47 +432,47 @@ int64_t id); /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*getPublicId) ( + OrthancPluginErrorCode (*getPublicId) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload, int64_t id); - int32_t (*getResourceCount) ( + OrthancPluginErrorCode (*getResourceCount) ( /* outputs */ uint64_t* target, /* inputs */ void* payload, OrthancPluginResourceType resourceType); - int32_t (*getResourceType) ( + OrthancPluginErrorCode (*getResourceType) ( /* outputs */ OrthancPluginResourceType* resourceType, /* inputs */ void* payload, int64_t id); - int32_t (*getTotalCompressedSize) ( + OrthancPluginErrorCode (*getTotalCompressedSize) ( /* outputs */ uint64_t* target, /* inputs */ void* payload); - int32_t (*getTotalUncompressedSize) ( + OrthancPluginErrorCode (*getTotalUncompressedSize) ( /* outputs */ uint64_t* target, /* inputs */ void* payload); - int32_t (*isExistingResource) ( + OrthancPluginErrorCode (*isExistingResource) ( /* outputs */ int32_t* existing, /* inputs */ void* payload, int64_t id); - int32_t (*isProtectedPatient) ( + OrthancPluginErrorCode (*isProtectedPatient) ( /* outputs */ int32_t* isProtected, /* inputs */ @@ -480,7 +480,7 @@ int64_t id); /* Output: Use OrthancPluginDatabaseAnswerInt32() */ - int32_t (*listAvailableMetadata) ( + OrthancPluginErrorCode (*listAvailableMetadata) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -488,25 +488,25 @@ int64_t id); /* Output: Use OrthancPluginDatabaseAnswerInt32() */ - int32_t (*listAvailableAttachments) ( + OrthancPluginErrorCode (*listAvailableAttachments) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload, int64_t id); - int32_t (*logChange) ( + OrthancPluginErrorCode (*logChange) ( /* inputs */ void* payload, const OrthancPluginChange* change); - int32_t (*logExportedResource) ( + OrthancPluginErrorCode (*logExportedResource) ( /* inputs */ void* payload, const OrthancPluginExportedResource* exported); /* Output: Use OrthancPluginDatabaseAnswerAttachment() */ - int32_t (*lookupAttachment) ( + OrthancPluginErrorCode (*lookupAttachment) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -515,7 +515,7 @@ int32_t contentType); /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*lookupGlobalProperty) ( + OrthancPluginErrorCode (*lookupGlobalProperty) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -523,7 +523,7 @@ int32_t property); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*lookupIdentifier) ( + OrthancPluginErrorCode (*lookupIdentifier) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -531,7 +531,7 @@ const OrthancPluginDicomTag* tag); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*lookupIdentifier2) ( + OrthancPluginErrorCode (*lookupIdentifier2) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -539,7 +539,7 @@ const char* value); /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*lookupMetadata) ( + OrthancPluginErrorCode (*lookupMetadata) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -548,7 +548,7 @@ int32_t metadata); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*lookupParent) ( + OrthancPluginErrorCode (*lookupParent) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -556,7 +556,7 @@ int64_t id); /* Output: Use OrthancPluginDatabaseAnswerResource() */ - int32_t (*lookupResource) ( + OrthancPluginErrorCode (*lookupResource) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -564,68 +564,68 @@ const char* publicId); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*selectPatientToRecycle) ( + OrthancPluginErrorCode (*selectPatientToRecycle) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload); /* Output: Use OrthancPluginDatabaseAnswerInt64() */ - int32_t (*selectPatientToRecycle2) ( + OrthancPluginErrorCode (*selectPatientToRecycle2) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ void* payload, int64_t patientIdToAvoid); - int32_t (*setGlobalProperty) ( + OrthancPluginErrorCode (*setGlobalProperty) ( /* inputs */ void* payload, int32_t property, const char* value); - int32_t (*setMainDicomTag) ( + OrthancPluginErrorCode (*setMainDicomTag) ( /* inputs */ void* payload, int64_t id, const OrthancPluginDicomTag* tag); - int32_t (*setIdentifierTag) ( + OrthancPluginErrorCode (*setIdentifierTag) ( /* inputs */ void* payload, int64_t id, const OrthancPluginDicomTag* tag); - int32_t (*setMetadata) ( + OrthancPluginErrorCode (*setMetadata) ( /* inputs */ void* payload, int64_t id, int32_t metadata, const char* value); - int32_t (*setProtectedPatient) ( + OrthancPluginErrorCode (*setProtectedPatient) ( /* inputs */ void* payload, int64_t id, int32_t isProtected); - int32_t (*startTransaction) ( + OrthancPluginErrorCode (*startTransaction) ( /* inputs */ void* payload); - int32_t (*rollbackTransaction) ( + OrthancPluginErrorCode (*rollbackTransaction) ( /* inputs */ void* payload); - int32_t (*commitTransaction) ( + OrthancPluginErrorCode (*commitTransaction) ( /* inputs */ void* payload); - int32_t (*open) ( + OrthancPluginErrorCode (*open) ( /* inputs */ void* payload); - int32_t (*close) ( + OrthancPluginErrorCode (*close) ( /* inputs */ void* payload); @@ -635,7 +635,7 @@ typedef struct { /* Output: Use OrthancPluginDatabaseAnswerString() */ - int32_t (*getAllPublicIdsWithLimit) ( + OrthancPluginErrorCode (*getAllPublicIdsWithLimit) ( /* outputs */ OrthancPluginDatabaseContext* context, /* inputs */ @@ -644,13 +644,13 @@ uint64_t since, uint64_t limit); - int32_t (*getDatabaseVersion) ( + OrthancPluginErrorCode (*getDatabaseVersion) ( /* outputs */ uint32_t* version, /* inputs */ void* payload); - int32_t (*upgradeDatabase) ( + OrthancPluginErrorCode (*upgradeDatabase) ( /* inputs */ void* payload, uint32_t targetVersion,
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Fri Sep 18 16:46:35 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Fri Sep 18 17:45:59 2015 +0200 @@ -109,7 +109,7 @@ #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 0 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 9 -#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 4 +#define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 5
--- a/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Fri Sep 18 16:46:35 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCppDatabasePlugin.h Fri Sep 18 17:45:59 2015 +0200 @@ -62,6 +62,29 @@ //! @endcond + /** + * @ingroup Callbacks + **/ + class DatabaseException + { + private: + OrthancPluginErrorCode code_; + + public: + DatabaseException() : code_(OrthancPluginErrorCode_Plugin) + { + } + + DatabaseException(OrthancPluginErrorCode code) : code_(code) + { + } + + OrthancPluginErrorCode GetErrorCode() const + { + return code_; + } + }; + /** * @ingroup Callbacks @@ -463,9 +486,9 @@ } - static int32_t AddAttachment(void* payload, - int64_t id, - const OrthancPluginAttachment* attachment) + static OrthancPluginErrorCode AddAttachment(void* payload, + int64_t id, + const OrthancPluginAttachment* attachment) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -473,19 +496,23 @@ try { backend->AddAttachment(id, *attachment); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t AttachChild(void* payload, - int64_t parent, - int64_t child) + static OrthancPluginErrorCode AttachChild(void* payload, + int64_t parent, + int64_t child) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -493,17 +520,21 @@ try { backend->AttachChild(parent, child); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t ClearChanges(void* payload) + static OrthancPluginErrorCode ClearChanges(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -511,17 +542,21 @@ try { backend->ClearChanges(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t ClearExportedResources(void* payload) + static OrthancPluginErrorCode ClearExportedResources(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -529,20 +564,24 @@ try { backend->ClearExportedResources(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t CreateResource(int64_t* id, - void* payload, - const char* publicId, - OrthancPluginResourceType resourceType) + static OrthancPluginErrorCode CreateResource(int64_t* id, + void* payload, + const char* publicId, + OrthancPluginResourceType resourceType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -550,19 +589,23 @@ try { *id = backend->CreateResource(publicId, resourceType); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t DeleteAttachment(void* payload, - int64_t id, - int32_t contentType) + static OrthancPluginErrorCode DeleteAttachment(void* payload, + int64_t id, + int32_t contentType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -570,19 +613,23 @@ try { backend->DeleteAttachment(id, contentType); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t DeleteMetadata(void* payload, - int64_t id, - int32_t metadataType) + static OrthancPluginErrorCode DeleteMetadata(void* payload, + int64_t id, + int32_t metadataType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -590,18 +637,22 @@ try { backend->DeleteMetadata(id, metadataType); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t DeleteResource(void* payload, - int64_t id) + static OrthancPluginErrorCode DeleteResource(void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -609,19 +660,23 @@ try { backend->DeleteResource(id); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetAllPublicIds(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType) + static OrthancPluginErrorCode GetAllPublicIds(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -639,21 +694,25 @@ it->c_str()); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetAllPublicIdsWithLimit(OrthancPluginDatabaseContext* context, - void* payload, - OrthancPluginResourceType resourceType, - uint64_t since, - uint64_t limit) + static OrthancPluginErrorCode GetAllPublicIdsWithLimit(OrthancPluginDatabaseContext* context, + void* payload, + OrthancPluginResourceType resourceType, + uint64_t since, + uint64_t limit) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -671,20 +730,24 @@ it->c_str()); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetChanges(OrthancPluginDatabaseContext* context, - void* payload, - int64_t since, - uint32_t maxResult) + static OrthancPluginErrorCode GetChanges(OrthancPluginDatabaseContext* context, + void* payload, + int64_t since, + uint32_t maxResult) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); @@ -700,19 +763,23 @@ backend->GetOutput().database_); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetChildrenInternalId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode GetChildrenInternalId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -729,19 +796,23 @@ backend->GetOutput().database_, *it); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetChildrenPublicId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode GetChildrenPublicId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -759,20 +830,24 @@ it->c_str()); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetExportedResources(OrthancPluginDatabaseContext* context, - void* payload, - int64_t since, - uint32_t maxResult) + static OrthancPluginErrorCode GetExportedResources(OrthancPluginDatabaseContext* context, + void* payload, + int64_t since, + uint32_t maxResult) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); @@ -787,18 +862,22 @@ OrthancPluginDatabaseAnswerExportedResourcesDone(backend->GetOutput().context_, backend->GetOutput().database_); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetLastChange(OrthancPluginDatabaseContext* context, - void* payload) + static OrthancPluginErrorCode GetLastChange(OrthancPluginDatabaseContext* context, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Change); @@ -806,18 +885,22 @@ try { backend->GetLastChange(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetLastExportedResource(OrthancPluginDatabaseContext* context, - void* payload) + static OrthancPluginErrorCode GetLastExportedResource(OrthancPluginDatabaseContext* context, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_ExportedResource); @@ -825,19 +908,23 @@ try { backend->GetLastExportedResource(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetMainDicomTags(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode GetMainDicomTags(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_DicomTag); @@ -845,19 +932,23 @@ try { backend->GetMainDicomTags(id); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetPublicId(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode GetPublicId(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -869,19 +960,23 @@ backend->GetOutput().database_, s.c_str()); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetResourceCount(uint64_t* target, - void* payload, - OrthancPluginResourceType resourceType) + static OrthancPluginErrorCode GetResourceCount(uint64_t* target, + void* payload, + OrthancPluginResourceType resourceType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -889,19 +984,23 @@ try { *target = backend->GetResourceCount(resourceType); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetResourceType(OrthancPluginResourceType* resourceType, - void* payload, - int64_t id) + static OrthancPluginErrorCode GetResourceType(OrthancPluginResourceType* resourceType, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -909,18 +1008,22 @@ try { *resourceType = backend->GetResourceType(id); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetTotalCompressedSize(uint64_t* target, - void* payload) + static OrthancPluginErrorCode GetTotalCompressedSize(uint64_t* target, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -928,18 +1031,22 @@ try { *target = backend->GetTotalCompressedSize(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetTotalUncompressedSize(uint64_t* target, - void* payload) + static OrthancPluginErrorCode GetTotalUncompressedSize(uint64_t* target, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -947,19 +1054,23 @@ try { *target = backend->GetTotalUncompressedSize(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t IsExistingResource(int32_t* existing, - void* payload, - int64_t id) + static OrthancPluginErrorCode IsExistingResource(int32_t* existing, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -967,19 +1078,23 @@ try { *existing = backend->IsExistingResource(id); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t IsProtectedPatient(int32_t* isProtected, - void* payload, - int64_t id) + static OrthancPluginErrorCode IsProtectedPatient(int32_t* isProtected, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -987,19 +1102,23 @@ try { *isProtected = backend->IsProtectedPatient(id); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t ListAvailableMetadata(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode ListAvailableMetadata(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1017,19 +1136,23 @@ *it); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t ListAvailableAttachments(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode ListAvailableAttachments(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1047,18 +1170,22 @@ *it); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LogChange(void* payload, - const OrthancPluginChange* change) + static OrthancPluginErrorCode LogChange(void* payload, + const OrthancPluginChange* change) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1066,18 +1193,22 @@ try { backend->LogChange(*change); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LogExportedResource(void* payload, - const OrthancPluginExportedResource* exported) + static OrthancPluginErrorCode LogExportedResource(void* payload, + const OrthancPluginExportedResource* exported) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1085,20 +1216,24 @@ try { backend->LogExportedResource(*exported); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupAttachment(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id, - int32_t contentType) + static OrthancPluginErrorCode LookupAttachment(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id, + int32_t contentType) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_Attachment); @@ -1106,19 +1241,23 @@ try { backend->LookupAttachment(id, contentType); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupGlobalProperty(OrthancPluginDatabaseContext* context, - void* payload, - int32_t property) + static OrthancPluginErrorCode LookupGlobalProperty(OrthancPluginDatabaseContext* context, + void* payload, + int32_t property) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1133,19 +1272,23 @@ s.c_str()); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupIdentifier(OrthancPluginDatabaseContext* context, - void* payload, - const OrthancPluginDicomTag* tag) + static OrthancPluginErrorCode LookupIdentifier(OrthancPluginDatabaseContext* context, + void* payload, + const OrthancPluginDicomTag* tag) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1162,19 +1305,23 @@ backend->GetOutput().database_, *it); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupIdentifier2(OrthancPluginDatabaseContext* context, - void* payload, - const char* value) + static OrthancPluginErrorCode LookupIdentifier2(OrthancPluginDatabaseContext* context, + void* payload, + const char* value) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1191,20 +1338,24 @@ backend->GetOutput().database_, *it); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupMetadata(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id, - int32_t metadata) + static OrthancPluginErrorCode LookupMetadata(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id, + int32_t metadata) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1218,19 +1369,23 @@ backend->GetOutput().database_, s.c_str()); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupParent(OrthancPluginDatabaseContext* context, - void* payload, - int64_t id) + static OrthancPluginErrorCode LookupParent(OrthancPluginDatabaseContext* context, + void* payload, + int64_t id) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1244,19 +1399,23 @@ backend->GetOutput().database_, parent); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t LookupResource(OrthancPluginDatabaseContext* context, - void* payload, - const char* publicId) + static OrthancPluginErrorCode LookupResource(OrthancPluginDatabaseContext* context, + void* payload, + const char* publicId) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1272,18 +1431,22 @@ id, type); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SelectPatientToRecycle(OrthancPluginDatabaseContext* context, - void* payload) + static OrthancPluginErrorCode SelectPatientToRecycle(OrthancPluginDatabaseContext* context, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1297,19 +1460,23 @@ backend->GetOutput().database_, id); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SelectPatientToRecycle2(OrthancPluginDatabaseContext* context, - void* payload, - int64_t patientIdToAvoid) + static OrthancPluginErrorCode SelectPatientToRecycle2(OrthancPluginDatabaseContext* context, + void* payload, + int64_t patientIdToAvoid) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1323,19 +1490,23 @@ backend->GetOutput().database_, id); } - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SetGlobalProperty(void* payload, - int32_t property, - const char* value) + static OrthancPluginErrorCode SetGlobalProperty(void* payload, + int32_t property, + const char* value) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1343,19 +1514,23 @@ try { backend->SetGlobalProperty(property, value); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SetMainDicomTag(void* payload, - int64_t id, - const OrthancPluginDicomTag* tag) + static OrthancPluginErrorCode SetMainDicomTag(void* payload, + int64_t id, + const OrthancPluginDicomTag* tag) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1363,19 +1538,23 @@ try { backend->SetMainDicomTag(id, tag->group, tag->element, tag->value); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SetIdentifierTag(void* payload, - int64_t id, - const OrthancPluginDicomTag* tag) + static OrthancPluginErrorCode SetIdentifierTag(void* payload, + int64_t id, + const OrthancPluginDicomTag* tag) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1383,20 +1562,24 @@ try { backend->SetIdentifierTag(id, tag->group, tag->element, tag->value); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SetMetadata(void* payload, - int64_t id, - int32_t metadata, - const char* value) + static OrthancPluginErrorCode SetMetadata(void* payload, + int64_t id, + int32_t metadata, + const char* value) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1404,19 +1587,23 @@ try { backend->SetMetadata(id, metadata, value); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t SetProtectedPatient(void* payload, - int64_t id, - int32_t isProtected) + static OrthancPluginErrorCode SetProtectedPatient(void* payload, + int64_t id, + int32_t isProtected) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1424,17 +1611,21 @@ try { backend->SetProtectedPatient(id, (isProtected != 0)); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t StartTransaction(void* payload) + static OrthancPluginErrorCode StartTransaction(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1442,17 +1633,21 @@ try { backend->StartTransaction(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t RollbackTransaction(void* payload) + static OrthancPluginErrorCode RollbackTransaction(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1460,17 +1655,21 @@ try { backend->RollbackTransaction(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t CommitTransaction(void* payload) + static OrthancPluginErrorCode CommitTransaction(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1478,17 +1677,21 @@ try { backend->CommitTransaction(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t Open(void* payload) + static OrthancPluginErrorCode Open(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1496,17 +1699,21 @@ try { backend->Open(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t Close(void* payload) + static OrthancPluginErrorCode Close(void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None); @@ -1514,49 +1721,61 @@ try { backend->Close(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t GetDatabaseVersion(uint32_t* version, - void* payload) + static OrthancPluginErrorCode GetDatabaseVersion(uint32_t* version, + void* payload) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); try { *version = backend->GetDatabaseVersion(); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } } - static int32_t UpgradeDatabase(void* payload, - uint32_t targetVersion, - OrthancPluginStorageArea* storageArea) + static OrthancPluginErrorCode UpgradeDatabase(void* payload, + uint32_t targetVersion, + OrthancPluginStorageArea* storageArea) { IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload); try { backend->UpgradeDatabase(targetVersion, storageArea); - return 0; + return OrthancPluginErrorCode_Success; } catch (std::runtime_error& e) { LogError(backend, e); - return -1; + return OrthancPluginErrorCode_Plugin; + } + catch (DatabaseException& e) + { + return e.GetErrorCode(); } }