CppCMS

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
cppcms::plugin::manager Class Reference

`#include <cppcms/plugin.h>`

## Public Types
typedef booster::intrusive_ptr< booster::refcounted > | refcounted_ptr
typedef refcounted_ptr(* | entry_point_type) ()

## Public Member Functions
template<typename Signature >
booster::callback< Signature > | entry (std::string const &plugin_name, std::string const &entry_name)
template<typename Signature >
bool | has_entry (std::string const &plugin, std::string const &name)
entry_point_type | get_entry (std::string const &plugin, std::string const &name)
std::string | signature (std::string const &plugin, std::string const &name)
void | add_entry (char const *plugin_name, char const *entry_name, entry_point_type entry, char const *signature)
void | remove_entry (entry_point_type entry)
std::set< std::string > | plugins ()
std::set< std::string > | entries (std::string const &plugin)
bool | has_plugin (std::string const &name)

## Static Public Member Functions
static manager & | instance ()

## Related Functions
(Note that these are not member functions.)
#define | CPPCMS_FULL_PLUGIN_ENTRY(plugin_name, entry_name, call, type)
#define | CPPCMS_PLUGIN_ENTRY(name, call, type) CPPCMS_FULL_PLUGIN_ENTRY(#name,#call,& name :: call,type)
#define | CPPCMS_NAMED_PLUGIN_ENTRY(name, entry, call, type) CPPCMS_FULL_PLUGIN_ENTRY(#name,#entry,& name :: call,type)

## Detailed Description

Central class that manages registration of plugins.

It is used as singleton and accessed via manager::instance().

Each plugin registers itself in the constructor and destructor implemented in shared library.

New in CppCMS 1.2

## Member Typedef Documentation

typedef refcounted_ptr(* cppcms::plugin::manager::entry_point_type) ()

Functions registered as plugin entry points

## Member Function Documentation

void cppcms::plugin::manager::add_entry | ( | char const * | plugin_name,
|  | char const * | entry_name,
|  | entry_point_type | entry,
|  | char const * | signature
| ) |  |

Addes entry to the plugin manager - thread safe function

std::set<std::string> cppcms::plugin::manager::entries | ( | std::string const & | plugin | ) |

Get list of all entry names for plugin

template<typename Signature >

booster::callback<Signature> cppcms::plugin::manager::entry | ( | std::string const & | plugin_name,
|  | std::string const & | entry_name
| ) |  |
| inline

Get plugin entry by plugin_name, entry_name and Signature

If entry is not found or no entry point is created throws cppcms_error,if Signature mismatches the callback type throws booster::bad_cast

For example

booster::callback<cppcms::application *(cppcms::service &)> cb = :manager::instance().entry<cppcms::application *(cppcms::service &)>("foo","application");
cppcms::application *app =cb(service());
attach(app,"/plugins/foo(/.*)",1); // attach new application

Or

cppcms::application *app = manager::instance().entry<cppcms::application *(cppcms::service &)>("myapi","app::generator")(service());
attach(app,"/plugins/foo(/.*)",1);

References get_entry().

entry_point_type cppcms::plugin::manager::get_entry | ( | std::string const & | plugin,
|  | std::string const & | name
| ) |  |

Get entry point that creates a base of booster::callback::callable_type

Referenced by entry().

template<typename Signature >

bool cppcms::plugin::manager::has_entry | ( | std::string const & | plugin,
|  | std::string const & | name
| ) |  |
| inline

Check if plugin entry of type Signature exists in a plugin plugin named name

bool cppcms::plugin::manager::has_plugin | ( | std::string const & | name | ) |

Returns true if plugin name is loaded

static manager& cppcms::plugin::manager::instance | ( |  | ) |
| static

Get the instance of the manager

std::set<std::string> cppcms::plugin::manager::plugins | ( |  | ) |

Get list of all plugin names

void cppcms::plugin::manager::remove_entry | ( | entry_point_type | entry | ) |

Removes entry from the plugin manager - thread safe function

std::string cppcms::plugin::manager::signature | ( | std::string const & | plugin,
|  | std::string const & | name
| ) |  |

Get textual representation of entry point signature - for logging purposes, if not found returns empty string

## Friends And Related Function Documentation

#define CPPCMS_FULL_PLUGIN_ENTRY | ( |  | plugin_name,
|  |  | entry_name,
|  |  | call,
|  |  | type
| ) |  |
| related

Value:
namespace { \
struct CPPCMS_PLUGIN_CONCAT2(stpg_ , __LINE__) { \
static booster::intrusive_ptr<booster::refcounted> entry() \
{ \
typedef booster::callback<type> ct; \
ct cb = call; \
booster::refcounted *tmp = cb.get_pointer().get(); \
booster::intrusive_ptr<booster::refcounted> ptr(tmp); \
return ptr; \
} \
CPPCMS_PLUGIN_CONCAT2(stpg_,__LINE__) () { \
cppcms::plugin::manager::instance().add_entry( \
plugin_name,entry_name,&entry,#type \
); \
\
} \
~CPPCMS_PLUGIN_CONCAT2(stpg_,__LINE__)() { \
cppcms::plugin::manager::instance().remove_entry(&entry); \
} \
} CPPCMS_PLUGIN_CONCAT2(instance_of_stpg_,__LINE__); \
}

Install generic plugin entry in plugin named plugin_name - string, the entry name entry_name - string and such that following expression is valid callback iniitalization: `booster::callback<type> cb = call;`

For example

class my_class : public plugin_api {
public:
statuc my_class *create(std::string const &parameter) { return new my_class(parameter); }
...
};
CPPCMS_PLUGIN_ENTRY("myplugin","api",&my_class::create,plugin_api *(std::string const &))
}

it is accessed as `manager::instance().entry<plugin_api *(std::string const &)>("myplugin","my_class::create")`

#define CPPCMS_NAMED_PLUGIN_ENTRY | ( |  | name,
|  |  | entry,
|  |  | call,
|  |  | type
| ) |  | CPPCMS_FULL_PLUGIN_ENTRY(#name,#entry,& name :: call,type)
| related

Install common function entry such that name is plugin name, entry is entry name and `&name::call` is valid assignment for booster::callback<type>

Usually name should be namespace or class name, call is function or static member functions

For example

namespace myplugin {
class my_class : public plugin_api {
public:
statuc my_class *create(std::string const &parameter) { return new my_class(parameter); }
...
};
CPPCMS_NAMED_PLUGIN_ENTRY(myplugin,api,my_class::create,plugin_api *(std::string const &))
}

it is accessed as `manager::instance().entry<plugin_api *(std::string const &)>("myplugin","api")`

#define CPPCMS_PLUGIN_ENTRY | ( |  | name,
|  |  | call,
|  |  | type
| ) |  | CPPCMS_FULL_PLUGIN_ENTRY(#name,#call,& name :: call,type)
| related

Install common function entry such that name is plugin name, call is entry name and `&name::call` is valid assignment for booster::callback<type>

Usually name should be namespace or class name, call is function or static member functions

For example

namespace myplugin {
class my_class : public plugin_api {
public:
statuc my_class *create(std::string const &parameter) { return new my_class(parameter); }
...
};
CPPCMS_PLUGIN_ENTRY(myplugin,my_class::create,plugin_api *(std::string const &))
}

it is accessed as `manager::instance().entry<plugin_api *(std::string const &)>("myplugin","my_class::create")`

The documentation for this class was generated from the following file:

- cppcms/plugin.h