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 {
37 }
38 
39 // PluginCapabilities::PluginCapabilities(const PluginCapabilities& rhs)
40 // {
41 // // do actual copying here;
42 // }
43 
45 {
46 }
47 
48 //
49 // assignment operators
50 //
51 // const PluginCapabilities& PluginCapabilities::operator=(const PluginCapabilities& rhs)
52 // {
53 // //An exception safe implementation is
54 // PluginCapabilities temp(rhs);
55 // swap(rhs);
56 //
57 // return *this;
58 // }
59 
60 //
61 // member functions
62 //
63 bool
65 {
66  void* sym;
67  if( not iLoadable.symbol("SEAL_CAPABILITIES",sym) ) {
68  return false;
69  }
70 
71  const char** names;
72  int size;
73  //reinterpret_cast<void (*)(const char**&,int&)>(sym)(names,size);
74  reinterpret_cast<void (*)(const char**&,int&)>(reinterpret_cast<unsigned long>(sym))(names,size);
75 
77  for(int i=0; i < size; ++i) {
78  std::string name(names[i]);
79  classToLoadable_[name]=iLoadable.path();
80 
81  //NOTE: can't use newPlugin(name) to do the work since it assumes
82  // we haven't yet returned from PluginManager::load method
83  info.name_ = name;
84  info.loadable_ = iLoadable.path();
85  this->newPluginAdded_(category(),info);
86  }
87  return true;
88 }
89 
90 void
92 {
93  if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
95  iName);
96  //read the items from the 'capabilities' symbol
97  if(not tryToFind(lib) ) {
98  throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
99  <<lib.path().string()<<"'\n but no dictionaries are in that file.\n"
100  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
101  }
102 
103  if(classToLoadable_.end() == classToLoadable_.find(iName)) {
104  throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
105  <<lib.path().string()<<"'\n but was not found.\n"
106  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "<<lib.path().string()<<"'.";
107  }
108  }
109 }
110 
111 bool
113 {
114  if(classToLoadable_.end() == classToLoadable_.find(iName) ) {
116  iName);
117  if( nullptr == lib) {
118  return false;
119  }
120  //read the items from the 'capabilities' symbol
121  if(not tryToFind(*lib) ) {
122  throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName <<"' is supposed to be in file\n '"
123  <<lib->path().string()<<"'\n but no dictionaries are in that file.\n"
124  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
125  }
126 
127  if(classToLoadable_.end() == classToLoadable_.find(iName)) {
128  throw cms::Exception("PluginNotFound")<<"The dictionary for class '"<<iName<<"' is supposed to be in file\n '"
129  <<lib->path().string()<<"'\n but was not found.\n"
130  "It appears like the cache is wrong. Please do 'EdmPluginRefresh "<<lib->path().string()<<"'.";
131  }
132  }
133  return true;
134 }
135 //
136 // const member functions
137 //
138 std::vector<PluginInfo>
140 {
142  std::vector<PluginInfo> infos;
143  infos.reserve(classToLoadable_.size());
144 
145  for(std::map<std::string, boost::filesystem::path>::const_iterator it = classToLoadable_.begin();
146  it != classToLoadable_.end();
147  ++it) {
148  info.name_ = it->first;
149  info.loadable_ = it->second;
150  infos.push_back(info);
151  }
152  return infos;
153 }
154 
155 const std::string&
157 {
158  static const std::string s_cat("Capability");
159  return s_cat;
160 }
161 
162 //
163 // static member functions
164 //
167  CMS_THREAD_SAFE static PluginCapabilities s_instance;
168  return &s_instance;
169 }
170 
171 }
bool symbol(const std::string &iSymbolName, void *&iSymbol) const
size
Write out results.
static const TGPicture * info(bool iBackgroundIsBlack)
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
static const HistoName names[]
bool tryToFind(const SharedLibrary &iLoadable)
Check to see if any capabilities are in the file, returns &#39;true&#39; if found.
std::vector< PluginInfo > available() const override
return info about all plugins which are already available in the program
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
static PluginCapabilities * get()
#define CMS_THREAD_SAFE
bool tryToLoad(const std::string &iName)
std::map< std::string, boost::filesystem::path > classToLoadable_
const std::string & category() const override
returns the name of the category to which this plugin factory belongs
std::string name_
Definition: PluginInfo.h:29
void load(const std::string &iName)
boost::filesystem::path loadable_
Definition: PluginInfo.h:30
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
const boost::filesystem::path & path() const
Definition: SharedLibrary.h:38
static PluginManager * get()