Orocos Real-Time Toolkit  2.9.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
RTT::plugin::PluginLoader Class Reference

Loads plugins found on the filesystem and keeps track of found plugins, typekits and services. More...

#include <rtt/plugin/PluginLoader.hpp>

Public Types

typedef boost::shared_ptr< PluginLoadershared_ptr
 

Public Member Functions

 PluginLoader ()
 
 ~PluginLoader ()
 
bool loadLibrary (std::string const &path)
 Loads a library as plugin or typekit. More...
 
bool loadTypekits (std::string const &path_list)
 Load any typekit found in the 'types/' subdirectory of each path in path_list in the process. More...
 
bool loadTypekit (std::string const &name, std::string const &path_list)
 Load a typekit found in the 'types/' subdirectory of a package present in path_list. More...
 
bool loadPlugins (std::string const &path_list)
 Loads any plugin found in the 'plugins/' subdirectory of each path in path_list in the current process. More...
 
bool isLoaded (std::string name)
 Checks if a given plugin or filename has been loaded. More...
 
bool loadPlugin (std::string const &name, std::string const &path_list)
 Loads a plugin found in the 'plugins/' subdirectory of each path in path_list in the current process. More...
 
bool loadService (std::string const &servicename, TaskContext *tc)
 Loads an earlier discovered service into a TaskContext. More...
 
std::vector< std::string > listServices () const
 Lists all services discovered by the PluginLoader. More...
 
std::vector< std::string > listPlugins () const
 Lists all plugins (= services + typekits) discovered by the PluginLoader. More...
 
std::vector< std::string > listTypekits () const
 Lists all typekits discovered by the PluginLoader. More...
 
std::string getPluginPath () const
 Returns the current plugin path list. More...
 
void setPluginPath (std::string const &newpath)
 Sets the plugin path list. More...
 

Static Public Member Functions

static boost::shared_ptr< PluginLoaderInstance ()
 Create the instance of the PluginLoader. More...
 
static void Release ()
 Release the PluginLoader, erasing all knowledge of loaded libraries. More...
 

Detailed Description

Loads plugins found on the filesystem and keeps track of found plugins, typekits and services.

It has no facilities of unloading plugins. Plugins remain in memory until the process terminates.

Plugin Paths

The PluginLoader reads the RTT_COMPONENT_PATH variable when the application starts and stores it using setPluginPath(). Paths are scanned in this order:

** First the paths specified by the function argument path_list if the function takes such argument ** Second the paths specified using the setPluginPath() function.

If neither is specified, it looks for plugins in the current directory (".").

See also
Plugin.hpp

Definition at line 68 of file PluginLoader.hpp.

Member Typedef Documentation

Definition at line 157 of file PluginLoader.hpp.

Constructor & Destructor Documentation

PluginLoader::PluginLoader ( )

Definition at line 312 of file PluginLoader.cpp.

PluginLoader::~PluginLoader ( )

Definition at line 313 of file PluginLoader.cpp.

Member Function Documentation

std::string PluginLoader::getPluginPath ( ) const

Returns the current plugin path list.

Defaults to the value of RTT_COMPONENT_PATH, when the RTT was started for the current process.

Returns
A colon separated list of paths or the empty string if not set.

Definition at line 779 of file PluginLoader.cpp.

boost::shared_ptr< PluginLoader > PluginLoader::Instance ( )
static

Create the instance of the PluginLoader.

It will keep track of the loaded libraries for this process.

Returns
A singleton.

Definition at line 316 of file PluginLoader.cpp.

Referenced by RTT::TaskContext::connectServices(), RTT::ComponentLoader::import(), RTT::TaskContext::loadService(), RTT::internal::GlobalService::require(), and RTT_corba_COperationInterface_i::sendOperationOneway().

bool PluginLoader::isLoaded ( std::string  name)

Checks if a given plugin or filename has been loaded.

This function accepts full filenames ('libthe_plugin.so.1.99.0'), short names ('the_plugin') or the name provided by the plugin ('The Plugin').

Parameters
namename of a file or the plugin name.
Returns
true if so.

Definition at line 622 of file PluginLoader.cpp.

