CppCMS
service.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_SERVICE_H
9 #define CPPCMS_SERVICE_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/function.h>
15 #include <locale>
16 #include <memory>
17 #include <cppcms/locale_fwd.h>
18 #include <cppcms/json.h>
19 
20 namespace booster {
21  namespace aio {
22  class io_service;
23  }
24 }
25 
29 namespace cppcms {
30  namespace impl {
31  struct cached_settings;
32  class service;
33  namespace cgi {
34  class acceptor;
35  }
36  }
37 
38  class applications_pool;
39  class thread_pool;
40  class session_pool;
41  class cache_pool;
42  class forwarder;
43 
44  namespace json {
45  class value;
46  }
47  namespace views {
48  class manager;
49  }
50 
58 
59  class CPPCMS_API service : public booster::noncopyable
60  {
61  public:
67  static json::value load_settings(int argc,char *argv[]);
71  service(json::value const &v);
78  service(int argc,char *argv[]);
84  ~service();
85 
95  void run();
96 
100  void shutdown();
101 
105  json::value const &settings();
106 
122  cppcms::views::manager &views_pool();
126  cppcms::cache_pool &cache_pool();
131 
135  locale::generator const &generator();
139  std::locale locale();
143  std::locale locale(std::string const &name);
144 
145 
150  booster::aio::io_service &get_io_service();
151 
156  void post(booster::function<void()> const &handler);
157 
162  void after_fork(booster::function<void()> const &handler);
163 
167  int threads_no();
168 
172  int procs_no();
173 
186  int process_id();
187 
189 
190  // internal functions never call it directly
191 
192  cppcms::impl::service &impl();
193 
194  impl::cached_settings const &cached_settings();
195 
196 
198 
199  private:
200  void setup();
201  std::auto_ptr<cppcms::impl::cgi::acceptor> setup_acceptor(json::value const &,int,int shift=0);
202  void stop();
203  void start_acceptor(bool after_fork=false);
204  void setup_exit_handling();
205  bool prefork();
206  void run_prepare();
207  void after_fork_exec();
208  void run_acceptor();
209  void run_event_loop();
210  #ifdef CPPCMS_WIN32
211  void run_win_console();
212  #endif
213  #ifdef CPPCMS_WIN_NATIVE
214  void win_service_prepare();
215  void win_service_exec();
216  void run_win_service();
217  #endif
219  };
220 
221 } //
222 
223 
224 
225 
226 #endif
This class controls the views used my application it knows to load them dynamically and reload if nee...
Definition: views_pool.h:173
This class is central representation of json objects.
Definition: json.h:142
a smart pointer similar to std::auto_ptr but it is non-copyable and underlying object has same constn...
Definition: hold_ptr.h:18
This class represent the central event loop of the CppCMS applications.
Definition: service.h:59
This class provides an access to the thread pool where all CppCMS synchronous applications are execut...
Definition: thread_pool.h:29
This class provides an access to session management backends an allow customization.
Definition: session_pool.h:32
Definition: function.h:16
the major class used for locale generation
Definition: generator.h:74
Application pool is the central class that holds user created applications.
Definition: applications_pool.h:41
Stop conversion and throw conversion_error.
Definition: encoding_errors.h:56
this is the central event loop that dispatches all requests.
Definition: io_service.h:37
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
Class responsble for automaticall forwarding of HTTP/CGI requests to other hosts over SCGI...
Definition: forwarder.h:31