File indexing completed on 2024-04-06 12:12:59
0001 #ifndef FWCore_PluginManager_PluginManager_h
0002 #define FWCore_PluginManager_PluginManager_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <filesystem>
0023 #include <map>
0024 #include <memory>
0025 #include <mutex>
0026 #include <string>
0027 #include <vector>
0028
0029 #include "oneapi/tbb/concurrent_unordered_map.h"
0030
0031
0032 #include "FWCore/Utilities/interface/Signal.h"
0033 #include "FWCore/PluginManager/interface/SharedLibrary.h"
0034 #include "FWCore/PluginManager/interface/PluginInfo.h"
0035
0036
0037 namespace edmplugin {
0038 class DummyFriend;
0039 class PluginFactoryBase;
0040
0041 struct PluginManagerPathHasher {
0042 size_t operator()(std::filesystem::path const& iPath) const { return std::hash<std::string>{}(iPath.native()); }
0043 };
0044
0045 class PluginManager {
0046 friend class DummyFriend;
0047
0048 public:
0049 typedef std::vector<std::string> SearchPath;
0050 typedef std::vector<PluginInfo> Infos;
0051 typedef std::map<std::string, Infos> CategoryToInfos;
0052
0053 class Config {
0054 public:
0055 Config() {}
0056 Config& searchPath(const SearchPath& iPath) {
0057 m_path = iPath;
0058 return *this;
0059 }
0060 const SearchPath& searchPath() const { return m_path; }
0061 void allowNoCache() { m_mustHaveCache = false; }
0062
0063 bool mustHaveCache() const { return m_mustHaveCache; }
0064
0065 private:
0066 SearchPath m_path;
0067 bool m_mustHaveCache = true;
0068 };
0069
0070 PluginManager(const PluginManager&) = delete;
0071 const PluginManager& operator=(const PluginManager&) = delete;
0072 ~PluginManager();
0073
0074
0075 const SharedLibrary& load(const std::string& iCategory, const std::string& iPlugin);
0076
0077 const std::filesystem::path& loadableFor(const std::string& iCategory, const std::string& iPlugin);
0078
0079
0080
0081
0082 const CategoryToInfos& categoryToInfos() const { return categoryToInfos_; }
0083
0084
0085 const SharedLibrary* tryToLoad(const std::string& iCategory, const std::string& iPlugin);
0086
0087
0088
0089 static const std::string& loadingFile() { return loadingLibraryNamed_(); }
0090
0091
0092 static const std::string& staticallyLinkedLoadingFileName();
0093
0094 static PluginManager* get();
0095 static PluginManager& configure(const Config&);
0096
0097 static bool isAvailable();
0098
0099
0100 edm::signalslot::Signal<void(const std::filesystem::path&)> goingToLoad_;
0101 edm::signalslot::Signal<void(const SharedLibrary&)> justLoaded_;
0102 edm::signalslot::Signal<void(const std::string&, const std::string&)> askedToLoadCategoryWithPlugin_;
0103
0104 private:
0105 PluginManager(const Config&);
0106
0107 void newFactory(const PluginFactoryBase*);
0108 static std::string& loadingLibraryNamed_();
0109 static PluginManager*& singleton();
0110
0111 std::recursive_mutex& pluginLoadMutex() { return pluginLoadMutex_; }
0112
0113 const std::filesystem::path& loadableFor_(const std::string& iCategory,
0114 const std::string& iPlugin,
0115 bool& ioThrowIfFailElseSucceedStatus);
0116
0117 SearchPath searchPath_;
0118 oneapi::tbb::concurrent_unordered_map<std::filesystem::path, std::shared_ptr<SharedLibrary>, PluginManagerPathHasher>
0119 loadables_;
0120
0121 CategoryToInfos categoryToInfos_;
0122 std::recursive_mutex pluginLoadMutex_;
0123 };
0124
0125 }
0126 #endif