ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

192 lines
5.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Lesser General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #ifndef CPPCMS_HTTP_CONTEXT_H
  20. #define CPPCMS_HTTP_CONTEXT_H
  21. #include <cppcms/defs.h>
  22. #include <booster/hold_ptr.h>
  23. #include <booster/intrusive_ptr.h>
  24. #include <booster/shared_ptr.h>
  25. #include <booster/enable_shared_from_this.h>
  26. #include <booster/callback.h>
  27. #include <locale>
  28. namespace cppcms {
  29. class service;
  30. class application;
  31. class cache_interface;
  32. class session_interface;
  33. namespace json { class value; }
  34. namespace impl { namespace cgi { class connection; } }
  35. ///
  36. /// \brief This namespace represent classes that are directly connected to handing HTTP requests and responses
  37. ///
  38. namespace http {
  39. class request;
  40. class response;
  41. ///
  42. /// \brief context is a central class that holds all specific connection related information.
  43. /// It encapsulates CGI request and response, cache, session and locale information
  44. ///
  45. /// Instance of this class is created upon client requests, it provides access to all
  46. /// connection related interfaces. This class is unique per each applications hierarchy
  47. /// and destroyed when HTTP request/response is completed
  48. ///
  49. class CPPCMS_API context :
  50. public booster::noncopyable,
  51. public booster::enable_shared_from_this<context>
  52. {
  53. public:
  54. /// \cond INTERNAL
  55. context(booster::shared_ptr<impl::cgi::connection> conn);
  56. ~context();
  57. impl::cgi::connection &connection();
  58. void run();
  59. /// \endcond
  60. ///
  61. /// Get an interface to HTTP request
  62. ///
  63. http::request &request();
  64. ///
  65. /// Get an interface to HTTP response
  66. ///
  67. http::response &response();
  68. ///
  69. /// Get global settings. Same as cppcms::service::settings
  70. ///
  71. json::value const &settings();
  72. ///
  73. /// Get an interface to CppCMS Cache
  74. ///
  75. cache_interface &cache();
  76. ///
  77. /// Get an interface to current session
  78. ///
  79. /// Note, when using asynchronous CppCMS applications, session data is not fetched
  80. /// and is not updated, because session access may be not cheap, So when using
  81. /// session_interface in asynchronous application make sure you call session_inerface::load
  82. /// member function
  83. ///
  84. session_interface &session();
  85. ///
  86. /// Get current context locale
  87. ///
  88. std::locale locale();
  89. ///
  90. /// Set locale explicitly. Note, it changes the locale of the response().out() stream as
  91. /// well
  92. ///
  93. void locale(std::locale const &new_locale);
  94. ///
  95. /// Set locale by name. Similar to locale(service().generator(name)).
  96. ///
  97. /// Note: it changes the locale of the response().out() stream as well
  98. ///
  99. void locale(std::string const &name);
  100. ///
  101. /// Get the central service instance
  102. ///
  103. cppcms::service &service();
  104. ///
  105. /// Get current views skin name
  106. ///
  107. std::string skin();
  108. ///
  109. /// Set current views skin name
  110. ///
  111. void skin(std::string const &name);
  112. typedef enum {
  113. operation_completed, ///< Asynchronous operation completed successfully
  114. operation_aborted ///< Asynchronous operation was canceled
  115. } complition_type;
  116. typedef booster::callback<void(complition_type)> handler;
  117. ///
  118. /// Send all pending output data to the client and
  119. /// finalize the connection. Note, you can't use this
  120. /// object for communication any more.
  121. ///
  122. void complete_response();
  123. ///
  124. /// Send all pending output data to the client and
  125. /// finalize the connection. Note, you can't use this
  126. /// object for communication any more.
  127. ///
  128. void async_complete_response();
  129. ///
  130. /// Send all pending data to user, when operation is complete
  131. /// call handler \a h with status.
  132. ///
  133. /// Note: if the status is operation_aborted, you can't use
  134. /// this connection any more, the peer gone.
  135. ///
  136. void async_flush_output(handler const &h);
  137. ///
  138. /// Set handler for peer reset events. It is useful to cleanup
  139. /// connections that had timeout or just disconnected by user
  140. ///
  141. /// Notes:
  142. ///
  143. /// -# if async_complete_response was called, handler would not
  144. /// be called any more.
  145. /// -# If async_flush_output fails, this does not mean that
  146. /// this handler would be called as well, so you need to check both
  147. ///
  148. void async_on_peer_reset(booster::callback<void()> const &h);
  149. private:
  150. void on_request_ready(bool error);
  151. static void dispatch(booster::intrusive_ptr<application> app,std::string url,bool syncronous);
  152. void try_restart(bool e);
  153. booster::shared_ptr<context> self();
  154. struct _data;
  155. booster::hold_ptr<_data> d;
  156. booster::shared_ptr<impl::cgi::connection> conn_;
  157. };
  158. }
  159. };
  160. #endif