OpenASIP
2.0
|
#include <PluginTools.hh>
Public Member Functions | |
PluginTools (bool lazyResolution=true, bool local=false) | |
virtual | ~PluginTools () |
void | addSearchPath (const std::string &searchPath) |
void | removeSearchPath (const std::string &searchPath) |
void | clearSearchPaths () |
void | registerModule (const std::string &module) |
void | unregisterModule (const std::string &module) |
void | unregisterAllModules () |
template<typename T > | |
void | importSymbol (const std::string &symbolName, T *&target, const std::string &module) |
template<typename T > | |
void | importSymbol (const std::string &symbolName, T *&target) |
Private Types | |
typedef std::vector< std::string >::iterator | VecIter |
typedef std::map< std::string, void * >::iterator | MapIter |
typedef std::map< std::string, void * >::value_type | ValType |
Private Member Functions | |
void * | loadSym (const std::string &symbolName, const std::string &module="") |
std::string | findModule (const std::string &module) |
PluginTools (const PluginTools &) | |
Copying not allowed. More... | |
PluginTools & | operator= (const PluginTools &) |
Assignment not allowed. More... | |
Private Attributes | |
std::vector< std::string > | searchPaths_ |
Search paths of dynamic modules. More... | |
std::map< std::string, void * > | modules_ |
Map containing opened module handles. More... | |
bool | lazyResolution_ |
True if all undefined symbols should be resolved only when needed. More... | |
bool | localResolution_ |
True if the symbols defined in the loaded library should be made available for symbol resolution of subsequently loaded libraries. More... | |
Class that handles accessing of dynamic modules for providing run-time plug-in functionality.
Class allows defining search paths, in which modules are searched. This enables registering modules without absolut paths to modules. Symbols (variables, functions) are loaded from modules and automatically cast to correct types by means of the template mechanism.
Definition at line 53 of file PluginTools.hh.
|
private |
Definition at line 75 of file PluginTools.hh.
|
private |
Definition at line 76 of file PluginTools.hh.
|
private |
Definition at line 74 of file PluginTools.hh.
PluginTools::PluginTools | ( | bool | lazyResolution = true , |
bool | local = false |
||
) |
Constructor.
The created instance has no search paths registered.
lazyResolution | True if symbol resolution should be done lazily. |
localResolution | True in case the symbols are loaded locally to the process only and not made visible to later plugin loads. |
Definition at line 73 of file PluginTools.cc.
|
virtual |
Destructor.
Unregisters all modules.
Definition at line 83 of file PluginTools.cc.
References unregisterAllModules().
|
private |
Copying not allowed.
void PluginTools::addSearchPath | ( | const std::string & | searchPath | ) |
Adds a new search path in search path list.
searchPath | The search path to be added. |
FileNotFound | If path doesn't exist. |
Definition at line 95 of file PluginTools.cc.
References FileSystem::fileExists(), and searchPaths_.
Referenced by ProgramImageGenerator::createCompressor(), LLVMBackend::createPlugin(), GenerateProcessor::listICDecPluginParameters(), GenerateProcessorDialog::loadICDecoderGeneratorPlugin(), ProGe::ProGeUI::loadICDecoderGeneratorPlugin(), and CompiledSimController::reset().
void PluginTools::clearSearchPaths | ( | ) |
Clears all search paths from search path list.
Definition at line 119 of file PluginTools.cc.
References searchPaths_.
|
private |
Looks for the path for the module and returns it if it is found.
module | The module to be searched for. |
MultipleInstacesFound | If multiple instances of module are found. |
FileNotFOund | If module is not found at all. |
Definition at line 346 of file PluginTools.cc.
References StringTools::endsWith(), FileSystem::fileOfPath(), and modules_.
Referenced by loadSym(), and unregisterModule().
void PluginTools::importSymbol | ( | const std::string & | symbolName, |
T *& | target | ||
) |
void PluginTools::importSymbol | ( | const std::string & | symbolName, |
T *& | target, | ||
const std::string & | module | ||
) |
Referenced by LLVMBackend::compile(), CompiledSimulation::compileAndLoadFunction(), ProgramImageGenerator::createCompressor(), LLVMBackend::createPlugin(), OperationBehaviorLoader::importBehavior(), GenerateProcessor::listICDecPluginParameters(), GenerateProcessorDialog::loadICDecoderGeneratorPlugin(), ProGe::ProGeUI::loadICDecoderGeneratorPlugin(), and CompiledSimController::reset().
|
private |
Loads symbol from module.
If module is not given, then all modules are searched in order to find the symbol. Note that the search order of modules is not necessarily the same as the registration order!
symbolName | The symbol being loaded. |
module | The module where symbol is loaded. |
MultipleInstancesFound | If multiple instances of module are found. |
DynamicLibraryException | If dlsym() fails. |
FileNotFound | If module is not found. |
SymbolNotFound | If symbol to be loaded is not found. |
Definition at line 271 of file PluginTools.cc.
References __func__, MapTools::containsKey(), findModule(), FileSystem::isAbsolutePath(), modules_, and registerModule().
|
private |
Assignment not allowed.
void PluginTools::registerModule | ( | const std::string & | module | ) |
Registers a module in registry.
If module is not an absolute path, then it is searched from search paths added with addSearchPath() in the order of addition. First module found is used. If module already exists in the registry, it's not opened again. RTLD_LOCAL and RTLD_NOW flags are used by default when opening the module.
module | The module to be registered. |
FileNotFound | If module is not found. |
DynamicLibraryException | if dlopen() fails. |
Definition at line 138 of file PluginTools.cc.
References MapTools::containsKey(), DIR_SEP, FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::isAbsolutePath(), lazyResolution_, localResolution_, modules_, RTLD_LOCAL, and searchPaths_.
Referenced by CompiledSimulation::compileAndLoadFunction(), ProgramImageGenerator::createCompressor(), LLVMBackend::createPlugin(), GenerateProcessor::listICDecPluginParameters(), GenerateProcessorDialog::loadICDecoderGeneratorPlugin(), ProGe::ProGeUI::loadICDecoderGeneratorPlugin(), loadSym(), and CompiledSimController::reset().
void PluginTools::removeSearchPath | ( | const std::string & | searchPath | ) |
Removes search path from search path list if it is found.
searchPath | the search path to be removed. |
Definition at line 110 of file PluginTools.cc.
References ContainerTools::removeValueIfExists(), and searchPaths_.
void PluginTools::unregisterAllModules | ( | ) |
Unregisters all modules.
All modules are closed by using dlclose() and registry is emptied.
DynamicLibraryException | If dlclose() fails. |
Definition at line 236 of file PluginTools.cc.
References modules_.
Referenced by OperationBehaviorLoader::freeBehavior(), and ~PluginTools().
void PluginTools::unregisterModule | ( | const std::string & | module | ) |
A module is closed using dlclose() and it is removed from registry.
module | The module to be unregistered. |
FileNotFound | If module is not found. |
DynamicLibraryException | If dlclose() fails. |
MultipleInstancesFound | If multiple modules are found. |
Definition at line 207 of file PluginTools.cc.
References findModule(), FileSystem::isAbsolutePath(), and modules_.
|
private |
True if all undefined symbols should be resolved only when needed.
Definition at line 94 of file PluginTools.hh.
Referenced by registerModule().
|
private |
True if the symbols defined in the loaded library should be made available for symbol resolution of subsequently loaded libraries.
Definition at line 97 of file PluginTools.hh.
Referenced by registerModule().
|
private |
Map containing opened module handles.
Definition at line 91 of file PluginTools.hh.
Referenced by findModule(), loadSym(), registerModule(), unregisterAllModules(), and unregisterModule().
|
private |
Search paths of dynamic modules.
Definition at line 89 of file PluginTools.hh.
Referenced by addSearchPath(), clearSearchPaths(), registerModule(), and removeSearchPath().