00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PION_PLUGIN_SERVER_HEADER__
00011 #define __PION_PLUGIN_SERVER_HEADER__
00012
00013 #include <string>
00014 #include <boost/asio.hpp>
00015 #include <boost/bind.hpp>
00016 #include <boost/shared_ptr.hpp>
00017 #include <pion/config.hpp>
00018 #include <pion/plugin.hpp>
00019 #include <pion/plugin_manager.hpp>
00020 #include <pion/http/server.hpp>
00021 #include <pion/http/plugin_service.hpp>
00022
00023
00024 namespace pion {
00025 namespace http {
00026
00027
00031 class PION_API plugin_server :
00032 public http::server
00033 {
00034
00035 public:
00036
00038 virtual ~plugin_server() { clear(); }
00039
00045 explicit plugin_server(const unsigned int tcp_port = 0)
00046 : http::server(tcp_port)
00047 {
00048 set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
00049 }
00050
00056 explicit plugin_server(const boost::asio::ip::tcp::endpoint& endpoint)
00057 : http::server(endpoint)
00058 {
00059 set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
00060 }
00061
00068 explicit plugin_server(scheduler& sched, const unsigned int tcp_port = 0)
00069 : http::server(sched, tcp_port)
00070 {
00071 set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
00072 }
00073
00080 plugin_server(scheduler& sched, const boost::asio::ip::tcp::endpoint& endpoint)
00081 : http::server(sched, endpoint)
00082 {
00083 set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
00084 }
00085
00092 void add_service(const std::string& resource, http::plugin_service *service_ptr);
00093
00101 void load_service(const std::string& resource, const std::string& service_name);
00102
00110 void set_service_option(const std::string& resource,
00111 const std::string& name, const std::string& value);
00112
00125 void load_service_config(const std::string& config_name);
00126
00128 virtual void clear(void) {
00129 if (is_listening()) stop();
00130 m_services.clear();
00131 http::server::clear();
00132 }
00133
00134
00135 protected:
00136
00138 virtual void before_starting(void) {
00139
00140 m_services.run(boost::bind(&http::plugin_service::start, _1));
00141 }
00142
00144 virtual void after_stopping(void) {
00145
00146 m_services.run(boost::bind(&http::plugin_service::stop, _1));
00147 }
00148
00149
00150 private:
00151
00153 typedef plugin_manager<http::plugin_service> service_manager_t;
00154
00155
00157 service_manager_t m_services;
00158 };
00159
00160
00162 typedef boost::shared_ptr<plugin_server> plugin_server_ptr;
00163
00164
00165 }
00166 }
00167
00168 #endif