pion  5.0.6
HelloService.cpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #include "HelloService.hpp"
11 #include <pion/http/response_writer.hpp>
12 
13 using namespace pion;
14 
15 namespace pion { // begin namespace pion
16 namespace plugins { // begin namespace plugins
17 
18 
19 // HelloService member functions
20 
22 void HelloService::operator()(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn)
23 {
24  static const std::string HELLO_HTML = "<html><body>Hello World!</body></html>";
25  http::response_writer_ptr writer(http::response_writer::create(tcp_conn, *http_request_ptr,
26  boost::bind(&tcp::connection::finish, tcp_conn)));
27  writer->write_no_copy(HELLO_HTML);
28  writer->write_no_copy(http::types::STRING_CRLF);
29  writer->write_no_copy(http::types::STRING_CRLF);
30  writer->send();
31 }
32 
33 
34 } // end namespace plugins
35 } // end namespace pion
36 
37 
39 extern "C" PION_PLUGIN pion::plugins::HelloService *pion_create_HelloService(void)
40 {
41  return new pion::plugins::HelloService();
42 }
43 
45 extern "C" PION_PLUGIN void pion_destroy_HelloService(pion::plugins::HelloService *service_ptr)
46 {
47  delete service_ptr;
48 }
virtual void operator()(const pion::http::request_ptr &http_request_ptr, const pion::tcp::connection_ptr &tcp_conn)
handles requests for HelloService
static boost::shared_ptr< response_writer > create(const tcp::connection_ptr &tcp_conn, const http::response_ptr &http_response_ptr, finished_handler_t handler=finished_handler_t())