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;
36  class base_content;
37  class cache_interface;
38  class session_interface;
39 
40  namespace http {
41  class request;
42  class response;
43  class context;
44  }
45  namespace json {
46  class value;
47  }
48  namespace filters {
49  class streamable;
50  }
51 
52 
80 
81  class CPPCMS_API application : public booster::noncopyable {
82  public:
87 
91  virtual ~application();
92 
97 
101  json::value const &settings();
102 
106  http::context &context();
107 
111  http::request &request();
112 
116  http::response &response();
117 
125  url_dispatcher &dispatcher();
126 
134  url_mapper &mapper();
135 
139  cache_interface &cache();
140 
144  session_interface &session();
145 
152  void render(std::string template_name,base_content &content);
159  void render(std::string skin,std::string template_name,base_content &content);
160 
167  void render(std::string template_name,std::ostream &out,base_content &content);
168 
175  void render(std::string skin,std::string template_name,std::ostream &out,base_content &content);
176 
181  void add(application &app);
182 
191  void add(application &app,std::string const &regex,int part);
192 
203  void add(application &app,std::string const &name,std::string const &url,std::string const &regex,int part);
212  void add(application &app,std::string const &name,std::string const &url);
213 
217  void attach(application *app);
224  void attach(application *app,std::string const &regex,int part);
231  void attach(application *app,std::string const &name,std::string const &url);
240  void attach(application *app,std::string const &name,std::string const &url,std::string const &regex,int part);
241 
247  application *parent();
248 
253  application *root();
254 
261  booster::shared_ptr<http::context> release_context();
262 
267 
273  void assign_context(booster::shared_ptr<http::context> conn);
274 
278  bool is_asynchronous();
279 
280 
290  virtual void main(std::string url);
291 
296  virtual void init();
297 
301  virtual void clear();
302 
306  std::string translate(char const *context,char const *message);
310  std::string translate(char const *message);
314  std::string translate(char const *context,char const *single,char const *plural,int n);
318  std::string translate(char const *single,char const *plural,int n);
319 
320 
326  std::string url(std::string const &key);
327 
333  std::string url(std::string const &key,
334  filters::streamable const &p1);
335 
341  std::string url(std::string const &key,
342  filters::streamable const &p1,
343  filters::streamable const &p2);
344 
350  std::string url(std::string const &key,
351  filters::streamable const &p1,
352  filters::streamable const &p2,
353  filters::streamable const &p3);
354 
360  std::string url(std::string const &key,
361  filters::streamable const &p1,
362  filters::streamable const &p2,
363  filters::streamable const &p3,
364  filters::streamable const &p4);
370  std::string url(std::string const &key,
371  filters::streamable const &p1,
372  filters::streamable const &p2,
373  filters::streamable const &p3,
374  filters::streamable const &p4,
375  filters::streamable const &p5);
381  std::string url(std::string const &key,
382  filters::streamable const &p1,
383  filters::streamable const &p2,
384  filters::streamable const &p3,
385  filters::streamable const &p4,
386  filters::streamable const &p5,
387  filters::streamable const &p6);
388 
389  private:
390 
391  void recycle();
392  void parent(application *parent);
393 
394  void pool_id(int id);
395  int pool_id();
396 
397 
398  struct _data; // future use
400 
401  application *parent_;
402  application *root_;
403 
405  friend class applications_pool;
406  friend void booster::intrusive_ptr_add_ref(application *p);
407  friend void booster::intrusive_ptr_release(application *p);
408  };
409 
410 } // cppcms
411 
412 #endif
413 
414 
This class is central representation of json objects.
Definition: json.h:142
This class represent the central event loop of the CppCMS applications.
Definition: service.h:59
This class provides an access to an application for session management.
Definition: session_interface.h:69
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:45
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:31
application class is the base class for all user created applications.
Definition: application.h:81
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:137
basic_message< char > message
Definition: message.h:494
Application pool is the central class that holds user created applications.
Definition: applications_pool.h:41
This class is used to glue between member function of application class and urls. ...
Definition: url_dispatcher.h:45
A special proxy object for writing any object to a std::ostream.
Definition: filters.h:34
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:34