cppcms::service Class Reference

This class represent the central event loop of the CppCMS applications. More...

`#include <cppcms/service.h>`

Inheritance diagram for cppcms::service:

## Public Member Functions

| service (json::value const &v)
| service (int argc, char *argv[])
| ~service ()
void | run ()
void | shutdown ()
json::value const & | settings ()
cppcms::applications_pool & | applications_pool ()
cppcms::thread_pool & | thread_pool ()
cppcms::session_pool & | session_pool ()
cppcms::views::manager & | views_pool ()
cppcms::cache_pool & | cache_pool ()
cppcms::forwarder & | forwarder ()
locale::generator const & | generator ()
std::locale | locale ()
std::locale | locale (std::string const &name)
booster::aio::io_service & | get_io_service ()
void | post (booster::function< void()> const &handler)
void | after_fork (booster::function< void()> const &handler)
int | threads_no ()
int | procs_no ()
int | process_id ()

## Static Public Member Functions

static json::value | load_settings (int argc, char *argv[])

## Detailed Description

This class represent the central event loop of the CppCMS applications.

This is the central class that is responsible for management of CppCMS services: management of HTTP requests and responses, sessions, cache and much more services. It is the central class that runs during execution of any CppCMS service.

## Constructor & Destructor Documentation

cppcms::service::service | ( | json::value const & | v | ) |

Create a new service, passing all configuration settings via json::value instead of parsing command line parameters.

cppcms::service::service | ( | int | argc,
|  | char * | argv[]
| ) |  |

Parse command line parameters, get the configuration file and additional options and create the service.

Note for Windows users: argv is assumed to be UTF-8 encoded strings, if you want pass non-ascii or "wide" parameters you need convert them from UTF-16 to UTF-8. For example you can use booster::nowide::convert functions.

cppcms::service::~service | ( |  | ) |

Destroy the service - the last class to go down.

Note, if you have asynchronous applications that are not owned the service class they must be destroyed before it

## Member Function Documentation

void cppcms::service::after_fork | ( | booster::function< void()> const & | handler | ) |

Execute handler after forking processes (on POSIX platforms). This is useful when you want to start various asynchronous applications or services in separate processes.

cppcms::applications_pool& cppcms::service::applications_pool | ( |  | ) |

Get a cppcms::applications_pool instance of this service

cppcms::cache_pool& cppcms::service::cache_pool | ( |  | ) |

Get the cppcms::cache_pool instance of this service, never used directly by user level applications

cppcms::forwarder& cppcms::service::forwarder | ( |  | ) |

Get cppcms::forwarder instance of this service

locale::generator const& cppcms::service::generator | ( |  | ) |

Get locale::generator instance of this service

booster::aio::io_service& cppcms::service::get_io_service | ( |  | ) |

Get low level central event loop of the CppCMS service that allows you to connect asynchronous application with generic asynchronous sockets API or create any asynchronous TCP/IP servers over it.

static json::value cppcms::service::load_settings | ( | int | argc,
|  | char * | argv[]
| ) |  |

static

Load configuration settings from the command line parameters. This object can be passed to service(json::value const &v) constructor allowing to alter these settings before creating the actual service object.

std::locale cppcms::service::locale | ( |  | ) |

Get the default locale for this service.

std::locale cppcms::service::locale | ( | std::string const & | name | ) |

Get a locale by name, shortcut to generator().get(name);

void cppcms::service::post | ( | booster::function< void()> const & | handler | ) |

Post an execution handler handler to the event loop queue. This member function is thread safe allowing safe communication between event loop thread (where all asynchronous applications run) and any other threads.

int cppcms::service::process_id | ( |  | ) |

Get current process identification number. Note, this is not getpid() function.

When CppCMS service manages preforked process pool, each process gets its own id starting from 1 to procs_no() when the parent supervisor process gets an id 0. If one of the forked processes crash, it is replaced with a new process with same id.

So if an application want to run certain activity that can't be executed in multiple processes it can setup an after_fork handle that would check the process id and start this activity.

Under Windows and Cygwin it is always 0.

int cppcms::service::procs_no | ( |  | ) |

Get the number of forked processes used by the service. Always 0 on Windows and Cygwin.

void cppcms::service::run | ( |  | ) |

Start the central even loop of CppCMS service. By default, it also install signal handlers on POSIX platforms to handle SIGINT, SIGTERM and SIGUSR1 signals or uses SetConsoleCtrlHandler on Windows platforms waiting on C, BREAK, CLOSE and SHUTDOWN events.

This even call service::shutdown function that stops the main event loop and shutdowns the service properly.

If you want to disable these handlers, you may set service.disable_global_exit_handling option to true.

cppcms::session_pool& cppcms::service::session_pool | ( |  | ) |

Get a cppcms::session_pool instance of this service, never used directly by user level applications

json::value const& cppcms::service::settings | ( |  | ) |

Get the configuration setting the service was created with.

void cppcms::service::shutdown | ( |  | ) |

Stop the service event loop. This member function is both thread and signal safe.

cppcms::thread_pool& cppcms::service::thread_pool | ( |  | ) |

Get a cppcms::thread_pool instance of this service

int cppcms::service::threads_no | ( |  | ) |

Get the size of thread pool each of CppCMS processes will be running.

cppcms::views::manager& cppcms::service::views_pool | ( |  | ) |

Get the cppcms::views::manager instance

The documentation for this class was generated from the following file:

- cppcms/service.h