diff Core/HttpServer/HttpOutput.h @ 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 6e7e5ed91c2d
children f3672356c121
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.h	Mon Jun 29 14:43:08 2015 +0200
+++ b/Core/HttpServer/HttpOutput.h	Mon Jun 29 17:47:34 2015 +0200
@@ -38,6 +38,7 @@
 #include "../Enumerations.h"
 #include "IHttpOutputStream.h"
 #include "HttpHandler.h"
+#include "../Uuid.h"
 
 namespace Orthanc
 {
@@ -48,14 +49,16 @@
 
     class StateMachine : public boost::noncopyable
     {
-    private:
+    public:
       enum State
       {
         State_WritingHeader,      
         State_WritingBody,
+        State_WritingMultipart,
         State_Done
       };
 
+    private:
       IHttpOutputStream& stream_;
       State state_;
 
@@ -66,6 +69,9 @@
       bool keepAlive_;
       std::list<std::string> headers_;
 
+      std::string multipartBoundary_;
+      std::string multipartContentType_;
+
     public:
       StateMachine(IHttpOutputStream& stream,
                    bool isKeepAlive);
@@ -89,6 +95,18 @@
       void ClearHeaders();
 
       void SendBody(const void* buffer, size_t length);
+
+      void StartMultipart(const std::string& subType,
+                          const std::string& contentType);
+
+      void SendMultipartItem(const void* item, size_t length);
+
+      void CloseMultipart();
+
+      State GetState() const
+      {
+        return state_;
+      }
     };
 
     StateMachine stateMachine_;
@@ -140,5 +158,28 @@
     void Redirect(const std::string& path);
 
     void SendUnauthorized(const std::string& realm);
+
+    void StartMultipart(const std::string& subType,
+                        const std::string& contentType)
+    {
+      stateMachine_.StartMultipart(subType, contentType);
+    }
+
+    void SendMultipartItem(const std::string& item);
+
+    void SendMultipartItem(const void* item, size_t size)
+    {
+      stateMachine_.SendMultipartItem(item, size);
+    }
+
+    void CloseMultipart()
+    {
+      stateMachine_.CloseMultipart();
+    }
+
+    bool IsWritingMultipart() const
+    {
+      return stateMachine_.GetState() == StateMachine::State_WritingMultipart;
+    }
   };
 }