CppCMS
cppcms/application.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_APPLICATION_H
00009 #define CPPCMS_APPLICATION_H
00010 
00011 #include <cppcms/defs.h>
00012 #include <booster/noncopyable.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/atomic_counter.h>
00015 #include <booster/intrusive_ptr.h>
00016 #include <booster/shared_ptr.h>
00017 #include <string>
00018 
00019 namespace cppcms {
00020         class application;
00021 }
00022 
00023 namespace booster {
00024         void CPPCMS_API intrusive_ptr_add_ref(cppcms::application *p);
00025         void CPPCMS_API intrusive_ptr_release(cppcms::application *p);
00026 }
00027 
00028 
00029 namespace cppcms {
00030 
00031         class service;
00032         class url_dispatcher;
00033         class url_mapper;
00034         class applications_pool;
00035         class application;
00036         class base_content;
00037         class cache_interface;
00038         class session_interface;
00039 
00040         namespace http {
00041                 class request;
00042                 class response;
00043                 class context;
00044         }
00045         namespace json {
00046                 class value;
00047         }
00048         namespace filters {
00049                 class streamable;
00050         }
00051 
00052 
00080 
00081         class CPPCMS_API application : public booster::noncopyable {
00082         public:
00086                 application(cppcms::service &srv);
00087 
00091                 virtual ~application();
00092 
00096                 cppcms::service &service();
00097                 
00101                 json::value const &settings();
00102 
00106                 http::context &context();
00107 
00111                 http::request &request();
00112 
00116                 http::response &response();
00117 
00125                 url_dispatcher &dispatcher();
00126 
00134                 url_mapper &mapper();
00135 
00139                 cache_interface &cache();
00140                 
00144                 session_interface &session();
00145 
00152                 void render(std::string template_name,base_content &content);
00159                 void render(std::string skin,std::string template_name,base_content &content);
00160 
00167                 void render(std::string template_name,std::ostream &out,base_content &content);
00168 
00175                 void render(std::string skin,std::string template_name,std::ostream &out,base_content &content);
00176 
00181                 void add(application &app);
00182 
00191                 void add(application &app,std::string const &regex,int part);
00192 
00203                 void add(application &app,std::string const &name,std::string const &url,std::string const &regex,int part);
00212                 void add(application &app,std::string const &name,std::string const &url);
00213 
00217                 void attach(application *app);
00224                 void attach(application *app,std::string const &regex,int part);
00231                 void attach(application *app,std::string const &name,std::string const &url);
00240                 void attach(application *app,std::string const &name,std::string const &url,std::string const &regex,int part);
00241 
00247                 application *parent();
00248 
00253                 application *root();
00254 
00261                 booster::shared_ptr<http::context> release_context();
00262 
00266                 booster::shared_ptr<http::context> get_context();
00267 
00273                 void assign_context(booster::shared_ptr<http::context> conn);
00274 
00278                 bool is_asynchronous();
00279 
00280 
00290                 virtual void main(std::string url);
00291 
00296                 virtual void init();
00297 
00301                 virtual void clear();
00302 
00306                 std::string translate(char const *context,char const *message);
00310                 std::string translate(char const *message);
00314                 std::string translate(char const *context,char const *single,char const *plural,int n);
00318                 std::string translate(char const *single,char const *plural,int n);
00319 
00320 
00326                 std::string url(std::string const &key);
00327 
00333                 std::string url(std::string const &key,
00334                                 filters::streamable const &p1);
00335 
00341                 std::string url(std::string const &key,
00342                                 filters::streamable const &p1,
00343                                 filters::streamable const &p2);
00344 
00350                 std::string url(std::string const &key,
00351                                 filters::streamable const &p1,
00352                                 filters::streamable const &p2,
00353                                 filters::streamable const &p3);
00354 
00360                 std::string url(std::string const &key,
00361                                 filters::streamable const &p1,
00362                                 filters::streamable const &p2,
00363                                 filters::streamable const &p3,
00364                                 filters::streamable const &p4);
00370                 std::string url(std::string const &key,
00371                                 filters::streamable const &p1,
00372                                 filters::streamable const &p2,
00373                                 filters::streamable const &p3,
00374                                 filters::streamable const &p4,
00375                                 filters::streamable const &p5);
00381                 std::string url(std::string const &key,
00382                                 filters::streamable const &p1,
00383                                 filters::streamable const &p2,
00384                                 filters::streamable const &p3,
00385                                 filters::streamable const &p4,
00386                                 filters::streamable const &p5,
00387                                 filters::streamable const &p6);
00388 
00389         private:
00390 
00391                 void recycle();
00392                 void parent(application *parent);
00393 
00394                 void pool_id(int id);
00395                 int pool_id();
00396 
00397 
00398                 struct _data; // future use
00399                 booster::hold_ptr<_data> d;
00400 
00401                 application *parent_;
00402                 application *root_;
00403 
00404                 booster::atomic_counter refs_;
00405                 friend class applications_pool;
00406                 friend void booster::intrusive_ptr_add_ref(application *p);
00407                 friend void booster::intrusive_ptr_release(application *p);
00408         };
00409 
00410 } // cppcms
00411 
00412 #endif
00413 
00414