class_loader  master
The class_loader package is a ROS-independent package for loading plugins during runtime.
Classes | Typedefs | Functions
class_loader::impl Namespace Reference

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, FactoryMapBaseToFactoryMapMap
 
typedef std::pair< LibraryPath, std::shared_ptr< rcpputils::SharedLibrary > > LibraryPair
 
typedef std::vector< LibraryPairLibraryVector
 
typedef std::vector< AbstractMetaObjectBase * > MetaObjectVector
 

Functions

void printDebugInfoToScreen ()
 
BaseToFactoryMapMapgetGlobalPluginBaseToFactoryMapMap ()
 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...
 
LibraryVectorgetLoadedLibraryVector ()
 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...
 
ClassLoadergetCurrentlyActiveClassLoader ()
 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...
 
FactoryMapgetFactoryMapForBaseClass (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 >
FactoryMapgetFactoryMapForBaseClass ()
 Same as above but uses a type parameter instead of string for more safety if info is available. More...
 
std::recursive_mutexgetLoadedLibraryVectorMutex ()
 To provide thread safety, all exposed plugin functions can only be run serially by multiple threads. More...
 
std::recursive_mutexgetPluginBaseToFactoryMapMapMutex ()
 
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::stringgetAvailableClasses (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::stringgetAllLibrariesUsedByClassLoader (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 Documentation

◆ LibraryPath

◆ ClassName

◆ BaseClassName

◆ FactoryMap

◆ BaseToFactoryMapMap

◆ LibraryPair

◆ LibraryVector

◆ MetaObjectVector

Function Documentation

◆ printDebugInfoToScreen()

void class_loader::impl::printDebugInfoToScreen ( )

◆ getGlobalPluginBaseToFactoryMapMap()

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).

Returns
A reference to the global base to factory map

◆ getLoadedLibraryVector()

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.

Returns
A reference to the global vector that tracks loaded libraries

◆ getCurrentlyLoadingLibraryName()

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.

Returns
The currently set loading library name as a string

◆ setCurrentlyLoadingLibraryName()

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.

Parameters
library_name- The name of library that is being loaded currently

◆ getCurrentlyActiveClassLoader()

ClassLoader* class_loader::impl::getCurrentlyActiveClassLoader ( )

Gets the ClassLoader currently in scope which used when a library is being loaded.

Returns
A pointer to the currently active ClassLoader.

◆ setCurrentlyActiveClassLoader()

void class_loader::impl::setCurrentlyActiveClassLoader ( ClassLoader loader)

Sets the ClassLoader currently in scope which used when a library is being loaded.

Parameters
loader- pointer to the currently active ClassLoader.

◆ getFactoryMapForBaseClass() [1/2]

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.

Returns
A reference to the FactoryMap contained within the global Base-to-FactoryMap map.

◆ getFactoryMapForBaseClass() [2/2]

template<typename Base >
FactoryMap& class_loader::impl::getFactoryMapForBaseClass ( )

Same as above but uses a type parameter instead of string for more safety if info is available.

Returns
A reference to the FactoryMap contained within the global Base-to-FactoryMap map.

◆ getLoadedLibraryVectorMutex()

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.

Returns
A reference to the global mutex

◆ getPluginBaseToFactoryMapMapMutex()

std::recursive_mutex& class_loader::impl::getPluginBaseToFactoryMapMapMutex ( )

◆ hasANonPurePluginLibraryBeenOpened() [1/2]

bool class_loader::impl::hasANonPurePluginLibraryBeenOpened ( )

Indicates if a library containing more than just plugins has been opened by the running process.

Returns
True if a non-pure plugin library has been opened, otherwise false

◆ hasANonPurePluginLibraryBeenOpened() [2/2]

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.

Parameters
hasIt- The flag

◆ registerPlugin()

template<typename Derived , typename Base >
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.

Parameters
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)

◆ createInstance()

template<typename Base >
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.

Parameters
derived_class_name- The name of the derived class (unmangled)
loader- The ClassLoader whose scope we are within
Returns
A pointer to newly created plugin, note caller is responsible for object destruction

◆ getAvailableClasses()

template<typename Base >
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.

Parameters
loader- The pointer to the ClassLoader whose scope we are within,
Returns
A vector of strings where each string is a plugin we can create

◆ getAllLibrariesUsedByClassLoader()

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.

Parameters
loader- The ClassLoader whose scope we are within
Returns
A vector of strings where each string is the path+name of each library that are within a ClassLoader's visible scope

◆ isLibraryLoaded()

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.

Parameters
library_path- The name of the library we wish to check is open
loader- The pointer to the ClassLoader whose scope we are within
Returns
true if the library is loaded within loader's scope, else false

◆ isLibraryLoadedByAnybody()

bool class_loader::impl::isLibraryLoadedByAnybody ( const std::string library_path)

Indicates if passed library has been loaded by ANY ClassLoader.

Parameters
library_path- The name of the library we wish to check is open
Returns
true if the library is loaded in memory, otherwise false

◆ loadLibrary()

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.

Parameters
library_path- The name of the library to open
loader- The pointer to the ClassLoader whose scope we are within

◆ unloadLibrary()

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.

Parameters
library_path- The name of the library to open
loader- The pointer to the ClassLoader whose scope we are within