changeset 6340:7de5b2b09072 queues-timeout tip

OrthancPlugins::Queue::Reserve + Acknowledge
author Alain Mazy <am@orthanc.team>
date Fri, 17 Oct 2025 14:44:26 +0200
parents 22931817cced
children
files OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h
diffstat 2 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Mon Oct 13 09:25:16 2025 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Fri Oct 17 14:44:26 2025 +0200
@@ -4643,4 +4643,45 @@
     }
   }
 #endif
+
+#if HAS_ORTHANC_PLUGIN_EXTENDED_QUEUES == 1
+  bool Queue::ReserveInternal(std::string& value, uint64_t& valueId, OrthancPluginQueueOrigin origin, uint32_t releaseTimeout)
+  {
+    uint8_t found = false;
+    OrthancPlugins::MemoryBuffer valueBuffer;
+
+    OrthancPluginErrorCode code = OrthancPluginReserveQueueValue(OrthancPlugins::GetGlobalContext(), &found,
+                                                                 *valueBuffer, &valueId, queueId_.c_str(), origin, releaseTimeout);
+
+    if (code != OrthancPluginErrorCode_Success)
+    {
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
+    }
+    else if (found)
+    {
+      valueBuffer.ToString(value);
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+
+  bool Queue::ReserveBack(std::string& value, uint64_t& valueId, uint32_t releaseTimeout)
+  {
+    return ReserveInternal(value, valueId, OrthancPluginQueueOrigin_Back, releaseTimeout);
+  }
+    
+  bool Queue::ReserveFront(std::string& value, uint64_t& valueId, uint32_t releaseTimeout)
+  {
+    return ReserveInternal(value, valueId, OrthancPluginQueueOrigin_Front, releaseTimeout);
+  }
+
+  void Queue::Acknowledge(uint64_t valueId)
+  {
+    OrthancPluginAcknowledgeQueueValue(OrthancPlugins::GetGlobalContext(), queueId_.c_str(), valueId);
+  }
+#endif
+
 }
--- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Mon Oct 13 09:25:16 2025 +0200
+++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Fri Oct 17 14:44:26 2025 +0200
@@ -142,6 +142,12 @@
 #  define HAS_ORTHANC_PLUGIN_QUEUES            0
 #endif
 
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 10)
+#  define HAS_ORTHANC_PLUGIN_EXTENDED_QUEUES   1
+#else
+#  define HAS_ORTHANC_PLUGIN_EXTENDED_QUEUES   0
+#endif
+
 
 // Macro to tag a function as having been deprecated
 #if (__cplusplus >= 201402L)  // C++14
@@ -1726,6 +1732,10 @@
 
     bool DequeueInternal(std::string& value, OrthancPluginQueueOrigin origin);
 
+#if HAS_ORTHANC_PLUGIN_EXTENDED_QUEUES == 1
+    bool ReserveInternal(std::string& value, uint64_t& valueId, OrthancPluginQueueOrigin origin, uint32_t releaseTimeout);
+#endif
+
   public:
     explicit Queue(const std::string& queueId) :
       queueId_(queueId)
@@ -1745,17 +1755,29 @@
       Enqueue(value.empty() ? NULL : value.c_str(), value.size());
     }
 
+    // Use ReserveBack instead
+    ORTHANC_PLUGIN_DEPRECATED
     bool DequeueBack(std::string& value)
     {
       return DequeueInternal(value, OrthancPluginQueueOrigin_Back);
     }
 
+    // Use ReserveFront instead
+    ORTHANC_PLUGIN_DEPRECATED
     bool DequeueFront(std::string& value)
     {
       return DequeueInternal(value, OrthancPluginQueueOrigin_Front);
     }
 
     uint64_t GetSize();
+
+#if HAS_ORTHANC_PLUGIN_EXTENDED_QUEUES == 1
+    bool ReserveBack(std::string& value, uint64_t& valueId, uint32_t releaseTimeout);
+    
+    bool ReserveFront(std::string& value, uint64_t& valueId, uint32_t releaseTimeout);
+
+    void Acknowledge(uint64_t valueId);
+#endif
   };
 #endif
 }