Mercurial > hg > orthanc
changeset 6151:4d5fad701a17 attach-custom-data
fix consistency in valueSize
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 02 Jun 2025 15:40:52 +0200 |
parents | 9db300bcf873 |
children | 1639adc016f4 |
files | OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h |
diffstat | 3 files changed, 53 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h Fri May 30 16:22:49 2025 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancCPlugin.h Mon Jun 02 15:40:52 2025 +0200 @@ -9910,7 +9910,7 @@ const char* storeId; const char* key; const void* value; - uint64_t valueSize; + uint32_t valueSize; } _OrthancPluginStoreKeyValue; /** @@ -9928,7 +9928,7 @@ const char* storeId, /* in */ const char* key, /* in */ const void* value, /* in */ - uint64_t valueSize /* in */) + uint32_t valueSize /* in */) { _OrthancPluginStoreKeyValue params; params.storeId = storeId;
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Fri May 30 16:22:49 2025 +0200 +++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Mon Jun 02 15:40:52 2025 +0200 @@ -4423,10 +4423,16 @@ #if HAS_ORTHANC_PLUGIN_KEY_VALUE_STORES == 1 void KeyValueStore::Store(const std::string& key, - const std::string& value) - { + const void* value, + size_t valueSize) + { + if (static_cast<size_t>(static_cast<uint32_t>(valueSize)) != valueSize) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); + } + OrthancPluginErrorCode code = OrthancPluginStoreKeyValue(OrthancPlugins::GetGlobalContext(), storeId_.c_str(), - key.c_str(), value.c_str(), value.size()); + key.c_str(), value, static_cast<uint32_t>(valueSize)); if (code != OrthancPluginErrorCode_Success) { ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); @@ -4484,10 +4490,16 @@ #if HAS_ORTHANC_PLUGIN_QUEUES == 1 - void Queue::PushBack(const std::string& value) - { + void Queue::Enqueue(const void* value, + size_t valueSize) + { + if (static_cast<size_t>(static_cast<uint32_t>(valueSize)) != valueSize) + { + ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); + } + OrthancPluginErrorCode code = OrthancPluginEnqueueValue(OrthancPlugins::GetGlobalContext(), - queueId_.c_str(), value.c_str(), value.size()); + queueId_.c_str(), value, static_cast<uint32_t>(valueSize)); if (code != OrthancPluginErrorCode_Success) { @@ -4498,8 +4510,8 @@ #if HAS_ORTHANC_PLUGIN_QUEUES == 1 - bool Queue::PopInternal(std::string& value, - OrthancPluginQueueOrigin origin) + bool Queue::DequeueInternal(std::string& value, + OrthancPluginQueueOrigin origin) { uint8_t found = false; OrthancPlugins::MemoryBuffer valueBuffer;
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h Fri May 30 16:22:49 2025 +0200 +++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h Mon Jun 02 15:40:52 2025 +0200 @@ -1658,8 +1658,20 @@ { } + const std::string& GetStoreId() const + { + return storeId_; + } + void Store(const std::string& key, - const std::string& value); + const void* value, + size_t valueSize); + + void Store(const std::string& key, + const std::string& value) + { + Store(key, value.empty() ? NULL : value.c_str(), value.size()); + } bool GetValue(std::string& value, const std::string& key); @@ -1677,7 +1689,7 @@ private: std::string queueId_; - bool PopInternal(std::string& value, OrthancPluginQueueOrigin origin); + bool DequeueInternal(std::string& value, OrthancPluginQueueOrigin origin); public: explicit Queue(const std::string& queueId) : @@ -1685,16 +1697,27 @@ { } - void PushBack(const std::string& value); - - bool PopBack(std::string& value) + const std::string& GetQueueId() const { - return PopInternal(value, OrthancPluginQueueOrigin_Back); + return queueId_; } - bool PopFront(std::string& value) + void Enqueue(const void* value, + size_t valueSize); + + void Enqueue(const std::string& value) { - return PopInternal(value, OrthancPluginQueueOrigin_Front); + Enqueue(value.empty() ? NULL : value.c_str(), value.size()); + } + + bool DequeueBack(std::string& value) + { + return DequeueInternal(value, OrthancPluginQueueOrigin_Back); + } + + bool DequeueFront(std::string& value) + { + return DequeueInternal(value, OrthancPluginQueueOrigin_Front); } uint64_t GetSize();