Fawkes API  Fawkes Development Version
fawkes::PluginLoader Class Reference

This class manages plugins. More...

#include <>>

Public Member Functions

 PluginLoader (const char *plugin_base_dir, Configuration *config)
 Constructor. More...
 
 ~PluginLoader ()
 Destructor. More...
 
Pluginload (const char *plugin_name)
 Load a specific plugin The plugin loader is clever and guarantees that every plugin is only loaded once (as long as you use only one instance of the PluginLoader, using multiple instances is discouraged. More...
 
void unload (Plugin *plugin)
 Unload the given plugin This will unload the given plugin. More...
 
std::string get_description (const char *plugin_name)
 Get plugin description. More...
 
bool is_loaded (const char *plugin_name)
 Check if a plugin is loaded. More...
 
ModuleManagerget_module_manager () const
 Get module manager. More...
 

Detailed Description

This class manages plugins.

With this class plugins can be loaded and unloaded. Information is kept about active plugins.

Author
Tim Niemueller

Definition at line 61 of file loader.h.

Constructor & Destructor Documentation

◆ PluginLoader()

fawkes::PluginLoader::PluginLoader ( const char *  plugin_base_dir,
Configuration config 
)

Constructor.

Parameters
plugin_base_dirThe base directory where to search for the shared libraries which contain the plugins
configFawkes configuration

Definition at line 129 of file loader.cpp.

◆ ~PluginLoader()

fawkes::PluginLoader::~PluginLoader ( )

Destructor.

Definition at line 138 of file loader.cpp.

Member Function Documentation

◆ get_description()

std::string fawkes::PluginLoader::get_description ( const char *  plugin_name)

Get plugin description.

Parameters
plugin_namename of the plugin
Returns
plugin description tring
Exceptions
PluginLoadExceptionthrown if opening the plugin fails

Definition at line 333 of file loader.cpp.

References fawkes::Module::get_symbol(), and fawkes::Module::has_symbol().

Referenced by fawkes::PluginManager::fam_event(), and fawkes::PluginManager::init_pinfo_cache().

◆ get_module_manager()

ModuleManager * fawkes::PluginLoader::get_module_manager ( ) const

Get module manager.

This should be used rarely, but may be useful, for example, to pass specific module opening flags in some situations.

Returns
internally used module manager

Definition at line 151 of file loader.cpp.

References fawkes::Module::get_symbol(), fawkes::Module::has_symbol(), and fawkes::Plugin::set_name().

Referenced by fawkes::PluginManager::PluginManager(), and fawkes::PluginManager::set_module_flags().

◆ is_loaded()

bool fawkes::PluginLoader::is_loaded ( const char *  plugin_name)

Check if a plugin is loaded.

Parameters
plugin_namename of the plugin to chekc
Returns
true if the plugin is loaded, false otherwise

Definition at line 358 of file loader.cpp.

Referenced by fawkes::PluginManager::fam_event(), and fawkes::PluginManager::is_loaded().

◆ load()

Plugin * fawkes::PluginLoader::load ( const char *  plugin_name)

Load a specific plugin The plugin loader is clever and guarantees that every plugin is only loaded once (as long as you use only one instance of the PluginLoader, using multiple instances is discouraged.

If you try to open a plugin a second time it will return the very same instance that it returned on previous load()s.

Parameters
plugin_nameThe name of the plugin to be loaded, the plugin name has to correspond to a plugin name and the name of the shared object that will be opened for this plugin (for instance on Linux systems opening the plugin test_plugin will look for plugin_base_dir/test_plugin.so)
Returns
Returns a pointer to the opened plugin. Do not under any circumstances delete this object, use unload() instead! Since the delete operator could be overloaded this would result in memory chaos.
Exceptions
PluginLoadExceptionthrown if plugin could not be loaded
ModuleOpenExceptionpassed along from module manager

Definition at line 211 of file loader.cpp.

References fawkes::Exception::end(), and fawkes::Exception::Exception().

Referenced by fawkes::PluginManager::load().

◆ unload()

void fawkes::PluginLoader::unload ( Plugin plugin)

Unload the given plugin This will unload the given plugin.

The plugin is destroyed with the proper destroy method from the shared object. The shared object is unloaded after the destruction of the plugin. Note that even though you may call load() multiple times per plugin you may only unload() it once! Every further access will lead to a segmentation fault. Make sure that you have closed any resources claimed by the plugin like threads, memory access etc.

Parameters
pluginThe plugin that has to be unloaded

Definition at line 376 of file loader.cpp.

Referenced by fawkes::PluginManager::load(), fawkes::PluginManager::unload(), and fawkes::PluginManager::~PluginManager().


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