CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PluginFactoryBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PluginManager
4 // Class : PluginFactoryBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Apr 4 13:09:50 EDT 2007
11 // $Id: PluginFactoryBase.cc,v 1.8 2011/08/24 12:28:53 eulisse Exp $
12 //
13 
14 // system include files
15 
16 // user include files
21 
22 
23 namespace edmplugin {
24 //
25 // constants, enums and typedefs
26 //
27 
28 //
29 // static data member definitions
30 //
31 
32 //
33 // constructors and destructor
34 //
35 
36 // PluginFactoryBase::PluginFactoryBase(const PluginFactoryBase& rhs)
37 // {
38 // // do actual copying here;
39 // }
40 
42 {
43 }
44 
45 //
46 // assignment operators
47 //
48 // const PluginFactoryBase& PluginFactoryBase::operator=(const PluginFactoryBase& rhs)
49 // {
50 // //An exception safe implementation is
51 // PluginFactoryBase temp(rhs);
52 // swap(rhs);
53 //
54 // return *this;
55 // }
56 
57 //
58 // member functions
59 //
60 void
62 {
64 }
65 
66 void
68 {
71  info.name_=iName;
72  newPluginAdded_(category(),info);
73 }
74 
75 
76 PluginFactoryBase::Plugins::const_iterator
78 {
79  //do we already have it?
80  Plugins::const_iterator itFound = m_plugins.find(iName);
81  if(itFound == m_plugins.end()) {
82  std::string lib = PluginManager::get()->load(this->category(),iName).path().string();
83  itFound = m_plugins.find(iName);
84  if(itFound == m_plugins.end()) {
85  throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
86  <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
87  }
88  } else {
89  checkProperLoadable(iName,itFound->second.front().second);
90  }
91  return itFound;
92 }
93 
94 
95 PluginFactoryBase::Plugins::const_iterator
97 {
98  //do we already have it?
99  Plugins::const_iterator itFound = m_plugins.find(iName);
100  if(itFound == m_plugins.end()) {
101  const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(),iName);
102  if(0!=slib) {
103  std::string lib = slib->path().string();
104  itFound = m_plugins.find(iName);
105  if(itFound == m_plugins.end()) {
106  throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
107  <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
108  }
109  }
110  } else {
111  checkProperLoadable(iName,itFound->second.front().second);
112  }
113  return itFound;
114 }
115 
116 void
118  PluginInfo& iInfo,
119  std::vector<PluginInfo>& iReturn ) const {
120  for(PMakers::const_iterator it = makers.begin();
121  it != makers.end();
122  ++it) {
123  iInfo.loadable_ = it->second;
124  iReturn.push_back(iInfo);
125  }
126 }
127 
128 void
129 PluginFactoryBase::fillAvailable(std::vector<PluginInfo>& iReturn) const {
131  for( Plugins::const_iterator it = m_plugins.begin();
132  it != m_plugins.end();
133  ++it) {
134  info.name_ = it->first;
135  fillInfo(it->second,
136  info, iReturn);
137  }
138 }
139 
140 void
141 PluginFactoryBase::checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const
142 {
143  //should check to see if this is from the proper loadable if it
144  // was not statically linked
145  if (iLoadedFrom != PluginManager::staticallyLinkedLoadingFileName() &&
147  if( iLoadedFrom != PluginManager::get()->loadableFor(category(),iName).string() ) {
148  throw cms::Exception("WrongPluginLoaded")<<"The plugin '"<<iName<<"' should have been loaded from\n '"
149  <<PluginManager::get()->loadableFor(category(),iName).string()
150  <<"'\n but instead it was already loaded from\n '"
151  <<iLoadedFrom<<"'\n because some other plugin was loaded from the latter loadables.\n"
152  "To work around the problem the plugin '"<<iName<<"' should only be defined in one of these loadables.";
153  }
154  }
155 }
156 
157 
158 void
159 PluginFactoryBase::registerPMaker(void* iPMaker, const std::string& iName) {
160  m_plugins[iName].push_back(std::pair<void*,std::string>(iPMaker,PluginManager::loadingFile()));
161  newPlugin(iName);
162 }
163 
164 std::vector<PluginInfo>
166  std::vector<PluginInfo> returnValue;
167  returnValue.reserve(m_plugins.size());
168  fillAvailable(returnValue);
169  return returnValue;
170 }
171 
172 //
173 // const member functions
174 //
175 
176 //
177 // static member functions
178 //
179 }
const boost::filesystem::path & loadableFor(const std::string &iCategory, const std::string &iPlugin)
const SharedLibrary * tryToLoad(const std::string &iCategory, const std::string &iPlugin)
void registerPMaker(void *iPMaker, const std::string &iName)
static const std::string & staticallyLinkedLoadingFileName()
if the value returned from loadingFile matches this string then the file is statically linked ...
std::vector< std::pair< void *, std::string > > PMakers
void fillAvailable(std::vector< PluginInfo > &iReturn) const
edm::signalslot::Signal< void(const std::string &, const PluginInfo &)> newPluginAdded_
signal containing plugin category, and plugin info for newly added plugin
void checkProperLoadable(const std::string &iName, const std::string &iLoadedFrom) const
static const std::string & loadingFile()
file name of the shared object being loaded
Definition: PluginManager.h:81
void fillInfo(const PMakers &makers, PluginInfo &iInfo, std::vector< PluginInfo > &iReturn) const
void addFactory(const PluginFactoryBase *)
virtual const std::string & category() const =0
returns the name of the category to which this plugin factory belongs
Plugins::const_iterator tryToFindPMaker(const std::string &iName) const
std::string name_
Definition: PluginInfo.h:30
virtual std::vector< PluginInfo > available() const
return info about all plugins which are already available in the program
boost::filesystem::path loadable_
Definition: PluginInfo.h:31
Plugins::const_iterator findPMaker(const std::string &iName) const
const SharedLibrary & load(const std::string &iCategory, const std::string &iPlugin)
const boost::filesystem::path & path() const
Definition: SharedLibrary.h:42
static PluginManager * get()
static PluginFactoryManager * get()
void newPlugin(const std::string &iName)