# net/services/HelloService.cpp

    00001 // ------------------------------------------------------------------
    00002 // pion-net: a C++ framework for building lightweight HTTP interfaces
    00003 // ------------------------------------------------------------------
    00004 // Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
    00005 //
    00006 // Distributed under the Boost Software License, Version 1.0.
    00007 // See http://www.boost.org/LICENSE_1_0.txt
    00008 //
    00009
    00010 #include "HelloService.hpp"
    00011 #include <pion/net/HTTPResponseWriter.hpp>
    00012
    00013 using namespace pion;
    00014 using namespace pion::net;
    00015
    00016 namespace pion {        // begin namespace pion
    00017 namespace plugins {     // begin namespace plugins
    00018
    00019
    00020 // HelloService member functions
    00021
    00023 void HelloService::operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
    00024 {
    00025     static const std::string HELLO_HTML = "<html><body>Hello World!</body></html>";
    00026     HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
    00027                                                             boost::bind(&TCPConnection::finish, tcp_conn)));
    00028     writer->writeNoCopy(HELLO_HTML);
    00029     writer->writeNoCopy(HTTPTypes::STRING_CRLF);
    00030     writer->writeNoCopy(HTTPTypes::STRING_CRLF);
    00031     writer->send();
    00032 }
    00033
    00034
    00035 }   // end namespace plugins
    00036 }   // end namespace pion
    00037
    00038
    00040 extern "C" PION_SERVICE_API pion::plugins::HelloService *pion_create_HelloService(void)
    00041 {
    00042     return new pion::plugins::HelloService();
    00043 }
    00044
    00046 extern "C" PION_SERVICE_API void pion_destroy_HelloService(pion::plugins::HelloService *service_ptr)
    00047 {
    00048     delete service_ptr;
    00049 }