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 
49 {
50  friend class DummyFriend;
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 {
64  return m_path;
65  }
66  void allowNoCache() {
67  m_mustHaveCache = false;
68  }
69 
70  bool mustHaveCache() const {
71  return m_mustHaveCache;
72  }
73  private:
74  SearchPath m_path;
75  bool m_mustHaveCache = true;
76  };
77 
78  ~PluginManager();
79 
80  // ---------- const member functions ---------------------
81  const SharedLibrary& load(const std::string& iCategory,
82  const std::string& iPlugin);
83 
84  const boost::filesystem::path& loadableFor(const std::string& iCategory,
85  const std::string& iPlugin);
86 
90  const CategoryToInfos& categoryToInfos() const {
91  return categoryToInfos_;
92  }
93 
94  //If can not find iPlugin in category iCategory return null pointer, any other failure will cause a throw
95  const SharedLibrary* tryToLoad(const std::string& iCategory,
96  const std::string& iPlugin);
97 
98  // ---------- static member functions --------------------
100  static const std::string& loadingFile() {
101  return loadingLibraryNamed_();}
102 
104  static const std::string& staticallyLinkedLoadingFileName();
105 
106 
107  static PluginManager* get();
108  static PluginManager& configure(const Config& );
109 
110  static bool isAvailable();
111 
112  // ---------- member functions ---------------------------
116  private:
117  PluginManager(const Config&);
118  PluginManager(const PluginManager&) = delete; // stop default
119 
120  const PluginManager& operator=(const PluginManager&) = delete; // stop default
121 
122  void newFactory(const PluginFactoryBase* );
123  static std::string& loadingLibraryNamed_();
124  static PluginManager*& singleton();
125 
126  std::recursive_mutex& pluginLoadMutex() {return pluginLoadMutex_;}
127 
128  const boost::filesystem::path& loadableFor_(const std::string& iCategory,
129  const std::string& iPlugin,
130  bool& ioThrowIfFailElseSucceedStatus);
131  // ---------- member data --------------------------------
132  SearchPath searchPath_;
133  tbb::concurrent_unordered_map<boost::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher > loadables_;
134 
135  CategoryToInfos categoryToInfos_;
136  std::recursive_mutex pluginLoadMutex_;
137 };
138 
139 }
140 #endif
CategoryToInfos categoryToInfos_
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:90
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
const SearchPath & searchPath() const
Definition: PluginManager.h:63
static const std::string & loadingFile()
file name of the shared object being loaded
std::map< std::string, Infos > CategoryToInfos
Definition: PluginManager.h:54
std::vector< std::string > SearchPath
Definition: PluginManager.h:52
edm::signalslot::Signal< void(const SharedLibrary &)> justLoaded_
edm::signalslot::Signal< void(const std::string &, const std::string &)> askedToLoadCategoryWithPlugin_
def load(fileName)
Definition: svgfig.py:546
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_