CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 <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  private:
68  };
69 
71 
72  // ---------- const member functions ---------------------
73  const SharedLibrary& load(const std::string& iCategory,
74  const std::string& iPlugin);
75 
76  const boost::filesystem::path& loadableFor(const std::string& iCategory,
77  const std::string& iPlugin);
78 
83  return categoryToInfos_;
84  }
85 
86  //If can not find iPlugin in category iCategory return null pointer, any other failure will cause a throw
87  const SharedLibrary* tryToLoad(const std::string& iCategory,
88  const std::string& iPlugin);
89 
90  // ---------- static member functions --------------------
92  static const std::string& loadingFile() {
93  return loadingLibraryNamed_();}
94 
97 
98 
99  static PluginManager* get();
100  static PluginManager& configure(const Config& );
101 
102  static bool isAvailable();
103 
104  // ---------- member functions ---------------------------
108  private:
109  PluginManager(const Config&);
110  PluginManager(const PluginManager&); // stop default
111 
112  const PluginManager& operator=(const PluginManager&); // stop default
113 
114  void newFactory(const PluginFactoryBase* );
116  static PluginManager*& singleton();
117 
118  std::recursive_mutex& pluginLoadMutex() {return pluginLoadMutex_;}
119 
120  const boost::filesystem::path& loadableFor_(const std::string& iCategory,
121  const std::string& iPlugin,
122  bool& ioThrowIfFailElseSucceedStatus);
123  // ---------- member data --------------------------------
125  tbb::concurrent_unordered_map<boost::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher > loadables_;
126 
128  std::recursive_mutex pluginLoadMutex_;
129 };
130 
131 }
132 #endif
CategoryToInfos categoryToInfos_
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
tbb::concurrent_unordered_map< boost::filesystem::path, std::shared_ptr< SharedLibrary >, PluginManagerPathHasher > loadables_
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
static PluginManager & configure(const Config &)
static PluginManager *& singleton()
const boost::filesystem::path & loadableFor_(const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus)
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:63
tuple path
else: Piece not in the list, fine.
const PluginManager & operator=(const PluginManager &)
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:92
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_
std::recursive_mutex & pluginLoadMutex()
edm::signalslot::Signal< void(const boost::filesystem::path &)> goingToLoad_
Config & searchPath(const SearchPath &iPath)
Definition: PluginManager.h:59
size_t operator()(boost::filesystem::path const &iPath) const
Definition: PluginManager.h:42
tuple Config
Definition: helper.py:9
static std::string & loadingLibraryNamed_()
std::vector< PluginInfo > Infos
Definition: PluginManager.h:53
void newFactory(const PluginFactoryBase *)
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
std::recursive_mutex pluginLoadMutex_
PluginManager(const Config &)