File indexing completed on 2024-04-06 12:12:59
0001 #ifndef FWCore_PluginManager_PluginFactoryBase_h
0002 #define FWCore_PluginManager_PluginFactoryBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <string>
0024 #include <vector>
0025 #include <map>
0026 #include <atomic>
0027 #include "oneapi/tbb/concurrent_unordered_map.h"
0028 #include "oneapi/tbb/concurrent_vector.h"
0029 #include "FWCore/Utilities/interface/zero_allocator.h"
0030 #include "FWCore/Utilities/interface/Signal.h"
0031 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0032
0033 #include "FWCore/PluginManager/interface/PluginInfo.h"
0034
0035
0036 namespace edmplugin {
0037 class PluginFactoryBase {
0038 public:
0039 PluginFactoryBase() {}
0040 PluginFactoryBase(const PluginFactoryBase&) = delete;
0041 const PluginFactoryBase& operator=(const PluginFactoryBase&) = delete;
0042 virtual ~PluginFactoryBase();
0043
0044 struct PluginMakerInfo {
0045 PluginMakerInfo(void* iPtr, const std::string& iName) : m_name(iName), m_ptr() {
0046 m_ptr.store(iPtr, std::memory_order_release);
0047 }
0048
0049 PluginMakerInfo(const PluginMakerInfo& iOther) : m_name(iOther.m_name), m_ptr() {
0050 m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
0051 }
0052
0053 PluginMakerInfo& operator=(const PluginMakerInfo& iOther) {
0054 m_name = iOther.m_name;
0055 m_ptr.store(iOther.m_ptr.load(std::memory_order_acquire), std::memory_order_release);
0056 return *this;
0057 }
0058 std::string m_name;
0059
0060
0061 std::atomic<void*> m_ptr;
0062 };
0063
0064 typedef oneapi::tbb::concurrent_vector<PluginMakerInfo, edm::zero_allocator<PluginMakerInfo>> PMakers;
0065 typedef oneapi::tbb::concurrent_unordered_map<std::string, PMakers> Plugins;
0066
0067
0068
0069
0070 virtual std::vector<PluginInfo> available() const;
0071
0072
0073 virtual const std::string& category() const = 0;
0074
0075
0076
0077 CMS_THREAD_SAFE mutable edm::signalslot::Signal<void(const std::string&, const PluginInfo&)> newPluginAdded_;
0078
0079
0080
0081
0082
0083 protected:
0084
0085
0086
0087
0088 void finishedConstruction();
0089
0090 void newPlugin(const std::string& iName);
0091
0092
0093
0094
0095 void* findPMaker(const std::string& iName) const;
0096
0097
0098 void* tryToFindPMaker(const std::string& iName) const;
0099
0100 void fillInfo(const PMakers& makers, PluginInfo& iInfo, std::vector<PluginInfo>& iReturn) const;
0101
0102 void fillAvailable(std::vector<PluginInfo>& iReturn) const;
0103
0104 void registerPMaker(void* iPMaker, const std::string& iName);
0105
0106 private:
0107 void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const;
0108
0109 Plugins m_plugins;
0110 };
0111
0112 }
0113 #endif