1 #ifndef MARLINMT_PLUGINMANAGER_h 2 #define MARLINMT_PLUGINMANAGER_h 1 21 #define MARLINMT_DECLARE_PLUGIN( Base, Class ) MARLINMT_DECLARE_PLUGIN_NAME( Base, Class, #Class ) 23 #define MARLINMT_DECLARE_PLUGIN_NAME( Base, Class, NameStr ) \ 24 namespace marlinmt_plugins { \ 25 struct PluginDeclaration_##Class { \ 26 PluginDeclaration_##Class() { \ 27 marlinmt::PluginManager::instance().registerPlugin<Base, Class>( NameStr, false ) ; \ 30 static PluginDeclaration_##Class __instance_##Class ; \ 34 #define MARLINMT_DECLARE_PROCESSOR( Class ) namespace { \ 35 static const auto __processortype__ = Class().type() ; \ 36 MARLINMT_DECLARE_PLUGIN_NAME( marlinmt::Processor, Class, __processortype__ ) \ 40 #define MARLINMT_DECLARE_GEOMETRY( Class ) MARLINMT_DECLARE_PLUGIN( marlinmt::GeometryPlugin, Class ) 41 #define MARLINMT_DECLARE_GEOMETRY_NAME( Class, NameStr ) MARLINMT_DECLARE_PLUGIN_NAME( marlinmt::GeometryPlugin, Class, NameStr ) 44 #define MARLINMT_DECLARE_DATASOURCE( Class ) MARLINMT_DECLARE_PLUGIN( marlinmt::DataSourcePlugin, Class ) 45 #define MARLINMT_DECLARE_DATASOURCE_NAME( Class, NameStr ) MARLINMT_DECLARE_PLUGIN_NAME( marlinmt::DataSourcePlugin, Class, NameStr ) 48 #define MARLINMT_DECLARE_CONFIG_READER( Class ) MARLINMT_DECLARE_PLUGIN( marlinmt::ConfigReader, Class ) 49 #define MARLINMT_DECLARE_CONFIG_READER_NAME( Class, NameStr ) MARLINMT_DECLARE_PLUGIN_NAME( marlinmt::ConfigReader, Class, NameStr ) 52 #define MARLINMT_DECLARE_CONFIG_WRITER( Class ) MARLINMT_DECLARE_PLUGIN( marlinmt::ConfigWriter, Class ) 53 #define MARLINMT_DECLARE_CONFIG_WRITER_NAME( Class, NameStr ) MARLINMT_DECLARE_PLUGIN_NAME( marlinmt::ConfigWriter, Class, NameStr ) 115 template <
typename B,
typename T>
116 void registerPlugin(
const std::string &name,
bool ignoreDuplicate =
false ) ;
140 void loadLibraries(
const std::vector<std::string> &libraries ) ;
150 template <
typename Base>
168 template <
typename T>
169 std::unique_ptr<T>
create(
const std::string &name )
const ;
201 template <
typename B,
typename T>
204 return std::make_unique<T>() ;
206 std::any anyFactory = factoryFunction ;
212 template <
typename Base>
214 std::vector<std::string> names {} ;
218 names.push_back( p.first ) ;
220 catch(
const std::bad_any_cast& e) {
229 template <
typename T>
241 catch(
const std::bad_any_cast& e) {
std::function< std::unique_ptr< B >()> FactoryFunctionT
Logger _logger
The plugin manager logger.
std::string _libraryName
The name of the library of the plugin.
void doLoadLibrary(const std::string &library)
the workhorse !
std::recursive_mutex mutex_type
void loadLibrary(const std::string &library)
Load a shared library to populate the list of plugins.
FactoryFunction _factory
The plugin factory.
std::map< std::string, FactoryData > PluginFactoryMap
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.
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.
PluginManager & operator=(const PluginManager &)=delete
void dump() const
Dump plugin manager content in console.
Logger logger() const
Get the plugin manager logger.
std::shared_ptr< streamlog::logstreamT< mutex_type > > Logger
PluginManager()
Constructor.
std::unique_ptr< T > create(const std::string &name) const
Create a new plugin instance.
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::map< std::filesystem::path, void * > LibraryList