Main  /  Edit  /  History  /   /  Users Area

cppcms::worker_thread & cppcms::application

Table of Contents


worker_thread and application are very similar classes that gives user similar APIs but they have important differences:

worker_thread has single instance in each worker thread or process, it is usually not used directly, but it is referenced by several application classes.

In many cases, we need to have more then one application or sub application in our process (for example wiki and forum or users panel and administration panel).

All these application share same controls like access to cache and sessions, access for HTTP requests --- all these stored in worker_thread class.

In terms of API, both classes are very similar with the difference that worker_thread stores actual data and application stores references to this data in worker_thread.

In most of cases developers should derive their own classes from cppcms::application and not from cppcms::worker_thread.


worker_thread(manager const &s);
application(worker_thread &w);

worker_thread and application constructors should receive a reference to manager and primary worker_thread.

For example:

class my_application : public application {
  my_application(worker_thread &w) : application(w) {

Public Members


worker_thread &worker;
url_parser &url;
manager const &app;
cgicc::Cgicc *&cgi;
cgicc::CgiEnvironment const *&env;
cgicc_connection *&cgi_conn;
cache_iface &cache;
session_interface &session;
ostream &cout;
boost::signal<void()> &on_start;
boost::signal<void()> &on_end;


url_parser url;
manager const &app;
cgicc::Cgicc *cgi;
cgicc::CgiEnvironment const *env;
cgicc_connection *cgi_conn;
cache_iface cache;
session_interface session;
ostream cout;
boost::signal<void()> on_start;
boost::signal<void()> on_end;


Public Member Functions

HTTP Headers

Fine Granted Output Control

These functions are available starting from CppCMS 0.0.3


Setting language dynamically:

Translating strings:

Note: In contrary to GNU gettext library, these functions are thread safe --- you can use different languages in different threads safely.

Working with different domain:

Templates rendering

Setting skins

void use_template(string s="");

Set template. If no specified, default is used. For example:


Rendering output

void render(string teml,base_content &c);
void render(string view,string teml,base_content &c);
void render(string teml,base_content &c,ostream &o);
void render(string view,string teml,base_content &c,ostream &o);

Render specific function templ using content c. If view specified, render using view view instead of default.

If ostream &o specified render template to o instead of cout. The recent is useful to create partial renderings and caching them. For example:

ostringstream tmp;

cppcms::application member functions

Virtual Member functions

Note: these functions are used only in cppcms::application class where user can override default functionality. They does not exist in worker_thread or have different semantics.

Public Template Member Functions

These functions are used for easier connection of SQL libraries to an application. Assuming you have persistent SQL connection per thread.

These functions implemented as template functions in order to prevent linking with specific libraries.


template<typename SQL>
void soci_load(SQL &sql)

Connect to SQL database using SOCI.

CppCMS Configuration parameters:


template<typename SQL>
void dbixx_load(SQL &sql);

Connects to database using dbixx library, it uses following parameters:

All other parameters are taken from configuration using prefix given in dbixx.driver. For example:


Refer to libdbi-drivers documentation pages for setting up correct parameters.


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

Поддержать проект

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0