CppCMS
applications_pool.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_APPLICATIONS_POOL_H
9 #define CPPCMS_APPLICATIONS_POOL_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/intrusive_ptr.h>
15 
16 #include <memory>
17 #include <string>
18 
19 namespace cppcms {
20 
21  class application;
22  class service;
23  class mount_point;
24 
41  class CPPCMS_API applications_pool {
42  public:
43 
47  struct factory : public booster::noncopyable {
51  virtual std::auto_ptr<application> operator()(service &) const = 0;
52  virtual ~factory(){}
53  };
54 
61  void mount(std::auto_ptr<factory> aps);
62 
69 
70  void mount(std::auto_ptr<factory> aps,mount_point const &point);
71 
85  void mount(booster::intrusive_ptr<application> app,mount_point const &point);
86 
87 
89 
91  get(char const *h,char const *s,char const *path_info,std::string &match);
92 
93  void put(application *app);
94  applications_pool(service &srv,int pool_size_limit);
96 
98 
99  private:
100  struct basic_app_data;
101  struct app_data;
102  struct long_running_app_data;
103  struct _data;
104  service *srv_;
106  };
107 
109  namespace details {
110  template<typename T>
111  struct simple_factory0 : public applications_pool::factory
112  {
113  std::auto_ptr<application> operator()(service &s) const
114  {
115  std::auto_ptr<application> app(new T(s));
116  return app;
117  }
118  };
119  template<typename T,typename P1>
120  struct simple_factory1 : public applications_pool::factory
121  {
122  simple_factory1(P1 p1) : p1_(p1) {}
123  P1 p1_;
124  std::auto_ptr<application> operator()(service &s) const
125  {
126  std::auto_ptr<application> app(new T(s,p1_));
127  return app;
128  }
129  };
130  template<typename T,typename P1,typename P2>
131  struct simple_factory2 : public applications_pool::factory
132  {
133  simple_factory2(P1 p1,P2 p2) : p1_(p1),p2_(p2) {}
134  P1 p1_;
135  P2 p2_;
136  std::auto_ptr<application> operator()(service &s) const
137  {
138  std::auto_ptr<application> app(new T(s,p1_,p2_));
139  return app;
140  }
141  };
142  } // details
143 
145 
150  template<typename T>
151  std::auto_ptr<applications_pool::factory> applications_factory()
152  {
153  std::auto_ptr<applications_pool::factory> f(new details::simple_factory0<T>);
154  return f;
155  }
156 
161  template<typename T,typename P1>
162  std::auto_ptr<applications_pool::factory> applications_factory(P1 p1)
163  {
164  std::auto_ptr<applications_pool::factory> f(new details::simple_factory1<T,P1>(p1));
165  return f;
166  }
167 
172  template<typename T,typename P1,typename P2>
173  std::auto_ptr<applications_pool::factory> applications_factory(P1 p1,P2 p2)
174  {
175  std::auto_ptr<applications_pool::factory> f(new details::simple_factory2<T,P1,P2>(p1,p2));
176  return f;
177  }
178 
179 
180 } // cppcms
181 
182 
183 
184 #endif
a base class for user application factories
Definition: applications_pool.h:47
This class represent the central event loop of the CppCMS applications.
Definition: service.h:59
std::auto_ptr< applications_pool::factory > applications_factory()
Definition: applications_pool.h:151
intrusive_ptr is the class taken as-is from boost.
Definition: intrusive_ptr.h:42
This class represents application's mount point or the rule on which specific application is selected...
Definition: mount_point.h:24
application class is the base class for all user created applications.
Definition: application.h:81
Application pool is the central class that holds user created applications.
Definition: applications_pool.h:41
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15