// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PluginRegistry::PluginEntry PluginRegistry::open(const std::string &file) const { // Load shared library #ifdef WIN32 void *handle = LoadLibrary(file.c_str()); #else void *handle = dlopen(file.c_str(), RTLD_NOW | RTLD_GLOBAL); #endif if ( !handle ) { SEISCOMP_ERROR("Loading plugin %s failed: %s", file.c_str(), sysLastError().c_str()); return PluginEntry(NULL, NULL, file); } if ( findLibrary(handle) ) { return PluginEntry(handle, NULL, file); } #ifndef WIN32 // Reset errors dlerror(); // Load factory Core::Plugin::CreateFunc func; *(void **)(&func) = dlsym(handle, "createSCPlugin"); #else Core::Plugin::CreateFunc func = (Core::Plugin::CreateFunc)GetProcAddress((HMODULE)handle, "createSCPlugin"); #endif if ( !func ) { SEISCOMP_ERROR("Could not load symbol createPlugin: %s", sysLastError().c_str()); #ifndef WIN32 dlclose(handle); #else FreeLibrary((HMODULE)handle); #endif return PluginEntry(NULL, NULL, file); } Core::Plugin *plugin = func(); if ( !plugin ) { SEISCOMP_ERROR("No plugin return from %s", file.c_str()); #ifndef WIN32 dlclose(handle); #else FreeLibrary((HMODULE)handle); #endif return PluginEntry(NULL, NULL, file); } // Do not warn for different patch versions. They must be binary compatible // by definition. if ( (SC_API_VERSION_MAJOR(plugin->description().apiVersion) != SC_API_VERSION_MAJOR(SC_API_VERSION)) || (SC_API_VERSION_MINOR(plugin->description().apiVersion) > SC_API_VERSION_MINOR(SC_API_VERSION)) ) { SEISCOMP_WARNING("API version mismatch (%d.%d != %d.%d) can lead to unpredicted behaviour: %s", SC_API_VERSION_MAJOR(plugin->description().apiVersion), SC_API_VERSION_MINOR(plugin->description().apiVersion), SC_API_VERSION_MAJOR(SC_API_VERSION), SC_API_VERSION_MINOR(SC_API_VERSION), file.c_str()); } return PluginEntry(handle, plugin, file); }
explicit LookaheadPluginsStorage(typename P::Iterator::Ptr iterator) : Offset() { for (; iterator->IsValid(); iterator->Next()) { const typename P::Ptr plugin = iterator->Get(); Plugins.push_back(PluginEntry(plugin)); } }
PluginRegistry() : mDefaultPlugin(PluginEntry(QStringLiteral("application/octet-stream@QByteArray"), s_defaultItemSerializerPlugin)) , mOverridePlugin(0) { const PluginLoader *pl = PluginLoader::self(); if (!pl) { qWarning() << "Cannot instantiate plugin loader!" << endl; return; } const QStringList names = pl->names(); qDebug() << "ItemSerializerPluginLoader: " << "found" << names.size() << "plugins." << endl; QMap<QString, MimeTypeEntry> map; QRegExp rx(QStringLiteral("(.+)@(.+)")); QMimeDatabase mimeDb; Q_FOREACH (const QString &name, names) { if (rx.exactMatch(name)) { const QMimeType mime = mimeDb.mimeTypeForName(rx.cap(1)); if (mime.isValid()) { const QString mimeType = mime.name(); const QByteArray classType = rx.cap(2).toLatin1(); QMap<QString, MimeTypeEntry>::iterator it = map.find(mimeType); if (it == map.end()) { it = map.insert(mimeType, MimeTypeEntry(mimeType)); } it->add(classType, PluginEntry(name)); } } else { qDebug() << "ItemSerializerPluginLoader: " << "name" << name << "doesn't look like mimetype@classtype" << endl; } } const QString APPLICATION_OCTETSTREAM = QLatin1String(_APPLICATION_OCTETSTREAM); QMap<QString, MimeTypeEntry>::iterator it = map.find(APPLICATION_OCTETSTREAM); if (it == map.end()) { it = map.insert(APPLICATION_OCTETSTREAM, MimeTypeEntry(APPLICATION_OCTETSTREAM)); } it->add("QByteArray", mDefaultPlugin); it->add(LEGACY_NAME, mDefaultPlugin); const int size = map.size(); allMimeTypes.reserve(size); std::copy(map.begin(), map.end(), std::back_inserter(allMimeTypes)); }