SOFA API  ca665544
Open source framework for multi-physics simuation
sofa::helper::system::PluginManager Class Reference

#include <PluginManager.h>

Static Public Attributes

static std::string s_gui_postfix = "gui"
 the postfix to gui plugin, default="gui" (e.g. myplugin_gui.so) More...
 

Public Member Functions

PluginLoadStatus loadPlugin (const std::string &plugin, const std::string &suffix=getDefaultSuffix(), bool ignoreCase=true, bool recursive=true, std::ostream *errlog=nullptr)
 
PluginLoadStatus loadPluginByPath (const std::string &path, std::ostream *errlog=nullptr)
 
PluginLoadStatus loadPluginByName (const std::string &pluginName, const std::string &suffix=getDefaultSuffix(), bool ignoreCase=true, bool recursive=true, std::ostream *errlog=nullptr)
 
bool unloadPlugin (const std::string &path, std::ostream *errlog=nullptr)
 
PluginLoadStatus registerPlugin (const std::string &plugin, const std::string &suffix=getDefaultSuffix(), bool ignoreCase=true, bool recursive=true, std::ostream *errlog=nullptr)
 Register a plugin. Merely an alias for loadPlugin() More...
 
const std::unordered_set< std::string > & unloadedPlugins () const
 
bool isPluginUnloaded (const std::string &pluginName) const
 
void init ()
 
void init (const std::string &pluginPath)
 
void cleanup ()
 
std::string findPlugin (const std::string &pluginName, const std::string &suffix=getDefaultSuffix(), bool ignoreCase=true, bool recursive=true, int maxRecursiveDepth=3)
 
bool pluginIsLoaded (const std::string &plugin)
 
std::pair< std::string, boolisPluginLoaded (const std::string &plugin)
 
bool checkDuplicatedPlugin (const Plugin &plugin, const std::string &pluginPath)
 
PluginMapgetPluginMap ()
 
PlugingetPlugin (const std::string &plugin, const std::string &=getDefaultSuffix(), bool=true)
 
PlugingetPluginByName (const std::string &pluginName)
 
template<typename Entry >
bool getEntryFromPlugin (const Plugin *plugin, Entry &entry)
 
void readFromIniFile (const std::string &path)
 
void readFromIniFile (const std::string &path, type::vector< std::string > &listLoadedPlugins)
 
void writeToIniFile (const std::string &path)
 
void addOnPluginLoadedCallback (const std::string &key, std::function< void(const std::string &, const Plugin &)> callback)
 
void addOnPluginCleanupCallbacks (const std::string &key, std::function< void()> callback)
 
void removeOnPluginLoadedCallback (const std::string &key)
 
void removeOnPluginCleanupCallbacks (const std::string &key)
 

Static Public Member Functions

static PluginManagergetInstance ()
 
static std::string getDefaultSuffix ()
 
static std::string GetPluginNameFromPath (const std::string &pluginPath)
 

Friends

std::ostream & operator<< (std::ostream &os, const PluginManager &pluginManager)
 
std::istream & operator>> (std::istream &in, PluginManager &pluginManager)
 

Attribute details

◆ s_gui_postfix

std::string sofa::helper::system::PluginManager::s_gui_postfix = "gui"
static

the postfix to gui plugin, default="gui" (e.g. myplugin_gui.so)

Function details

◆ addOnPluginCleanupCallbacks()

void sofa::helper::system::PluginManager::addOnPluginCleanupCallbacks ( const std::string &  key,
std::function< void()>  callback 
)

◆ addOnPluginLoadedCallback()

void sofa::helper::system::PluginManager::addOnPluginLoadedCallback ( const std::string &  key,
std::function< void(const std::string &, const Plugin &)>  callback 
)

◆ checkDuplicatedPlugin()

bool sofa::helper::system::PluginManager::checkDuplicatedPlugin ( const Plugin plugin,
const std::string &  pluginPath 
)

◆ cleanup()

void sofa::helper::system::PluginManager::cleanup ( )

◆ findPlugin()

std::string sofa::helper::system::PluginManager::findPlugin ( const std::string &  pluginName,
const std::string &  suffix = getDefaultSuffix(),
bool  ignoreCase = true,
bool  recursive = true,
int  maxRecursiveDepth = 3 
)

◆ getDefaultSuffix()

std::string sofa::helper::system::PluginManager::getDefaultSuffix ( )
static

Get the default suffix applied to plugin names to find the actual lib to load Returns "_d" in debug configuration and an empty string otherwise

Get the default suffix applied to plugin names to find the actual lib to load (depends on platform, version, debug/release build)

◆ getEntryFromPlugin()

template<typename Entry >
bool sofa::helper::system::PluginManager::getEntryFromPlugin ( const Plugin plugin,
Entry &  entry 
)
inline

◆ getInstance()

PluginManager & sofa::helper::system::PluginManager::getInstance ( )
static

◆ getPlugin()

Plugin * sofa::helper::system::PluginManager::getPlugin ( const std::string &  plugin,
const std::string &  = getDefaultSuffix(),
bool  = true 
)

◆ getPluginByName()

