26#ifndef TESSERACT_COMMON_PLUGIN_LOADER_HPP 
   27#define TESSERACT_COMMON_PLUGIN_LOADER_HPP 
   31#include <boost/algorithm/string.hpp> 
   32#include <console_bridge/console.h> 
   43  std::set<std::string> list;
 
   44  char* 
env_var = std::getenv(env_variable.c_str());
 
   48  std::string evn_str = std::string(
env_var);
 
   50  boost::split(list, evn_str, boost::is_any_of(
":"), boost::token_compress_on);
 
   52  boost::split(list, evn_str, boost::is_any_of(
";"), boost::token_compress_on);
 
   58                                               const std::set<std::string>& existing_search_paths)
 
   61  if (!search_paths_env.empty())
 
   64    search_paths.insert(existing_search_paths.begin(), existing_search_paths.end());
 
   68  return existing_search_paths;
 
   72                                                   const std::set<std::string>& existing_search_libraries)
 
   75  if (!search_libraries_env.empty())
 
   78    search_libraries.insert(existing_search_libraries.begin(), existing_search_libraries.end());
 
   82  return existing_search_libraries;
 
   92  std::set<std::string> libraries_with_fullpath;
 
   93  for (
auto it = library_names.begin(); 
it != library_names.end();)
 
   95    if (boost::filesystem::exists(*
it) && boost::filesystem::path(*it).is_absolute())
 
   97      libraries_with_fullpath.insert(*
it);
 
   98      it = library_names.erase(
it);
 
  106  return libraries_with_fullpath;
 
  109template <
class PluginBase>
 
  114  if (library_names.empty())
 
  116    CONSOLE_BRIDGE_logError(
"No plugin libraries were provided!");
 
  121  for (
const auto& library_fullpath : libraries_with_fullpath)
 
  124      return ClassLoader::createSharedInstance<PluginBase>(plugin_name, library_fullpath);
 
  129  for (
const auto& 
path : search_paths_local)
 
  134        return ClassLoader::createSharedInstance<PluginBase>(plugin_name, library, 
path);
 
  144        return ClassLoader::createSharedInstance<PluginBase>(plugin_name, library);
 
  148  std::stringstream msg;
 
  150    msg << std::endl << 
"Search Paths (Search System Folders: True):" << std::endl;
 
  152    msg << std::endl << 
"Search Paths (Search System Folders: False):" << std::endl;
 
  154  for (
const auto& 
path : search_paths_local)
 
  155    msg << 
"    - " + 
path << std::endl;
 
  157  msg << 
"Search Libraries:" << std::endl;
 
  161  CONSOLE_BRIDGE_logError(
"Failed to instantiate plugin '%s', Details: %s", plugin_name.c_str(), msg.str().c_str());
 
  170  if (library_names.empty())
 
  172    CONSOLE_BRIDGE_logError(
"No plugin libraries were provided!");
 
  178  for (
const auto& library_fullpath : libraries_with_fullpath)
 
  186  for (
const auto& 
path : search_paths_local)
 
  208template <
class PluginBase>
 
  216  std::vector<std::string> 
plugins;
 
  220  if (library_names.empty())
 
  222    CONSOLE_BRIDGE_logError(
"No plugin libraries were provided!");
 
  228  for (
const auto& library_fullpath : libraries_with_fullpath)
 
  231    plugins.insert(
plugins.end(), lib_plugins.begin(), lib_plugins.end());
 
  236  for (
const auto& 
path : search_paths_local)
 
  241      plugins.insert(
plugins.end(), lib_plugins.begin(), lib_plugins.end());
 
  254  if (library_names.empty())
 
  256    CONSOLE_BRIDGE_logError(
"No plugin libraries were provided!");
 
  262  for (
const auto& library_fullpath : libraries_with_fullpath)
 
  270  for (
const auto& 
path : search_paths_local)
 
  289  std::string env_var_str;
 
  296  boost::filesystem::path lib_path = boost::filesystem::canonical(boost::dll::symbol_location_ptr(symbol_ptr));
 
  298  if (env_var_str.empty())
 
  300    env_var_str = lib_path.string();
 
  305    env_var_str = env_var_str + 
":" + lib_path.string();
 
  307    env_var_str = env_var_str + 
";" + lib_path.string();
 
Class Loader to be used throughout Tesseract for loading plugins.
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.
Definition: plugin_loader.hpp:287
std::set< std::string > search_paths
A list of paths to search for plugins.
Definition: plugin_loader.h:63
std::string search_paths_env
The environment variable containing plugin search paths.
Definition: plugin_loader.h:69
std::shared_ptr< PluginBase > instantiate(const std::string &plugin_name) const
Instantiate a plugin with the provided name.
Definition: plugin_loader.hpp:110
std::vector< std::string > getAvailableSections(bool include_hidden=false) const
Get the available sections within the provided search libraries.
Definition: plugin_loader.hpp:248
int count() const
The number of plugins stored. The size of plugins variable.
Definition: plugin_loader.hpp:282
std::set< std::string > search_libraries
A list of library names without the prefix or suffix that contain plugins.
Definition: plugin_loader.h:66
bool isPluginAvailable(const std::string &plugin_name) const
Check if plugin is available.
Definition: plugin_loader.hpp:166
std::vector< std::string > getAvailablePlugins() const
Get the available plugins for the provided PluginBase type.
Definition: plugin_loader.hpp:209
std::string search_libraries_env
The environment variable containing plugins.
Definition: plugin_loader.h:77
bool search_system_folders
Indicate is system folders may be search if plugin is not found in any of the paths.
Definition: plugin_loader.h:60
auto it
Definition: collision_core_unit.cpp:208
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: allowed_collision_matrix.h:16
std::set< std::string > getAllSearchPaths(const std::string &search_paths_env, const std::set< std::string > &existing_search_paths)
Definition: plugin_loader.hpp:57
std::set< std::string > getAllSearchLibraries(const std::string &search_libraries_env, const std::set< std::string > &existing_search_libraries)
Definition: plugin_loader.hpp:71
std::set< std::string > extractLibrariesWithFullPath(std::set< std::string > &library_names)
This will remove libraries with full path in the provided library_names and return them.
Definition: plugin_loader.hpp:90
std::set< std::string > parseEnvironmentVariableList(const std::string &env_variable)
Definition: plugin_loader.hpp:41
Plugin Loader to be used throughout Tesseract for loading plugins.
sections
Definition: plugin_loader_unit.cpp:65
std::string env_var
Definition: resource_locator_unit.cpp:95
static bool isClassAvailable(const std::string &symbol_name, const std::string &library_name, const std::string &library_directory="")
Check if the symbol is available in the library_name searching system folders for library.
Definition: class_loader.hpp:82
static std::vector< std::string > getAvailableSections(const std::string &library_name, const std::string &library_directory="", bool include_hidden=false)
Get a list of available sections.
Definition: class_loader.hpp:148
static std::vector< std::string > getAvailableSymbols(const std::string §ion, const std::string &library_name, const std::string &library_directory="")
Get a list of available symbols under the provided section.
Definition: class_loader.hpp:113
static std::string decorate(const std::string &library_name, const std::string &library_directory="")
Give library name without prefix and suffix it will return the library name with the prefix and suffi...
Definition: class_loader.hpp:196
object discrete_plugin_infos plugins["plugin_key"]
Definition: tesseract_common_serialization_unit.cpp:148
tesseract_common::fs::path path
Definition: tesseract_srdf_unit.cpp:1992