New Plugin API in 1.2
CppCMS 1.2 introduces a new plugin API together with new improved support of dynamic templates
Writing Plugins
Plugins are shared object that can register their functions within cppcms::plugin::manager
singleton. For example:
For example you write some class that implements a certain API:
namespace myplugin { class my_class : public plugin_api { public: statuc my_class *create(std::string const ¶meter) { return new my_class(parameter); } ... }; }
Than you can register it within the plugin::manager
using special macro.
CPPCMS_PLUGIN_ENTRY(myplugin,my_class::create,plugin_api *(std::string const &))
Note: the 3rd parameter that defines the signature of the entry for typesafe plugin access.
Than you can access the required plugins from the main code calling
// callback object booster::callback<plugin_api *(std::string const &)> cb; // get it from plugin cb = cppcms::manager::instance().entry<plugin_api *(std::string const &)>("myplugin","my_class::create"); // call it plugin_api *ptr = cb("foo");
Loading plugins
Plugin lifetime is managed by cppcms::plugin::scope
class. cppcms::service
provides an instance of one and allows to load the plugins from the configuration
You can also use plugin::scope
independently so you can have separate lifetime of cppcms::service
and your plugins.
You can also link the views with the same plugin and they will be loaded automatically.
Template System Support
In order to create dynamically loaded templates from plugins, there are several improvements in template systems:
You can create abstract and inline views so plugins can easily extend them.
Using new view helpers you can call specific functions from templates by their names
<% using master_api as m from a_skin, "api" %> <% include foo() from m %> <% end using %>
You can use specific gettext
domain for each of the views separately so plugin can run withing its own domain transparently from its caller.