Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
tesseract_common::PluginLoader Class Reference

This is a utility class for loading plugins within Tesseract. More...

#include <plugin_loader.h>

Inheritance diagram for tesseract_common::PluginLoader:
Inheritance graph
[legend]
Collaboration diagram for tesseract_common::PluginLoader:
Collaboration graph
[legend]

Public Member Functions

template<class PluginBase >
std::shared_ptr< PluginBase > instantiate (const std::string &plugin_name) const
 Instantiate a plugin with the provided name. More...
 
bool isPluginAvailable (const std::string &plugin_name) const
 Check if plugin is available. More...
 
template<class PluginBase >
std::vector< std::string > getAvailablePlugins () const
 Get the available plugins for the provided PluginBase type. More...
 
std::vector< std::string > getAvailablePlugins (const std::string &section) const
 Get the available plugins under the provided section. More...
 
std::vector< std::string > getAvailableSections (bool include_hidden=false) const
 Get the available sections within the provided search libraries. More...
 
int count () const
 The number of plugins stored. The size of plugins variable. More...
 

Static Public Member Functions

static void addSymbolLibraryToSearchLibrariesEnv (const void *symbol_ptr, const std::string &search_libraries_env)
 Utility function to add library containing symbol to the search env variable. More...
 

Public Attributes

bool search_system_folders { true }
 Indicate is system folders may be search if plugin is not found in any of the paths. More...
 
std::set< std::string > search_paths
 A list of paths to search for plugins. More...
 
std::set< std::string > search_libraries
 A list of library names without the prefix or suffix that contain plugins. More...
 
std::string search_paths_env
 The environment variable containing plugin search paths. More...
 
std::string search_libraries_env
 The environment variable containing plugins. More...
 

Detailed Description

This is a utility class for loading plugins within Tesseract.

The library_name should not include the prefix 'lib' or suffix '.so'. It will add the correct prefix and suffix based on the OS.

It supports providing additional search paths and set environment variable which should be used when searching for plugins.

The plugin must be exported using the macro TESSERACT_ADD_PLUGIN. In the example below, the first parameter is the derived object and the second is the assigned symbol name which is used for loading Example: TESSERACT_ADD_PLUGIN(my_namespace::MyPlugin, plugin)

PluginLoader loader; loader.search_libraries.insert("my_plugin"); // libmy_plugin.so std::shared_ptr<PluginBase> p = loader.instantiate<PluginBase>("plugin");

Member Function Documentation

◆ addSymbolLibraryToSearchLibrariesEnv()

void tesseract_common::PluginLoader::addSymbolLibraryToSearchLibrariesEnv ( const void *  symbol_ptr,
const std::string &  search_libraries_env 
)
inlinestatic

Utility function to add library containing symbol to the search env variable.

In some cases the name and location of a library is unknown at runtime, but a symbol can be linked at compile time. This is true for Python auditwheel distributions. This utility function will determine the location of the library, and add it to the library search environment variable so it can be found.

Parameters
symbol_ptrPointer to the symbol to find
search_libraries_envThe environmental variable to modify

◆ count()

int tesseract_common::PluginLoader::count ( ) const
inline

The number of plugins stored. The size of plugins variable.

Returns
The number of plugins.

◆ getAvailablePlugins() [1/2]

template<class PluginBase >
std::vector< std::string > tesseract_common::PluginLoader::getAvailablePlugins

Get the available plugins for the provided PluginBase type.

This expects the Plugin base to have a static std::string SECTION_NAME which is used for looking up plugins

Returns
A list of available plugins for the provided PluginBase type

◆ getAvailablePlugins() [2/2]

std::vector< std::string > tesseract_common::PluginLoader::getAvailablePlugins ( const std::string &  section) const
inline

Get the available plugins under the provided section.

Parameters
sectionThe section name to get all available plugins
Returns
A list of available plugins under the provided section

◆ getAvailableSections()

std::vector< std::string > tesseract_common::PluginLoader::getAvailableSections ( bool  include_hidden = false) const
inline

Get the available sections within the provided search libraries.

Returns
A list of available sections

◆ instantiate()

template<class PluginBase >
std::shared_ptr< PluginBase > tesseract_common::PluginLoader::instantiate ( const std::string &  plugin_name) const

Instantiate a plugin with the provided name.

Parameters
plugin_nameThe plugin name to find
Returns
A instantiate of the plugin, if nullptr it failed to create plugin

◆ isPluginAvailable()

bool tesseract_common::PluginLoader::isPluginAvailable ( const std::string &  plugin_name) const
inline

Check if plugin is available.

Parameters
plugin_nameThe plugin name to find
Returns
True if plugin is found

Member Data Documentation

◆ search_libraries

std::set<std::string> tesseract_common::PluginLoader::search_libraries

A list of library names without the prefix or suffix that contain plugins.

◆ search_libraries_env

std::string tesseract_common::PluginLoader::search_libraries_env

The environment variable containing plugins.

The plugins are store ins the following format. The library name does not contain prefix or suffix Format: library_name:library_name1:library_name2

◆ search_paths

std::set<std::string> tesseract_common::PluginLoader::search_paths

A list of paths to search for plugins.

◆ search_paths_env

std::string tesseract_common::PluginLoader::search_paths_env

The environment variable containing plugin search paths.

◆ search_system_folders

bool tesseract_common::PluginLoader::search_system_folders { true }

Indicate is system folders may be search if plugin is not found in any of the paths.


The documentation for this class was generated from the following files: