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 "oneapi/tbb/concurrent_unordered_map.h"
28 #include "oneapi/tbb/concurrent_vector.h"
32 // user include files
34 
35 // forward declarations
36 namespace edmplugin {
38  public:
40  PluginFactoryBase(const PluginFactoryBase&) = delete; // stop default
41  const PluginFactoryBase& operator=(const PluginFactoryBase&) = delete; // stop default
42  virtual ~PluginFactoryBase();
43 
44  struct PluginMakerInfo {
45  PluginMakerInfo(void* iPtr, const std::string& iName) : m_name(iName), m_ptr() {
46  m_ptr.store(iPtr, std::memory_order_release);
47  }
48 
49  PluginMakerInfo(const PluginMakerInfo& iOther) : m_name(iOther.m_name), m_ptr() {
50  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
51  }
52 
54  m_name = iOther.m_name;
55  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
56  return *this;
57  }
59  //NOTE: this has to be last since once it is non zero it signals
60  // that the construction has finished
61  std::atomic<void*> m_ptr;
62  };
63 
64  typedef oneapi::tbb::concurrent_vector<PluginMakerInfo, edm::zero_allocator<PluginMakerInfo>> PMakers;
65  typedef oneapi::tbb::concurrent_unordered_map<std::string, PMakers> Plugins;
66 
67  // ---------- const member functions ---------------------
68 
70  virtual std::vector<PluginInfo> available() const;
71 
73  virtual const std::string& category() const = 0;
74 
75  //The signal is only modified during a shared library load which is protected by a mutex by the operating system
78 
79  // ---------- static member functions --------------------
80 
81  // ---------- member functions ---------------------------
82 
83  protected:
88  void finishedConstruction();
89 
90  void newPlugin(const std::string& iName);
91 
92  //since each inheriting class has its own Container type to hold their PMakers
93  // this function allows them to share the same code when doing the lookup
94  // this routine will throw an exception if iName is unknown therefore the return value is always valid
95  void* findPMaker(const std::string& iName) const;
96 
97  //similar to findPMaker but will return 'end()' if iName is known
98  void* tryToFindPMaker(const std::string& iName) const;
99 
100  void fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const;
101 
102  void fillAvailable(std::vector<PluginInfo>& iReturn) const;
103 
104  void registerPMaker(void* iPMaker, const std::string& iName);
105 
106  private:
107  void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const;
108  // ---------- member data --------------------------------
110  };
111 
112 } // namespace edmplugin
113 #endif
void fillAvailable(std::vector< PluginInfo > &iReturn) const
oneapi::tbb::concurrent_unordered_map< std::string, PMakers > Plugins
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
const PluginFactoryBase & operator=(const PluginFactoryBase &)=delete
void registerPMaker(void *iPMaker, const std::string &iName)
PluginMakerInfo(void *iPtr, const std::string &iName)
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
#define CMS_THREAD_SAFE
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
void * tryToFindPMaker(const std::string &iName) const
void * findPMaker(const std::string &iName) const
oneapi::tbb::concurrent_vector< PluginMakerInfo, edm::zero_allocator< PluginMakerInfo > > PMakers
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
void newPlugin(const std::string &iName)