#include <PluginManager.h>
Classes | |
class | Config |
Public Types | |
typedef std::map< std::string, Infos > | CategoryToInfos |
typedef std::vector< PluginInfo > | Infos |
typedef std::vector< std::string > | SearchPath |
Public Member Functions | |
const CategoryToInfos & | categoryToInfos () const |
const SharedLibrary & | load (const std::string &iCategory, const std::string &iPlugin) |
const boost::filesystem::path & | loadableFor (const std::string &iCategory, const std::string &iPlugin) |
const SharedLibrary * | tryToLoad (const std::string &iCategory, const std::string &iPlugin) |
~PluginManager () | |
Static Public Member Functions | |
static PluginManager & | configure (const Config &) |
static PluginManager * | get () |
static bool | isAvailable () |
static const std::string & | loadingFile () |
file name of the shared object being loaded | |
static const std::string & | staticallyLinkedLoadingFileName () |
if the value returned from loadingFile matches this string then the file is statically linked | |
Public Attributes | |
sigc::signal< void, const std::string &, const std::string & > | askedToLoadCategoryWithPlugin_ |
sigc::signal< void, const boost::filesystem::path & > | goingToLoad_ |
sigc::signal< void, const SharedLibrary & > | justLoaded_ |
Private Member Functions | |
const boost::filesystem::path & | loadableFor_ (const std::string &iCategory, const std::string &iPlugin, bool &ioThrowIfFailElseSucceedStatus) |
void | newFactory (const PluginFactoryBase *) |
const PluginManager & | operator= (const PluginManager &) |
PluginManager (const Config &) | |
PluginManager (const PluginManager &) | |
Static Private Member Functions | |
static std::string & | loadingLibraryNamed_ () |
static PluginManager *& | singleton () |
Private Attributes | |
CategoryToInfos | categoryToInfos_ |
std::map < boost::filesystem::path, boost::shared_ptr < SharedLibrary > > | loadables_ |
SearchPath | searchPath_ |
Friends | |
class | DummyFriend |
Definition at line 37 of file PluginManager.h.
typedef std::map<std::string, Infos > edmplugin::PluginManager::CategoryToInfos |
Definition at line 43 of file PluginManager.h.
typedef std::vector<PluginInfo> edmplugin::PluginManager::Infos |
Definition at line 42 of file PluginManager.h.
typedef std::vector<std::string> edmplugin::PluginManager::SearchPath |
Definition at line 41 of file PluginManager.h.
PluginManager::~PluginManager | ( | ) |
Definition at line 98 of file PluginManager.cc.
{ }
PluginManager::PluginManager | ( | const Config & | iConfig | ) | [private] |
Definition at line 44 of file PluginManager.cc.
References edmplugin::PluginFactoryManager::begin(), edmplugin::standard::cachefileName(), categoryToInfos_, dir, alignCSCRings::e, edmplugin::PluginFactoryManager::end(), Exception, mergeVDriftHistosByStation::file, get(), i, loadingLibraryNamed_(), newFactory(), edmplugin::PluginFactoryManager::newFactory_, scaleCards::path, SiPixelLorentzAngle_cfi::read, and searchPath_.
Referenced by configure().
: searchPath_( iConfig.searchPath() ) { const boost::filesystem::path kCacheFile(standard::cachefileName()); //NOTE: This may not be needed :/ PluginFactoryManager* pfm = PluginFactoryManager::get(); pfm->newFactory_.connect(boost::bind(boost::mem_fn(&PluginManager::newFactory),this,_1)); // When building a single big executable the plugins are already registered in the // PluginFactoryManager, we therefore only need to populate the categoryToInfos_ map // with the relevant information. for (PluginFactoryManager::const_iterator i = pfm->begin(), e = pfm->end(); i != e; ++i) { categoryToInfos_[(*i)->category()] = (*i)->available(); } //read in the files //Since we are looping in the 'precidence' order then the lists in categoryToInfos_ will also be // in that order std::set<std::string> alreadySeen; for(SearchPath::const_iterator itPath=searchPath_.begin(), itEnd = searchPath_.end(); itPath != itEnd; ++itPath) { //take care of the case where the same path is passed in multiple times if (alreadySeen.find(*itPath) != alreadySeen.end() ) { continue; } alreadySeen.insert(*itPath); boost::filesystem::path dir(*itPath); if( exists( dir) ) { if(not is_directory(dir) ) { throw cms::Exception("PluginManagerBadPath") <<"The path '"<<dir.string()<<"' for the PluginManager is not a directory"; } boost::filesystem::path cacheFile = dir/kCacheFile; if(exists(cacheFile) ) { std::ifstream file(cacheFile.string().c_str()); if(not file) { throw cms::Exception("PluginMangerCacheProblem")<<"Unable to open the cache file '"<<cacheFile.string() <<"'. Please check permissions on file"; } CacheParser::read(file, dir, categoryToInfos_); } } } //Since this should not be called until after 'main' has started, we can set the value loadingLibraryNamed_()="<loaded by another plugin system>"; }
edmplugin::PluginManager::PluginManager | ( | const PluginManager & | ) | [private] |
const CategoryToInfos& edmplugin::PluginManager::categoryToInfos | ( | ) | const [inline] |
The container is ordered by category, then plugin name and then by precidence order of the plugin files. Therefore the first match on category and plugin name will be the proper file to load
Definition at line 71 of file PluginManager.h.
References categoryToInfos_.
Referenced by PrintLoadingPlugins::askedToLoad(), edm::RootAutoLibraryLoader::loadAll(), and edm::service::LoadAllDictionaries::LoadAllDictionaries().
{ return categoryToInfos_; }
PluginManager & PluginManager::configure | ( | const Config & | iConfig | ) | [static] |
Definition at line 282 of file PluginManager.cc.
References Exception, PluginManager(), alignCSCRings::s, edmplugin::PluginManager::Config::searchPath(), and singleton().
Referenced by AutoLibraryLoader::enable(), StorageFactory::getMaker(), HcalO2OManager::HcalO2OManager(), evf::iDie::initFramework(), cond::Utilities::initializePluginManager(), HPDNoiseLibraryReader::initializeServices(), main(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().
{ PluginManager*& s = singleton(); if( 0 != s ){ throw cms::Exception("PluginManagerReconfigured"); } Config realConfig = iConfig; if (realConfig.searchPath().empty() ) { throw cms::Exception("PluginManagerEmptySearchPath"); } s = new PluginManager (realConfig); return *s; }
PluginManager * PluginManager::get | ( | void | ) | [static] |
Definition at line 272 of file PluginManager.cc.
References Exception, and singleton().
Referenced by PrintLoadingPlugins::askedToLoad(), edmplugin::PluginFactoryBase::checkProperLoadable(), FWEveViewManager::FWEveViewManager(), PluginManager(), and PrintLoadingPlugins::PrintLoadingPlugins().
{ PluginManager* manager = singleton(); if(0==manager) { throw cms::Exception("PluginManagerNotConfigured")<<"PluginManager::get() was called before PluginManager::configure."; } return manager; }
bool PluginManager::isAvailable | ( | ) | [static] |
Definition at line 319 of file PluginManager.cc.
References singleton().
Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), StorageFactory::getMaker(), HPDNoiseLibraryReader::initializeServices(), edm::ProblemTracker::ProblemTracker(), and cond::topinit().
{ return 0 != singleton(); }
const SharedLibrary & PluginManager::load | ( | const std::string & | iCategory, |
const std::string & | iPlugin | ||
) |
Definition at line 218 of file PluginManager.cc.
References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, scaleCards::path, and alignCSCRings::s.
{ askedToLoadCategoryWithPlugin_(iCategory,iPlugin); const boost::filesystem::path& p = loadableFor(iCategory,iPlugin); //have we already loaded this? std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = loadables_.find(p); if(itLoaded == loadables_.end()) { //try to make one goingToLoad_(p); Sentry s(loadingLibraryNamed_(), p.string()); //boost::filesystem::path native(p.string()); boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) ); loadables_[p]=ptr; justLoaded_(*ptr); return *ptr; } return *(itLoaded->second); }
const boost::filesystem::path & PluginManager::loadableFor | ( | const std::string & | iCategory, |
const std::string & | iPlugin | ||
) |
Definition at line 134 of file PluginManager.cc.
References loadableFor_().
Referenced by load().
{ bool throwIfFail = true; return loadableFor_(iCategory, iPlugin,throwIfFail); }
const boost::filesystem::path & PluginManager::loadableFor_ | ( | const std::string & | iCategory, |
const std::string & | iPlugin, | ||
bool & | ioThrowIfFailElseSucceedStatus | ||
) | [private] |
Definition at line 142 of file PluginManager.cc.
References categoryToInfos_, Exception, i, edmplugin::PluginInfo::name_, and scaleCards::path.
Referenced by loadableFor(), and tryToLoad().
{ const bool throwIfFail = ioThrowIfFailElseSucceedStatus; ioThrowIfFailElseSucceedStatus = true; CategoryToInfos::iterator itFound = categoryToInfos_.find(iCategory); if(itFound == categoryToInfos_.end()) { if(throwIfFail) { throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin<< "' because the category '"<<iCategory<<"' has no known plugins"; } else { ioThrowIfFailElseSucceedStatus = false; static boost::filesystem::path s_path; return s_path; } } PluginInfo i; i.name_ = iPlugin; typedef std::vector<PluginInfo>::iterator PIItr; std::pair<PIItr,PIItr> range = std::equal_range(itFound->second.begin(), itFound->second.end(), i, PICompare() ); if(range.first == range.second) { if(throwIfFail) { throw cms::Exception("PluginNotFound")<<"Unable to find plugin '"<<iPlugin <<"'. Please check spelling of name."; } else { ioThrowIfFailElseSucceedStatus = false; static boost::filesystem::path s_path; return s_path; } } if(range.second - range.first > 1 ) { //see if the come from the same directory if(range.first->loadable_.branch_path() == (range.first+1)->loadable_.branch_path()) { //std::cout<<range.first->name_ <<" " <<(range.first+1)->name_<<std::endl; throw cms::Exception("MultiplePlugins")<<"The plugin '"<<iPlugin<<"' is found in multiple files \n" " '"<<range.first->loadable_.leaf()<<"'\n '" <<(range.first+1)->loadable_.leaf()<<"'\n" "in directory '"<<range.first->loadable_.branch_path().string()<<"'.\n" "The code must be changed so the plugin only appears in one plugin file. " "You will need to remove the macro which registers the plugin so it only appears in" " one of these files.\n" " If none of these files register such a plugin, " "then the problem originates in a library to which all these files link.\n" "The plugin registration must be removed from that library since plugins are not allowed in regular libraries."; } } return range.first->loadable_; }
static const std::string& edmplugin::PluginManager::loadingFile | ( | ) | [inline, static] |
file name of the shared object being loaded
Definition at line 81 of file PluginManager.h.
References loadingLibraryNamed_().
Referenced by edmplugin::PluginFactoryBase::newPlugin(), and edmplugin::PluginFactoryBase::registerPMaker().
{ return loadingLibraryNamed_();}
std::string & PluginManager::loadingLibraryNamed_ | ( | ) | [static, private] |
Definition at line 306 of file PluginManager.cc.
References staticallyLinkedLoadingFileName().
Referenced by load(), loadingFile(), PluginManager(), and tryToLoad().
{ static std::string s_name(staticallyLinkedLoadingFileName()); return s_name; }
void PluginManager::newFactory | ( | const PluginFactoryBase * | ) | [private] |
const PluginManager& edmplugin::PluginManager::operator= | ( | const PluginManager & | ) | [private] |
PluginManager *& PluginManager::singleton | ( | ) | [static, private] |
Definition at line 312 of file PluginManager.cc.
Referenced by configure(), get(), and isAvailable().
{ static PluginManager* s_singleton; return s_singleton; }
const std::string & PluginManager::staticallyLinkedLoadingFileName | ( | ) | [static] |
if the value returned from loadingFile matches this string then the file is statically linked
Definition at line 299 of file PluginManager.cc.
Referenced by edmplugin::PluginFactoryBase::checkProperLoadable(), and loadingLibraryNamed_().
{ static std::string s_name("static"); return s_name; }
const SharedLibrary * PluginManager::tryToLoad | ( | const std::string & | iCategory, |
const std::string & | iPlugin | ||
) |
Definition at line 241 of file PluginManager.cc.
References askedToLoadCategoryWithPlugin_, goingToLoad_, justLoaded_, loadableFor_(), loadables_, loadingLibraryNamed_(), AlCaHLTBitMon_ParallelJobs::p, scaleCards::path, and alignCSCRings::s.
{ askedToLoadCategoryWithPlugin_(iCategory,iPlugin); bool ioThrowIfFailElseSucceedStatus = false; const boost::filesystem::path& p = loadableFor_(iCategory,iPlugin, ioThrowIfFailElseSucceedStatus); if( not ioThrowIfFailElseSucceedStatus ) { return 0; } //have we already loaded this? std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> >::iterator itLoaded = loadables_.find(p); if(itLoaded == loadables_.end()) { //try to make one goingToLoad_(p); Sentry s(loadingLibraryNamed_(), p.string()); //boost::filesystem::path native(p.string()); boost::shared_ptr<SharedLibrary> ptr( new SharedLibrary(p) ); loadables_[p]=ptr; justLoaded_(*ptr); return ptr.get(); } return (itLoaded->second).get(); }
friend class DummyFriend [friend] |
Definition at line 39 of file PluginManager.h.
sigc::signal<void,const std::string&,const std::string&> edmplugin::PluginManager::askedToLoadCategoryWithPlugin_ |
Definition at line 96 of file PluginManager.h.
Referenced by load(), PrintLoadingPlugins::PrintLoadingPlugins(), and tryToLoad().
Definition at line 114 of file PluginManager.h.
Referenced by categoryToInfos(), loadableFor_(), and PluginManager().
sigc::signal<void,const boost::filesystem::path&> edmplugin::PluginManager::goingToLoad_ |
Definition at line 94 of file PluginManager.h.
Referenced by load(), PrintLoadingPlugins::PrintLoadingPlugins(), and tryToLoad().
sigc::signal<void,const SharedLibrary&> edmplugin::PluginManager::justLoaded_ |
Definition at line 95 of file PluginManager.h.
Referenced by load(), and tryToLoad().
std::map<boost::filesystem::path, boost::shared_ptr<SharedLibrary> > edmplugin::PluginManager::loadables_ [private] |
Definition at line 112 of file PluginManager.h.
Referenced by load(), and tryToLoad().
Definition at line 111 of file PluginManager.h.
Referenced by PluginManager().