charon-core
0.3.1
|
Manages ParameteredObject based plugins and their instances. More...
#include <charon-core/PluginManager.h>
Public Member Functions | |
PluginManager (const std::vector< std::string > &pluginPaths, bool debugSuffix=DEFAULT_DEBUG_SUFFIX, bool initializeOnLoad=false, PluginVersionCheckLevel versionInfo=PluginVersionIgnore) | |
default constructor More... | |
PluginManager (const std::string &globalPath, const std::string &localPath="", bool debugSuffix=DEFAULT_DEBUG_SUFFIX, bool initializeOnLoad=false, PluginVersionCheckLevel versionInfo=PluginVersionIgnore) | |
default constructor More... | |
virtual | ~PluginManager () |
default destructor More... | |
void | createDynamicMetadata (const ParameterFile ¶mFile, const std::string &filePrefix) |
generate plugin metadata for dynamic plugins and store to given path More... | |
void | createDynamicMetadata (const std::string &pluginName, const ParameterFile ¶mFile, const std::string &fileName) |
generate plugin metadata for a single dynamic plugin and store to given file name More... | |
ParameteredObject * | createInstance (std::string pluginName, ParameteredObject::template_type t, std::string instanceName="") throw (AbstractPluginLoader::PluginException) |
Create a new instance of a plugin. More... | |
ParameteredObject * | createInstance (const std::string &pluginName, const std::string &instanceName="") throw (AbstractPluginLoader::PluginException) |
Create a new instance of a plugin. More... | |
void | createMetadata (const std::string &targetPath="") |
generate plugin metadata and store to given path More... | |
void | destroyInstance (ParameteredObject *toDestroy) throw (AbstractPluginLoader::PluginException) |
Delete an instance of a loaded plugin. More... | |
std::list< ParameteredObject * > | determineExecutionOrder () |
Determine execution order. More... | |
charon_DEPRECATED void | executeWorkflow () |
for compatibility, use runWorkflow instead | |
ParameteredObject::template_type | getDefaultTemplateType () const |
Get the default template type property. More... | |
ParameteredObject * | getInstance (const std::string &instanceName) const throw (AbstractPluginLoader::PluginException) |
get an existing instance of a loaded plugin. More... | |
size_t | getInstancesCount () const |
number of handled instances | |
size_t | getLoadedPluginsCount () const |
number of loaded plugins | |
const std::map< std::string, ParameteredObject * > & | getObjectList () const |
Get names of existing instances. More... | |
const std::vector< std::string > & | getPluginPaths () const |
Gets the plugin paths. | |
virtual bool | initializePluginOnLoad () const |
void | insertInstance (ParameteredObject *instance) |
Insert an existing parametered object instance. More... | |
bool | isLoaded (const std::string &name) const |
Checks if a plugin is loaded. More... | |
void | loadParameterFile (const ParameterFile &pf) |
Reads a parameter file. More... | |
void | loadParameterFile (const std::string &path) |
Reads a parameter file. More... | |
void | loadPlugin (std::string name) throw (AbstractPluginLoader::PluginException) |
Loads a plugin stored in the previously declared folder. More... | |
void | reset () |
reset plugin manager More... | |
void | resetExecuted () |
Set the executed flags of the objects to false. More... | |
void | runWorkflow () |
run whole workflow More... | |
void | saveParameterFile (ParameterFile ¶mFile) const |
save parameters and connections of all managed plugins More... | |
void | saveParameterFile (const std::string &path) const |
save parameters and connections of all managed plugins More... | |
void | setDefaultTemplateType (ParameteredObject::template_type t) |
Set the default template type property. More... | |
void | setExcludeList (const std::vector< std::string > &list) |
set exclude list | |
virtual void | setInitiailizePluginOnLoad (bool initOnLoad) |
virtual std::string | templateTypeToString (ParameteredObject::template_type t) const |
Converts template_type to std::string. More... | |
void | unloadPlugin (const std::string &name) throw (AbstractPluginLoader::PluginException) |
Unloads a plugin. More... | |
![]() | |
virtual | ~PluginManagerInterface () |
Default destructor. | |
Private Member Functions | |
void | _destroyAllInstances (PLUGIN_LOADER *p) |
Deletes all instances of a loaded plugin. More... | |
std::list< ParameteredObject * > | _determineTargetPoints () |
Look for execution target points. More... | |
bool | _generateMetadataForPlugin (const std::string &pluginName, const std::string &filename) |
Creates metadata information for a specific plugin. More... | |
void | _unloadAllPlugins () |
Unloads all Plugins and destroys all instances. | |
void | _unloadPlugin (PLUGIN_LOADER *p, bool erase=true) |
Unloads a plugin and destroys instances. More... | |
bool | isInternal (ParameteredObject *obj) |
Check if parametered object is an internal object. | |
Private Attributes | |
ParameteredObject::template_type | _defaultTemplateType |
current default template type. | |
std::vector< std::string > | _excludeList |
exclude list for metadata generation | |
bool | _initializePluginOnLoad |
std::map< ParameteredObject *, PLUGIN_LOADER * > | _instances |
Links the instances to their PluginLoader. More... | |
std::map< std::string, PLUGIN_LOADER * > | _loadedPlugins |
Saves the currently loaded plugins. | |
PluginVersionCheckLevel | _versionInfo |
load plugin regardless of version information in the library file | |
std::string | libSuffix |
Lib suffix e.g. _d for debug builds. | |
std::map< std::string, ParameteredObject * > | objects |
currently existing instances that are handled by this PluginManager | |
std::vector< std::string > | pluginPaths |
Paths where the plugins are stored. | |
Formerly part of the ParameteredObject class | |
void | _getConnected (std::set< std::string > &visited, const std::set< std::string > &cur) const |
Recurse into object list and find connected objects. More... | |
void | _getConnected (std::set< std::string > &visited, const std::set< std::string > &cur, const ParameterFile &pf) const |
Recurse into object list and find connected objects. More... | |
std::set< std::string > | getNeighbours (const std::string &root) const |
Convenience function to get neighbours of given object. More... | |
std::set< std::string > | getNeighbours (const std::string &root, const ParameterFile &pf) const |
Convenience function to get neighbours of given object. More... | |
virtual std::set< std::string > | getConnected (const std::string &root, const ParameterFile &pf) const |
Recurse into object list and find connected objects. More... | |
std::set< std::string > | getConnected (const std::string &root) const |
Recurse into object list and find connected objects. More... | |
std::set< std::string > | getConnected (ParameterFile &pf, ParameteredObject *obj) const |
parameterFile version of getConnected(const std::string&) const | |
bool | connect (Slot &slot1, Slot &slot2) |
Connect slots. More... | |
bool | connect (Slot *slot1, Slot *slot2) |
Same method, but taking pointers. More... | |
bool | connect (const std::string &slot1, const std::string &slot2) |
Connect slots by name. More... | |
bool | disconnect (Slot &slot1, Slot &slot2) |
Disconnect slots. More... | |
bool | disconnect (const std::string &slot1, const std::string &slot2) |
Disconnect slots by name. More... | |
Additional Inherited Members | |
![]() | |
enum | PluginVersionCheckLevel { PluginVersionIgnore = 0, PluginVersionWarn = 1, PluginVersionDiscard = 2 } |
info how to handle version information | |
Offers methods to
Also, some methods which were previously members of the ParameteredObject class are now members of this class.
There may be multiple paths where Plugins are located. These paths have to be given to the PluginManager constructor. For compatibility reasons, there are constructors taking two paths (global and local path) as arguments, but arbitrary numbers of paths may be given to the stringlist versions of the constructor.
If using the two-paths version, note that the local path (if given) gets a higher priority than the global path. I.e. if the same Module exists twice (in global and local path) the local one is found first and will be used in workflows.
If using the stringlist version of the constructor, the paths are searched in the order as given.
To be able to use plugins in their debug and release build configuration side by side, it is possible to name the debug library with the suffix _d
. Regarding a plugin called example
, the libraries could be named e.g. example.dll
and example_d.dll
(Win/MSVC) or e.g. libexample.so
and libexample_d.so
(Linux/GCC). Since the names are different, both versions may be placed side by side in the same folder.
A mechanism to create the libraries easily this way is provided by the CMake variable CMAKE_DEBUG_SUFFIX (see CMake Documentation for more information).
This line should be added to your main CMakeLists.txt
(i.e. located in the top folder) to split up your debug/release libraries:
Which version of the libraries is preferred may be given to the PluginManager constructor using the debugSuffix parameter:
If this parameter is set to true
(default on Debug builds), libraries with debug suffix are preferred (i.e. if both versions exist, the suffixed module will be loaded. If only one of them exists, there is no choice, the found one will be loaded).
If debugSuffix is set to false
(default on Release builds), suffixed modules are completely ignored (even if only a suffixed file is found, it will not be loaded).
Per default, all generated plugins are created with their metadata description stored within the ParameteredObject. It can be retrieved via ParameteredObject::getMetadata(). Calling ParameteredObject::clearMetadata(), the metadata cache is cleared e.g. to save space. In the PluginManager, all created plugins are shipped with their metadata. The only exception is on loading a whole workflow file. I.e. loadParameterFile(const ParameterFile&) and loadParameterFile(const std::string&) delete the metadata information, because they are usually called just before running a workflow.
Definition at line 141 of file PluginManager.h.
PluginManager::PluginManager | ( | const std::vector< std::string > & | pluginPaths, |
bool | debugSuffix = DEFAULT_DEBUG_SUFFIX , |
||
bool | initializeOnLoad = false , |
||
PluginVersionCheckLevel | versionInfo = PluginVersionIgnore |
||
) |
Creates a new PluginManager instance and sets the path to the plugins to the value of pluginPaths.
pluginPaths | Paths where the plugins are stored. Search order as given. |
debugSuffix | Look for libraries with debug suffix (_d ), fallback to libs without suffix. |
initializeOnLoad | ask Gerald |
versionInfo | en/disable additional version check for plugins |
Definition at line 31 of file PluginManager.cpp.
References libSuffix, and pluginPaths.
PluginManager::PluginManager | ( | const std::string & | globalPath, |
const std::string & | localPath = "" , |
||
bool | debugSuffix = DEFAULT_DEBUG_SUFFIX , |
||
bool | initializeOnLoad = false , |
||
PluginVersionCheckLevel | versionInfo = PluginVersionIgnore |
||
) |
Creates a new PluginManager instance and sets the path to the plugins to the value of path1 and path2. This is a convenience function to preserve compatibility to the old non-vector style call.
globalPath,localPath | Paths where the plugins are stored. localPath is searched first. |
debugSuffix | Look for libraries with debug suffix (_d ), fallback to libs without suffix. |
initializeOnLoad | ask Gerald |
versionInfo | set how to handle version check on plugin load |
Definition at line 44 of file PluginManager.cpp.
References libSuffix, and pluginPaths.
|
virtual |
Deletes all existing instances of any loaded plugin and then unloads all plugins. Frees the memory.
Definition at line 833 of file PluginManager.cpp.
References reset().
|
private |
p | Plugin loader which has created the instances |
Definition at line 63 of file PluginManager.cpp.
References _instances, and objects.
|
private |
Iterates through the currently existing instances and looks for target points. Every instance which has no connected output slots is considered to be a target point.
Definition at line 762 of file PluginManager.cpp.
|
private |
Loads the plugin (if not already loaded), creates an instance of the plugin and destroys it immediately. If the plugin was not already loaded, unloads the plugin afterwards. The metadata information is stored in a parameter text file called "${targetPath}/${pluginName}.wrp"
pluginName | Name of the plugin (without prefix or extension) |
filename | Path to a file to store the metadata info |
Definition at line 698 of file PluginManager.cpp.
References createInstance(), destroyInstance(), AbstractPluginLoader::PluginException::getErrorCode(), ParameteredObject::getMetadata(), AbstractPluginLoader::PluginException::getPluginName(), AbstractPluginLoader::PluginException::INVALID_PLUGIN_FORMAT, isLoaded(), loadPlugin(), ParameterFile::save(), sout, unloadPlugin(), and AbstractPluginLoader::PluginException::VERSION_INFORMATION_MISSING.
|
private |
visited | List of visited objects (= result) |
cur | List of objects to look for neighbours |
Definition at line 377 of file PluginManager.cpp.
References getNeighbours().
|
private |
This search is based on the parameterfile content instead of the real existing connections.
visited | List of visited objects (= result) |
cur | List of objects to look for neighbours |
pf | ParameterFile to read connections from. |
Definition at line 404 of file PluginManager.cpp.
References _getConnected(), and getNeighbours().
|
private |
p | Plugin zo unload |
erase | If true, erases the plugin from map |
Definition at line 99 of file PluginManager.cpp.
References _destroyAllInstances(), _loadedPlugins, and StringTool::toLowerCase().
Both slots are connected with each other.
slot1 | Slot1 (in or out) |
slot2 | Slot2 (out or in) |
true | operation successful |
Definition at line 469 of file PluginManager.cpp.
References Slot::connect(), ParameteredObject::getInputSlots(), Slot::getName(), ParameteredObject::getOutputSlots(), Slot::getParent(), Slot::printWarning(), and sout.
slot1 | Slot1 (in or out) |
slot2 | Slot2 (out or in) |
true | operation successful |
Definition at line 502 of file PluginManager.cpp.
References connect().
bool PluginManager::connect | ( | const std::string & | slot1, |
const std::string & | slot2 | ||
) |
You have to provide the slot names as "objectname.slotname", i.e. the same way you find them in the parameter file. Both slots are connected with each other. You have to make sure, that both objects already exist.
slot1 | Slot1 (e.g. "object1.slot1") |
slot2 | Slot2 (e.g. "object2.slot1") |
true | operation successful |
Definition at line 506 of file PluginManager.cpp.
References connect(), objects, Slot::printWarning(), and sout.
void PluginManager::createDynamicMetadata | ( | const ParameterFile & | paramFile, |
const std::string & | filePrefix | ||
) |
Creates metadata of all dynamic plugins in given parameter file. FilePrefix should be some/file_prefix instead of some/file_prefix.wrp since this method writes the metadata into some/file_prefix_instance_name.wrp
The given parameter file is passed to the dynamic modules' prepareDynamicInterface function to add metadata for the parameter/slots in the scope of a dynamic plugin instance.
paramFile | ParameterFile containing parameters for plugin |
filePrefix | File prefix to determine save file names |
Definition at line 886 of file PluginManager.cpp.
References _defaultTemplateType, createInstance(), destroyInstance(), ParameterFile::get(), ParameterFile::getKeyList(), ParameteredObject::getMetadata(), isLoaded(), ParameterFile::isSet(), loadPlugin(), ParameteredObject::prepareDynamicInterface(), ParameterFile::save(), sout, ParameteredObject::TYPE_DOUBLE, ParameteredObject::TYPE_FLOAT, ParameteredObject::TYPE_INT, and unloadPlugin().
void PluginManager::createDynamicMetadata | ( | const std::string & | pluginName, |
const ParameterFile & | paramFile, | ||
const std::string & | fileName | ||
) |
Creates metadata of dynamic plugin based on parameter file
pluginName | Name of dynamic plugin |
paramFile | ParameterFile containing parameters for plugin |
fileName | File in which to save metadata |
Definition at line 943 of file PluginManager.cpp.
References createInstance(), destroyInstance(), AbstractPluginLoader::PluginException::getErrorCode(), ParameteredObject::getMetadata(), AbstractPluginLoader::PluginException::getPluginName(), AbstractPluginLoader::PluginException::INVALID_PLUGIN_FORMAT, isLoaded(), loadPlugin(), ParameteredObject::prepareDynamicInterface(), ParameterFile::save(), sout, and unloadPlugin().
ParameteredObject * PluginManager::createInstance | ( | std::string | pluginName, |
ParameteredObject::template_type | t, | ||
std::string | instanceName = "" |
||
) | |||
throw | ( | AbstractPluginLoader::PluginException | |
) |
If the requested plugin isn't loaded yet, PluginManager will try to load it. If the instance name is an empty string, a unique name will be generated.
The generated instance is shipped with it's metdata information.
pluginName | Name of the plugin |
t | Template type.
|
instanceName | Name of the instance |
Definition at line 174 of file PluginManager.cpp.
References AbstractPluginLoader::PluginException::DUPLICATE_INSTANCE_NAME, ParameteredObject::getName(), ParameteredObject::getTemplateType(), PLUGIN_LOADER, sout, and StringTool::toLowerCase().
ParameteredObject * PluginManager::createInstance | ( | const std::string & | pluginName, |
const std::string & | instanceName = "" |
||
) | |||
throw | ( | AbstractPluginLoader::PluginException | |
) |
Same Method as above but allowing to leave the template type out. Current default template type will be used (initially, it's ParameteredObject::TYPE_DOUBLE).
pluginName | Name of the plugin |
instanceName | Name of the instance |
Definition at line 214 of file PluginManager.cpp.
void PluginManager::createMetadata | ( | const std::string & | targetPath = "" | ) |
Iterates through the plugins available inside the plugin path and creates metadata information for them.
targetPath | Path to save the metadata files to. Defaults to the plugin path if empty. |
Definition at line 621 of file PluginManager.cpp.
References _excludeList, _generateMetadataForPlugin(), FileTool::changeDir(), FileTool::getCurrentDir(), FileTool::getFilesWithSuffix(), PLUGIN_EXTENSION, pluginPaths, and sout.
void PluginManager::destroyInstance | ( | ParameteredObject * | toDestroy | ) | |
throw | ( | AbstractPluginLoader::PluginException | |||
) |
Calls the Destructor the instance.
toDestroy | Pointer to an instance of a plugin |
Definition at line 220 of file PluginManager.cpp.
References AbstractPluginLoader::PluginException::NO_SUCH_INSTANCE, and sout.
std::list< ParameteredObject * > PluginManager::determineExecutionOrder | ( | ) |
Get topological sorted list of module instance names, i.e. an order of instances where each instance depends on predecessors only. This means that input slots of the objects are connected to preceeding objects only. If an object is executed multiple times, the first execution counts.
Definition at line 793 of file PluginManager.cpp.
References _determineTargetPoints(), ParameteredObject::getInputSlots(), and FileTool::remove().
Both slots are disconnected from each other.
slot1 | Slot1 (in or out) |
slot2 | Slot2 (out or in) |
true | operation successful |
Definition at line 561 of file PluginManager.cpp.
References Slot::disconnect().
bool PluginManager::disconnect | ( | const std::string & | slot1, |
const std::string & | slot2 | ||
) |
You have to provide the slot names as "objectname.slotname", i.e. the same way you find them in the parameter file. Both slots are disconnected with each other.
slot1 | Slot1 (e.g. "object1.slot1") |
slot2 | Slot2 (e.g. "object2.slot1") |
true | operation successful |
Definition at line 565 of file PluginManager.cpp.
References disconnect(), objects, Slot::printWarning(), and sout.
|
virtual |
This is based on the content of the given ParameterFile, i.e. the connected objects need not to exist really. This is also independend of the existing connections of the current object, it is only based on the connections saved in the parameter file. Nonexistent objects are created, so you have to make sure, that the object factory is up and running. The root object itself is also part of the connected component.
root | Starting point for connected object search |
pf | ParameterFile to read connections from. |
Implements PluginManagerInterface.
Definition at line 450 of file PluginManager.cpp.
References _getConnected(), and getNeighbours().
std::set< std::string > PluginManager::getConnected | ( | const std::string & | root | ) | const |
This is based on the "real" slot connections, i.e. independend of some parameter file content. The root object itself is also part of the connected component.
root | Starting point for connected object search |
Definition at line 460 of file PluginManager.cpp.
References _getConnected(), and getNeighbours().
ParameteredObject::template_type PluginManager::getDefaultTemplateType | ( | ) | const |
Returns the current default template type property. Initially, it is set to ParameteredObject::TYPE_DOUBLE.
Definition at line 349 of file PluginManager.cpp.
References _defaultTemplateType.
|
virtual |
instanceName | Name of the instance |
Implements PluginManagerInterface.
Definition at line 160 of file PluginManager.cpp.
References AbstractPluginLoader::PluginException::NO_SUCH_INSTANCE.
std::set< std::string > PluginManager::getNeighbours | ( | const std::string & | root | ) | const |
root | name of the root object to start neighbour search |
Definition at line 431 of file PluginManager.cpp.
References objects.
std::set< std::string > PluginManager::getNeighbours | ( | const std::string & | root, |
const ParameterFile & | pf | ||
) | const |
root | name of the root object to start neighbour search |
pf | ParameterFile to read connections from. |
Definition at line 440 of file PluginManager.cpp.
References objects.
|
inline |
Definition at line 324 of file PluginManager.h.
void PluginManager::insertInstance | ( | ParameteredObject * | instance | ) |
instance | Instance to insert. |
Definition at line 842 of file PluginManager.cpp.
References ParameteredObject::getName(), and objects.
bool PluginManager::isLoaded | ( | const std::string & | name | ) | const |
name | name of the plugin |
Definition at line 147 of file PluginManager.cpp.
References _loadedPlugins, and StringTool::toLowerCase().
void PluginManager::loadParameterFile | ( | const ParameterFile & | pf | ) |
pf | ParameterFile to load from |
Definition at line 251 of file PluginManager.cpp.
References _defaultTemplateType, ParameteredObject::clearMetadata(), createInstance(), ParameterFile::get(), ParameterFile::getKeyList(), isLoaded(), ParameterFile::isSet(), loadPlugin(), objects, ParameteredObject::prepareDynamicInterface(), reset(), sout, TypeDetector::type(), ParameteredObject::TYPE_DOUBLE, ParameteredObject::TYPE_FLOAT, and ParameteredObject::TYPE_INT.
void PluginManager::loadParameterFile | ( | const std::string & | path | ) |
Same method as above, but loads a ParameterFile from the given path.
path | Path to the parameter file |
Definition at line 317 of file PluginManager.cpp.
References loadParameterFile().
void PluginManager::loadPlugin | ( | std::string | name | ) | |
throw | ( | AbstractPluginLoader::PluginException | |||
) |
name | the file name of the plugin |
Definition at line 110 of file PluginManager.cpp.
References AbstractPluginLoader::PluginException::ALREADY_LOADED, PLUGIN_LOADER, sout, and StringTool::toLowerCase().
void PluginManager::reset | ( | ) |
Resets this PluginManager instance to its initial state. Unloads all plugins, resets defaultTemplateType parameter and deletes target points.
Definition at line 757 of file PluginManager.cpp.
References _defaultTemplateType, _unloadAllPlugins(), and ParameteredObject::TYPE_DOUBLE.
void PluginManager::resetExecuted | ( | ) |
This function leaves the objects otherwise untouched
Definition at line 863 of file PluginManager.cpp.
References objects, and AbstractPluginLoader::PluginException::OTHER.
void PluginManager::runWorkflow | ( | ) |
Calls run() on every target point.
Definition at line 359 of file PluginManager.cpp.
References _determineTargetPoints(), and AbstractPluginLoader::PluginException::OTHER.
void PluginManager::saveParameterFile | ( | ParameterFile & | paramFile | ) | const |
Save content of all currently loaded instances to the given ParameterFile. All registered parameters and slot connections are saved.
paramFile | ParameterFile to save to |
Definition at line 321 of file PluginManager.cpp.
References _defaultTemplateType, objects, ParameterFile::set(), and templateTypeToString().
void PluginManager::saveParameterFile | ( | const std::string & | path | ) | const |
Same method, but writes the file to the given path.
path | Path where the parameter file should be saved. |
Definition at line 343 of file PluginManager.cpp.
References ParameterFile::save(), and saveParameterFile().
void PluginManager::setDefaultTemplateType | ( | ParameteredObject::template_type | t | ) |
New instances created without explicitly specifying another tempate type are created using this template type. Initially, the value is set to ParameteredObject::TYPE_DOUBLE.
t | New default template type
|
Definition at line 353 of file PluginManager.cpp.
References _defaultTemplateType.
|
virtual |
t | template type to convert |
Implements PluginManagerInterface.
Definition at line 992 of file PluginManager.cpp.
References ParameteredObject::TYPE_DOUBLE, ParameteredObject::TYPE_FLOAT, and ParameteredObject::TYPE_INT.
void PluginManager::unloadPlugin | ( | const std::string & | name | ) | |
throw | ( | AbstractPluginLoader::PluginException | |||
) |
name | Name of the plugin |
Definition at line 135 of file PluginManager.cpp.
References AbstractPluginLoader::PluginException::PLUGIN_NOT_LOADED, and StringTool::toLowerCase().
|
private |
so the PluginManager can determine of which type the instance is
Definition at line 154 of file PluginManager.h.