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 
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 tbb::concurrent_vector<PluginMakerInfo> PMakers;
65  typedef 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
edmplugin::PluginFactoryBase::category
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
edmplugin
Definition: AlignmentAlgorithmPluginFactory.cc:9
edmplugin::PluginFactoryBase::PluginMakerInfo::m_name
std::string m_name
Definition: PluginFactoryBase.h:58
edmplugin::PluginFactoryBase::PMakers
tbb::concurrent_vector< PluginMakerInfo > PMakers
Definition: PluginFactoryBase.h:64
edmplugin::PluginFactoryBase::operator=
const PluginFactoryBase & operator=(const PluginFactoryBase &)=delete
edmplugin::PluginFactoryBase::PluginMakerInfo::PluginMakerInfo
PluginMakerInfo(const PluginMakerInfo &iOther)
Definition: PluginFactoryBase.h:49
edmplugin::PluginFactoryBase::~PluginFactoryBase
virtual ~PluginFactoryBase()
Definition: PluginFactoryBase.cc:40
edmplugin::PluginFactoryBase::available
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
Definition: PluginFactoryBase.cc:152
edmplugin::PluginFactoryBase::PluginMakerInfo::PluginMakerInfo
PluginMakerInfo(void *iPtr, const std::string &iName)
Definition: PluginFactoryBase.h:45
edmplugin::PluginFactoryBase::checkProperLoadable
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
Definition: PluginFactoryBase.cc:130
edmplugin::PluginFactoryBase::findPMaker
void * findPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:66
PluginInfo.h
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::PluginFactoryBase::newPluginAdded_
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
Definition: PluginFactoryBase.h:77
edmplugin::PluginFactoryBase::fillInfo
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:113
thread_safety_macros.h
edmplugin::PluginFactoryBase::m_plugins
Plugins m_plugins
Definition: PluginFactoryBase.h:109
edmplugin::PluginFactoryBase::PluginMakerInfo::m_ptr
std::atomic< void * > m_ptr
Definition: PluginFactoryBase.h:61
Signal.h
edmplugin::PluginFactoryBase
Definition: PluginFactoryBase.h:37
edmplugin::PluginFactoryBase::fillAvailable
void fillAvailable(std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:122
edmplugin::PluginFactoryBase::PluginMakerInfo::operator=
PluginMakerInfo & operator=(const PluginMakerInfo &iOther)
Definition: PluginFactoryBase.h:53
edmplugin::PluginFactoryBase::PluginFactoryBase
PluginFactoryBase()
Definition: PluginFactoryBase.h:39
edmplugin::PluginFactoryBase::PluginMakerInfo
Definition: PluginFactoryBase.h:44
edmplugin::PluginFactoryBase::Plugins
tbb::concurrent_unordered_map< std::string, PMakers > Plugins
Definition: PluginFactoryBase.h:65
edmplugin::PluginFactoryBase::finishedConstruction
void finishedConstruction()
Definition: PluginFactoryBase.cc:57
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edmplugin::PluginFactoryBase::newPlugin
void newPlugin(const std::string &iName)
Definition: PluginFactoryBase.cc:59
edmplugin::PluginFactoryBase::registerPMaker
void registerPMaker(void *iPMaker, const std::string &iName)
Definition: PluginFactoryBase.cc:146
edm::signalslot::Signal
Definition: DelayedReader.h:26
edmplugin::PluginFactoryBase::tryToFindPMaker
void * tryToFindPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:88
edmplugin::PluginInfo
Definition: PluginInfo.h:28