diff Plugins/Engine/PluginsHttpHandler.cpp @ 908:e078ea944089 plugins

refactoring HttpOutput
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jun 2014 17:47:39 +0200
parents 9b8298234254
children ef71057d8b26
line wrap: on
line diff
--- a/Plugins/Engine/PluginsHttpHandler.cpp	Thu Jun 19 14:28:43 2014 +0200
+++ b/Plugins/Engine/PluginsHttpHandler.cpp	Thu Jun 19 17:47:39 2014 +0200
@@ -42,6 +42,39 @@
 
 namespace Orthanc
 {
+  namespace
+  {
+    // Anonymous namespace to avoid clashes between compilation modules
+    class StringHttpOutput : public HttpOutput
+    {
+    private:
+      std::string target_;
+
+    public:
+      const std::string& GetOutput() const
+      {
+        return target_;
+      }
+
+      virtual void SendHeaderData(const void* buffer, size_t length)
+      {
+      }
+
+      virtual void SendBodyData(const void* buffer, size_t length)
+      {
+        size_t pos = target_.size();
+        target_.resize(pos + length);
+
+        if (length > 0)
+        {
+          memcpy(&target_[pos], buffer, length);
+        }
+      }
+    };
+  }
+
+
+
   struct PluginsHttpHandler::PImpl
   {
     typedef std::pair<boost::regex*, OrthancPluginRestCallback> Callback;
@@ -49,8 +82,9 @@
 
     ServerContext& context_;
     Callbacks callbacks_;
+    OrthancRestApi* restApi_;
 
-    PImpl(ServerContext& context) : context_(context)
+    PImpl(ServerContext& context) : context_(context), restApi_(NULL)
     {
     }
   };
@@ -298,4 +332,10 @@
     }
   }
 
+
+  void PluginsHttpHandler::SetOrthancRestApi(OrthancRestApi& restApi)
+  {
+    pimpl_->restApi_ = &restApi;
+  }
+
 }