Loading...
Searching...
No Matches
BALL::PluginManager Class Reference

`#include <BALL/PLUGIN/pluginManager.h>`

## Public Member Functions

virtual | ~PluginManager ()
bool | addPluginDirectory (const QString &dir)
bool | removePluginDirectory (const QString &dir)
std::vector< QString > | getPluginDirectories () const
BALLPlugin * | loadPlugin (const QString &plugin_name)
bool | unloadPlugin (const QString &plugin)
QObject * | getPluginInstance (const QString &plugin)
QObject * | getPluginInstance (int pos)
bool | startPlugin (int plugin)
bool | startPlugin (const QString &plugin)
bool | startPlugin (BALLPlugin *plugin)
bool | stopPlugin (int plugin)
bool | stopPlugin (const QString &plugin)
bool | stopPlugin (BALLPlugin *plugin)
void | unloadAllPlugins ()
int | getPluginCount () const
void | registerHandler (PluginHandler *h)
void | registerHandler (const boost::shared_ptr< PluginHandler > &h)
bool | unregisterHandler (PluginHandler *h)
virtual bool | getPluginDirectories (String &value) const
virtual bool | setPluginDirectories (const String &)
virtual QString | getAutoActivatePlugins () const
virtual bool | setAutoActivatePlugins (const QString &)
void | autoActivatePlugin (const QString &str)
void | doNotAutoActivatePlugin (const QString &str)

## Static Public Member Functions

static PluginManager & | instance ()

## Protected Types

typedef std::map< QString, vector< BALLPlugin * > > | PluginDirMap

## Protected Member Functions

| PluginManager ()
| PluginManager (const PluginManager &)
PluginManager & | operator= (const PluginManager &)
bool | unloadDirectoryPlugins_ (PluginDirMap::iterator it)

## Protected Attributes

PluginDirMap | loaded_plugin_dirs_
QHash< QString, QPluginLoader * > | loaders_
std::list< PluginHandler * > | handlers_
std::list< boost::shared_ptr< PluginHandler > > | shared_handlers_
QStringList | autoactivate_plugins_
QReadWriteLock | handler_mutex_
QReadWriteLock | loader_mutex_

## Static Protected Attributes

static const char * | BETWEEN_PLUGINDIR_SEPERATOR
static boost::shared_ptr< PluginManager > | manager_
static QMutex | mutex_

## Detailed Description

A singleton that takes care of handling all plugins. It is responsible for loading, starting and stopping plugins. For the task of properly initializing the plugins it utilizes the PluginHandler helper classes, that need to be supplemented for each new plugin type.

Definition at line 38 of file pluginManager.h.

## Member Typedef Documentation

## PluginDirMap

typedef std::map<QString, vector<BALLPlugin*> > BALL::PluginManager::PluginDirMap

protected

Definition at line 213 of file pluginManager.h.

## Constructor & Destructor Documentation

## ~PluginManager()

virtual BALL::PluginManager::~PluginManager | ( |  | ) |

virtual

## PluginManager() [1/2]

BALL::PluginManager::PluginManager | ( |  | ) |

protected

## PluginManager() [2/2]

BALL::PluginManager::PluginManager | ( | const PluginManager & |  | ) |

protected

## Member Function Documentation

## addPluginDirectory()

bool BALL::PluginManager::addPluginDirectory | ( | const QString & | dir | ) |

Tries to load all plugins (files named like: pluginMyPlugin.$LIBRARY_SUFFIX) located in the specified directoy dir.

Parameters

  dir | the directory to search for plugins.

Returns
  true if the directory could successfully be loaded. false if it has already been loaded or is invalid.

## autoActivatePlugin()

void BALL::PluginManager::autoActivatePlugin | ( | const QString & | str | ) |

## doNotAutoActivatePlugin()

void BALL::PluginManager::doNotAutoActivatePlugin | ( | const QString & | str | ) |

## getAutoActivatePlugins()

virtual QString BALL::PluginManager::getAutoActivatePlugins | ( |  | ) | const

virtual

## getPluginCount()

int BALL::PluginManager::getPluginCount | ( |  | ) | const

Returns the number of loaded plugins.

## getPluginDirectories() [1/2]

std::vector< QString > BALL::PluginManager::getPluginDirectories | ( |  | ) | const

Return a list of directories currently searched for plugins.

## getPluginDirectories() [2/2]

virtual bool BALL::PluginManager::getPluginDirectories | ( | String & | value | ) | const

virtual

## getPluginInstance() [1/2]

QObject * BALL::PluginManager::getPluginInstance | ( | const QString & | plugin | ) |

Searches for the plugin and returns a pointer to it if it has been loaded.

Parameters

  plugin | The name of the plugin to search

Returns
  NULL if the plugin could not be found, a pointer to it otherwise

## getPluginInstance() [2/2]

QObject * BALL::PluginManager::getPluginInstance | ( | int | pos | ) |

Searches for the plugin and returns a pointer to it if it has been loaded.

Parameters

  pos | The position of the plugin in the plugin list

Returns
  NULL if the plugin could not be found, a pointer to it otherwise

## instance()

PluginManager & BALL::PluginManager::instance | ( |  | ) |

static

Use this method to obtain the PluginManager instance.

This method is thread safe.

## loadPlugin()

BALLPlugin * BALL::PluginManager::loadPlugin | ( | const QString & | plugin_name | ) |

Loads the plugin specified by plugin_name.

