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 {
43  tbb::tbb_hash<std::string> hasher;
44  return hasher(iPath.native());
45  }
46  };
47 
48  class PluginManager {
49  friend class DummyFriend;
50 
51  public:
52  typedef std::vector<std::string> SearchPath;
53  typedef std::vector<PluginInfo> Infos;
54  typedef std::map<std::string, Infos> CategoryToInfos;
55 
56  class Config {
57  public:
58  Config() {}
59  Config& searchPath(const SearchPath& iPath) {
60  m_path = iPath;
61  return *this;
62  }
63  const SearchPath& searchPath() const { return m_path; }
64  void allowNoCache() { m_mustHaveCache = false; }
65 
66  bool mustHaveCache() const { return m_mustHaveCache; }
67 
68  private:
69  SearchPath m_path;
70  bool m_mustHaveCache = true;
71  };
72 
73  ~PluginManager();
74 
75  // ---------- const member functions ---------------------
76  const SharedLibrary& load(const std::string& iCategory, const std::string& iPlugin);
77 
78  const boost::filesystem::path& loadableFor(const std::string& iCategory, const std::string& iPlugin);
79 
83  const CategoryToInfos& categoryToInfos() const { return categoryToInfos_; }
84 
85  //If can not find iPlugin in category iCategory return null pointer, any other failure will cause a throw
86  const SharedLibrary* tryToLoad(const std::string& iCategory, const std::string& iPlugin);
87 
88  // ---------- static member functions --------------------
90  static const std::string& loadingFile() { return loadingLibraryNamed_(); }
91 
93  static const std::string& staticallyLinkedLoadingFileName();
94 
95  static PluginManager* get();
96  static PluginManager& configure(const Config&);
97 
98  static bool isAvailable();
99 
100  // ---------- member functions ---------------------------
104 
105  private:
106  PluginManager(const Config&);
107  PluginManager(const PluginManager&) = delete; // stop default
108 
109  const PluginManager& operator=(const PluginManager&) = delete; // stop default
110 
111  void newFactory(const PluginFactoryBase*);
112  static std::string& loadingLibraryNamed_();
113  static PluginManager*& singleton();
114 
115  std::recursive_mutex& pluginLoadMutex() { return pluginLoadMutex_; }
116 
117  const boost::filesystem::path& loadableFor_(const std::string& iCategory,
118  const std::string& iPlugin,
119  bool& ioThrowIfFailElseSucceedStatus);
120  // ---------- member data --------------------------------
121  SearchPath searchPath_;
122  tbb::concurrent_unordered_map<boost::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher>
124 
125  CategoryToInfos categoryToInfos_;
126  std::recursive_mutex pluginLoadMutex_;
127  };
128 
129 } // namespace edmplugin
130 #endif
CategoryToInfos categoryToInfos_
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:83
std::map< std::string, Infos > CategoryToInfos
Definition: PluginManager.h:54
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
const SearchPath & searchPath() const
Definition: PluginManager.h:63
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:90
std::vector< std::string > SearchPath
Definition: PluginManager.h:52
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
def load(fileName)
Definition: svgfig.py:547
std::recursive_mutex & pluginLoadMutex()
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Definition: Config.py:1
Config & searchPath(const SearchPath &iPath)
Definition: PluginManager.h:59
size_t operator()(boost::filesystem::path const &iPath) const
Definition: PluginManager.h:42
std::vector< PluginInfo > Infos
Definition: PluginManager.h:53
std::recursive_mutex pluginLoadMutex_