applications_pool.h
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
#ifndef CPPCMS_APPLICATIONS_POOL_H
#define CPPCMS_APPLICATIONS_POOL_H
#include <cppcms/defs.h>
#include <booster/noncopyable.h>
#include <booster/hold_ptr.h>
#include <booster/intrusive_ptr.h>
#include <memory>
#include <string>
namespace cppcms {
class application;
class service;
class mount_point;
class CPPCMS_API applications_pool {
public:
struct factory : public booster::noncopyable {
virtual std::auto_ptr<application> operator()(service &) const = 0;
virtual ~factory(){}
};
void mount(std::auto_ptr<factory> aps);
void mount(std::auto_ptr<factory> aps,mount_point const &point);
void mount(booster::intrusive_ptr<application> app);
void mount(booster::intrusive_ptr<application> app,mount_point const &point);
booster::intrusive_ptr<application>
get(char const *h,char const *s,char const *path_info,std::string &match);
void put(application *app);
applications_pool(service &srv,int pool_size_limit);
~applications_pool();
private:
struct basic_app_data;
struct app_data;
struct long_running_app_data;
struct _data;
service *srv_;
booster::hold_ptr<_data> d;
};
namespace details {
template<typename T>
struct simple_factory0 : public applications_pool::factory
{
std::auto_ptr<application> operator()(service &s) const
{
std::auto_ptr<application> app(new T(s));
return app;
}
};
template<typename T,typename P1>
struct simple_factory1 : public applications_pool::factory
{
simple_factory1(P1 p1) : p1_(p1) {}
P1 p1_;
std::auto_ptr<application> operator()(service &s) const
{
std::auto_ptr<application> app(new T(s,p1_));
return app;
}
};
template<typename T,typename P1,typename P2>
struct simple_factory2 : public applications_pool::factory
{
simple_factory2(P1 p1,P2 p2) : p1_(p1),p2_(p2) {}
P1 p1_;
P2 p2_;
std::auto_ptr<application> operator()(service &s) const
{
std::auto_ptr<application> app(new T(s,p1_,p2_));
return app;
}
};
} // details
template<typename T>
std::auto_ptr<applications_pool::factory> applications_factory()
{
std::auto_ptr<applications_pool::factory> f(new details::simple_factory0<T>);
return f;
}
template<typename T,typename P1>
std::auto_ptr<applications_pool::factory> applications_factory(P1 p1)
{
std::auto_ptr<applications_pool::factory> f(new details::simple_factory1<T,P1>(p1));
return f;
}
template<typename T,typename P1,typename P2>
std::auto_ptr<applications_pool::factory> applications_factory(P1 p1,P2 p2)
{
std::auto_ptr<applications_pool::factory> f(new details::simple_factory2<T,P1,P2>(p1,p2));
return f;
}
} // cppcms
#endif
booster::hold_ptr< _data >
cppcms::applications_pool::factory
a base class for user application factories
Definition: applications_pool.h:47
cppcms::service
This class represent the central event loop of the CppCMS applications.
Definition: service.h:59
cppcms::applications_factory
std::auto_ptr< applications_pool::factory > applications_factory()
Definition: applications_pool.h:151
booster::intrusive_ptr
intrusive_ptr is the class taken as-is from boost.
Definition: intrusive_ptr.h:42
cppcms::mount_point
This class represents application's mount point or the rule on which specific application is selected...
Definition: mount_point.h:24
cppcms::application
application class is the base class for all user created applications.
Definition: application.h:81
cppcms::applications_pool
Application pool is the central class that holds user created applications.
Definition: applications_pool.h:41
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15