00001 #ifndef FWCore_PluginManager_PluginFactoryBase_h
00002 #define FWCore_PluginManager_PluginFactoryBase_h
00003
00004
00005
00006
00007
00017
00018
00019
00020
00021
00022
00023
00024 #include <string>
00025 #include <vector>
00026 #include "sigc++/signal.h"
00027
00028 #include "FWCore/PluginManager/interface/PluginInfo.h"
00029 #include "FWCore/PluginManager/interface/PluginManager.h"
00030 #include "FWCore/Utilities/interface/Exception.h"
00031
00032
00033 namespace edmplugin {
00034 class PluginFactoryBase
00035 {
00036
00037 public:
00038 PluginFactoryBase() {}
00039 virtual ~PluginFactoryBase();
00040
00041
00042
00044 virtual std::vector<PluginInfo> available() const = 0;
00045
00047 virtual const std::string& category() const = 0;
00048
00050 mutable sigc::signal<void,const std::string&, const PluginInfo&> newPluginAdded_;
00051
00052
00053
00054
00055
00056 protected:
00061 void finishedConstruction();
00062
00063 void newPlugin(const std::string& iName);
00064
00065
00066
00067
00068 template<typename Plugins>
00069 typename Plugins::const_iterator findPMaker(const std::string& iName,
00070 const Plugins& iPlugins) const {
00071
00072 typename Plugins::const_iterator itFound = iPlugins.find(iName);
00073 if(itFound == iPlugins.end()) {
00074 std::string lib = PluginManager::get()->load(this->category(),iName).path().native_file_string();
00075 itFound = iPlugins.find(iName);
00076 if(itFound == iPlugins.end()) {
00077 throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
00078 <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
00079 }
00080 } else {
00081 checkProperLoadable(iName,itFound->second.front().second);
00082 }
00083 return itFound;
00084 }
00085
00086
00087 template<typename Plugins>
00088 typename Plugins::const_iterator tryToFindPMaker(const std::string& iName,
00089 const Plugins& iPlugins) const
00090 {
00091
00092 typename Plugins::const_iterator itFound = iPlugins.find(iName);
00093 if(itFound == iPlugins.end()) {
00094 const SharedLibrary* slib = PluginManager::get()->tryToLoad(this->category(),iName);
00095 if(0!=slib) {
00096 std::string lib = slib->path().native_file_string();
00097 itFound = iPlugins.find(iName);
00098 if(itFound == iPlugins.end()) {
00099 throw cms::Exception("PluginCacheError")<<"The plugin '"<<iName<<"' should have been in loadable\n '"
00100 <<lib<<"'\n but was not there. This means the plugin cache is incorrect. Please run 'EdmPluginRefresh "<<lib<<"'";
00101 }
00102 }
00103 } else {
00104 checkProperLoadable(iName,itFound->second.front().second);
00105 }
00106 return itFound;
00107 }
00108
00109
00110 template<typename MakersItr>
00111 static void fillInfo(MakersItr iBegin, MakersItr iEnd,
00112 PluginInfo& iInfo,
00113 std::vector<PluginInfo>& iReturn ) {
00114 for(MakersItr it = iBegin;
00115 it != iEnd;
00116 ++it) {
00117 iInfo.loadable_ = it->second;
00118 iReturn.push_back(iInfo);
00119 }
00120 }
00121 template<typename PluginsItr>
00122 static void fillAvailable(PluginsItr iBegin,
00123 PluginsItr iEnd,
00124 std::vector<PluginInfo>& iReturn) {
00125 PluginInfo info;
00126 for( PluginsItr it = iBegin;
00127 it != iEnd;
00128 ++it) {
00129 info.name_ = it->first;
00130 fillInfo(it->second.begin(),it->second.end(),
00131 info, iReturn);
00132 }
00133 }
00134
00135
00136 private:
00137 PluginFactoryBase(const PluginFactoryBase&);
00138
00139 const PluginFactoryBase& operator=(const PluginFactoryBase&);
00140
00141 void checkProperLoadable(const std::string& iName, const std::string& iLoadedFrom) const {
00142
00143
00144 if (iLoadedFrom != PluginManager::staticallyLinkedLoadingFileName() &&
00145 PluginManager::isAvailable()) {
00146 if( iLoadedFrom != PluginManager::get()->loadableFor(category(),iName).native_file_string() ) {
00147 throw cms::Exception("WrongPluginLoaded")<<"The plugin '"<<iName<<"' should have been loaded from\n '"
00148 <<PluginManager::get()->loadableFor(category(),iName).native_file_string()
00149 <<"'\n but instead it was already loaded from\n '"
00150 <<iLoadedFrom<<"'\n because some other plugin was loaded from the latter loadables.\n"
00151 "To work around the problem the plugin '"<<iName<<"' should only be defined in one of these loadables.";
00152 }
00153 }
00154 }
00155
00156
00157 };
00158
00159 }
00160 #endif