diff Plugins/Engine/OrthancPlugins.cpp @ 1430:ad94a3583b07

Plugins can send answers as multipart messages
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Jun 2015 17:47:34 +0200
parents 97268448bdfc
children 461e7554bff7
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Mon Jun 29 14:43:08 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Mon Jun 29 17:47:34 2015 +0200
@@ -426,6 +426,12 @@
                        &request);
     }
 
+    if (error == 0 && 
+        output.IsWritingMultipart())
+    {
+      output.CloseMultipart();
+    }
+
     if (error < 0)
     {
       LOG(ERROR) << "Plugin callback failed with error code " << error;
@@ -1232,6 +1238,26 @@
         return true;
       }
 
+      case _OrthancPluginService_StartMultipartAnswer:
+      {
+        const _OrthancPluginStartMultipartAnswer& p =
+          *reinterpret_cast<const _OrthancPluginStartMultipartAnswer*>(parameters);
+        HttpOutput* output = reinterpret_cast<HttpOutput*>(p.output);
+        output->StartMultipart(p.subType, p.contentType);
+        return true;
+      }
+
+      case _OrthancPluginService_SendMultipartItem:
+      {
+        // An exception might be raised in this function if the
+        // connection was closed by the HTTP client.
+        const _OrthancPluginAnswerBuffer& p =
+          *reinterpret_cast<const _OrthancPluginAnswerBuffer*>(parameters);
+        HttpOutput* output = reinterpret_cast<HttpOutput*>(p.output);
+        output->SendMultipartItem(p.answer, p.answerSize);
+        return true;
+      }
+
       default:
         return false;
     }