Mercurial > hg > orthanc
changeset 6169:86a076ceaf3a attach-custom-data
refactoring OrthancPlugins.cpp
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Jun 2025 16:55:15 +0200 |
parents | dbe67b2c2d9c |
children | 9fce9208f24f |
files | OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Plugins/Engine/OrthancPlugins.h OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h |
diffstat | 7 files changed, 142 insertions(+), 170 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Wed Jun 11 16:55:15 2025 +0200 @@ -1061,11 +1061,11 @@ if (database_.GetDatabaseCapabilities().HasAttachmentCustomDataSupport()) { DatabasePluginMessages::TransactionRequest request; - request.mutable_update_attachment_custom_data()->set_uuid(attachmentUuid); - request.mutable_update_attachment_custom_data()->set_custom_data(customData, customDataSize); + request.mutable_set_attachment_custom_data()->set_uuid(attachmentUuid); + request.mutable_set_attachment_custom_data()->set_custom_data(customData, customDataSize); DatabasePluginMessages::TransactionResponse response; - ExecuteTransaction(response, DatabasePluginMessages::OPERATION_UPDATE_ATTACHMENT_CUSTOM_DATA, request); + ExecuteTransaction(response, DatabasePluginMessages::OPERATION_SET_ATTACHMENT_CUSTOM_DATA, request); } else {
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Wed Jun 11 16:55:15 2025 +0200 @@ -4682,9 +4682,20 @@ } } + static void CheckAttachmentCustomDataSupport(ServerContext& context) + { + if (!context.GetIndex().HasAttachmentCustomDataSupport()) + { + throw OrthancException(ErrorCode_NotImplemented, "The database engine does not support custom data for attachments"); + } + } + void OrthancPlugins::ApplyGetAttachmentCustomData(const _OrthancPluginGetAttachmentCustomData& parameters) { PImpl::ServerContextReference lock(*pimpl_); + + CheckAttachmentCustomDataSupport(lock.GetContext()); + FileInfo fileInfo; int64_t revision; @@ -4698,27 +4709,38 @@ } } - void OrthancPlugins::ApplyUpdateAttachmentCustomData(const _OrthancPluginUpdateAttachmentCustomData& parameters) + void OrthancPlugins::ApplySetAttachmentCustomData(const _OrthancPluginSetAttachmentCustomData& parameters) { PImpl::ServerContextReference lock(*pimpl_); - lock.GetContext().GetIndex().UpdateAttachmentCustomData(parameters.attachmentUuid, parameters.customData, parameters.customDataSize); + + CheckAttachmentCustomDataSupport(lock.GetContext()); + + lock.GetContext().GetIndex().SetAttachmentCustomData(parameters.attachmentUuid, parameters.customData, parameters.customDataSize); } - bool OrthancPlugins::HasKeyValueStoresSupport() + static void CheckKeyValueStoresSupport(ServerContext& context) { - PImpl::ServerContextReference lock(*pimpl_); - return lock.GetContext().GetIndex().HasKeyValueStoresSupport(); + if (!context.GetIndex().HasKeyValueStoresSupport()) + { + throw OrthancException(ErrorCode_NotImplemented, "The database engine does not support key-value stores"); + } } void OrthancPlugins::ApplyStoreKeyValue(const _OrthancPluginStoreKeyValue& parameters) { PImpl::ServerContextReference lock(*pimpl_); + + CheckKeyValueStoresSupport(lock.GetContext()); + lock.GetContext().GetIndex().StoreKeyValue(parameters.storeId, parameters.key, parameters.value, parameters.valueSize); } void OrthancPlugins::ApplyDeleteKeyValue(const _OrthancPluginDeleteKeyValue& parameters) { PImpl::ServerContextReference lock(*pimpl_); + + CheckKeyValueStoresSupport(lock.GetContext()); + lock.GetContext().GetIndex().DeleteKeyValue(parameters.storeId, parameters.key); } @@ -4726,6 +4748,8 @@ { PImpl::ServerContextReference lock(*pimpl_); + CheckKeyValueStoresSupport(lock.GetContext()); + std::string value; if (lock.GetContext().GetIndex().GetKeyValue(value, parameters.storeId, parameters.key)) @@ -4739,15 +4763,30 @@ } } - bool OrthancPlugins::HasQueuesSupport() + void OrthancPlugins::ApplyCreateKeysValuesIterator(const _OrthancPluginCreateKeysValuesIterator& parameters) { PImpl::ServerContextReference lock(*pimpl_); - return lock.GetContext().GetIndex().HasQueuesSupport(); + + CheckKeyValueStoresSupport(lock.GetContext()); + + *parameters.target = reinterpret_cast<OrthancPluginKeysValuesIterator*>( + new StatelessDatabaseOperations::KeysValuesIterator(lock.GetContext().GetIndex(), parameters.storeId)); + } + + static void CheckQueuesSupport(ServerContext& context) + { + if (!context.GetIndex().HasQueuesSupport()) + { + throw OrthancException(ErrorCode_NotImplemented, "The database engine does not support queues"); + } } void OrthancPlugins::ApplyEnqueueValue(const _OrthancPluginEnqueueValue& parameters) { PImpl::ServerContextReference lock(*pimpl_); + + CheckQueuesSupport(lock.GetContext()); + lock.GetContext().GetIndex().EnqueueValue(parameters.queueId, parameters.value, parameters.valueSize); } @@ -4755,6 +4794,8 @@ { PImpl::ServerContextReference lock(*pimpl_); + CheckQueuesSupport(lock.GetContext()); + std::string value; if (lock.GetContext().GetIndex().DequeueValue(value, parameters.queueId, Plugins::Convert(parameters.origin))) @@ -4772,6 +4813,8 @@ { PImpl::ServerContextReference lock(*pimpl_); + CheckQueuesSupport(lock.GetContext()); + *parameters.size = lock.GetContext().GetIndex().GetQueueSize(parameters.queueId); } @@ -5845,181 +5888,104 @@ case _OrthancPluginService_AdoptAttachment: { - const _OrthancPluginAdoptAttachment& p = - *reinterpret_cast<const _OrthancPluginAdoptAttachment*>(parameters); + const _OrthancPluginAdoptAttachment& p = *reinterpret_cast<const _OrthancPluginAdoptAttachment*>(parameters); ApplyAdoptAttachment(p); return true; } case _OrthancPluginService_GetAttachmentCustomData: { - const _OrthancPluginGetAttachmentCustomData& p = - *reinterpret_cast<const _OrthancPluginGetAttachmentCustomData*>(parameters); + const _OrthancPluginGetAttachmentCustomData& p = *reinterpret_cast<const _OrthancPluginGetAttachmentCustomData*>(parameters); ApplyGetAttachmentCustomData(p); return true; } - case _OrthancPluginService_UpdateAttachmentCustomData: - { - const _OrthancPluginUpdateAttachmentCustomData& p = - *reinterpret_cast<const _OrthancPluginUpdateAttachmentCustomData*>(parameters); - ApplyUpdateAttachmentCustomData(p); + case _OrthancPluginService_SetAttachmentCustomData: + { + const _OrthancPluginSetAttachmentCustomData& p = *reinterpret_cast<const _OrthancPluginSetAttachmentCustomData*>(parameters); + ApplySetAttachmentCustomData(p); return true; } case _OrthancPluginService_StoreKeyValue: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginStoreKeyValue& p = - *reinterpret_cast<const _OrthancPluginStoreKeyValue*>(parameters); - ApplyStoreKeyValue(p); - return true; - } + { + const _OrthancPluginStoreKeyValue& p = *reinterpret_cast<const _OrthancPluginStoreKeyValue*>(parameters); + ApplyStoreKeyValue(p); + return true; + } case _OrthancPluginService_DeleteKeyValue: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginDeleteKeyValue& p = - *reinterpret_cast<const _OrthancPluginDeleteKeyValue*>(parameters); - ApplyDeleteKeyValue(p); - return true; - } + { + const _OrthancPluginDeleteKeyValue& p = *reinterpret_cast<const _OrthancPluginDeleteKeyValue*>(parameters); + ApplyDeleteKeyValue(p); + return true; + } case _OrthancPluginService_GetKeyValue: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginGetKeyValue& p = - *reinterpret_cast<const _OrthancPluginGetKeyValue*>(parameters); - ApplyGetKeyValue(p); - return true; - } + { + const _OrthancPluginGetKeyValue& p = *reinterpret_cast<const _OrthancPluginGetKeyValue*>(parameters); + ApplyGetKeyValue(p); + return true; + } case _OrthancPluginService_CreateKeysValuesIterator: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginCreateKeysValuesIterator& p = - *reinterpret_cast<const _OrthancPluginCreateKeysValuesIterator*>(parameters); - - { - PImpl::ServerContextReference lock(*pimpl_); - *p.target = reinterpret_cast<OrthancPluginKeysValuesIterator*>(new StatelessDatabaseOperations::KeysValuesIterator(lock.GetContext().GetIndex(), p.storeId)); - } - - return true; - } + { + const _OrthancPluginCreateKeysValuesIterator& p = *reinterpret_cast<const _OrthancPluginCreateKeysValuesIterator*>(parameters); + ApplyCreateKeysValuesIterator(p); + return true; + } case _OrthancPluginService_FreeKeysValuesIterator: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginFreeKeysValuesIterator& p = - *reinterpret_cast<const _OrthancPluginFreeKeysValuesIterator*>(parameters); - delete reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); - return true; - } + { + const _OrthancPluginFreeKeysValuesIterator& p = *reinterpret_cast<const _OrthancPluginFreeKeysValuesIterator*>(parameters); + delete reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); + return true; + } case _OrthancPluginService_KeysValuesIteratorNext: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginKeysValuesIteratorNext& p = - *reinterpret_cast<const _OrthancPluginKeysValuesIteratorNext*>(parameters); - - StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); - *p.done = iterator.Next() ? 1 : 0; - return true; - } + { + const _OrthancPluginKeysValuesIteratorNext& p = *reinterpret_cast<const _OrthancPluginKeysValuesIteratorNext*>(parameters); + StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); + *p.done = iterator.Next() ? 1 : 0; + return true; + } case _OrthancPluginService_KeysValuesIteratorGetKey: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginKeysValuesIteratorGetKey& p = - *reinterpret_cast<const _OrthancPluginKeysValuesIteratorGetKey*>(parameters); - - StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); - *p.target = iterator.GetKey().c_str(); - return true; - } + { + const _OrthancPluginKeysValuesIteratorGetKey& p = *reinterpret_cast<const _OrthancPluginKeysValuesIteratorGetKey*>(parameters); + StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); + *p.target = iterator.GetKey().c_str(); + return true; + } case _OrthancPluginService_KeysValuesIteratorGetValue: - if (!HasKeyValueStoresSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support key-value stores"); - } - else - { - const _OrthancPluginKeysValuesIteratorGetValue& p = - *reinterpret_cast<const _OrthancPluginKeysValuesIteratorGetValue*>(parameters); - - StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); - CopyToMemoryBuffer(*p.target, iterator.GetValue()); - return true; - } + { + const _OrthancPluginKeysValuesIteratorGetValue& p = *reinterpret_cast<const _OrthancPluginKeysValuesIteratorGetValue*>(parameters); + StatelessDatabaseOperations::KeysValuesIterator& iterator = *reinterpret_cast<StatelessDatabaseOperations::KeysValuesIterator*>(p.iterator); + CopyToMemoryBuffer(*p.target, iterator.GetValue()); + return true; + } case _OrthancPluginService_EnqueueValue: - if (!HasQueuesSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support queues"); - } - else - { - const _OrthancPluginEnqueueValue& p = - *reinterpret_cast<const _OrthancPluginEnqueueValue*>(parameters); - ApplyEnqueueValue(p); - return true; - } + { + const _OrthancPluginEnqueueValue& p = *reinterpret_cast<const _OrthancPluginEnqueueValue*>(parameters); + ApplyEnqueueValue(p); + return true; + } case _OrthancPluginService_DequeueValue: - if (!HasQueuesSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support queues"); - } - else - { - const _OrthancPluginDequeueValue& p = - *reinterpret_cast<const _OrthancPluginDequeueValue*>(parameters); - ApplyDequeueValue(p); - return true; - } + { + const _OrthancPluginDequeueValue& p = *reinterpret_cast<const _OrthancPluginDequeueValue*>(parameters); + ApplyDequeueValue(p); + return true; + } case _OrthancPluginService_GetQueueSize: - if (!HasQueuesSupport()) - { - throw OrthancException(ErrorCode_NotImplemented, "The DB engine does not support queues"); - } - else - { - const _OrthancPluginGetQueueSize& p = - *reinterpret_cast<const _OrthancPluginGetQueueSize*>(parameters); - ApplyGetQueueSize(p); - return true; - } + { + const _OrthancPluginGetQueueSize& p = *reinterpret_cast<const _OrthancPluginGetQueueSize*>(parameters); + ApplyGetQueueSize(p); + return true; + } default: return false;
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.h Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.h Wed Jun 11 16:55:15 2025 +0200 @@ -227,9 +227,7 @@ void ApplyGetAttachmentCustomData(const _OrthancPluginGetAttachmentCustomData& parameters); - void ApplyUpdateAttachmentCustomData(const _OrthancPluginUpdateAttachmentCustomData& parameters); - - bool HasKeyValueStoresSupport(); + void ApplySetAttachmentCustomData(const _OrthancPluginSetAttachmentCustomData& parameters); void ApplyStoreKeyValue(const _OrthancPluginStoreKeyValue& parameters); @@ -237,7 +235,7 @@ void ApplyGetKeyValue(const _OrthancPluginGetKeyValue& parameters); - bool HasQueuesSupport(); + void ApplyCreateKeysValuesIterator(const _OrthancPluginCreateKeysValuesIterator& parameters); void ApplyEnqueueValue(const _OrthancPluginEnqueueValue& parameters);
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h Wed Jun 11 16:55:15 2025 +0200 @@ -471,7 +471,7 @@ _OrthancPluginService_LogMessage = 45, /* New in Orthanc 1.12.4 */ _OrthancPluginService_AdoptAttachment = 46, /* New in Orthanc 1.12.8 */ _OrthancPluginService_GetAttachmentCustomData = 47, /* New in Orthanc 1.12.8 */ - _OrthancPluginService_UpdateAttachmentCustomData = 48, /* New in Orthanc 1.12.8 */ + _OrthancPluginService_SetAttachmentCustomData = 48, /* New in Orthanc 1.12.8 */ _OrthancPluginService_StoreKeyValue = 49, /* New in Orthanc 1.12.8 */ _OrthancPluginService_DeleteKeyValue = 50, /* New in Orthanc 1.12.8 */ _OrthancPluginService_GetKeyValue = 51, /* New in Orthanc 1.12.8 */ @@ -9882,7 +9882,7 @@ const char* attachmentUuid; /* in */ const void* customData; /* in */ uint32_t customDataSize; /* in */ - } _OrthancPluginUpdateAttachmentCustomData; + } _OrthancPluginSetAttachmentCustomData; /** @@ -9891,18 +9891,18 @@ * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). TODO_ATTACH_CUSTOM_DATA TODO TODO **/ - ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginUpdateAttachmentCustomData( + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetAttachmentCustomData( OrthancPluginContext* context, const char* attachmentUuid, /* in */ const void* customData, /* in */ uint32_t customDataSize /* in */) { - _OrthancPluginUpdateAttachmentCustomData params; + _OrthancPluginSetAttachmentCustomData params; params.attachmentUuid = attachmentUuid; params.customData = customData; params.customDataSize = customDataSize; - return context->InvokeService(context, _OrthancPluginService_UpdateAttachmentCustomData, ¶ms); + return context->InvokeService(context, _OrthancPluginService_SetAttachmentCustomData, ¶ms); }
--- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Wed Jun 11 16:55:15 2025 +0200 @@ -338,7 +338,7 @@ OPERATION_DEQUEUE_VALUE = 58; // New in Orthanc 1.12.8 OPERATION_GET_QUEUE_SIZE = 59; // New in Orthanc 1.12.8 OPERATION_GET_ATTACHMENT = 60; // New in Orthanc 1.12.8 - OPERATION_UPDATE_ATTACHMENT_CUSTOM_DATA = 61; // New in Orthanc 1.12.8 + OPERATION_SET_ATTACHMENT_CUSTOM_DATA = 61; // New in Orthanc 1.12.8 } @@ -1087,7 +1087,7 @@ } } -message UpdateAttachmentCustomData { +message SetAttachmentCustomData { message Request { string uuid = 1; bytes custom_data = 2; @@ -1162,7 +1162,7 @@ DequeueValue.Request dequeue_value = 158; GetQueueSize.Request get_queue_size = 159; GetAttachment.Request get_attachment = 160; - UpdateAttachmentCustomData.Request update_attachment_custom_data = 161; + SetAttachmentCustomData.Request set_attachment_custom_data = 161; } message TransactionResponse { @@ -1227,7 +1227,7 @@ DequeueValue.Response dequeue_value = 158; GetQueueSize.Response get_queue_size = 159; GetAttachment.Response get_attachment = 160; - UpdateAttachmentCustomData.Response update_attachment_custom_data = 161; + SetAttachmentCustomData.Response set_attachment_custom_data = 161; } enum RequestType {
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Wed Jun 11 16:55:15 2025 +0200 @@ -3200,6 +3200,12 @@ return db_.GetDatabaseCapabilities().HasFindSupport(); } + bool StatelessDatabaseOperations::HasAttachmentCustomDataSupport() + { + boost::shared_lock<boost::shared_mutex> lock(mutex_); + return db_.GetDatabaseCapabilities().HasAttachmentCustomDataSupport(); + } + bool StatelessDatabaseOperations::HasKeyValueStoresSupport() { boost::shared_lock<boost::shared_mutex> lock(mutex_); @@ -3589,9 +3595,9 @@ return operations.HasFound(); } - void StatelessDatabaseOperations::UpdateAttachmentCustomData(const std::string& attachmentUuid, - const void* customData, - size_t customDataSize) + void StatelessDatabaseOperations::SetAttachmentCustomData(const std::string& attachmentUuid, + const void* customData, + size_t customDataSize) { class Operations : public IReadWriteOperations { @@ -3612,7 +3618,7 @@ virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE { - transaction.UpdateAttachmentCustomData(attachmentUuid_, customData_, customDataSize_); + transaction.SetAttachmentCustomData(attachmentUuid_, customData_, customDataSize_); } };
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Wed Jun 11 16:01:06 2025 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Wed Jun 11 16:55:15 2025 +0200 @@ -486,7 +486,7 @@ return transaction_.DequeueValue(value, queueId, origin); } - void UpdateAttachmentCustomData(const std::string& attachmentUuid, + void SetAttachmentCustomData(const std::string& attachmentUuid, const void* customData, size_t customDataSize) { @@ -592,7 +592,7 @@ int64_t& revision, const std::string& attachmentUuid); - void UpdateAttachmentCustomData(const std::string& attachmentUuid, + void SetAttachmentCustomData(const std::string& attachmentUuid, const void* customData, size_t customDataSize); @@ -618,6 +618,8 @@ bool HasFindSupport(); + bool HasAttachmentCustomDataSupport(); + bool HasKeyValueStoresSupport(); bool HasQueuesSupport();