plugin_server.hpp
// ---------------------------------------------------------------------
// pion: a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//
#ifndef __PION_PLUGIN_SERVER_HEADER__
#define __PION_PLUGIN_SERVER_HEADER__
#include <string>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <pion/config.hpp>
#include <pion/plugin.hpp>
#include <pion/plugin_manager.hpp>
#include <pion/http/server.hpp>
#include <pion/http/plugin_service.hpp>
namespace pion { // begin namespace pion
namespace http { // begin namespace http
class PION_API plugin_server :
public http::server
{
public:
virtual ~plugin_server() { clear(); }
explicit plugin_server(const unsigned int tcp_port = 0)
: http::server(tcp_port)
{
set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
}
explicit plugin_server(const boost::asio::ip::tcp::endpoint& endpoint)
: http::server(endpoint)
{
set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
}
explicit plugin_server(scheduler& sched, const unsigned int tcp_port = 0)
: http::server(sched, tcp_port)
{
set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
}
plugin_server(scheduler& sched, const boost::asio::ip::tcp::endpoint& endpoint)
: http::server(sched, endpoint)
{
set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
}
void add_service(const std::string& resource, http::plugin_service *service_ptr);
void load_service(const std::string& resource, const std::string& service_name);
void set_service_option(const std::string& resource,
const std::string& name, const std::string& value);
void load_service_config(const std::string& config_name);
virtual void clear(void) {
if (is_listening()) stop();
m_services.clear();
http::server::clear();
}
protected:
virtual void before_starting(void) {
// call the start() method for each web service associated with this server
m_services.run(boost::bind(&http::plugin_service::start, _1));
}
virtual void after_stopping(void) {
// call the stop() method for each web service associated with this server
m_services.run(boost::bind(&http::plugin_service::stop, _1));
}
private:
typedef plugin_manager<http::plugin_service> service_manager_t;
service_manager_t m_services;
};
typedef boost::shared_ptr<plugin_server> plugin_server_ptr;
} // end namespace http
} // end namespace pion
#endif
pion::http::plugin_server::plugin_server
plugin_server(scheduler &sched, const unsigned int tcp_port=0)
Definition: plugin_server.hpp:68
pion::http::plugin_server::before_starting
virtual void before_starting(void)
called before the TCP server starts listening for new connections
Definition: plugin_server.hpp:138
pion::http::plugin_service
Definition: plugin_service.hpp:29
pion::http::plugin_server
Definition: plugin_server.hpp:31
pion::http::plugin_server::plugin_server
plugin_server(const unsigned int tcp_port=0)
Definition: plugin_server.hpp:45
pion::http::plugin_server::plugin_server
plugin_server(scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint)
Definition: plugin_server.hpp:80
pion::plugin_manager< http::plugin_service >
pion::http::server::clear
virtual void clear(void)
clears the collection of resources recognized by the HTTP server
Definition: server.hpp:148
pion::http::server
Definition: server.hpp:36
pion::http::plugin_server::~plugin_server
virtual ~plugin_server()
default destructor
Definition: plugin_server.hpp:38
pion::http::plugin_server::after_stopping
virtual void after_stopping(void)
called after the TCP server has stopped listening for new connections
Definition: plugin_server.hpp:144
pion::http::plugin_service::stop
virtual void stop(void)
called when the web service&#39;s server is stopping
Definition: plugin_service.hpp:62
pion
Definition: admin_rights.hpp:19
pion::http::plugin_server::clear
virtual void clear(void)
clears all the web services that are currently configured
Definition: plugin_server.hpp:128
pion::http::plugin_server::plugin_server
plugin_server(const boost::asio::ip::tcp::endpoint &endpoint)
Definition: plugin_server.hpp:56
pion::http::plugin_service::start
virtual void start(void)
called when the web service&#39;s server is starting
Definition: plugin_service.hpp:59
pion::scheduler
Definition: scheduler.hpp:34