comparison 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
comparison
equal deleted inserted replaced
907:9b8298234254 908:e078ea944089
40 #include <boost/regex.hpp> 40 #include <boost/regex.hpp>
41 #include <glog/logging.h> 41 #include <glog/logging.h>
42 42
43 namespace Orthanc 43 namespace Orthanc
44 { 44 {
45 namespace
46 {
47 // Anonymous namespace to avoid clashes between compilation modules
48 class StringHttpOutput : public HttpOutput
49 {
50 private:
51 std::string target_;
52
53 public:
54 const std::string& GetOutput() const
55 {
56 return target_;
57 }
58
59 virtual void SendHeaderData(const void* buffer, size_t length)
60 {
61 }
62
63 virtual void SendBodyData(const void* buffer, size_t length)
64 {
65 size_t pos = target_.size();
66 target_.resize(pos + length);
67
68 if (length > 0)
69 {
70 memcpy(&target_[pos], buffer, length);
71 }
72 }
73 };
74 }
75
76
77
45 struct PluginsHttpHandler::PImpl 78 struct PluginsHttpHandler::PImpl
46 { 79 {
47 typedef std::pair<boost::regex*, OrthancPluginRestCallback> Callback; 80 typedef std::pair<boost::regex*, OrthancPluginRestCallback> Callback;
48 typedef std::list<Callback> Callbacks; 81 typedef std::list<Callback> Callbacks;
49 82
50 ServerContext& context_; 83 ServerContext& context_;
51 Callbacks callbacks_; 84 Callbacks callbacks_;
52 85 OrthancRestApi* restApi_;
53 PImpl(ServerContext& context) : context_(context) 86
87 PImpl(ServerContext& context) : context_(context), restApi_(NULL)
54 { 88 {
55 } 89 }
56 }; 90 };
57 91
58 92
296 default: 330 default:
297 return false; 331 return false;
298 } 332 }
299 } 333 }
300 334
335
336 void PluginsHttpHandler::SetOrthancRestApi(OrthancRestApi& restApi)
337 {
338 pimpl_->restApi_ = &restApi;
339 }
340
301 } 341 }