CMS 3D CMS Logo

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 "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  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
edmplugin::PluginManager::Config::Config
Config()
Definition: PluginManager.h:55
edmplugin
Definition: AlignmentAlgorithmPluginFactory.cc:9
edmplugin::PluginManager::searchPath_
SearchPath searchPath_
Definition: PluginManager.h:117
edmplugin::PluginManager::DummyFriend
friend class DummyFriend
Definition: PluginManager.h:46
edmplugin::PluginManager::SearchPath
std::vector< std::string > SearchPath
Definition: PluginManager.h:49
edmplugin::PluginManager::load
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:226
SharedLibrary.h
edmplugin::PluginManager::Config::searchPath
const SearchPath & searchPath() const
Definition: PluginManager.h:60
edmplugin::PluginManager::loadables_
tbb::concurrent_unordered_map< std::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
Definition: PluginManager.h:119
edmplugin::PluginManager::Config::mustHaveCache
bool mustHaveCache() const
Definition: PluginManager.h:63
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:306
edmplugin::PluginManager::categoryToInfos
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
edmplugin::PluginManager
Definition: PluginManager.h:45
edmplugin::PluginManagerPathHasher::operator()
size_t operator()(std::filesystem::path const &iPath) const
Definition: PluginManager.h:42
edmplugin::PluginManager::pluginLoadMutex
std::recursive_mutex & pluginLoadMutex()
Definition: PluginManager.h:111
edmplugin::PluginManager::goingToLoad_
edm::signalslot::Signal< void(const std::filesystem::path &)> goingToLoad_
Definition: PluginManager.h:100
edmplugin::PluginManager::loadableFor
const std::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:150
edmplugin::PluginManager::CategoryToInfos
std::map< std::string, Infos > CategoryToInfos
Definition: PluginManager.h:51
PluginInfo.h
edmplugin::PluginManager::Config::allowNoCache
void allowNoCache()
Definition: PluginManager.h:61
edmplugin::PluginManager::Config::m_mustHaveCache
bool m_mustHaveCache
Definition: PluginManager.h:67
edmplugin::PluginManagerPathHasher
Definition: PluginManager.h:41
edmplugin::PluginManager::~PluginManager
~PluginManager()
Definition: PluginManager.cc:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::PluginManager::singleton
static PluginManager *& singleton()
Definition: PluginManager.cc:341
edmplugin::PluginManager::Infos
std::vector< PluginInfo > Infos
Definition: PluginManager.h:50
edmplugin::PluginManager::pluginLoadMutex_
std::recursive_mutex pluginLoadMutex_
Definition: PluginManager.h:122
edmplugin::PluginManager::operator=
const PluginManager & operator=(const PluginManager &)=delete
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:315
edmplugin::PluginManager::PluginManager
PluginManager(const PluginManager &)=delete
edmplugin::PluginManager::Config::m_path
SearchPath m_path
Definition: PluginManager.h:66
edmplugin::PluginManager::loadingLibraryNamed_
static std::string & loadingLibraryNamed_()
Definition: PluginManager.cc:334
Signal.h
edmplugin::PluginFactoryBase
Definition: PluginFactoryBase.h:37
edmplugin::PluginManager::newFactory
void newFactory(const PluginFactoryBase *)
Definition: PluginManager.cc:140
edmplugin::PluginManager::Config::searchPath
Config & searchPath(const SearchPath &iPath)
Definition: PluginManager.h:56
edmplugin::PluginManager::askedToLoadCategoryWithPlugin_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
Definition: PluginManager.h:102
edmplugin::PluginManager::loadableFor_
const std::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
Definition: PluginManager.cc:155
edmplugin::PluginManager::categoryToInfos_
CategoryToInfos categoryToInfos_
Definition: PluginManager.h:121
PluginFactoryBase
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
edmplugin::PluginManager::staticallyLinkedLoadingFileName
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked
Definition: PluginManager.cc:329
Config
Definition: Config.py:1
edm::signalslot::Signal
Definition: DelayedReader.h:26
edmplugin::SharedLibrary
Definition: SharedLibrary.h:29
edmplugin::PluginManager::loadingFile
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:89
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:346
edmplugin::PluginManager::tryToLoad
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:262
edmplugin::PluginManager::justLoaded_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
Definition: PluginManager.h:101