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.
 
 
 
 
 
 

196 lines
5.8 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_APPLICATIONS_POOL_H
  20. #define CPPCMS_APPLICATIONS_POOL_H
  21. #include <cppcms/defs.h>
  22. #include <booster/noncopyable.h>
  23. #include <booster/hold_ptr.h>
  24. #include <booster/intrusive_ptr.h>
  25. #include <memory>
  26. #include <string>
  27. namespace cppcms {
  28. class application;
  29. class service;
  30. class mount_point;
  31. ///
  32. /// \brief Application pool is the central class that holds user created applications
  33. ///
  34. /// Form the user perspective this class provides an API for mounting user application to the CppCMS service.
  35. ///
  36. /// There are two kind of \a mount member functions, that allow:
  37. ///
  38. /// - Mounting a \a factory of user applications -- for execution of synchronous requests by multiple
  39. /// instances of application.
  40. /// - Mounting single application -- for processing asynchronous requests by single instance of an application
  41. ///
  42. /// The life cycle of synchronous application is defined by application pool itself, and the life cycle
  43. /// of asynchronous depends on its own reference count.
  44. ///
  45. /// This class is thread safe and can be accessed from multiple threads simultaneously.
  46. ///
  47. class CPPCMS_API applications_pool {
  48. public:
  49. ///
  50. /// \brief a base class for user application factories
  51. ///
  52. struct factory : public booster::noncopyable {
  53. ///
  54. /// Returns newly created instance of an application.
  55. ///
  56. virtual std::auto_ptr<application> operator()(service &) const = 0;
  57. virtual ~factory(){}
  58. };
  59. ///
  60. /// Mount an application factory \a aps for processing of any incoming requests. Application
  61. /// would receive PATH_INFO CGI variable for URL matching.
  62. ///
  63. /// This member function is thread safe.
  64. ///
  65. void mount(std::auto_ptr<factory> aps);
  66. ///
  67. /// Mount an application factory \a app by mount_point \a point application matching and
  68. /// URL selection rules
  69. ///
  70. /// This member function is thread safe.
  71. ///
  72. void mount(std::auto_ptr<factory> aps,mount_point const &point);
  73. ///
  74. /// Mount an asynchronous application \a app for processing of any incoming requests. Application
  75. /// would receive PATH_INFO CGI variable for URL matching.
  76. ///
  77. /// This member function is thread safe.
  78. ///
  79. void mount(booster::intrusive_ptr<application> app);
  80. ///
  81. /// Mount an asynchronous application \a app by mount_point \a point application matching and
  82. /// URL selection rules
  83. ///
  84. /// This member function is thread safe.
  85. ///
  86. void mount(booster::intrusive_ptr<application> app,mount_point const &point);
  87. /// \cond INTERNAL
  88. booster::intrusive_ptr<application>
  89. get(char const *h,char const *s,char const *path_info,std::string &match);
  90. void put(application *app);
  91. applications_pool(service &srv,int pool_size_limit);
  92. ~applications_pool();
  93. /// \endcond
  94. private:
  95. struct basic_app_data;
  96. struct app_data;
  97. struct long_running_app_data;
  98. struct _data;
  99. service *srv_;
  100. booster::hold_ptr<_data> d;
  101. };
  102. /// \cond INTERNAL
  103. namespace details {
  104. template<typename T>
  105. struct simple_factory0 : public applications_pool::factory
  106. {
  107. std::auto_ptr<application> operator()(service &s) const
  108. {
  109. std::auto_ptr<application> app(new T(s));
  110. return app;
  111. }
  112. };
  113. template<typename T,typename P1>
  114. struct simple_factory1 : public applications_pool::factory
  115. {
  116. simple_factory1(P1 p1) : p1_(p1) {}
  117. P1 p1_;
  118. std::auto_ptr<application> operator()(service &s) const
  119. {
  120. std::auto_ptr<application> app(new T(s,p1_));
  121. return app;
  122. }
  123. };
  124. template<typename T,typename P1,typename P2>
  125. struct simple_factory2 : public applications_pool::factory
  126. {
  127. simple_factory2(P1 p1,P2 p2) : p1_(p1),p2_(p2) {}
  128. P1 p1_;
  129. P2 p2_;
  130. std::auto_ptr<application> operator()(service &s) const
  131. {
  132. std::auto_ptr<application> app(new T(s,p1_,p2_));
  133. return app;
  134. }
  135. };
  136. } // details
  137. /// \endcond
  138. ///
  139. /// Create application factory for application of type T, such as T has a constructor
  140. /// T::T(cppcms::service &s);
  141. ///
  142. template<typename T>
  143. std::auto_ptr<applications_pool::factory> applications_factory()
  144. {
  145. std::auto_ptr<applications_pool::factory> f(new details::simple_factory0<T>);
  146. return f;
  147. }
  148. ///
  149. /// Create application factory for application of type T, such as T has a constructor
  150. /// T::T(cppcms::service &s,P1);
  151. ///
  152. template<typename T,typename P1>
  153. std::auto_ptr<applications_pool::factory> applications_factory(P1 p1)
  154. {
  155. std::auto_ptr<applications_pool::factory> f(new details::simple_factory1<T,P1>(p1));
  156. return f;
  157. }
  158. ///
  159. /// Create application factory for application of type T, such as T has a constructor
  160. /// T::T(cppcms::service &s,P1,P2);
  161. ///
  162. template<typename T,typename P1,typename P2>
  163. std::auto_ptr<applications_pool::factory> applications_factory(P1 p1,P2 p2)
  164. {
  165. std::auto_ptr<applications_pool::factory> f(new details::simple_factory2<T,P1,P2>(p1,p2));
  166. return f;
  167. }
  168. } // cppcms
  169. #endif