changeset 104:87fdb1a108db

updated signature of IncomingCStoreInstanceFilter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Feb 2022 10:13:38 +0100
parents d2259c4cd677
children 912cbabbe427
files Sources/IncomingInstanceFilter.cpp
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Sources/IncomingInstanceFilter.cpp	Wed Feb 23 09:28:19 2022 +0100
+++ b/Sources/IncomingInstanceFilter.cpp	Wed Feb 23 10:13:38 2022 +0100
@@ -31,8 +31,12 @@
 static PyObject*   incomingCStoreInstanceFilter_ = NULL;
 
 
-static int32_t IncomingCStoreInstanceFilter(const OrthancPluginDicomInstance *instance)
+static int32_t IncomingCStoreInstanceFilter(uint16_t* dimseStatus,
+                                            const OrthancPluginDicomInstance *instance)
 {
+  assert(dimseStatus != NULL &&
+         instance != NULL);
+  
   try
   {
     PythonLock lock;
@@ -64,9 +68,31 @@
     }
     else
     {
-      if (PyLong_Check(result.GetPyObject()))
+      if (PyNumber_Check(result.GetPyObject()))
       {
-        return static_cast<int32_t>(PyLong_AsLong(result.GetPyObject()));
+        int32_t code = PyLong_AsLong(result.GetPyObject());
+
+        if (code < 0)
+        {
+          OrthancPlugins::LogError("The Python incoming-cstore-instance filter has returned a negative value");
+          return -1;
+        }
+        else if (code == 0)
+        {
+          return 1;  // The instance is to be stored
+        }
+        else if (code <= 0xffff)
+        {
+          // The instance is to be discarded with a custom DIMSE status
+          *dimseStatus = static_cast<uint16_t>(code);
+          return 0;  // Discard
+        }
+        else
+        {
+          OrthancPlugins::LogError("The Python incoming-cstore-instance filter has returned an out-of-range DIMSE status: " +
+                                   boost::lexical_cast<std::string>(code));
+          return -1;
+        }
       }
       else
       {