Parameters

  plugin_name | The path to the plugin to load

Returns
  NULL if the plugin could not be loaded. A valid pointer to the loaded plugin otherwise.

## operator=()

PluginManager & BALL::PluginManager::operator= | ( | const PluginManager & |  | ) |

protected

## registerHandler() [1/2]

void BALL::PluginManager::registerHandler | ( | const boost::shared_ptr< PluginHandler > & | h | ) |

Register a new PluginHandler. This handler will then be available for starting new plugins.

This method is a convenience funtion that takes a boost shared_ptr which is stored in the PluginManager and hence destroyed once the PluginManager is unloaded.

## registerHandler() [2/2]

void BALL::PluginManager::registerHandler | ( | PluginHandler * | h | ) |

Register a new PluginHandler. This handler will then be available for starting new plugins.

## removePluginDirectory()

bool BALL::PluginManager::removePluginDirectory | ( | const QString & | dir | ) |

Tries to unload all plugins (files named like: pluginMyPlugin.$LIBRARY_SUFFIX) located in the specified directoy dir.

Parameters

  dir | the directory to search for plugins to remove.

Returns
  true if the plugin could be successfully removed.

## setAutoActivatePlugins()

virtual bool BALL::PluginManager::setAutoActivatePlugins | ( | const QString & |  | ) |

virtual

## setPluginDirectories()

virtual bool BALL::PluginManager::setPluginDirectories | ( | const String & |  | ) |

virtual

## startPlugin() [1/3]

bool BALL::PluginManager::startPlugin | ( | BALLPlugin * | plugin | ) |

Starts the specified plugin through a applicable PluginHandler

Parameters

  plugin | A pointer to the plugin to be started

Returns
  false if no suitable handler could be found, true otherwise.

## startPlugin() [2/3]

bool BALL::PluginManager::startPlugin | ( | const QString & | plugin | ) |

See startPlugin(BALLPlugin* plugin)

## startPlugin() [3/3]

bool BALL::PluginManager::startPlugin | ( | int | plugin | ) |

See startPlugin(BALLPlugin* plugin)

## stopPlugin() [1/3]

bool BALL::PluginManager::stopPlugin | ( | BALLPlugin * | plugin | ) |

Stops the specified plugin by letting all PluginHandlers stop it.

Parameters

  plugin | A pointer to the plugin to be stopped

Returns
  false if one handler could not stop the plugin, true otherwise.

## stopPlugin() [2/3]

bool BALL::PluginManager::stopPlugin | ( | const QString & | plugin | ) |

See stopPlugin(BALLPlugin* plugin)

## stopPlugin() [3/3]

bool BALL::PluginManager::stopPlugin | ( | int | plugin | ) |

See stopPlugin(BALLPlugin* plugin)

## unloadAllPlugins()

void BALL::PluginManager::unloadAllPlugins | ( |  | ) |

Unload all registered plugins.

## unloadDirectoryPlugins_()

bool BALL::PluginManager::unloadDirectoryPlugins_ | ( | PluginDirMap::iterator | it | ) |

protected

## unloadPlugin()

bool BALL::PluginManager::unloadPlugin | ( | const QString & | plugin | ) |

Unloads the plugin specified by plugin_name.

Parameters

  plugin_name | The name of the plugin to unload

## unregisterHandler()

bool BALL::PluginManager::unregisterHandler | ( | PluginHandler * | h | ) |

Unregister a PluginHandler.

If the handler was not registered this function does nothing. Otherwise all plugins for which the handler is responsible will be unloaded and the handler will no longer be available.

Every registered PluginHandler should call this function before it is destroyed. Otherwise segmentation faults will happen!

Warning
  All plugins run by this handler will be unloaded, even if there are other handlers handling them!

Parameters

  h | the handler that should be unregistered

Returns
  true if the handler was unregistered successfully; false if there was an error during the deactivation of running plugins

## Member Data Documentation

## autoactivate_plugins_

QStringList BALL::PluginManager::autoactivate_plugins_

protected

Definition at line 226 of file pluginManager.h.

## BETWEEN_PLUGINDIR_SEPERATOR

const char* BALL::PluginManager::BETWEEN_PLUGINDIR_SEPERATOR

static protected

Definition at line 211 of file pluginManager.h.

## handler_mutex_

QReadWriteLock BALL::PluginManager::handler_mutex_

mutable protected

Definition at line 233 of file pluginManager.h.

## handlers_

std::list<PluginHandler*> BALL::PluginManager::handlers_

protected

Definition at line 223 of file pluginManager.h.

## loaded_plugin_dirs_

PluginDirMap BALL::PluginManager::loaded_plugin_dirs_

protected

Definition at line 220 of file pluginManager.h.

## loader_mutex_

QReadWriteLock BALL::PluginManager::loader_mutex_

mutable protected

Definition at line 235 of file pluginManager.h.

## loaders_

QHash<QString, QPluginLoader*> BALL::PluginManager::loaders_

protected

Definition at line 222 of file pluginManager.h.

## manager_

boost::shared_ptr<PluginManager> BALL::PluginManager::manager_

static protected

Definition at line 228 of file pluginManager.h.

## mutex_

QMutex BALL::PluginManager::mutex_

static protected

Definition at line 231 of file pluginManager.h.

## shared_handlers_

std::list<boost::shared_ptr<PluginHandler> > BALL::PluginManager::shared_handlers_

protected

Definition at line 224 of file pluginManager.h.