CMS 3D CMS Logo

PluginCapabilities.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PluginManager
4 // Class : PluginCapabilities
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Apr 6 12:36:24 EDT 2007
11 //
12 
13 // system include files
14 
15 // user include files
21 
22 namespace edmplugin {
23  //
24  // constants, enums and typedefs
25  //
26 
27  //
28  // static data member definitions
29  //
30 
31  //
32  // constructors and destructor
33  //
35 
36  // PluginCapabilities::PluginCapabilities(const PluginCapabilities& rhs)
37  // {
38  // // do actual copying here;
39  // }
40 
42 
43  //
44  // assignment operators
45  //
46  // const PluginCapabilities& PluginCapabilities::operator=(const PluginCapabilities& rhs)
47  // {
48  // //An exception safe implementation is
49  // PluginCapabilities temp(rhs);
50  // swap(rhs);
51  //
52  // return *this;
53  // }
54 
55  //
56  // member functions
57  //
59  void* sym;
60  if (not iLoadable.symbol("SEAL_CAPABILITIES", sym)) {
61  return false;
62  }
63 
64  const char** names;
65  int size;
66  //reinterpret_cast<void (*)(const char**&,int&)>(sym)(names,size);
67  reinterpret_cast<void (*)(const char**&, int&)>(reinterpret_cast<unsigned long>(sym))(names, size);
68 
70  for (int i = 0; i < size; ++i) {
72  classToLoadable_[name] = iLoadable.path();
73 
74  //NOTE: can't use newPlugin(name) to do the work since it assumes
75  // we haven't yet returned from PluginManager::load method
76  info.name_ = name;
77  info.loadable_ = iLoadable.path();
78  this->newPluginAdded_(category(), info);
79  }
80  return true;
81  }
82 
84  if (classToLoadable_.end() == classToLoadable_.find(iName)) {
85  const SharedLibrary& lib = PluginManager::get()->load(category(), iName);
86  //read the items from the 'capabilities' symbol
87  if (not tryToFind(lib)) {
88  throw cms::Exception("PluginNotFound")
89  << "The dictionary for class '" << iName << "' is supposed to be in file\n '" << lib.path().string()
90  << "'\n but no dictionaries are in that file.\n"
91  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "
92  << lib.path().string() << "'.";
93  }
94 
95  if (classToLoadable_.end() == classToLoadable_.find(iName)) {
96  throw cms::Exception("PluginNotFound")
97  << "The dictionary for class '" << iName << "' is supposed to be in file\n '" << lib.path().string()
98  << "'\n but was not found.\n"
99  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "
100  << lib.path().string() << "'.";
101  }
102  }
103  }
104 
106  if (classToLoadable_.end() == classToLoadable_.find(iName)) {
107  const SharedLibrary* lib = PluginManager::get()->tryToLoad(category(), iName);
108  if (nullptr == lib) {
109  return false;
110  }
111  //read the items from the 'capabilities' symbol
112  if (not tryToFind(*lib)) {
113  throw cms::Exception("PluginNotFound")
114  << "The dictionary for class '" << iName << "' is supposed to be in file\n '" << lib->path().string()
115  << "'\n but no dictionaries are in that file.\n"
116  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "
117  << lib->path().string() << "'.";
118  }
119 
120  if (classToLoadable_.end() == classToLoadable_.find(iName)) {
121  throw cms::Exception("PluginNotFound")
122  << "The dictionary for class '" << iName << "' is supposed to be in file\n '" << lib->path().string()
123  << "'\n but was not found.\n"
124  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "
125  << lib->path().string() << "'.";
126  }
127  }
128  return true;
129  }
130  //
131  // const member functions
132  //
133  std::vector<PluginInfo> PluginCapabilities::available() const {
135  std::vector<PluginInfo> infos;
136  infos.reserve(classToLoadable_.size());
137 
138  for (std::map<std::string, std::filesystem::path>::const_iterator it = classToLoadable_.begin();
139  it != classToLoadable_.end();
140  ++it) {
141  info.name_ = it->first;
142  info.loadable_ = it->second;
143  infos.push_back(info);
144  }
145  return infos;
146  }
147 
149  static const std::string s_cat("Capability");
150  return s_cat;
151  }
152 
153  //
154  // static member functions
155  //
157  CMS_THREAD_SAFE static PluginCapabilities s_instance;
158  return &s_instance;
159  }
160 
161 } // namespace edmplugin
size
Write out results.
static const TGPicture * info(bool iBackgroundIsBlack)
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
bool tryToFind(const SharedLibrary &iLoadable)
Check to see if any capabilities are in the file, returns &#39;true&#39; if found.
const std::string names[nVars_]
std::map< std::string, std::filesystem::path > classToLoadable_
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
static PluginCapabilities * get()
const std::string & category() const override
returns the name of the category to which this plugin factory belongs
#define CMS_THREAD_SAFE
bool tryToLoad(const std::string &iName)
bool symbol(const std::string &iSymbolName, void *&iSymbol) const
const std::filesystem::path & path() const
Definition: SharedLibrary.h:38
std::vector< PluginInfo > available() const override
return info about all plugins which are already available in the program
void load(const std::string &iName)
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
static PluginManager * get()