CppCMS
|
application class is the base class for all user created applications. More...
#include <cppcms/application.h>
Public Member Functions | |
application (cppcms::service &srv) | |
virtual | ~application () |
cppcms::service & | service () |
json::value const & | settings () |
http::context & | context () |
http::request & | request () |
http::response & | response () |
url_dispatcher & | dispatcher () |
url_mapper & | mapper () |
cache_interface & | cache () |
session_interface & | session () |
void | render (std::string template_name, base_content &content) |
void | render (std::string skin, std::string template_name, base_content &content) |
void | render (std::string template_name, std::ostream &out, base_content &content) |
void | render (std::string skin, std::string template_name, std::ostream &out, base_content &content) |
void | add (application &app) |
void | add (application &app, std::string const ®ex, int part) |
void | add (application &app, std::string const &name, std::string const &url, std::string const ®ex, int part) |
void | add (application &app, std::string const &name, std::string const &url) |
void | attach (application *app) |
void | attach (application *app, std::string const ®ex, int part) |
void | attach (application *app, std::string const &name, std::string const &url) |
void | attach (application *app, std::string const &name, std::string const &url, std::string const ®ex, int part) |
application * | parent () |
application * | root () |
booster::shared_ptr< http::context > | release_context () |
booster::shared_ptr< http::context > | get_context () |
void | assign_context (booster::shared_ptr< http::context > conn) |
void | add_context (http::context &conn) |
void | remove_context () |
bool | is_asynchronous () |
bool | has_context () |
bool | owns_context () |
virtual void | main (std::string url) |
virtual void | init () |
virtual void | clear () |
std::string | translate (char const *context, char const *message) |
std::string | translate (char const *message) |
std::string | translate (char const *context, char const *single, char const *plural, int n) |
std::string | translate (char const *single, char const *plural, int n) |
std::string | url (std::string const &key) |
std::string | url (std::string const &key, filters::streamable const &p1) |
std::string | url (std::string const &key, filters::streamable const &p1, filters::streamable const &p2) |
std::string | url (std::string const &key, filters::streamable const &p1, filters::streamable const &p2, filters::streamable const &p3) |
std::string | url (std::string const &key, filters::streamable const &p1, filters::streamable const &p2, filters::streamable const &p3, filters::streamable const &p4) |
std::string | url (std::string const &key, filters::streamable const &p1, filters::streamable const &p2, filters::streamable const &p3, filters::streamable const &p4, filters::streamable const &p5) |
std::string | url (std::string const &key, filters::streamable const &p1, filters::streamable const &p2, filters::streamable const &p3, filters::streamable const &p4, filters::streamable const &p5, filters::streamable const &p6) |
Friends | |
class | applications_pool |
class | application_specific_pool |
void | booster::intrusive_ptr_add_ref (application *p) |
void | booster::intrusive_ptr_release (application *p) |
application class is the base class for all user created applications.
This class is the base for all user actions required for web page generation. User application classes are created upon web page request and then cached in application_pool.
Applications can be bundled to hierarchies. You may add a sub application to hierarchy, and they will always be connected with topmost application and their lifetime would be binded to them.
application class is reference counted and may be used with intrusive_ptr. But reference count semantics is very different form an ordinary semantics for other classes derived from cppcms::refcounted.
There two ways to add sub-applications to hierarchy:
cppcms::application::application | ( | cppcms::service & | srv | ) |
Create a new application running on service srv, with a parent parent
|
virtual |
Destroys an application and all assigned application children.
void cppcms::application::add | ( | application & | app | ) |
Register an application app as child. Ownership of app is not transfered to parent, however it would shared it's parent reference count.
void cppcms::application::add | ( | application & | app, |
std::string const & | regex, | ||
int | part | ||
) |
Register an application app as child and mount it into url dispatched calling dispatcher().mount(regex,app,part);
Ownership of app is not transfered to parent, however it would shared it's parent reference count.
void cppcms::application::add | ( | application & | app, |
std::string const & | name, | ||
std::string const & | url, | ||
std::string const & | regex, | ||
int | part | ||
) |
Register an application app as child and mount it into:
url_mapper calling mapper().mount(name,url,app);
Ownership of app is not transfered to parent, however it would shared it's parent reference count.
void cppcms::application::add | ( | application & | app, |
std::string const & | name, | ||
std::string const & | url | ||
) |
Register an application app as child and mount it into url_mapper calling mapper().mount(name,url,app);
Ownership of app is not transfered to parent, however it would shared it's parent reference count.
void cppcms::application::add_context | ( | http::context & | conn | ) |
Add context to applications such that context ownership isn't transferred to the application
void cppcms::application::assign_context | ( | booster::shared_ptr< http::context > | conn | ) |
Set context to the application. The application gets shared ownership on the context.
Note: because application hierarchy shared same context, it affects all classes in it.
void cppcms::application::attach | ( | application * | app | ) |
Register an application app as child. Ownership of app is transfered to parent
void cppcms::application::attach | ( | application * | app, |
std::string const & | regex, | ||
int | part | ||
) |
Register an application app as child and mount it into url_dispatcher calling dispatcher().mount(regex,*app,part);
Ownership of app is transfered to parent.
void cppcms::application::attach | ( | application * | app, |
std::string const & | name, | ||
std::string const & | url | ||
) |
Register an application app as child and mount it into url_mapper calling mapper().mount(name,url,*app);
Ownership of app is transfered to parent.
void cppcms::application::attach | ( | application * | app, |
std::string const & | name, | ||
std::string const & | url, | ||
std::string const & | regex, | ||
int | part | ||
) |
Register an application app as child and mount it into:
url_mapper calling mapper().mount(name,url,*app);
Ownership of app is transfered to parent.
cache_interface& cppcms::application::cache | ( | ) |
Get a cache_interface instance. Same as context().cache();
|
virtual |
This function is used for cleanup unused stuff, it should not throw
Referenced by cppcms::url_dispatcher::assign().
http::context& cppcms::application::context | ( | ) |
Get a context of the single HTTP request/response.
url_dispatcher& cppcms::application::dispatcher | ( | ) |
Get a dispatched class – class that responsible on mapping between URLs and a member functions of application class.
This member function is application specific and not Connection specific.
booster::shared_ptr<http::context> cppcms::application::get_context | ( | ) |
Get reference counted pointer to the http::context
bool cppcms::application::has_context | ( | ) |
Returns true if there is a context added or assigned to application
|
virtual |
This member function called when URL is dispatched to this application, it is useful when member functions of applications are called, by default does nothing
bool cppcms::application::is_asynchronous | ( | ) |
Returns true if current application was created as asynchronous application.
|
virtual |
This is main function of the application that is called when it is matched according to the regular expression in the applications_pool class.
By default, main calls dispatcher().dispatch(url). And if the last fails, it creates 404 Error page. This allows developers to create its own hooks for reaction on incoming URL as, initialization and cleanup of general resources, Custom 404 and error handlers etc.
Reimplemented in cppcms::rpc::json_rpc_server.
url_mapper& cppcms::application::mapper | ( | ) |
Get a url_mapper class – class that responsible on mapping between real objects and urls displayer on the page.
This member function is application specific and not Connection specific.
bool cppcms::application::owns_context | ( | ) |
Returns true if the application owns a context (that can be released for example)
application* cppcms::application::parent | ( | ) |
Get the parent of the application, if the application is the topmost class in hierarchy, it would return this, So, if you want to check if the application has any parent test app->parent()!=app;
booster::shared_ptr<http::context> cppcms::application::release_context | ( | ) |
Request from an application give-up on ownership of the http::context class and give it to the user control. Usually it is required for processing asynchronous requests.
Note: because application hierarchy shared same context, it affects all classes in it.
void cppcms::application::remove_context | ( | ) |
Remove context added with add_context
void cppcms::application::render | ( | std::string | template_name, |
base_content & | content | ||
) |
Render a template template_name of default skin using content content.
Side effect requires: output stream for response class, causes all updated session data be saved and all headers be written. You can't change headers after calling this function.
void cppcms::application::render | ( | std::string | skin, |
std::string | template_name, | ||
base_content & | content | ||
) |
Render a template template_name of skin skin using content content.
Side effect requires: output stream for response class, causes all updated session data be saved and all headers be written. You can't change headers after calling this function.
void cppcms::application::render | ( | std::string | template_name, |
std::ostream & | out, | ||
base_content & | content | ||
) |
void cppcms::application::render | ( | std::string | skin, |
std::string | template_name, | ||
std::ostream & | out, | ||
base_content & | content | ||
) |
http::request& cppcms::application::request | ( | ) |
http::response& cppcms::application::response | ( | ) |
Get a HTTP response information class, same as context().response();
application* cppcms::application::root | ( | ) |
Get the root application of the hierarchy. Note, if the application is the topmost one, this pointer would be returned
cppcms::service& cppcms::application::service | ( | ) |
Get the main service
session_interface& cppcms::application::session | ( | ) |
Get current session_interface instance. Same as context().session();
json::value const& cppcms::application::settings | ( | ) |
Get global service settings
std::string cppcms::application::translate | ( | char const * | context, |
char const * | message | ||
) |
Translate a message in current locale for given message in context
std::string cppcms::application::translate | ( | char const * | message | ) |
Translate a message in current locale for given message
std::string cppcms::application::translate | ( | char const * | context, |
char const * | single, | ||
char const * | plural, | ||
int | n | ||
) |
Translate a message in current locale for given single and plural form for number n in context.
std::string cppcms::application::translate | ( | char const * | single, |
char const * | plural, | ||
int | n | ||
) |
Translate a message in current locale for given single and plural form for number n
std::string cppcms::application::url | ( | std::string const & | key | ) |
Map url-key key to actual URL, without parameters
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1 | ||
) |
Map url-key key to actual URL, with parameter p1
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1, | ||
filters::streamable const & | p2 | ||
) |
Map url-key key to actual URL, with parameters p1, p2
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1, | ||
filters::streamable const & | p2, | ||
filters::streamable const & | p3 | ||
) |
Map url-key key to actual URL, with parameters p1, p2, p3
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1, | ||
filters::streamable const & | p2, | ||
filters::streamable const & | p3, | ||
filters::streamable const & | p4 | ||
) |
Map url-key key to actual URL, with parameters p1, p2, p3, p4
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1, | ||
filters::streamable const & | p2, | ||
filters::streamable const & | p3, | ||
filters::streamable const & | p4, | ||
filters::streamable const & | p5 | ||
) |
Map url-key key to actual URL, with parameters p1, p2, p3, p4, p5
Effectively it calls mapper().map(...)
std::string cppcms::application::url | ( | std::string const & | key, |
filters::streamable const & | p1, | ||
filters::streamable const & | p2, | ||
filters::streamable const & | p3, | ||
filters::streamable const & | p4, | ||
filters::streamable const & | p5, | ||
filters::streamable const & | p6 | ||
) |
Map url-key key to actual URL, with parameters p1, p2, p3, p4, p5, p6
Effectively it calls mapper().map(...)