26 if ( not ignoreDuplicate ) {
29 _logger->log<DEBUG2>() <<
"Plugin '" << name <<
"' already registered. Skipping ..." << std::endl ;
34 fdata._factory = factoryFunction ;
36 _logger->log<DEBUG5>() <<
"New plugin registered: '" << name <<
"'" <<std::endl ;
72 for (
const auto &library : libraries ) {
81 std::map<std::string, std::vector<std::string>> pluginMap ;
82 _logger->log<MESSAGE>() <<
"------------------------------------" << std::endl ;
83 _logger->log<MESSAGE>() <<
" ** MarlinMT plugin manager dump ** " << std::endl ;
85 _logger->log<MESSAGE>() <<
" No plugin entry !" << std::endl ;
89 pluginMap[iter.second._libraryName].push_back( iter.first ) ;
91 for (
auto iter : pluginMap ) {
92 _logger->log<MESSAGE>() <<
"Library: " << iter.first << std::endl ;
93 for(
auto p : iter.second ) {
94 _logger->log<MESSAGE>() <<
" - " << p << std::endl ;
98 _logger->log<MESSAGE>() <<
"----------------------------------" << std::endl ;
110 auto libraryPath = std::filesystem::absolute(library) ;
111 auto libIter =
_libraries.find( libraryPath ) ;
112 auto libraryName = libraryPath.filename() ;
113 auto libraryStr = libraryPath.string() ;
114 _logger->log<MESSAGE>() <<
"Loading shared library : " << libraryStr << std::endl ;
116 MARLINMT_THROW(
"ERROR loading shared library '" + libraryStr +
"': duplicated library" ) ;
119 void* libPointer = ::dlopen(
_currentLibrary.c_str() , RTLD_LAZY | RTLD_GLOBAL) ;
121 if(
nullptr == libPointer ) {
122 MARLINMT_THROW(
"ERROR loading shared library '" + libraryStr +
"': " + std::string(dlerror()) ) ;
124 _libraries.insert( {libraryStr, libPointer} ) ;
Logger _logger
The plugin manager logger.
std::string _libraryName
The name of the library of the plugin.
static Logger createLogger(const std::string &name)
Create a standalone logger instance.
void doLoadLibrary(const std::string &library)
the workhorse !
void loadLibrary(const std::string &library)
Load a shared library to populate the list of plugins.
std::string _currentLibrary
The current library being loaded.
bool pluginRegistered(const std::string &name) const
Whether the plugin with of a given name is registered.
#define MARLINMT_THROW(message)
void loadLibraries(const std::vector< std::string > &libraries)
Load shared libraries to populate the list of plugins.
std::vector< std::string > pluginNames() const
Get all registered plugin name.
mutex_type _mutex
The synchronization mutex.
void dump() const
Dump plugin manager content in console.
Logger logger() const
Get the plugin manager logger.
PluginManager()
Constructor.
void registerPlugin(const std::string &name, bool ignoreDuplicate=false)
Register a new plugin to the manager.
PluginManager singleton class Responsible for loading shared libraries and collecting processor facto...
std::lock_guard< mutex_type > lock_type
LibraryList _libraries
The list of loaded libraries.
static PluginManager & instance()
Get the plugin manager instance.
PluginFactoryMap _pluginFactories
The map of plugin factories.
std::vector< K > keys(const std::map< K, V > &m)