Public Member Functions | Protected Member Functions
pluma::Pluma Class Reference

Pluma plugins management. More...

#include <Pluma.hpp>

Inheritance diagram for pluma::Pluma:
pluma::PluginManager

List of all members.

Public Member Functions

 Pluma ()
 Default Constructor.
template<typename ProviderType >
void acceptProviderType ()
 Tell Pluma to accept a certain type of providers.
template<typename ProviderType >
void getProviders (std::vector< ProviderType * > &providers)
 Get the stored providers of a certain type.
template<typename ProviderType >
void acceptProviderType ()
template<typename ProviderType >
void getProviders (std::vector< ProviderType * > &providers)
bool load (const std::string &path)
 Load a plugin given it's path.
bool load (const std::string &folder, const std::string &pluginName)
 Load a plugin from a given folder.
int loadFromFolder (const std::string &folder, bool recursive=false)
 Load all plugins from a given folder.
bool unload (const std::string &pluginName)
 Unload a plugin.
void unloadAll ()
 Unload all loaded plugins.
bool addProvider (Provider *provider)
 Directly add a new provider.
void getLoadedPlugins (std::vector< const std::string * > &pluginNames) const
 Get the name of all loaded plugins.
bool isLoaded (const std::string &pluginName) const
 Check if a plug-in is loaded.

Protected Member Functions

void registerType (const std::string &type, unsigned int version, unsigned int lowestVersion)
 Register a provider type.
const std::list< Provider * > * getProviders (const std::string &type) const
 Get providers of a certain type.

Detailed Description

Pluma plugins management.

Pluma is the main class of Pluma library. Allows hosting applications to load/unload dlls in runtime (plugins), and to get providers of shared interface objects.

Example:

 pluma::Pluma pluma;
 // Tell it to accept providers of the type DeviceProvider
 pluma.acceptProviderType<DeviceProvider>();
 // Load some dll
 pluma.load("plugins/standard_devices");
 // Get device providers into a vector
 std::vector<DeviceProvider*> providers;
 pluma.getProviders(providers);
 // create a Device from the first provider
 if (!providers.empty()){
     Device* myDevice = providers.first()->create();
     // do something with myDevice
     std::cout << device->getDescription() << std::endl;
     // (...)
     delete myDevice;
 }

It is also possible to add local providers, providers that are defined directly on the host application. That can be useful to provide and use default implementations of certain interfaces, along with plugin implementations.

Definition at line 110 of file Pluma.hpp.


Constructor & Destructor Documentation

Pluma::Pluma ( ) [inline]

Default Constructor.

Definition at line 27 of file Pluma.inl.


Member Function Documentation

template<typename ProviderType >
void pluma::Pluma::acceptProviderType ( )

Tell Pluma to accept a certain type of providers.

A Pluma object is able to accept multiple types of providers. When a plugin is loaded, it tries to register it's providers implementations. Those are only accepted by the host application if it's accepting providers of that kind.

Template Parameters:
ProviderTypetype of provider.
bool pluma::PluginManager::addProvider ( Provider provider) [inherited]

Directly add a new provider.

Parameters:
providerProvider.
void pluma::PluginManager::getLoadedPlugins ( std::vector< const std::string * > &  pluginNames) const [inherited]

Get the name of all loaded plugins.

Parameters:
pluginNamesA vector to fill with the plugins names.
template<typename ProviderType >
void pluma::Pluma::getProviders ( std::vector< ProviderType * > &  providers)

Get the stored providers of a certain type.

Providers are added at the end of the providers vector.

Template Parameters:
ProviderTypetype of provider to be returned.
Parameters:
[out]providersVector to fill with the existing providers.
const std::list<Provider*>* pluma::PluginManager::getProviders ( const std::string &  type) const [protected, inherited]

Get providers of a certain type.

Parameters:
typeProvider type.
Returns:
Pointer to the list of providers of that type, or NULL if type is not registered.
See also:
Host::getProviders
bool pluma::PluginManager::isLoaded ( const std::string &  pluginName) const [inherited]

Check if a plug-in is loaded.

Parameters:
pluginNamethe plug-in tname o check.
bool pluma::PluginManager::load ( const std::string &  folder,
const std::string &  pluginName 
) [inherited]

Load a plugin from a given folder.

Parameters:
folderThe folder path.
pluginNameName of the plugin. File extension may be included, but is discouraged for better cross platform code. If file extension is omitted, Pluma will deduce it from the operating system.
Returns:
True if the plugin is successfully loaded.
See also:
load(const std::string&)
loadFromFolder
unload
unloadAll
bool pluma::PluginManager::load ( const std::string &  path) [inherited]

Load a plugin given it's path.

Parameters:
pathPath for the plugin, including plugin name. File extension may be included, but is discouraged for better cross platform code. If file extension isn't present on the path, Pluma will deduce it from the operating system.
Returns:
True if the plugin is successfully loaded.
See also:
load(const std::string&, const std::string&)
loadFromFolder
unload
unloadAll
int pluma::PluginManager::loadFromFolder ( const std::string &  folder,
bool  recursive = false 
) [inherited]

Load all plugins from a given folder.

Parameters:
folderPath for the folder where the plug-ins are.
recursiveIf true it will search on sub-folders as well
Returns:
Number of successfully loaded plug-ins.
See also:
load(const std::string&, const std::string&)
load(const std::string&)
unload
unloadAll
void pluma::PluginManager::registerType ( const std::string &  type,
unsigned int  version,
unsigned int  lowestVersion 
) [protected, inherited]

Register a provider type.

Parameters:
typeProvider type.
versionCurrent version of that provider type.
lowestVersionLowest compatible version of that provider type.
See also:
Host::registerType
bool pluma::PluginManager::unload ( const std::string &  pluginName) [inherited]

Unload a plugin.

Parameters:
pluginNameName or path of the plugin.
Returns:
True if the plugin is successfully unloaded, false if no such plugin exists on the manager.
See also:
load(const std::string&, const std::string&)
load(const std::string&)
loadFromFolder
unloadAll
void pluma::PluginManager::unloadAll ( ) [inherited]

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