SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PluginManager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2019-2022 Université de Genève, LMU Munich - Faculty of Physics, IAP-CNRS/Sorbonne Université
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 /*
19  * PluginManager.h
20  *
21  * Created on: Jul 27, 2016
22  * Author: mschefer
23  */
24 
25 #ifndef _SEFRAMEWORK_PLUGIN_PLUGINMANAGER_H_
26 #define _SEFRAMEWORK_PLUGIN_PLUGINMANAGER_H_
27 
28 #include <boost/version.hpp>
29 #define USE_BOOST_DLL BOOST_VERSION >= 105500
30 
31 #if USE_BOOST_DLL
32 #include <boost/dll/shared_library.hpp>
33 #endif
34 #include <boost/filesystem/path.hpp>
35 
36 #include <memory>
37 #include <vector>
38 
42 
43 namespace SourceXtractor {
44 
45 class Plugin;
46 
54 class PluginManager : public PluginAPI {
55 public:
56 
57  ~PluginManager() override = default;
58 
60  std::shared_ptr<OutputRegistry> output_registry,
61  std::string plugin_path,
62  std::vector<std::string> plugin_list) :
63  m_plugin_path(plugin_path),
64  m_plugin_list(std::move(plugin_list)),
65  m_task_factory_registry(std::move(task_factory_registry)),
66  m_output_registry(std::move(output_registry)) {}
67 
69  void loadPlugins();
70 
71  // PluginAPI implementation
74  }
75 
76  OutputRegistry& getOutputRegistry() const override {
77  return *m_output_registry;
78  }
79 
81  template<typename T>
82  static void registerStaticPlugin() {
83  s_static_plugins.emplace_back(new T);
84  }
85 
86 private:
87  boost::filesystem::path m_plugin_path;
89 
92 
93 #if USE_BOOST_DLL
94  static std::vector<boost::dll::shared_library> s_loaded_plugins;
103 #endif
105 };
106 
107 }
108 
109 #endif /* _SEFRAMEWORK_PLUGIN_PLUGINMANAGER_H_ */
void loadPlugins()
loads all the available plugins. Both those linked at compile-time and those loaded at run-time ...
std::shared_ptr< OutputRegistry > m_output_registry
Definition: PluginManager.h:91
std::shared_ptr< TaskFactoryRegistry > m_task_factory_registry
Definition: PluginManager.h:90
PluginManager(std::shared_ptr< TaskFactoryRegistry > task_factory_registry, std::shared_ptr< OutputRegistry > output_registry, std::string plugin_path, std::vector< std::string > plugin_list)
Definition: PluginManager.h:59
~PluginManager() override=default
std::vector< std::string > m_plugin_list
Definition: PluginManager.h:88
STL class.
boost::filesystem::path m_plugin_path
Definition: PluginManager.h:87
TaskFactoryRegistry & getTaskFactoryRegistry() const override
Definition: PluginManager.h:72
This interface is given to the plugin to let it access object instances from the framework.
Definition: PluginAPI.h:40
T move(T...args)
static void registerStaticPlugin()
registers a plugin, this is used to register plugins linked at compile-time
Definition: PluginManager.h:82
OutputRegistry & getOutputRegistry() const override
Definition: PluginManager.h:76
static std::vector< std::unique_ptr< Plugin > > s_static_plugins
PluginManager handles the loading of plugins and calls their registration function, providing them with with a PluginAPI implementation.
Definition: PluginManager.h:54