class_loader
master
The class_loader package is a ROS-independent package for loading plugins during runtime.
|
Classes | |
class | AbstractMetaObject |
Abstract base class for factories where polymorphic type variable indicates base class for plugin interface. More... | |
class | AbstractMetaObjectBase |
A base class for MetaObjects that excludes a polymorphic type parameter. Subclasses are class templates though. More... | |
class | MetaObject |
The actual factory. More... | |
Typedefs | |
typedef std::string | LibraryPath |
typedef std::string | ClassName |
typedef std::string | BaseClassName |
typedef std::map< ClassName, impl::AbstractMetaObjectBase * > | FactoryMap |
typedef std::map< BaseClassName, FactoryMap > | BaseToFactoryMapMap |
typedef std::pair< LibraryPath, std::shared_ptr< rcpputils::SharedLibrary > > | LibraryPair |
typedef std::vector< LibraryPair > | LibraryVector |
typedef std::vector< AbstractMetaObjectBase * > | MetaObjectVector |
Functions | |
void | printDebugInfoToScreen () |
BaseToFactoryMapMap & | getGlobalPluginBaseToFactoryMapMap () |
Gets a handle to a global data structure that holds a map of base class names (Base class describes plugin interface) to a FactoryMap which holds the factories for the various different concrete classes that can be instantiated. Note that the Base class is NOT THE LITERAL CLASSNAME, but rather the result of typeid(Base).name() which sometimes is the literal class name (as on Windows) but is often in mangled form (as on Linux). More... | |
LibraryVector & | getLoadedLibraryVector () |
Gets a handle to a list of open libraries in the form of LibraryPairs which encode the library path+name and the handle to the underlying shared library. More... | |
std::string | getCurrentlyLoadingLibraryName () |
When a library is being loaded, in order for factories to know which library they are being associated with, they use this function to query which library is being loaded. More... | |
void | setCurrentlyLoadingLibraryName (const std::string &library_name) |
When a library is being loaded, in order for factories to know which library they are being associated with, this function is called to set the name of the library currently being loaded. More... | |
ClassLoader * | getCurrentlyActiveClassLoader () |
Gets the ClassLoader currently in scope which used when a library is being loaded. More... | |
void | setCurrentlyActiveClassLoader (ClassLoader *loader) |
Sets the ClassLoader currently in scope which used when a library is being loaded. More... | |
FactoryMap & | getFactoryMapForBaseClass (const std::string &typeid_base_class_name) |
This function extracts a reference to the FactoryMap for appropriate base class out of the global plugin base to factory map. This function should be used by functions in this namespace that need to access the various factories so as to make sure the right key is generated to index into the global map. More... | |
template<typename Base > | |
FactoryMap & | getFactoryMapForBaseClass () |
Same as above but uses a type parameter instead of string for more safety if info is available. More... | |
std::recursive_mutex & | getLoadedLibraryVectorMutex () |
To provide thread safety, all exposed plugin functions can only be run serially by multiple threads. More... | |
std::recursive_mutex & | getPluginBaseToFactoryMapMapMutex () |
bool | hasANonPurePluginLibraryBeenOpened () |
Indicates if a library containing more than just plugins has been opened by the running process. More... | |
void | hasANonPurePluginLibraryBeenOpened (bool hasIt) |
Sets a flag indicating if a library containing more than just plugins has been opened by the running process. More... | |
template<typename Derived , typename Base > | |
void | registerPlugin (const std::string &class_name, const std::string &base_class_name) |
This function is called by the CLASS_LOADER_REGISTER_CLASS macro in plugin_register_macro.h to register factories. Classes that use that macro will cause this function to be invoked when the library is loaded. The function will create a MetaObject (i.e. factory) for the corresponding Derived class and insert it into the appropriate FactoryMap in the global Base-to-FactoryMap map. Note that the passed class_name is the literal class name and not the mangled version. More... | |
template<typename Base > | |
Base * | createInstance (const std::string &derived_class_name, ClassLoader *loader) |
This function creates an instance of a plugin class given the derived name of the class and returns a pointer of the Base class type. More... | |
template<typename Base > | |
std::vector< std::string > | getAvailableClasses (const ClassLoader *loader) |
This function returns all the available class_loader in the plugin system that are derived from Base and within scope of the passed ClassLoader. More... | |
std::vector< std::string > | getAllLibrariesUsedByClassLoader (const ClassLoader *loader) |
This function returns the names of all libraries in use by a given class loader. More... | |
bool | isLibraryLoaded (const std::string &library_path, const ClassLoader *loader) |
Indicates if passed library loaded within scope of a ClassLoader. The library maybe loaded in memory, but to the class loader it may not be. More... | |
bool | isLibraryLoadedByAnybody (const std::string &library_path) |
Indicates if passed library has been loaded by ANY ClassLoader. More... | |
void | loadLibrary (const std::string &library_path, ClassLoader *loader) |
Loads a library into memory if it has not already been done so. Attempting to load an already loaded library has no effect. More... | |
void | unloadLibrary (const std::string &library_path, ClassLoader *loader) |
Unloads a library if it loaded in memory and cleans up its corresponding class factories. If it is not loaded, the function has no effect. More... | |
typedef std::pair<LibraryPath, std::shared_ptr<rcpputils::SharedLibrary> > class_loader::impl::LibraryPair |
void class_loader::impl::printDebugInfoToScreen | ( | ) |
BaseToFactoryMapMap& class_loader::impl::getGlobalPluginBaseToFactoryMapMap | ( | ) |
Gets a handle to a global data structure that holds a map of base class names (Base class describes plugin interface) to a FactoryMap which holds the factories for the various different concrete classes that can be instantiated. Note that the Base class is NOT THE LITERAL CLASSNAME, but rather the result of typeid(Base).name() which sometimes is the literal class name (as on Windows) but is often in mangled form (as on Linux).
LibraryVector& class_loader::impl::getLoadedLibraryVector | ( | ) |
Gets a handle to a list of open libraries in the form of LibraryPairs which encode the library path+name and the handle to the underlying shared library.
std::string class_loader::impl::getCurrentlyLoadingLibraryName | ( | ) |
When a library is being loaded, in order for factories to know which library they are being associated with, they use this function to query which library is being loaded.
void class_loader::impl::setCurrentlyLoadingLibraryName | ( | const std::string & | library_name | ) |
When a library is being loaded, in order for factories to know which library they are being associated with, this function is called to set the name of the library currently being loaded.
library_name | - The name of library that is being loaded currently |
ClassLoader* class_loader::impl::getCurrentlyActiveClassLoader | ( | ) |
Gets the ClassLoader currently in scope which used when a library is being loaded.
void class_loader::impl::setCurrentlyActiveClassLoader | ( | ClassLoader * | loader | ) |
Sets the ClassLoader currently in scope which used when a library is being loaded.
loader | - pointer to the currently active ClassLoader. |
FactoryMap& class_loader::impl::getFactoryMapForBaseClass | ( | const std::string & | typeid_base_class_name | ) |
This function extracts a reference to the FactoryMap for appropriate base class out of the global plugin base to factory map. This function should be used by functions in this namespace that need to access the various factories so as to make sure the right key is generated to index into the global map.
FactoryMap& class_loader::impl::getFactoryMapForBaseClass | ( | ) |
Same as above but uses a type parameter instead of string for more safety if info is available.
std::recursive_mutex& class_loader::impl::getLoadedLibraryVectorMutex | ( | ) |
To provide thread safety, all exposed plugin functions can only be run serially by multiple threads.
This is implemented by using critical sections enforced by a single mutex which is locked and released with the following two functions.
std::recursive_mutex& class_loader::impl::getPluginBaseToFactoryMapMapMutex | ( | ) |
bool class_loader::impl::hasANonPurePluginLibraryBeenOpened | ( | ) |
Indicates if a library containing more than just plugins has been opened by the running process.
void class_loader::impl::hasANonPurePluginLibraryBeenOpened | ( | bool | hasIt | ) |
Sets a flag indicating if a library containing more than just plugins has been opened by the running process.
hasIt | - The flag |
void class_loader::impl::registerPlugin | ( | const std::string & | class_name, |
const std::string & | base_class_name | ||
) |
This function is called by the CLASS_LOADER_REGISTER_CLASS macro in plugin_register_macro.h to register factories. Classes that use that macro will cause this function to be invoked when the library is loaded. The function will create a MetaObject (i.e. factory) for the corresponding Derived class and insert it into the appropriate FactoryMap in the global Base-to-FactoryMap map. Note that the passed class_name is the literal class name and not the mangled version.
Derived | - parameteric type indicating concrete type of plugin |
Base | - parameteric type indicating base type of plugin |
class_name | - the literal name of the class being registered (NOT MANGLED) |
Base* class_loader::impl::createInstance | ( | const std::string & | derived_class_name, |
ClassLoader * | loader | ||
) |
This function creates an instance of a plugin class given the derived name of the class and returns a pointer of the Base class type.
derived_class_name | - The name of the derived class (unmangled) |
loader | - The ClassLoader whose scope we are within |
std::vector<std::string> class_loader::impl::getAvailableClasses | ( | const ClassLoader * | loader | ) |
This function returns all the available class_loader in the plugin system that are derived from Base and within scope of the passed ClassLoader.
loader | - The pointer to the ClassLoader whose scope we are within, |
std::vector<std::string> class_loader::impl::getAllLibrariesUsedByClassLoader | ( | const ClassLoader * | loader | ) |
This function returns the names of all libraries in use by a given class loader.
loader | - The ClassLoader whose scope we are within |
bool class_loader::impl::isLibraryLoaded | ( | const std::string & | library_path, |
const ClassLoader * | loader | ||
) |
Indicates if passed library loaded within scope of a ClassLoader. The library maybe loaded in memory, but to the class loader it may not be.
library_path | - The name of the library we wish to check is open |
loader | - The pointer to the ClassLoader whose scope we are within |
bool class_loader::impl::isLibraryLoadedByAnybody | ( | const std::string & | library_path | ) |
Indicates if passed library has been loaded by ANY ClassLoader.
library_path | - The name of the library we wish to check is open |
void class_loader::impl::loadLibrary | ( | const std::string & | library_path, |
ClassLoader * | loader | ||
) |
Loads a library into memory if it has not already been done so. Attempting to load an already loaded library has no effect.
library_path | - The name of the library to open |
loader | - The pointer to the ClassLoader whose scope we are within |
void class_loader::impl::unloadLibrary | ( | const std::string & | library_path, |
ClassLoader * | loader | ||
) |
Unloads a library if it loaded in memory and cleans up its corresponding class factories. If it is not loaded, the function has no effect.
library_path | - The name of the library to open |
loader | - The pointer to the ClassLoader whose scope we are within |