Plugin * sofa::helper::system::PluginManager::getPluginByName ( const std::string &  pluginName)

◆ getPluginMap()

PluginMap& sofa::helper::system::PluginManager::getPluginMap ( )
inline

◆ GetPluginNameFromPath()

std::string sofa::helper::system::PluginManager::GetPluginNameFromPath ( const std::string &  pluginPath)
static

◆ init() [1/2]

void sofa::helper::system::PluginManager::init ( void  )

◆ init() [2/2]

void sofa::helper::system::PluginManager::init ( const std::string &  pluginPath)

◆ isPluginLoaded()

std::pair< std::string, bool > sofa::helper::system::PluginManager::isPluginLoaded ( const std::string &  plugin)

Determine if a plugin name or plugin path is known from the plugin manager (i.e. has been loaded by the plugin manager) with the found path.

Parameters
pluginA path to a plugin or a plugin name
Returns
A pair consisting of the found plugin path (or the plugin path that was last tried) and a bool value set to true if the plugin has been found in the plugin registration map

◆ isPluginUnloaded()

bool sofa::helper::system::PluginManager::isPluginUnloaded ( const std::string &  pluginName) const

◆ loadPlugin()

auto sofa::helper::system::PluginManager::loadPlugin ( const std::string &  plugin,
const std::string &  suffix = getDefaultSuffix(),
bool  ignoreCase = true,
bool  recursive = true,
std::ostream *  errlog = nullptr 
)

Loads a plugin library in process memory and register into the map

  • if already registered into the map (and therefore loaded in memory), do nothing.
  • If not registered but loaded in memory, call entrypoints and register into the map
  • If not registered and not loaded in memory, it will load the plugin in memory, call entrypoints and register into the map
    Parameters
    pluginCan be just the filename of the library to load (without extension) or the full path
    suffixAn optional suffix to apply to the filename. Defaults to "_d" with debug builds and is empty otherwise.
    ignoreCaseSpecify if the plugin search should be case-insensitive (activated by default). Not used if the plugin string passed as a parameter is a full path
    errlogAn optional stream for error logging.

◆ loadPluginByName()

auto sofa::helper::system::PluginManager::loadPluginByName ( const std::string &  pluginName,
const std::string &  suffix = getDefaultSuffix(),
bool  ignoreCase = true,
bool  recursive = true,
std::ostream *  errlog = nullptr 
)

Loads a plugin library in process memory.

Parameters
pluginNameThe filename without extension of the plugin to load
suffixAn optional suffix to apply to the filename. Defaults to "_d" with debug builds, empty otherwise.
ignoreCaseSpecify if the plugin search should be case-insensitive (activated by default). Not used if the plugin string passed as a parameter is a full path
errlogAn optional stream for error logging.

◆ loadPluginByPath()

PluginManager::PluginLoadStatus sofa::helper::system::PluginManager::loadPluginByPath ( const std::string &  path,
std::ostream *  errlog = nullptr 
)

Loads a plugin library in process memory.

Parameters
pathThe full path of the plugin to load
errlogAn optional stream for error logging.

◆ pluginIsLoaded()

bool sofa::helper::system::PluginManager::pluginIsLoaded ( const std::string &  plugin)

◆ readFromIniFile() [1/2]

void sofa::helper::system::PluginManager::readFromIniFile ( const std::string &  path)

◆ readFromIniFile() [2/2]

void sofa::helper::system::PluginManager::readFromIniFile ( const std::string &  path,
type::vector< std::string > &  listLoadedPlugins 
)

◆ registerPlugin()

auto sofa::helper::system::PluginManager::registerPlugin ( const std::string &  plugin,
const std::string &  suffix = getDefaultSuffix(),
bool  ignoreCase = true,
bool  recursive = true,
std::ostream *  errlog = nullptr 
)

Register a plugin. Merely an alias for loadPlugin()

◆ removeOnPluginCleanupCallbacks()

void sofa::helper::system::PluginManager::removeOnPluginCleanupCallbacks ( const std::string &  key)

◆ removeOnPluginLoadedCallback()

void sofa::helper::system::PluginManager::removeOnPluginLoadedCallback ( const std::string &  key)

◆ unloadedPlugins()

const std::unordered_set< std::string > & sofa::helper::system::PluginManager::unloadedPlugins ( ) const

◆ unloadPlugin()

bool sofa::helper::system::PluginManager::unloadPlugin ( const std::string &  path,
std::ostream *  errlog = nullptr 
)

Unloads a plugin from the map Warning: a previously loaded plugin will always be in process memory.

◆ writeToIniFile()

void sofa::helper::system::PluginManager::writeToIniFile ( const std::string &  path)

Enum details

◆ PluginLoadStatus

Enumerator
SUCCESS 
ALREADY_LOADED 
PLUGIN_FILE_NOT_FOUND 
INVALID_LOADING 
MISSING_SYMBOL 
INIT_ERROR 

Related details

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const PluginManager pluginManager 
)
friend

◆ operator>>

std::istream& operator>> ( std::istream &  in,
PluginManager pluginManager 
)
friend