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 <locale>
00018 
00019 namespace cppcms {
00020 
00021         class service;
00022         class application;
00023         class cache_interface;
00024         class session_interface;
00025         namespace json { class value; }
00026         namespace impl { namespace cgi { class connection; } }
00027 
00031         namespace http {
00032                 class request;
00033                 class response;
00034 
00043                 
00044                 class CPPCMS_API context : 
00045                         public booster::noncopyable,
00046                         public booster::enable_shared_from_this<context>
00047                 {
00048                 public:
00050 
00051                         context(booster::shared_ptr<impl::cgi::connection> conn);
00052                         ~context();
00053                         impl::cgi::connection &connection();
00054                         void run();
00055 
00057 
00061                         http::request &request();
00062 
00066                         http::response &response();
00067 
00071                         json::value const &settings();
00072 
00076                         cache_interface &cache();
00077 
00086                         session_interface &session();
00087 
00091                         std::locale locale();
00092 
00097                         void locale(std::locale const &new_locale);
00098 
00104                         void locale(std::string const &name);
00105                         
00109                         cppcms::service &service();
00110 
00114                         std::string skin();
00115 
00119                         void skin(std::string const &name);
00120 
00121 
00122                         typedef enum {
00123                                 operation_completed, 
00124                                 operation_aborted    
00125                         } completion_type; 
00126 
00127                         typedef booster::callback<void(completion_type)> handler;
00128 
00134                         void complete_response();
00135 
00141                         void async_complete_response();
00142                         
00150 
00151                         void async_flush_output(handler const &h);
00152 
00164                         void async_on_peer_reset(booster::callback<void()> const &h);
00165                 private:
00166                         void on_request_ready(bool error);
00167                         static void dispatch(booster::intrusive_ptr<application> app,std::string url,bool syncronous);
00168                         void try_restart(bool e);
00169                         booster::shared_ptr<context> self();
00170 
00171                         struct _data;
00172                         booster::hold_ptr<_data> d;
00173                         booster::shared_ptr<impl::cgi::connection> conn_;
00174                 };
00175 
00176         }
00177 
00178 };
00179 
00180 #endif