References RTT::Debug, dlclose(), dlerror(), dlopen(), dlsym(), RTT::Error, RTT::Info, OROCOS_TARGET_NAME, RTLD_GLOBAL, and RTLD_NOW.

std::vector< std::string > PluginLoader::listPlugins ( ) const

Lists all plugins (= services + typekits) discovered by the PluginLoader.

Returns
A list of plugin names

Definition at line 760 of file PluginLoader.cpp.

std::vector< std::string > PluginLoader::listServices ( ) const

Lists all services discovered by the PluginLoader.

Returns
A list of service names

Definition at line 750 of file PluginLoader.cpp.

std::vector< std::string > PluginLoader::listTypekits ( ) const

Lists all typekits discovered by the PluginLoader.

Returns
A list of typekit names

Definition at line 769 of file PluginLoader.cpp.

bool PluginLoader::loadLibrary ( std::string const &  path)

Loads a library as plugin or typekit.

Parameters
pathan absolute or relative path to a library. Relative paths are interpreted with regard to the plugin path.

Definition at line 463 of file PluginLoader.cpp.

References RTT::Debug, RTT::Error, RTT::Info, OROCOS_TARGET_NAME, and RTT::Warning.

bool PluginLoader::loadPlugin ( std::string const &  name,
std::string const &  path_list 
)

Loads a plugin found in the 'plugins/' subdirectory of each path in path_list in the current process.

Parameters
nameThe name of the plugin to load, must match the library name (without lib/dll/so pre-/suffixes).
path_listA colon or semi-colon seperated list of paths to look for plugins. May be the empty string.
Exceptions
std::runtime_exceptionif the found plugin refused to load.

Definition at line 337 of file PluginLoader.cpp.

bool PluginLoader::loadPlugins ( std::string const &  path_list)

Loads any plugin found in the 'plugins/' subdirectory of each path in path_list in the current process.

Returns
false if some typekit caused an error, or some path was not found.
Parameters
path_listA colon or semi-colon seperated list of paths to look for plugins. May be the empty string.
Exceptions
std::runtime_exceptionif one of the found plugin refused to load.

Definition at line 342 of file PluginLoader.cpp.

bool PluginLoader::loadService ( std::string const &  servicename,
TaskContext tc 
)

Loads an earlier discovered service into a TaskContext.

Parameters
servicenameThe name of the service or plugin containing the service
tcThe TaskContext to load into.
Returns
false if the service or plugin refused to load into the TaskContext.

Definition at line 347 of file PluginLoader.cpp.

References RTT::Debug, RTT::Error, RTT::TaskContext::getName(), RTT::Info, RTT::internal::GlobalService::Instance(), isLoadableLibrary(), and RTT::Warning.

bool PluginLoader::loadTypekit ( std::string const &  name,
std::string const &  path_list 
)

Load a typekit found in the 'types/' subdirectory of a package present in path_list.

Parameters
nameThe name of the package (a directory name) which contains the typekit you wish to load.
path_listA colon or semi-colon seperated list of paths to look for the name subdirectory. If this list is empty, the current plugin path is searched and the current working directory.
Exceptions
std::runtime_exceptionif the found typekit refused to load.

Definition at line 332 of file PluginLoader.cpp.

bool PluginLoader::loadTypekits ( std::string const &  path_list)

Load any typekit found in the 'types/' subdirectory of each path in path_list in the process.

This is not a 'smart' function. It will only look into that directory and will not try to guess a target specific subdir or any other means for locating typekits.

Returns
false if some typekit caused an error, or some path was not found or if path_list was empty.
Parameters
path_listA colon or semi-colon seperated list of paths to look for typekits. No other paths will be searched.
Exceptions
std::runtime_exceptionif one of the found typekits refused to load.

Definition at line 327 of file PluginLoader.cpp.

void PluginLoader::Release ( )
static

Release the PluginLoader, erasing all knowledge of loaded libraries.

No libraries will be unloaded from the process.

Definition at line 323 of file PluginLoader.cpp.

void PluginLoader::setPluginPath ( std::string const &  newpath)

Sets the plugin path list.

This is typically done by RTT startup code with the contents of the RTT_COMPONENT_PATH variable.

Parameters
newpathThe new paths to look for plugins.

Definition at line 784 of file PluginLoader.cpp.


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