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 {
38 
39  public:
41  virtual ~PluginFactoryBase();
42 
43  struct PluginMakerInfo {
44  PluginMakerInfo(void* iPtr, const std::string& iName):
45  m_name(iName),
46  m_ptr() {
47  m_ptr.store(iPtr,std::memory_order_release);}
48 
50  m_name(iOther.m_name),
51  m_ptr() {
52  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire),
53  std::memory_order_release);
54  }
55 
57  m_name = iOther.m_name;
58  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire),std::memory_order_release);
59  return *this;
60  }
62  //NOTE: this has to be last since once it is non zero it signals
63  // that the construction has finished
64  std::atomic<void*> m_ptr;
65  };
66 
67  typedef tbb::concurrent_vector<PluginMakerInfo> PMakers;
68  typedef tbb::concurrent_unordered_map<std::string, PMakers > Plugins;
69 
70  // ---------- const member functions ---------------------
71 
73  virtual std::vector<PluginInfo> available() const;
74 
76  virtual const std::string& category() const = 0;
77 
80 
81  // ---------- static member functions --------------------
82 
83  // ---------- member functions ---------------------------
84 
85  protected:
90  void finishedConstruction();
91 
92  void newPlugin(const std::string& iName);
93 
94  //since each inheriting class has its own Container type to hold their PMakers
95  // this function allows them to share the same code when doing the lookup
96  // this routine will throw an exception if iName is unknown therefore the return value is always valid
97  void* findPMaker(const std::string& iName) const;
98 
99  //similar to findPMaker but will return 'end()' if iName is known
100  void* tryToFindPMaker(const std::string& iName) const;
101 
102  void fillInfo(const PMakers &makers,
103  PluginInfo& iInfo,
104  std::vector<PluginInfo>& iReturn ) const;
105 
106  void fillAvailable(std::vector<PluginInfo>& iReturn) const;
107 
108  void registerPMaker(void* iPMaker, const std::string& iName);
109 
110  private:
111  PluginFactoryBase(const PluginFactoryBase&); // stop default
112 
113  const PluginFactoryBase& operator=(const PluginFactoryBase&); // stop default
114 
115  void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const;
116  // ---------- member data --------------------------------
117  Plugins m_plugins;
118 
119 
120 };
121 
122 }
123 #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)