CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PluginManager.h
Go to the documentation of this file.
1 #ifndef FWCore_PluginManager_PluginManager_h
2 #define FWCore_PluginManager_PluginManager_h
3 // -*- C++ -*-
4 //
5 // Package: PluginManager
6 // Class : PluginManager
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Wed Apr 4 14:28:48 EDT 2007
19 //
20 
21 // system include files
22 #include <filesystem>
23 #include <map>
24 #include <memory>
25 #include <mutex>
26 #include <string>
27 #include <vector>
28 
29 #include "oneapi/tbb/concurrent_unordered_map.h"
30 
31 // user include files
35 
36 // forward declarations
37 namespace edmplugin {
38  class DummyFriend;
39  class PluginFactoryBase;
40 
42  size_t operator()(std::filesystem::path const& iPath) const { return std::hash<std::string>{}(iPath.native()); }
43  };
44 
45  class PluginManager {
46  friend class DummyFriend;
47 
48  public:
49  typedef std::vector<std::string> SearchPath;
50  typedef std::vector<PluginInfo> Infos;
51  typedef std::map<std::string, Infos> CategoryToInfos;
52 
53  class Config {
54  public:
55  Config() {}
56  Config& searchPath(const SearchPath& iPath) {
57  m_path = iPath;
58  return *this;
59  }
60  const SearchPath& searchPath() const { return m_path; }
61  void allowNoCache() { m_mustHaveCache = false; }
62 
63  bool mustHaveCache() const { return m_mustHaveCache; }
64 
65  private:
67  bool m_mustHaveCache = true;
68  };
69 
70  PluginManager(const PluginManager&) = delete; // stop default
71  const PluginManager& operator=(const PluginManager&) = delete; // stop default
73 
74  // ---------- const member functions ---------------------
75  const SharedLibrary& load(const std::string& iCategory, const std::string& iPlugin);
76 
77  const std::filesystem::path& loadableFor(const std::string& iCategory, const std::string& iPlugin);
78 
83 
84  //If can not find iPlugin in category iCategory return null pointer, any other failure will cause a throw
85  const SharedLibrary* tryToLoad(const std::string& iCategory, const std::string& iPlugin);
86 
87  // ---------- static member functions --------------------
89  static const std::string& loadingFile() { return loadingLibraryNamed_(); }
90 
93 
94  static PluginManager* get();
95  static PluginManager& configure(const Config&);
96 
97  static bool isAvailable();
98 
99  // ---------- member functions ---------------------------
103 
104  private:
105  PluginManager(const Config&);
106 
107  void newFactory(const PluginFactoryBase*);
109  static PluginManager*& singleton();
110 
111  std::recursive_mutex& pluginLoadMutex() { return pluginLoadMutex_; }
112 
113  const std::filesystem::path& loadableFor_(const std::string& iCategory,
114  const std::string& iPlugin,
115  bool& ioThrowIfFailElseSucceedStatus);
116  // ---------- member data --------------------------------
118  oneapi::tbb::concurrent_unordered_map<std::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher>
120 
122  std::recursive_mutex pluginLoadMutex_;
123  };
124 
125 } // namespace edmplugin
126 #endif
CategoryToInfos categoryToInfos_
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
static PluginManager & configure(const Config &)
edm::signalslot::Signal< void(const std::filesystem::path &)> goingToLoad_
static PluginManager *& singleton()
std::map< std::string, Infos > CategoryToInfos
Definition: PluginManager.h:51
oneapi::tbb::concurrent_unordered_map< std::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked ...
const SearchPath & searchPath() const
Definition: PluginManager.h:60
const std::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
size_t operator()(std::filesystem::path const &iPath) const
Definition: PluginManager.h:42
const PluginManager & operator=(const PluginManager &)=delete
PluginManager(const PluginManager &)=delete
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:89
std::vector< std::string > SearchPath
Definition: PluginManager.h:49
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
std::recursive_mutex & pluginLoadMutex()
const std::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Config & searchPath(const SearchPath &iPath)
Definition: PluginManager.h:56
static std::string & loadingLibraryNamed_()
std::vector< PluginInfo > Infos
Definition: PluginManager.h:50
void newFactory(const PluginFactoryBase *)
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
std::recursive_mutex pluginLoadMutex_
tuple Config
Definition: helper.py:10