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 <vector>
23 #include <map>
24 #include <string>
25 #include <mutex>
26 
27 #include <boost/filesystem/path.hpp>
28 #include <memory>
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()(boost::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 
71 
72  // ---------- const member functions ---------------------
73  const SharedLibrary& load(const std::string& iCategory, const std::string& iPlugin);
74 
75  const boost::filesystem::path& loadableFor(const std::string& iCategory, const std::string& iPlugin);
76 
81 
82  //If can not find iPlugin in category iCategory return null pointer, any other failure will cause a throw
83  const SharedLibrary* tryToLoad(const std::string& iCategory, const std::string& iPlugin);
84 
85  // ---------- static member functions --------------------
87  static const std::string& loadingFile() { return loadingLibraryNamed_(); }
88 
91 
92  static PluginManager* get();
93  static PluginManager& configure(const Config&);
94 
95  static bool isAvailable();
96 
97  // ---------- member functions ---------------------------
101 
102  private:
103  PluginManager(const Config&);
104  PluginManager(const PluginManager&) = delete; // stop default
105 
106  const PluginManager& operator=(const PluginManager&) = delete; // stop default
107 
108  void newFactory(const PluginFactoryBase*);
110  static PluginManager*& singleton();
111 
112  std::recursive_mutex& pluginLoadMutex() { return pluginLoadMutex_; }
113 
114  const boost::filesystem::path& loadableFor_(const std::string& iCategory,
115  const std::string& iPlugin,
116  bool& ioThrowIfFailElseSucceedStatus);
117  // ---------- member data --------------------------------
119  tbb::concurrent_unordered_map<boost::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher>
121 
123  std::recursive_mutex pluginLoadMutex_;
124  };
125 
126 } // namespace edmplugin
127 #endif
edmplugin::PluginManager::Config::Config
Config()
Definition: PluginManager.h:55
edmplugin
Definition: AlignmentAlgorithmPluginFactory.cc:9
edmplugin::PluginManager::searchPath_
SearchPath searchPath_
Definition: PluginManager.h:118
edmplugin::PluginManager::loadables_
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
Definition: PluginManager.h:120
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:227
SharedLibrary.h
edmplugin::PluginManager::Config::searchPath
const SearchPath & searchPath() const
Definition: PluginManager.h:60
edmplugin::PluginManager::Config::mustHaveCache
bool mustHaveCache() const
Definition: PluginManager.h:63
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:307
edmplugin::PluginManager::PluginManager
PluginManager(const Config &)
Definition: PluginManager.cc:59
edmplugin::PluginManager::categoryToInfos
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:80
edmplugin::PluginManager
Definition: PluginManager.h:45
edmplugin::PluginManager::pluginLoadMutex
std::recursive_mutex & pluginLoadMutex()
Definition: PluginManager.h:112
edmplugin::PluginManager::loadableFor
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:151
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:124
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::PluginManager::singleton
static PluginManager *& singleton()
Definition: PluginManager.cc:342
edmplugin::PluginManager::Infos
std::vector< PluginInfo > Infos
Definition: PluginManager.h:50
edmplugin::PluginManager::pluginLoadMutex_
std::recursive_mutex pluginLoadMutex_
Definition: PluginManager.h:123
edmplugin::PluginManager::operator=
const PluginManager & operator=(const PluginManager &)=delete
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:316
edmplugin::PluginManager::Config::m_path
SearchPath m_path
Definition: PluginManager.h:66
edmplugin::PluginManager::loadingLibraryNamed_
static std::string & loadingLibraryNamed_()
Definition: PluginManager.cc:335
Signal.h
edmplugin::PluginFactoryBase
Definition: PluginFactoryBase.h:37
edmplugin::PluginManagerPathHasher::operator()
size_t operator()(boost::filesystem::path const &iPath) const
Definition: PluginManager.h:42
edmplugin::PluginManager::newFactory
void newFactory(const PluginFactoryBase *)
Definition: PluginManager.cc:141
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:100
edmplugin::PluginManager::categoryToInfos_
CategoryToInfos categoryToInfos_
Definition: PluginManager.h:122
PluginFactoryBase
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:29
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:330
Config
Definition: Config.py:1
edm::signalslot::Signal
Definition: DelayedReader.h:26
edmplugin::SharedLibrary
Definition: SharedLibrary.h:29
edmplugin::PluginManager::goingToLoad_
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Definition: PluginManager.h:98
edmplugin::PluginManager::loadableFor_
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
Definition: PluginManager.cc:156
edmplugin::PluginManager::loadingFile
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:87
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:347
edmplugin::PluginManager::tryToLoad
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
Definition: PluginManager.cc:263
edmplugin::PluginManager::justLoaded_
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
Definition: PluginManager.h:99