pion-net  4.0.9
HelloService.cpp
1 // ------------------------------------------------------------------
2 // pion-net: a C++ framework for building lightweight HTTP interfaces
3 // ------------------------------------------------------------------
4 // Copyright (C) 2007-2008 Atomic Labs, Inc. (http://www.atomiclabs.com)
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/net/HTTPResponseWriter.hpp>
12 
13 using namespace pion;
14 using namespace pion::net;
15 
16 namespace pion { // begin namespace pion
17 namespace plugins { // begin namespace plugins
18 
19 
20 // HelloService member functions
21 
23 void HelloService::operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
24 {
25  static const std::string HELLO_HTML = "<html><body>Hello World!</body></html>";
26  HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
27  boost::bind(&TCPConnection::finish, tcp_conn)));
28  writer->writeNoCopy(HELLO_HTML);
29  writer->writeNoCopy(HTTPTypes::STRING_CRLF);
30  writer->writeNoCopy(HTTPTypes::STRING_CRLF);
31  writer->send();
32 }
33 
34 
35 } // end namespace plugins
36 } // end namespace pion
37 
38 
40 extern "C" PION_SERVICE_API pion::plugins::HelloService *pion_create_HelloService(void)
41 {
42  return new pion::plugins::HelloService();
43 }
44 
46 extern "C" PION_SERVICE_API void pion_destroy_HelloService(pion::plugins::HelloService *service_ptr)
47 {
48  delete service_ptr;
49 }
static boost::shared_ptr< HTTPResponseWriter > create(TCPConnectionPtr &tcp_conn, HTTPResponsePtr &http_response, FinishedHandler handler=FinishedHandler())