Main  /  Edit  /  History  /   /  Users Area

cppcms::worker_thread & cppcms::application

Table of Contents

Roles

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.

Constructors

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

cppcms::application

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;

cppcms::worker_thread

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;

Description

Public Member Functions

HTTP Headers

Fine Granted Output Control

These functions are available starting from CppCMS 0.0.3

Localization

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:

if(session.is_set("skin"))
    use_template(session["skin"]);

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;
render("sidebar",content,tmp);
cache.store_frame("sidebar",tmp.str());

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.

SOCI

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

Connect to SQL database using SOCI.

CppCMS Configuration parameters:

DbiXX

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:

dbixx.driver="sqlite3"
sqlite3.dbname="wikipp.db"
sqlite3.sqlite3_dbdir="./db/"

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

Hi. I have some suggestions: 1)For the tutorial, put all codes which are supposed to appear together in one cpp file or header file together at the end of the tutorial and make sure that line numbers do not start from 1. 2. 3. again in each section of tutorial. Currently, it is not clear where a function or a file begins and ends because there are broken pieces of codes and all being with 1. 2. 3. 2)I am not familiar with web programing. I think people like me prefer to use cpp files to wrap html codes or probably there are good html "designer", like GUI designers, that produces the code and I can copy-paste for the "view" in CMV.


Navigation

Main Page



Valid CSS | Valid XHTML 1.0