PWToolBox::PluginManager Class Reference

A generic, portable plugin manager. More...

#include <PluginManager.h>

List of all members.

Public Types

typedef std::vector< Plugin * > PluginList
 A listing of plugins loaded by the system.

Public Member Functions

 ~PluginManager ()
Plugin *const loadPlugin (boost::filesystem::path const path)
 Loads a plugin into the system if it is not already loaded.
bool const unloadPlugin (boost::filesystem::path const path)
 Unloads a plugin from the system.
bool const reloadPlugin (boost::filesystem::path const path)
 reloads a plugin into the system.
bool unloadAllPlugins ()
 Unloads all of the plugins from the system.
void reloadAllPlugins ()
 Reloads all of the plugins in the system.
PluginList const getLoadedPlugins () const
 Retrieves a list of currently loaded plugins.

Static Public Attributes

static std::string const PLUGIN_INIT_FUNC_NAME
static std::string const PLUGIN_DESTROY_FUNC_NAME


Detailed Description

A generic, portable plugin manager.

This class can be used to load in plugins (shared libraries) in a platform-independent way. When a plugin is loaded, its path is converted into an operating-specific native string before looking in the filesystem for the plugin.


Member Typedef Documentation

typedef std::vector<Plugin*> PWToolBox::PluginManager::PluginList

A listing of plugins loaded by the system.


Constructor & Destructor Documentation

PWToolBox::PluginManager::~PluginManager (  ) 


Member Function Documentation

Plugin* const PWToolBox::PluginManager::loadPlugin ( boost::filesystem::path const   path  ) 

Loads a plugin into the system if it is not already loaded.

Calling this on a plugin already loaded returns the plugin.

Parameters:
path The path of the plugin. This can be an existing boost::path or implicitly created from a string.
Remarks:
Path names are always case sensitive. This could be changed by using the equivalent operation in boost::filesystem. However, if equivalent is used, the map has to be wrapped in a wrapper class with its == operator overloaded to return true only if the path's are equivalent. This is due to the find algorithm only using the equality operator. It seems to be more trouble than it is worth.
Returns:
The Plugin associated with that path, assuming it could be loaded.
Exceptions:
SharedLibraryException Thrown when the plugin couldn't be initialized or the PLUGIN_INIT_FUNC_NAME symbol is not found.

bool const PWToolBox::PluginManager::unloadPlugin ( boost::filesystem::path const   path  ) 

Unloads a plugin from the system.

This does nothing if the plugin doesn't exist.

Parameters:
path The path of the plugin. This can be an existing boost::path or implicitly created from a string.
Returns:
Returns false if the plugin could not be found or if PLUGIN_DESTROY_FUNC_NAME could not be found.
Remarks:
Upon exiting this function, the plugin will always be unloaded from the system. However, the plugin would not have been deleted and is leaking memory if PLUGIN_DESTROY_FUNC_NAME wasn't found.

bool const PWToolBox::PluginManager::reloadPlugin ( boost::filesystem::path const   path  ) 

reloads a plugin into the system.

This does nothing if the plugin doesn't exist. It may be helpful to reload a plugin into a currently running application if the plugin has updated but the application cannot be forced to shut down.

Parameters:
path The path of the plugin. This can be an existing boost::path or implicitly created from a string.
Returns:
Returns false if the plugin could not be found, otherwise true.
Remarks:
If an exception is thrown, the plugin is first unloaded using unloadPlugin to return the system back to a deterministic state.
Exceptions:
SharedLibraryException Thrown the PLUGIN_DESTROY_FUNC_NAME or PLUGIN_INIT_FUNC_NAME symbol is not found or the plugin could not be initialized.

bool PWToolBox::PluginManager::unloadAllPlugins (  ) 

Unloads all of the plugins from the system.

This function is called by the destructor, so you don't need to call this function directly when cleaning up.

Returns:
Returns true if all the plugins were unloaded successfully. If the return value of this is false, at least one plugin wasn't successfully unloaded and is probably leaking memory.
Remarks:
The result of this function is all plugins will always be unloaded from the system (cleanly or not).

void PWToolBox::PluginManager::reloadAllPlugins (  ) 

Reloads all of the plugins in the system.

Remarks:
If an exception occurs, all the plugins are unloaded from the system using unloadAllPlugins. This returns the system back to a deterministic state.
Exceptions:
SharedLibraryException Thrown the PLUGIN_DESTROY_FUNC_NAME or PLUGIN_INIT_FUNC_NAME symbol is not found or the plugin could not be initialized.

PluginList const PWToolBox::PluginManager::getLoadedPlugins (  )  const

Retrieves a list of currently loaded plugins.

Returns:
A PluginList of plugins currently loaded.


Member Data Documentation

std::string const PWToolBox::PluginManager::PLUGIN_INIT_FUNC_NAME [static]

The name of the initialization function. This value is "PluginInit".

std::string const PWToolBox::PluginManager::PLUGIN_DESTROY_FUNC_NAME [static]

The name of the destruction function. This value is "PluginDestroy".


The documentation for this class was generated from the following file:
Generated on Sun Jul 13 14:18:26 2008 for PWToolBox by  doxygen 1.5.1