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 <booster/auto_ptr_inc.h>
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 plugin {
31  class scope;
32  }
33  namespace impl {
34  struct cached_settings;
35  class service;
36  namespace cgi {
37  class acceptor;
38  }
39  }
40 
41  class applications_pool;
42  class thread_pool;
43  class session_pool;
44  class cache_pool;
45  class forwarder;
46 
47  namespace json {
48  class value;
49  }
50  namespace views {
51  class manager;
52  }
53 
61 
62  class CPPCMS_API service : public booster::noncopyable
63  {
64  public:
70  static json::value load_settings(int argc,char *argv[]);
74  service(json::value const &v);
81  service(int argc,char *argv[]);
87  ~service();
88 
98  void run();
99 
103  void shutdown();
104 
108  json::value const &settings();
109 
125  cppcms::views::manager &views_pool();
129  cppcms::cache_pool &cache_pool();
134 
138  locale::generator const &generator();
142  std::locale locale();
146  std::locale locale(std::string const &name);
147 
148 
153  booster::aio::io_service &get_io_service();
154 
159  void post(booster::function<void()> const &handler);
160 
165  void after_fork(booster::function<void()> const &handler);
166 
170  int threads_no();
171 
175  int procs_no();
176 
189  int process_id();
190 
191 
195  plugin::scope &plugins();
196 
198 
199  // internal functions never call it directly
200 
201  cppcms::impl::service &impl();
202 
203  impl::cached_settings const &cached_settings();
204 
205 
207 
208  private:
209  void setup();
210  std::auto_ptr<cppcms::impl::cgi::acceptor> setup_acceptor(json::value const &,int,int shift=0);
211  void stop();
212  void start_acceptor(bool after_fork=false);
213  void setup_exit_handling();
214  bool prefork();
215  void run_prepare();
216  void after_fork_exec();
217  void run_acceptor();
218  void run_event_loop();
219  #ifdef CPPCMS_WIN32
220  void run_win_console();
221  #endif
222  #ifdef CPPCMS_WIN_NATIVE
223  void win_service_prepare();
224  void win_service_exec();
225  void run_win_service();
226  #endif
228  };
229 
230 } //
231 
232 
233 
234 
235 #endif
This class controls the views used my application it knows to load them dynamically and reload if nee...
Definition: views_pool.h:221
This class is central representation of json objects.
Definition: json.h:140
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:62
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
Definition: plugin.h:56
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:35
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
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:145
callback< void()> handler
Definition: types.h:58
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
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