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  virtual ~PluginFactoryBase();
41 
42  struct PluginMakerInfo {
43  PluginMakerInfo(void* iPtr, const std::string& iName) : m_name(iName), m_ptr() {
44  m_ptr.store(iPtr, std::memory_order_release);
45  }
46 
47  PluginMakerInfo(const PluginMakerInfo& iOther) : m_name(iOther.m_name), m_ptr() {
48  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
49  }
50 
52  m_name = iOther.m_name;
53  m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
54  return *this;
55  }
57  //NOTE: this has to be last since once it is non zero it signals
58  // that the construction has finished
59  std::atomic<void*> m_ptr;
60  };
61 
62  typedef tbb::concurrent_vector<PluginMakerInfo> PMakers;
63  typedef tbb::concurrent_unordered_map<std::string, PMakers> Plugins;
64 
65  // ---------- const member functions ---------------------
66 
68  virtual std::vector<PluginInfo> available() const;
69 
71  virtual const std::string& category() const = 0;
72 
73  //The signal is only modified during a shared library load which is protected by a mutex by the operating system
76 
77  // ---------- static member functions --------------------
78 
79  // ---------- member functions ---------------------------
80 
81  protected:
86  void finishedConstruction();
87 
88  void newPlugin(const std::string& iName);
89 
90  //since each inheriting class has its own Container type to hold their PMakers
91  // this function allows them to share the same code when doing the lookup
92  // this routine will throw an exception if iName is unknown therefore the return value is always valid
93  void* findPMaker(const std::string& iName) const;
94 
95  //similar to findPMaker but will return 'end()' if iName is known
96  void* tryToFindPMaker(const std::string& iName) const;
97 
98  void fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const;
99 
100  void fillAvailable(std::vector<PluginInfo>& iReturn) const;
101 
102  void registerPMaker(void* iPMaker, const std::string& iName);
103 
104  private:
105  PluginFactoryBase(const PluginFactoryBase&) = delete; // stop default
106 
107  const PluginFactoryBase& operator=(const PluginFactoryBase&) = delete; // stop default
108 
109  void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const;
110  // ---------- member data --------------------------------
112  };
113 
114 } // namespace edmplugin
115 #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:56
edmplugin::PluginFactoryBase::PMakers
tbb::concurrent_vector< PluginMakerInfo > PMakers
Definition: PluginFactoryBase.h:62
edmplugin::PluginFactoryBase::operator=
const PluginFactoryBase & operator=(const PluginFactoryBase &)=delete
edmplugin::PluginFactoryBase::PluginMakerInfo::PluginMakerInfo
PluginMakerInfo(const PluginMakerInfo &iOther)
Definition: PluginFactoryBase.h:47
edmplugin::PluginFactoryBase::~PluginFactoryBase
virtual ~PluginFactoryBase()
Definition: PluginFactoryBase.cc:39
edmplugin::PluginFactoryBase::available
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
Definition: PluginFactoryBase.cc:151
edmplugin::PluginFactoryBase::PluginMakerInfo::PluginMakerInfo
PluginMakerInfo(void *iPtr, const std::string &iName)
Definition: PluginFactoryBase.h:43
edmplugin::PluginFactoryBase::checkProperLoadable
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
Definition: PluginFactoryBase.cc:129
edmplugin::PluginFactoryBase::findPMaker
void * findPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:65
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:75
edmplugin::PluginFactoryBase::fillInfo
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:112
thread_safety_macros.h
edmplugin::PluginFactoryBase::m_plugins
Plugins m_plugins
Definition: PluginFactoryBase.h:111
edmplugin::PluginFactoryBase::PluginMakerInfo::m_ptr
std::atomic< void * > m_ptr
Definition: PluginFactoryBase.h:59
Signal.h
edmplugin::PluginFactoryBase
Definition: PluginFactoryBase.h:37
edmplugin::PluginFactoryBase::fillAvailable
void fillAvailable(std::vector< PluginInfo > &iReturn) const
Definition: PluginFactoryBase.cc:121
edmplugin::PluginFactoryBase::PluginMakerInfo::operator=
PluginMakerInfo & operator=(const PluginMakerInfo &iOther)
Definition: PluginFactoryBase.h:51
edmplugin::PluginFactoryBase::PluginFactoryBase
PluginFactoryBase()
Definition: PluginFactoryBase.h:39
edmplugin::PluginFactoryBase::PluginMakerInfo
Definition: PluginFactoryBase.h:42
edmplugin::PluginFactoryBase::Plugins
tbb::concurrent_unordered_map< std::string, PMakers > Plugins
Definition: PluginFactoryBase.h:63
edmplugin::PluginFactoryBase::finishedConstruction
void finishedConstruction()
Definition: PluginFactoryBase.cc:56
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:29
edmplugin::PluginFactoryBase::newPlugin
void newPlugin(const std::string &iName)
Definition: PluginFactoryBase.cc:58
edmplugin::PluginFactoryBase::registerPMaker
void registerPMaker(void *iPMaker, const std::string &iName)
Definition: PluginFactoryBase.cc:145
edm::signalslot::Signal
Definition: DelayedReader.h:26
edmplugin::PluginFactoryBase::tryToFindPMaker
void * tryToFindPMaker(const std::string &iName) const
Definition: PluginFactoryBase.cc:87
edmplugin::PluginInfo
Definition: PluginInfo.h:28