CppCMS
application.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_APPLICATION_H
9 #define CPPCMS_APPLICATION_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/atomic_counter.h>
15 #include <booster/intrusive_ptr.h>
16 #include <booster/shared_ptr.h>
17 #include <string>
18 
19 namespace cppcms {
20  class application;
21 }
22 
23 namespace booster {
24  void CPPCMS_API intrusive_ptr_add_ref(cppcms::application *p);
25  void CPPCMS_API intrusive_ptr_release(cppcms::application *p);
26 }
27 
28 
29 namespace cppcms {
30 
31  class service;
32  class url_dispatcher;
33  class url_mapper;
34  class applications_pool;
35  class application_specific_pool;
36  class application;
37  class base_content;
38  class cache_interface;
39  class session_interface;
40 
41  namespace http {
42  class request;
43  class response;
44  class context;
45  }
46  namespace json {
47  class value;
48  }
49  namespace filters {
50  class streamable;
51  }
52 
53 
81 
82  class CPPCMS_API application : public booster::noncopyable {
83  public:
88 
92  virtual ~application();
93 
98 
102  json::value const &settings();
103 
107  http::context &context();
108 
112  http::request &request();
113 
117  http::response &response();
118 
126  url_dispatcher &dispatcher();
127 
135  url_mapper &mapper();
136 
140  cache_interface &cache();
141 
145  session_interface &session();
146 
153  void render(std::string template_name,base_content &content);
160  void render(std::string skin,std::string template_name,base_content &content);
161 
168  void render(std::string template_name,std::ostream &out,base_content &content);
169 
176  void render(std::string skin,std::string template_name,std::ostream &out,base_content &content);
177 
182  void add(application &app);
183 
192  void add(application &app,std::string const &regex,int part);
193 
204  void add(application &app,std::string const &name,std::string const &url,std::string const &regex,int part);
213  void add(application &app,std::string const &name,std::string const &url);
214 
218  void attach(application *app);
225  void attach(application *app,std::string const &regex,int part);
232  void attach(application *app,std::string const &name,std::string const &url);
241  void attach(application *app,std::string const &name,std::string const &url,std::string const &regex,int part);
242 
248  application *parent();
249 
254  application *root();
255 
262  booster::shared_ptr<http::context> release_context();
263 
268 
274  void assign_context(booster::shared_ptr<http::context> conn);
275 
281  void add_context(http::context &conn);
282 
287  void remove_context();
288 
292  bool is_asynchronous();
293 
298  bool has_context();
299 
304  bool owns_context();
305 
306 
316  virtual void main(std::string url);
317 
322  virtual void init();
323 
327  virtual void clear();
328 
332  std::string translate(char const *context,char const *message);
336  std::string translate(char const *message);
340  std::string translate(char const *context,char const *single,char const *plural,int n);
344  std::string translate(char const *single,char const *plural,int n);
345 
346 
352  std::string url(std::string const &key);
353 
359  std::string url(std::string const &key,
360  filters::streamable const &p1);
361 
367  std::string url(std::string const &key,
368  filters::streamable const &p1,
369  filters::streamable const &p2);
370 
376  std::string url(std::string const &key,
377  filters::streamable const &p1,
378  filters::streamable const &p2,
379  filters::streamable const &p3);
380 
386  std::string url(std::string const &key,
387  filters::streamable const &p1,
388  filters::streamable const &p2,
389  filters::streamable const &p3,
390  filters::streamable const &p4);
396  std::string url(std::string const &key,
397  filters::streamable const &p1,
398  filters::streamable const &p2,
399  filters::streamable const &p3,
400  filters::streamable const &p4,
401  filters::streamable const &p5);
407  std::string url(std::string const &key,
408  filters::streamable const &p1,
409  filters::streamable const &p2,
410  filters::streamable const &p3,
411  filters::streamable const &p4,
412  filters::streamable const &p5,
413  filters::streamable const &p6);
414 
415  private:
416 
417  void recycle();
418  void parent(application *parent);
419 
422 
423 
424  struct _data; // future use
426 
427  application *parent_;
428  application *root_;
429 
431  friend class applications_pool;
432  friend class application_specific_pool;
433  friend void booster::intrusive_ptr_add_ref(application *p);
434  friend void booster::intrusive_ptr_release(application *p);
435  };
436 
437 } // cppcms
438 
439 #endif
440 
441 
This class is central representation of json objects.
Definition: json.h:140
This class represent the central event loop of the CppCMS applications.
Definition: service.h:62
This class provides an access to an application for session management.
Definition: session_interface.h:107
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
basic_message< CharType > translate(CharType const *msg)
Translate a message, msg is not copied.
Definition: message.h:530
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:47
This is a simple polymorphic class that every content for templates rendering should be derided from ...
Definition: base_content.h:23
class for mapping URLs - the opposite of dispatch
Definition: url_mapper.h:149
this class represents all HTTP/CGI response related API, generation of output content and HTTP header...
Definition: http_response.h:36
application class is the base class for all user created applications.
Definition: application.h:82
an interface for creating user applications
Definition: applications_pool.h:66
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:139
basic_message< char > message
Definition: message.h:494
Application pool is the central class that holds user created applications.
Definition: applications_pool.h:145
This class is used to glue between member function of application class and urls. ...
Definition: url_dispatcher.h:101
A special proxy object for writing any object to a std::ostream.
Definition: filters.h:67
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
Atomic counter is a class that allows perform counting in thread safe way.
Definition: atomic_counter.h:33
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
This class represents all information related to the HTTP/CGI request.
Definition: http_request.h:37