Pluma plugins management. More...
#include <Pluma.hpp>
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. | |
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.
| 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.
| ProviderType | type of provider. |
| bool pluma::PluginManager::addProvider | ( | Provider * | provider | ) | [inherited] |
Directly add a new provider.
| provider | Provider. |
| void pluma::PluginManager::getLoadedPlugins | ( | std::vector< const std::string * > & | pluginNames | ) | const [inherited] |
Get the name of all loaded plugins.
| pluginNames | A vector to fill with the plugins names. |
| 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.
| ProviderType | type of provider to be returned. |
| [out] | providers | Vector 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.
| type | Provider type. |
| bool pluma::PluginManager::isLoaded | ( | const std::string & | pluginName | ) | const [inherited] |
Check if a plug-in is loaded.
| pluginName | the 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.
| folder | The folder path. |
| pluginName | Name 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. |
| bool pluma::PluginManager::load | ( | const std::string & | path | ) | [inherited] |
Load a plugin given it's path.
| path | Path 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. |
| int pluma::PluginManager::loadFromFolder | ( | const std::string & | folder, |
| bool | recursive = false |
||
| ) | [inherited] |
Load all plugins from a given folder.
| folder | Path for the folder where the plug-ins are. |
| recursive | If true it will search on sub-folders as well |
| void pluma::PluginManager::registerType | ( | const std::string & | type, |
| unsigned int | version, | ||
| unsigned int | lowestVersion | ||
| ) | [protected, inherited] |
Register a provider type.
| type | Provider type. |
| version | Current version of that provider type. |
| lowestVersion | Lowest compatible version of that provider type. |
| bool pluma::PluginManager::unload | ( | const std::string & | pluginName | ) | [inherited] |
Unload a plugin.
| pluginName | Name or path of the plugin. |
| void pluma::PluginManager::unloadAll | ( | ) | [inherited] |
Unload all loaded plugins.