1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
pluginmanager.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Kevin Funk <kevin.funk@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include <config-gammaray.h>
#include "pluginmanager.h"
#include "paths.h"
#include <QCoreApplication>
#include <QStringList>
#include <QDebug>
#include <QDir>
#include <QPluginLoader>
#include <iostream>
#define IF_DEBUG(x)
using namespace GammaRay;
using namespace std;
PluginManagerBase::PluginManagerBase(QObject *parent)
: m_parent(parent)
{
}
PluginManagerBase::~PluginManagerBase() = default;
QStringList PluginManagerBase::pluginPaths()
{
#ifndef GAMMARAY_STATIC_PROBE
return Paths::pluginPaths(QStringLiteral(GAMMARAY_PROBE_ABI));
#else
return QStringList();
#endif
}
QStringList PluginManagerBase::pluginFilter()
{
QStringList filter;
#if defined(GAMMARAY_INSTALL_QT_LAYOUT)
filter.push_back(QStringLiteral("*") + QStringLiteral(GAMMARAY_PROBE_ABI) + Paths::pluginExtension());
#else
filter.push_back(QStringLiteral("*") + Paths::pluginExtension());
#endif
return filter;
}
void PluginManagerBase::scan(const QString &serviceType)
{
m_errors.clear();
QStringList loadedPluginNames;
foreach (const auto &staticPlugin, QPluginLoader::staticPlugins()) {
PluginInfo pluginInfo(staticPlugin);
if (!pluginInfo.isValid() || loadedPluginNames.contains(pluginInfo.id()) || pluginInfo.interfaceId() != serviceType) {
qDebug() << "skipping static plugin " << pluginInfo.id() << pluginInfo.interfaceId();
continue;
}
if (createProxyFactory(pluginInfo, m_parent))
loadedPluginNames.push_back(pluginInfo.id());
}
foreach (const QString &pluginPath, pluginPaths()) {
const QDir dir(pluginPath);
IF_DEBUG(cout << "checking plugin path: " << qPrintable(dir.absolutePath()) << endl);
foreach (const QString &plugin, dir.entryList(pluginFilter(), QDir::Files)) {
const QString pluginFile = dir.absoluteFilePath(plugin);
const PluginInfo pluginInfo(pluginFile);
if (!pluginInfo.isValid() || loadedPluginNames.contains(pluginInfo.id()))
continue;
if (pluginInfo.interfaceId() != serviceType) {
IF_DEBUG(
qDebug() << Q_FUNC_INFO << "skipping" << pluginFile << "not supporting service type" << serviceType << "service types are: " << pluginInfo.interfaceId();)
continue;
}
if (createProxyFactory(pluginInfo, m_parent))
loadedPluginNames.push_back(pluginInfo.id());
}
}
}
|