Commit 4bd87024 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

plugin manager: check concept of plugin before loading

parent 70a226d4
...@@ -53,6 +53,7 @@ public: ...@@ -53,6 +53,7 @@ public:
#define DTK_DECLARE_PLUGIN(type, Export) \ #define DTK_DECLARE_PLUGIN(type, Export) \
class Export type##Plugin : public dtkCorePluginBase{}; \ class Export type##Plugin : public dtkCorePluginBase{}; \
\ \
Q_DECLARE_METATYPE(type##Plugin*); \
Q_DECLARE_INTERFACE(type##Plugin, DTK_DECLARE_PLUGIN_INTERFACE(type)); Q_DECLARE_INTERFACE(type##Plugin, DTK_DECLARE_PLUGIN_INTERFACE(type));
// /////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////
......
...@@ -34,6 +34,7 @@ public: ...@@ -34,6 +34,7 @@ public:
QHash<QString, QVariant> names; QHash<QString, QVariant> names;
QHash<QString, QVariant> versions; QHash<QString, QVariant> versions;
QHash<QString, QVariantList> dependencies; QHash<QString, QVariantList> dependencies;
QHash<QString, QVariant> concept;
public: public:
QHash<QString, QPluginLoader *> loaders; QHash<QString, QPluginLoader *> loaders;
...@@ -46,6 +47,17 @@ public: ...@@ -46,6 +47,17 @@ public:
template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString& path) template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString& path)
{ {
bool status = true; bool status = true;
QString conceptName = QMetaType::typeName(qMetaTypeId<T*>());
conceptName.remove("Plugin*");
QString pluginConcept = this->concept.value(path).toString();
if (conceptName != pluginConcept) {
if (this->verboseLoading) {
dtkInfo() << "skip plugin: not an implementation of the current concept" << conceptName << ", current is " << pluginConcept;
}
return false;
}
foreach(QVariant item, this->dependencies.value(path)) { foreach(QVariant item, this->dependencies.value(path)) {
...@@ -172,6 +184,7 @@ template <typename T> void dtkCorePluginManager<T>::scan(const QString& path) ...@@ -172,6 +184,7 @@ template <typename T> void dtkCorePluginManager<T>::scan(const QString& path)
QPluginLoader *loader = new QPluginLoader(path); QPluginLoader *loader = new QPluginLoader(path);
d->names.insert(path, loader->metaData().value("MetaData").toObject().value("name").toVariant()); d->names.insert(path, loader->metaData().value("MetaData").toObject().value("name").toVariant());
d->concept.insert(path, loader->metaData().value("MetaData").toObject().value("concept").toVariant());
d->versions.insert(path, loader->metaData().value("MetaData").toObject().value("version").toVariant()); d->versions.insert(path, loader->metaData().value("MetaData").toObject().value("version").toVariant());
d->dependencies.insert(path, loader->metaData().value("MetaData").toObject().value("dependencies").toArray().toVariantList()); d->dependencies.insert(path, loader->metaData().value("MetaData").toObject().value("dependencies").toArray().toVariantList());
...@@ -202,6 +215,8 @@ template <typename T> void dtkCorePluginManager<T>::load(const QString& path) ...@@ -202,6 +215,8 @@ template <typename T> void dtkCorePluginManager<T>::load(const QString& path)
loader->setLoadHints(QLibrary::ExportExternalSymbolsHint); loader->setLoadHints(QLibrary::ExportExternalSymbolsHint);
if(d->verboseLoading) { dtkTrace() << "Loading plugin from " << path;}
if(!loader->load()) { if(!loader->load()) {
QString error = "Unable to load "; QString error = "Unable to load ";
error += path; error += path;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment