00001
00002
00003
00004
00005
00006
00008 #ifndef CPPCMS_SERVICE_H
00009 #define CPPCMS_SERVICE_H
00010
00011 #include <cppcms/defs.h>
00012 #include <booster/noncopyable.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/function.h>
00015 #include <locale>
00016 #include <memory>
00017 #include <cppcms/locale_fwd.h>
00018 #include <cppcms/json.h>
00019
00020 namespace booster {
00021 namespace aio {
00022 class io_service;
00023 }
00024 }
00025
00029 namespace cppcms {
00030 namespace impl {
00031 struct cached_settings;
00032 class service;
00033 namespace cgi {
00034 class acceptor;
00035 }
00036 }
00037
00038 class applications_pool;
00039 class thread_pool;
00040 class session_pool;
00041 class cache_pool;
00042 class forwarder;
00043
00044 namespace json {
00045 class value;
00046 }
00047 namespace views {
00048 class manager;
00049 }
00050
00058
00059 class CPPCMS_API service : public booster::noncopyable
00060 {
00061 public:
00067 static json::value load_settings(int argc,char *argv[]);
00071 service(json::value const &v);
00078 service(int argc,char *argv[]);
00084 ~service();
00085
00095 void run();
00096
00100 void shutdown();
00101
00105 json::value const &settings();
00106
00110 cppcms::applications_pool &applications_pool();
00114 cppcms::thread_pool &thread_pool();
00118 cppcms::session_pool &session_pool();
00122 cppcms::views::manager &views_pool();
00126 cppcms::cache_pool &cache_pool();
00130 cppcms::forwarder &forwarder();
00131
00135 locale::generator const &generator();
00139 std::locale locale();
00143 std::locale locale(std::string const &name);
00144
00145
00150 booster::aio::io_service &get_io_service();
00151
00156 void post(booster::function<void()> const &handler);
00157
00162 void after_fork(booster::function<void()> const &handler);
00163
00167 int threads_no();
00168
00172 int procs_no();
00173
00186 int process_id();
00187
00189
00190
00191
00192 cppcms::impl::service &impl();
00193
00194 impl::cached_settings const &cached_settings();
00195
00196
00198
00199 private:
00200 void setup();
00201 std::auto_ptr<cppcms::impl::cgi::acceptor> setup_acceptor(json::value const &,int,int shift=0);
00202 void stop();
00203 void start_acceptor(bool after_fork=false);
00204 void setup_exit_handling();
00205 bool prefork();
00206 void run_prepare();
00207 void after_fork_exec();
00208 void run_acceptor();
00209 void run_event_loop();
00210 #ifdef CPPCMS_WIN32
00211 void run_win_console();
00212 #endif
00213 #ifdef CPPCMS_WIN_NATIVE
00214 void win_service_prepare();
00215 void win_service_exec();
00216 void run_win_service();
00217 #endif
00218 booster::hold_ptr<impl::service> impl_;
00219 };
00220
00221 }
00222
00223
00224
00225
00226 #endif