CppCMS
cppcms/http_context.h
00001 
00002 //                                                                             
00003 //  Copyright (C) 2008-2012  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
00004 //                                                                             
00005 //  See accompanying file COPYING.TXT file for licensing details.
00006 //
00008 #ifndef CPPCMS_HTTP_CONTEXT_H
00009 #define CPPCMS_HTTP_CONTEXT_H
00010 
00011 #include <cppcms/defs.h>
00012 #include <booster/hold_ptr.h>
00013 #include <booster/intrusive_ptr.h>
00014 #include <booster/shared_ptr.h>
00015 #include <booster/enable_shared_from_this.h>
00016 #include <booster/callback.h>
00017 #include <booster/noncopyable.h>
00018 #include <locale>
00019 
00020 namespace cppcms {
00021 
00022         class service;
00023         class application;
00024         class cache_interface;
00025         class session_interface;
00026         namespace json { class value; }
00027         namespace impl { namespace cgi { class connection; } }
00028 
00032         namespace http {
00033                 class request;
00034                 class response;
00035 
00044                 
00045                 class CPPCMS_API context : 
00046                         public booster::noncopyable,
00047                         public booster::enable_shared_from_this<context>
00048                 {
00049                 public:
00051 
00052                         context(booster::shared_ptr<impl::cgi::connection> conn);
00053                         ~context();
00054                         impl::cgi::connection &connection();
00055                         void run();
00056 
00058 
00062                         http::request &request();
00063 
00067                         http::response &response();
00068 
00072                         json::value const &settings();
00073 
00077                         cache_interface &cache();
00078 
00087                         session_interface &session();
00088 
00092                         std::locale locale();
00093 
00098                         void locale(std::locale const &new_locale);
00099 
00105                         void locale(std::string const &name);
00106                         
00110                         cppcms::service &service();
00111 
00115                         std::string skin();
00116 
00120                         void skin(std::string const &name);
00121 
00122 
00123                         typedef enum {
00124                                 operation_completed, 
00125                                 operation_aborted    
00126                         } completion_type; 
00127 
00128                         typedef booster::callback<void(completion_type)> handler;
00129 
00135                         void complete_response();
00136 
00142                         void async_complete_response();
00143                         
00151 
00152                         void async_flush_output(handler const &h);
00153 
00165                         void async_on_peer_reset(booster::callback<void()> const &h);
00166                 private:
00167                         void on_request_ready(bool error);
00168                         static void dispatch(booster::intrusive_ptr<application> app,std::string url,bool syncronous);
00169                         void try_restart(bool e);
00170                         booster::shared_ptr<context> self();
00171 
00172                         struct _data;
00173                         booster::hold_ptr<_data> d;
00174                         booster::shared_ptr<impl::cgi::connection> conn_;
00175                 };
00176 
00177         }
00178 
00179 };
00180 
00181 #endif