Commit da387db7 authored by Julien Wintz's avatar Julien Wintz
Browse files

Merge branch 'feature/plugin_manager_api' into develop

parents 4dae5956 919077b9
......@@ -29,12 +29,12 @@
Registers the creator function \a func under key \a key.
*/
/*! \fn T *dtkCorePluginFactory::create(const QString& key)
/*! \fn T *dtkCorePluginFactory::create(const QString& key) const
Creates object from the creator function identified by \a key.
Returns null pointer if \a key is not found.
*/
/*! \fn QStringList dtkCorePluginFactory::keys(void)
/*! \fn QStringList dtkCorePluginFactory::keys(void) const
Returns all the recorded creator function keys.
*/
......@@ -10,7 +10,7 @@
\brief The dtkCorePluginManagerPrivate class is the private implementation of dtkCorePluginManager.
*/
/*! \fn bool dtkCorePluginManagerPrivate::check(const QString& path)
/*! \fn bool dtkCorePluginManagerPrivate::check(const QString& path, bool checkConceptLayer = true)
\internal
Checks validity of the plugin library \a path (name, version, dependencies).
*/
......@@ -59,18 +59,50 @@
\sa setVerboseLoading()
*/
/*! \fn void dtkCorePluginManager::setAutoLoading(bool value)
Set auto loading to \a value. If true, the plugin manager will load all the plugins it found in the given path. Otherwize, it will only store plugins names and metadata. Plugin can be manual loaded with loadFromName
\sa autoLoading(), loadFromName()
*/
/*! \fn bool dtkCorePluginManager::autoLoading(void) const
return current status of auto loading.
\sa setAutoLoading()
*/
/*! \fn void dtkCorePluginManager::setLayerVersion(const QString& layer_version)
Set layer version to \a layer_version value. This will be used when checking plugins: plugins compiled for another layer version will not be loaded.
*/
/*! \fn void dtkCorePluginManager::load(const QString& path)
Checks the validity of the plugin library \a path, and if so creates the plugin.
\sa initialize(), scan(), unload()
*/
/*! \fn void dtkCorePluginManager::loadFromName(const QString& plugin_name)
Checks the validity of the \a plugin_name, and if so creates the plugin.
\sa initialize(), scan(), unload()
*/
/*! \fn void dtkCorePluginManager::unload(const QString& path)
Destroys the plugin of the plugin library \a path. Destroys the related plugin loader.
\sa load()
*/
/*! \fn QStringList dtkCorePluginManager::plugins(void)
Returns all absolute path to all the plugin libraries handled by the manager.
/*! \fn QStringList dtkCorePluginManager::plugins(void) const
Returns all the loaded plugins .
*/
/*! \fn QStringList dtkCorePluginManager::availablePlugins(void) const
Returns all the plugin available, by name (not necessarily loaded ).
*/
/*! \fn QJsonObject dtkCorePluginManager::metaData(const QString& plugin) const
Returnsthe metadatas of the given \a plugin name
*/
......@@ -40,7 +40,7 @@ public:
void setAutoLoading(bool value);
bool autoLoading(void) const;
void loadFromName(const QString & plugin_name);
void setLayerVersion(QString layer_version);
void setLayerVersion(const QString& layer_version);
#pragma mark -
#pragma mark Plugin Management
......@@ -52,12 +52,13 @@ public:
#pragma mark -
#pragma mark Plugin Queries
QStringList plugins(void);
QStringList plugins(void) const ;
QStringList availablePlugins(void) const;
#pragma mark -
#pragma mark MetaData Queries
QJsonObject metaData(const QString& pluginKey);
QJsonObject metaData(const QString& plugin) const;
protected:
dtkCorePluginManagerPrivate<T> *d;
......
......@@ -26,7 +26,7 @@
template <typename T> class dtkCorePluginManagerPrivate
{
public:
bool check(const QString& path, bool checkConcept = true);
bool check(const QString& path, bool checkConceptLayer = true);
public:
bool verboseLoading;
......@@ -36,6 +36,7 @@ public:
public:
QHash<QString, QVariant> pluginsLayerVersion;
QHash<QString, QVariantList> dependencies;
QHash<QString, QJsonObject> metaData;
public:
QHash<QString, QPluginLoader *> loaders;
......@@ -45,15 +46,15 @@ public:
// dtkCorePluginManagerPrivate
// ///////////////////////////////////////////////////////////////////
template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString& path, bool checkConcept)
template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString& path, bool checkConceptLayer)
{
bool status = true;
if (checkConcept) {
if (checkConceptLayer) {
QString conceptName = QMetaType::typeName(qMetaTypeId<T*>());
conceptName.remove("Plugin*");
QString pluginConcept = dtkCorePluginManagerBase::instance()->concept(path).toString();
QString pluginConcept = dtkCorePluginManagerBase::instance()->concept(path);
if (conceptName != pluginConcept) {
if (this->verboseLoading) {
......@@ -64,7 +65,7 @@ template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString&
}
if (!layerVersion.isNull() && !checkVersion(layerVersion ,this->pluginsLayerVersion.value(path).toString())) {
if (checkConceptLayer && !layerVersion.isNull() && !checkVersion(layerVersion ,this->pluginsLayerVersion.value(path).toString())) {
dtkWarn() << " Version mismatch: layer version " << layerVersion
<< " plugin compiled for layer version" << this->pluginsLayerVersion.value(path).toString()
<< " for plugin " << path;
......@@ -74,19 +75,19 @@ template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString&
foreach(QVariant item, this->dependencies.value(path)) {
QVariantMap mitem = item.toMap();
QVariant na_mitem = mitem.value("name");
QVariant ve_mitem = mitem.value("version");
QString na_mitem = mitem.value("name").toString();
QString ve_mitem = mitem.value("version").toString();
QString key = dtkCorePluginManagerBase::instance()->pluginPath(na_mitem);
if(!dtkCorePluginManagerBase::instance()->hasName(na_mitem)) {
dtkWarn() << " Missing dependency:" << na_mitem.toString() << "for plugin" << path;
dtkWarn() << " Missing dependency:" << na_mitem << "for plugin" << path;
status = false;
continue;
}
if (!checkVersion(dtkCorePluginManagerBase::instance()->version(key).toString(), ve_mitem.toString())) {
dtkWarn() << " Version mismatch:" << na_mitem.toString() << "version" << dtkCorePluginManagerBase::instance()->version(key).toString() << "but" << ve_mitem.toString() << "required for plugin" << path;
if (!checkVersion(dtkCorePluginManagerBase::instance()->version(key), ve_mitem)) {
dtkWarn() << " Version mismatch:" << na_mitem << "version" << dtkCorePluginManagerBase::instance()->version(key) << "but" << ve_mitem << "required for plugin" << path;
status = false;
......@@ -94,7 +95,7 @@ template <typename T> bool dtkCorePluginManagerPrivate<T>::check(const QString&
}
if(!check(key, false)) {
dtkWarn() << "Corrupted dependency:" << na_mitem.toString() << "for plugin" << path;
dtkWarn() << "Corrupted dependency:" << na_mitem << "for plugin" << path;
status = false;
......@@ -158,7 +159,7 @@ template <typename T> void dtkCorePluginManager<T>::loadFromName(const QString &
auto e = dtkCorePluginManagerBase::instance()->namesEnd();
while (i != e) {
if(QString::compare(i.value().toString(), full_name) == 0) {
if(QString::compare(i.value(), full_name) == 0) {
this->load(i.key());
return;
}
......@@ -173,7 +174,7 @@ template <typename T> void dtkCorePluginManager<T>::loadFromName(const QString &
// set Layer Version
// /////////////////////////////////////////////////////////////////
template <typename T> void dtkCorePluginManager<T>::setLayerVersion(QString layer_version)
template <typename T> void dtkCorePluginManager<T>::setLayerVersion(const QString& layer_version)
{
d->layerVersion = layer_version;
}
......@@ -197,8 +198,12 @@ template <typename T> void dtkCorePluginManager<T>::initialize(const QString& pa
this->scan(info.absoluteFilePath());
if(d->autoLoading) {
foreach(QFileInfo info, dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot))
foreach(QFileInfo info, dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) {
dtkInfo() << "load" << info.absoluteFilePath();
this->load(info.absoluteFilePath());
}
} else {
dtkInfo() << "auto loading disabled";
}
}
}
......@@ -220,12 +225,13 @@ template <typename T> void dtkCorePluginManager<T>::scan(const QString& path)
QPluginLoader *loader = new QPluginLoader(path);
dtkCorePluginManagerBase::instance()->insertName(path, loader->metaData().value("MetaData").toObject().value("name").toVariant());
dtkCorePluginManagerBase::instance()->insertVersion(path, loader->metaData().value("MetaData").toObject().value("version").toVariant());
dtkCorePluginManagerBase::instance()->insertConcept(path, loader->metaData().value("MetaData").toObject().value("concept").toVariant());
dtkCorePluginManagerBase::instance()->insertName(path, loader->metaData().value("MetaData").toObject().value("name").toString());
dtkCorePluginManagerBase::instance()->insertVersion(path, loader->metaData().value("MetaData").toObject().value("version").toString());
dtkCorePluginManagerBase::instance()->insertConcept(path, loader->metaData().value("MetaData").toObject().value("concept").toString());
d->dependencies.insert(path, loader->metaData().value("MetaData").toObject().value("dependencies").toArray().toVariantList());
d->pluginsLayerVersion.insert(path, loader->metaData().value("MetaData").toObject().value("layerVersion").toVariant());
d->pluginsLayerVersion.insert(path, loader->metaData().value("MetaData").toObject().value("layerVersion").toString());
d->metaData.insert(path, loader->metaData().value("MetaData").toObject());
delete loader;
}
......@@ -311,19 +317,27 @@ template <typename T> void dtkCorePluginManager<T>::unload(const QString& path)
// Plugin Queries
// /////////////////////////////////////////////////////////////////
template <typename T> QStringList dtkCorePluginManager<T>::plugins(void)
template <typename T> QStringList dtkCorePluginManager<T>::plugins(void) const
{
return d->loaders.keys();
}
template <typename T> QStringList dtkCorePluginManager<T>::availablePlugins(void) const
{
return dtkCorePluginManagerBase::instance()->names();
}
// /////////////////////////////////////////////////////////////////
// metaData Queries
// /////////////////////////////////////////////////////////////////
template <typename T> QJsonObject dtkCorePluginManager<T>::metaData(const QString& pluginKey)
template <typename T> QJsonObject dtkCorePluginManager<T>::metaData(const QString& plugin) const
{
if(d->loaders.keys().contains(pluginKey))
return d->loaders[pluginKey]->metaData();
if(dtkCorePluginManagerBase::instance()->hasName(plugin)) {
return d->metaData.value(dtkCorePluginManagerBase::instance()->pluginPath(plugin));
}
dtkDebug() << "METADATA: no plugin found for" << plugin << dtkCorePluginManagerBase::instance()->pluginPaths();
return QJsonObject();
}
......
......@@ -22,9 +22,9 @@
class dtkCorePluginManagerBasePrivate
{
public:
QHash<QString, QVariant> names;
QHash<QString, QVariant> versions;
QHash<QString, QVariant> concepts;
QHash<QString, QString> names;
QHash<QString, QString> versions;
QHash<QString, QString> concepts;
};
// /////////////////////////////////////////////////////////////////
......@@ -45,44 +45,44 @@ dtkCorePluginManagerBase* dtkCorePluginManagerBase::instance(void)
return s_instance;
};
void dtkCorePluginManagerBase::insertName(const QString& path, const QVariant& name)
void dtkCorePluginManagerBase::insertName(const QString& path, const QString& name)
{
d->names.insert(path, name);
}
void dtkCorePluginManagerBase::insertVersion(const QString& path, const QVariant& version)
void dtkCorePluginManagerBase::insertVersion(const QString& path, const QString& version)
{
d->versions.insert(path, version);
}
void dtkCorePluginManagerBase::insertConcept(const QString& path, const QVariant& concept)
void dtkCorePluginManagerBase::insertConcept(const QString& path, const QString& concept)
{
d->concepts.insert(path, concept);
}
QString dtkCorePluginManagerBase::pluginPath(const QVariant& name) const
QString dtkCorePluginManagerBase::pluginPath(const QString& name) const
{
return d->names.key(name);
}
QVariant dtkCorePluginManagerBase::name(const QString& path) const
QString dtkCorePluginManagerBase::name(const QString& path) const
{
return d->names.value(path);
}
QVariant dtkCorePluginManagerBase::version(const QString& path) const
QString dtkCorePluginManagerBase::version(const QString& path) const
{
return d->versions.value(path);
}
QVariant dtkCorePluginManagerBase::concept(const QString& path) const
QString dtkCorePluginManagerBase::concept(const QString& path) const
{
return d->concepts.value(path);
}
bool dtkCorePluginManagerBase::hasName(const QVariant& name) const
bool dtkCorePluginManagerBase::hasName(const QString& name) const
{
for (const QVariant& n : d->names) {
for (const QString& n : d->names) {
if (n == name) {
return true;
}
......@@ -90,9 +90,9 @@ bool dtkCorePluginManagerBase::hasName(const QVariant& name) const
return false;
}
bool dtkCorePluginManagerBase::hasVersion(const QVariant& version) const
bool dtkCorePluginManagerBase::hasVersion(const QString& version) const
{
for (const QVariant& v : d->versions) {
for (const QString& v : d->versions) {
if (v == version) {
return true;
}
......@@ -100,9 +100,9 @@ bool dtkCorePluginManagerBase::hasVersion(const QVariant& version) const
return false;
}
bool dtkCorePluginManagerBase::hasConcept(const QVariant& concept) const
bool dtkCorePluginManagerBase::hasConcept(const QString& concept) const
{
for (const QVariant& c : d->concepts) {
for (const QString& c : d->concepts) {
if (c == concept) {
return true;
}
......@@ -110,32 +110,32 @@ bool dtkCorePluginManagerBase::hasConcept(const QVariant& concept) const
return false;
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::namesBegin(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::namesBegin(void) const
{
return d->names.cbegin();
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::namesEnd(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::namesEnd(void) const
{
return d->names.cend();
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::versionsBegin(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::versionsBegin(void) const
{
return d->versions.cbegin();
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::versionsEnd(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::versionsEnd(void) const
{
return d->versions.cend();
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::conceptsBegin(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::conceptsBegin(void) const
{
return d->concepts.cbegin();
}
QHash<QString, QVariant>::const_iterator dtkCorePluginManagerBase::conceptsEnd(void) const
QHash<QString, QString>::const_iterator dtkCorePluginManagerBase::conceptsEnd(void) const
{
return d->concepts.cend();
}
......@@ -145,17 +145,17 @@ QStringList dtkCorePluginManagerBase::pluginPaths(void) const
return d->names.keys();
}
QVariantList dtkCorePluginManagerBase::names(void) const
QStringList dtkCorePluginManagerBase::names(void) const
{
return d->names.values();
}
QVariantList dtkCorePluginManagerBase::versions(void) const
QStringList dtkCorePluginManagerBase::versions(void) const
{
return d->versions.values();
}
QVariantList dtkCorePluginManagerBase::concepts(void) const
QStringList dtkCorePluginManagerBase::concepts(void) const
{
return d->concepts.values();
}
......
......@@ -31,38 +31,38 @@ public:
static dtkCorePluginManagerBase *instance(void);
public:
void insertName(const QString& path, const QVariant& name);
void insertVersion(const QString& path, const QVariant& version);
void insertConcept(const QString& path, const QVariant& concept);
void insertName(const QString& path, const QString& name);
void insertVersion(const QString& path, const QString& version);
void insertConcept(const QString& path, const QString& concept);
public:
QString pluginPath(const QVariant& name) const;
QString pluginPath(const QString& name) const;
QVariant name(const QString& path) const;
QVariant version(const QString& path) const;
QVariant concept(const QString& path) const;
QString name(const QString& path) const;
QString version(const QString& path) const;
QString concept(const QString& path) const;
public:
bool hasName(const QVariant& name) const;
bool hasVersion(const QVariant& version) const;
bool hasConcept(const QVariant& concept) const;
bool hasName(const QString& name) const;
bool hasVersion(const QString& version) const;
bool hasConcept(const QString& concept) const;
public:
QHash<QString, QVariant>::const_iterator namesBegin(void) const;
QHash<QString, QVariant>::const_iterator namesEnd(void) const;
QHash<QString, QString>::const_iterator namesBegin(void) const;
QHash<QString, QString>::const_iterator namesEnd(void) const;
QHash<QString, QVariant>::const_iterator versionsBegin(void) const;
QHash<QString, QVariant>::const_iterator versionsEnd(void) const;
QHash<QString, QString>::const_iterator versionsBegin(void) const;
QHash<QString, QString>::const_iterator versionsEnd(void) const;
QHash<QString, QVariant>::const_iterator conceptsBegin(void) const;
QHash<QString, QVariant>::const_iterator conceptsEnd(void) const;
QHash<QString, QString>::const_iterator conceptsBegin(void) const;
QHash<QString, QString>::const_iterator conceptsEnd(void) const;
public:
QStringList pluginPaths(void) const;
QVariantList names(void) const;
QVariantList versions(void) const;
QVariantList concepts(void) const;
QStringList names(void) const;
QStringList versions(void) const;
QStringList concepts(void) const;
private:
dtkCorePluginManagerBase(void);
......
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