pion  5.0.6
plugin_server.hpp
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 #ifndef __PION_PLUGIN_SERVER_HEADER__
11 #define __PION_PLUGIN_SERVER_HEADER__
12 
13 #include <string>
14 #include <boost/asio.hpp>
15 #include <boost/bind.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <pion/config.hpp>
18 #include <pion/plugin.hpp>
19 #include <pion/plugin_manager.hpp>
20 #include <pion/http/server.hpp>
21 #include <pion/http/plugin_service.hpp>
22 
23 
24 namespace pion { // begin namespace pion
25 namespace http { // begin namespace http
26 
27 
31 class PION_API plugin_server :
32  public http::server
33 {
34 
35 public:
36 
38  virtual ~plugin_server() { clear(); }
39 
45  explicit plugin_server(const unsigned int tcp_port = 0)
46  : http::server(tcp_port)
47  {
48  set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
49  }
50 
56  explicit plugin_server(const boost::asio::ip::tcp::endpoint& endpoint)
57  : http::server(endpoint)
58  {
59  set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
60  }
61 
68  explicit plugin_server(scheduler& sched, const unsigned int tcp_port = 0)
69  : http::server(sched, tcp_port)
70  {
71  set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
72  }
73 
80  plugin_server(scheduler& sched, const boost::asio::ip::tcp::endpoint& endpoint)
81  : http::server(sched, endpoint)
82  {
83  set_logger(PION_GET_LOGGER("pion.http.plugin_server"));
84  }
85 
92  void add_service(const std::string& resource, http::plugin_service *service_ptr);
93 
101  void load_service(const std::string& resource, const std::string& service_name);
102 
110  void set_service_option(const std::string& resource,
111  const std::string& name, const std::string& value);
112 
125  void load_service_config(const std::string& config_name);
126 
128  virtual void clear(void) {
129  if (is_listening()) stop();
130  m_services.clear();
132  }
133 
134 
135 protected:
136 
138  virtual void before_starting(void) {
139  // call the start() method for each web service associated with this server
140  m_services.run(boost::bind(&http::plugin_service::start, _1));
141  }
142 
144  virtual void after_stopping(void) {
145  // call the stop() method for each web service associated with this server
146  m_services.run(boost::bind(&http::plugin_service::stop, _1));
147  }
148 
149 
150 private:
151 
154 
155 
157  service_manager_t m_services;
158 };
159 
160 
162 typedef boost::shared_ptr<plugin_server> plugin_server_ptr;
163 
164 
165 } // end namespace http
166 } // end namespace pion
167 
168 #endif
plugin_server(scheduler &sched, const unsigned int tcp_port=0)
virtual void before_starting(void)
called before the TCP server starts listening for new connections
plugin_server(const unsigned int tcp_port=0)
plugin_server(scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint)
virtual void clear(void)
clears the collection of resources recognized by the HTTP server
Definition: server.hpp:148
virtual ~plugin_server()
default destructor
virtual void after_stopping(void)
called after the TCP server has stopped listening for new connections
virtual void stop(void)
called when the web service&#39;s server is stopping
virtual void clear(void)
clears all the web services that are currently configured
plugin_server(const boost::asio::ip::tcp::endpoint &endpoint)
virtual void start(void)
called when the web service&#39;s server is starting