CppCMS
http_context.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_HTTP_CONTEXT_H
9 #define CPPCMS_HTTP_CONTEXT_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/hold_ptr.h>
13 #include <booster/intrusive_ptr.h>
14 #include <booster/shared_ptr.h>
15 #include <booster/enable_shared_from_this.h>
16 #include <booster/callback.h>
17 #include <booster/noncopyable.h>
18 #include <locale>
19 
20 namespace cppcms {
21 
22  class service;
23  class application;
24  class application_specific_pool;
25  class cache_interface;
26  class session_interface;
27  namespace json { class value; }
28  namespace impl { namespace cgi { class connection; } }
29 
33  namespace http {
34  class request;
35  class response;
36  class file;
37 
46 
47  class CPPCMS_API context :
48  public booster::noncopyable,
49  public booster::enable_shared_from_this<context>
50  {
51  public:
53 
55  ~context();
56  impl::cgi::connection &connection();
57  void run();
58 
60 
65 
70 
74  json::value const &settings();
75 
79  cache_interface &cache();
80 
89  session_interface &session();
90 
94  std::locale locale();
95 
100  void locale(std::locale const &new_locale);
101 
107  void locale(std::string const &name);
108 
113 
117  std::string skin();
118 
122  void skin(std::string const &name);
123 
124 
125  typedef enum {
127  operation_aborted
128  } completion_type;
129 
131 
137  void complete_response();
138 
144  void async_complete_response();
145 
153 
154  void async_flush_output(handler const &h);
155 
167  void async_on_peer_reset(booster::callback<void()> const &h);
180  void submit_to_pool(booster::shared_ptr<application_specific_pool> pool,std::string const &matched_url);
194  void submit_to_asynchronous_application(booster::intrusive_ptr<application> app,std::string const &matched_url);
195 
196  private:
197  struct holder { virtual ~holder() {} };
198  template<typename T>
199  struct specific_holder : public holder {
200  specific_holder(T *ptr) : p(ptr) {}
201  virtual ~specific_holder() {}
203  };
204  public:
210  template<typename T>
212  {
213  specific_holder<T> *sh=dynamic_cast<specific_holder<T> *>(get_holder());
214  if(!sh)
215  return 0;
216  return sh->p.get();
217  }
222  template<typename T>
223  void reset_specific(T *ptr = 0)
224  {
225  if(ptr == 0) {
226  set_holder(0);
227  return;
228  }
229  specific_holder<T> *sh=dynamic_cast<specific_holder<T> *>(get_holder());
230  if(sh) {
231  sh->p.reset(ptr);
232  }
233  else {
234  specific_holder<T> *sh = new specific_holder<T>(ptr);
235  set_holder(sh);
236  }
237  }
242  template<typename T>
244  {
245  T *r = 0;
246  specific_holder<T> *sh=dynamic_cast<specific_holder<T> *>(get_holder());
247  if(sh) {
248  r = sh->p.release();
249  }
250  set_holder(0);
251  return r;
252  }
253  private:
254 
255  void set_holder(holder *p);
256  holder *get_holder();
257 
258  friend class impl::cgi::connection;
259  int on_content_progress(size_t n);
260  int on_headers_ready();
261  int translate_exception();
262  void make_error_message(std::exception const &e);
263  void on_request_ready(bool error);
264  void submit_to_pool_internal(booster::shared_ptr<application_specific_pool> pool,std::string const &matched,bool now);
265  static void dispatch(booster::shared_ptr<application_specific_pool> const &pool,booster::shared_ptr<context> const &self,std::string const &url);
266  static void dispatch(booster::intrusive_ptr<application> const &app,std::string const &url,bool syncronous);
267  void try_restart(bool e);
269 
270  struct _data;
273  };
274 
275  }
276 
277 };
278 
279 #endif
completion_type
Definition: http_context.h:125
This class is central representation of json objects.
Definition: json.h:140
a smart pointer similar to std::auto_ptr but it is non-copyable and underlying object has same constn...
Definition: hold_ptr.h:18
void reset_specific(T *ptr=0)
Definition: http_context.h:223
This class represent the central event loop of the CppCMS applications.
Definition: service.h:62
Definition: callback.h:18
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
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
T * get_specific()
Definition: http_context.h:211
intrusive_ptr is the class taken as-is from boost.
Definition: intrusive_ptr.h:42
Asynchronous operation completed successfully.
Definition: http_context.h:126
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
this class represents all HTTP/CGI response related API, generation of output content and HTTP header...
Definition: http_response.h:36
This class is the major gateway of the application to CppCMS caching abilities. Any access too cache ...
Definition: cache_interface.h:139
This class is borrowed from boost.
Definition: enable_shared_from_this.h:30
T * release_specific()
Definition: http_context.h:243
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