CMS 3D CMS Logo

PluginFactoryBase.h
Go to the documentation of this file.
1 #ifndef FWCore_PluginManager_PluginFactoryBase_h
2 #define FWCore_PluginManager_PluginFactoryBase_h
3 // -*- C++ -*-
4 //
5 // Package: PluginManager
6 // Class : PluginFactoryBase
7 //
17 //
18 // Original Author: Chris Jones
19 // Created: Wed Apr 4 12:24:44 EDT 2007
20 //
21 
22 // system include files
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <atomic>
27 #include "tbb/concurrent_unordered_map.h"
28 #include "tbb/concurrent_vector.h"
29 
31 // user include files
33 
34 // forward declarations
35 namespace edmplugin {
37  public:
39  virtual ~PluginFactoryBase();
40 
41  struct PluginMakerInfo {
42  PluginMakerInfo(void* iPtr, const std::string& iName) : m_name(iName), m_ptr() {
43  m_ptr.store(iPtr, std::memory_order_release);
44  }
45 
46  PluginMakerInfo(const PluginMakerInfo& iOther) : m_name(iOther.m_name), m_ptr() {
47  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
48  }
49 
51  m_name = iOther.m_name;
52  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
53  return *this;
54  }
56  //NOTE: this has to be last since once it is non zero it signals
57  // that the construction has finished
58  std::atomic<void*> m_ptr;
59  };
60 
61  typedef tbb::concurrent_vector<PluginMakerInfo> PMakers;
62  typedef tbb::concurrent_unordered_map<std::string, PMakers> Plugins;
63 
64  // ---------- const member functions ---------------------
65 
67  virtual std::vector<PluginInfo> available() const;
68 
70  virtual const std::string& category() const = 0;
71 
74 
75  // ---------- static member functions --------------------
76 
77  // ---------- member functions ---------------------------
78 
79  protected:
84  void finishedConstruction();
85 
86  void newPlugin(const std::string& iName);
87 
88  //since each inheriting class has its own Container type to hold their PMakers
89  // this function allows them to share the same code when doing the lookup
90  // this routine will throw an exception if iName is unknown therefore the return value is always valid
91  void* findPMaker(const std::string& iName) const;
92 
93  //similar to findPMaker but will return 'end()' if iName is known
94  void* tryToFindPMaker(const std::string& iName) const;
95 
96  void fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const;
97 
98  void fillAvailable(std::vector<PluginInfo>& iReturn) const;
99 
100  void registerPMaker(void* iPMaker, const std::string& iName);
101 
102  private:
103  PluginFactoryBase(const PluginFactoryBase&) = delete; // stop default
104 
105  const PluginFactoryBase& operator=(const PluginFactoryBase&) = delete; // stop default
106 
107  void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const;
108  // ---------- member data --------------------------------
109  Plugins m_plugins;
110  };
111 
112 } // namespace edmplugin
113 #endif
tbb::concurrent_unordered_map< std::string, PMakers > Plugins
void registerPMaker(void *iPMaker, const std::string &iName)
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
PluginMakerInfo(void *iPtr, const std::string &iName)
void fillAvailable(std::vector< PluginInfo > &iReturn) const
PluginMakerInfo & operator=(const PluginMakerInfo &iOther)
PluginMakerInfo(const PluginMakerInfo &iOther)
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
tbb::concurrent_vector< PluginMakerInfo > PMakers
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
void * findPMaker(const std::string &iName) const
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
void * tryToFindPMaker(const std::string &iName) const
void newPlugin(const std::string &iName)