Public Member Functions | Protected Member Functions | List of all members
pluma::Pluma Class Reference

Pluma plugins management. More...

#include <Pluma.hpp>

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

Public Member Functions

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

Protected Member Functions

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

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:

// 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 94 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.

Definition at line 168 of file PluginManager.cpp.

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.

Definition at line 178 of file PluginManager.cpp.

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
protectedinherited

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

Definition at line 194 of file PluginManager.cpp.

bool pluma::PluginManager::isLoaded ( const std::string &  pluginName) const
inherited

Check if a plug-in is loaded.

Parameters
pluginNamethe plug-in tname o check.

Definition at line 188 of file PluginManager.cpp.

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

Definition at line 49 of file PluginManager.cpp.

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

Definition at line 85 of file PluginManager.cpp.

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

Definition at line 95 of file PluginManager.cpp.

void pluma::PluginManager::registerType ( const std::string &  type,
unsigned int  version,
unsigned int  lowestVersion 
)
protectedinherited

Register a provider type.

Parameters
typeProvider type.
versionCurrent version of that provider type.
lowestVersionLowest compatible version of that provider type.
See Also
Host::registerType

Definition at line 162 of file PluginManager.cpp.

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

Definition at line 109 of file PluginManager.cpp.

void pluma::PluginManager::unloadAll ( )
inherited

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