From d95c5fee483816558246586c4621d96c84b224c0 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Fri, 11 Nov 2011 10:46:31 +1000 Subject: remove qmobilitypluginsearch and use the QFactoryLoader instead. Change-Id: Ifdd2031d309a5ac4cbeedc5d7cdb6ba9cbb845c3 Reviewed-by: Lincoln Ramsay Sanity-Review: Lincoln Ramsay --- .../shake/qshakesensorgestureplugin.h | 5 +- src/plugins/sensors/dummy/main.cpp | 3 +- src/plugins/sensors/generic/main.cpp | 3 +- src/plugins/sensors/simulator/main.cpp | 5 +- .../gestures/qsensorgesturemanagerprivate.cpp | 22 ++- .../gestures/qsensorgestureplugininterface.cpp | 11 ++ .../gestures/qsensorgestureplugininterface.h | 15 +- src/sensors/qmobilitypluginsearch.h | 173 --------------------- src/sensors/qsensormanager.cpp | 9 +- src/sensors/qsensorplugin.h | 9 +- src/sensors/qsensorpluginloader.cpp | 27 ++-- src/sensors/qsensorpluginloader_p.h | 1 - 12 files changed, 67 insertions(+), 216 deletions(-) delete mode 100644 src/sensors/qmobilitypluginsearch.h (limited to 'src') diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h index d11b9ee9..068656f2 100644 --- a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h +++ b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h @@ -47,10 +47,11 @@ #include -class QShakeSensorGesturePlugin : public QObject, QSensorGesturePluginInterface +class QShakeSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface { Q_OBJECT - Q_INTERFACES(QSensorGesturePluginInterface) + Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface) + public: explicit QShakeSensorGesturePlugin(); ~QShakeSensorGesturePlugin(); diff --git a/src/plugins/sensors/dummy/main.cpp b/src/plugins/sensors/dummy/main.cpp index f7cf85f6..9b9bc237 100644 --- a/src/plugins/sensors/dummy/main.cpp +++ b/src/plugins/sensors/dummy/main.cpp @@ -50,7 +50,7 @@ class dummySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory { Q_OBJECT - Q_INTERFACES(QSensorPluginInterface) + Q_INTERFACES(QSensorPluginInterface:QFactoryInterface) public: void registerSensors() { @@ -71,6 +71,7 @@ public: return 0; } + QStringList keys() const { return QStringList() << "dummy";} }; Q_EXPORT_PLUGIN2(qtsensors_dummy, dummySensorPlugin) diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp index 7714ce02..d72abdd3 100644 --- a/src/plugins/sensors/generic/main.cpp +++ b/src/plugins/sensors/generic/main.cpp @@ -51,7 +51,7 @@ class genericSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory { Q_OBJECT - Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) + Q_INTERFACES(QSensorPluginInterface:QFactoryInterface QSensorChangesInterface) public: void registerSensors() { @@ -92,6 +92,7 @@ public: return 0; } + QStringList keys() const { return QStringList() << "generic";} }; Q_EXPORT_PLUGIN2(qtsensors_generic, genericSensorPlugin) diff --git a/src/plugins/sensors/simulator/main.cpp b/src/plugins/sensors/simulator/main.cpp index 641f7a69..c470d12a 100644 --- a/src/plugins/sensors/simulator/main.cpp +++ b/src/plugins/sensors/simulator/main.cpp @@ -49,10 +49,10 @@ #include #include -class SimulatorSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +class SimulatorSensorPlugin : public QSensorPluginInterface,public QObject, public QSensorBackendFactory { Q_OBJECT - Q_INTERFACES(QSensorPluginInterface) + Q_INTERFACES(QSensorPluginInterface:QFactoryInterface) public: void registerSensors() { @@ -92,6 +92,7 @@ public: return 0; } + QStringList keys() const { return QStringList() << "simulator";} }; Q_EXPORT_PLUGIN2(libsensors_simulator, SimulatorSensorPlugin) diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp index 2f85561b..292248b4 100644 --- a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp +++ b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp @@ -42,13 +42,19 @@ #include #include +#include + #include "qsensorgesturerecognizer.h" #include "qsensorgesturemanagerprivate_p.h" #include "qsensorgestureplugininterface.h" -#include "qmobilitypluginsearch.h" QT_BEGIN_NAMESPACE +#ifndef QT_NO_LIBRARY +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QSensorGestureFactoryInterface_iid, QLatin1String("/sensorgestures"))) +#endif + QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) : QObject(parent) { @@ -58,7 +64,6 @@ QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) : QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate() { qDeleteAll(registeredSensorGestures); - qDeleteAll(plugins); } @@ -87,17 +92,10 @@ QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate() */ void QSensorGestureManagerPrivate::loadPlugins() { - // Qt-style static plugins - Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) { - initPlugin(plugin); - } - - QStringList gestureplugins = mobilityPlugins(QLatin1String("sensorgestures")); - for (int i = 0; i < gestureplugins.count(); i++) { - - QPluginLoader *loader = new QPluginLoader(gestureplugins.at(i), this); + QFactoryLoader *l = loader(); + foreach (const QString &key, l->keys()) { - QObject *plugin = loader->instance(); + QObject *plugin = l->instance(key); if (plugin) { initPlugin(plugin); } diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp index 8a68fbcf..95ceca3b 100644 --- a/src/sensors/gestures/qsensorgestureplugininterface.cpp +++ b/src/sensors/gestures/qsensorgestureplugininterface.cpp @@ -80,4 +80,15 @@ Returns this plugins name. */ +QT_BEGIN_NAMESPACE +QSensorGesturePluginInterface::QSensorGesturePluginInterface() +{ +} + +QSensorGesturePluginInterface::~QSensorGesturePluginInterface() +{ + +} + +QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h index 93185b77..8128f0e4 100644 --- a/src/sensors/gestures/qsensorgestureplugininterface.h +++ b/src/sensors/gestures/qsensorgestureplugininterface.h @@ -44,24 +44,29 @@ #include #include - +#include +#include #include "qsensorgesture.h" #include "qsensorgesturerecognizer.h" QT_BEGIN_NAMESPACE class QSensorGestureRecognizer; -class Q_SENSORS_EXPORT QSensorGesturePluginInterface +#define QSensorGestureFactoryInterface_iid "com.Nokia.QSensorGesturePluginInterface" + + +class Q_SENSORS_EXPORT QSensorGesturePluginInterface : public QFactoryInterface { public: + QSensorGesturePluginInterface(); + virtual ~QSensorGesturePluginInterface(); virtual QList createRecognizers() = 0; virtual QStringList supportedIds() const = 0; virtual QString name() const = 0; - + QStringList keys() const { return QStringList() << name(); } }; -Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, "com.Nokia.QSensorGesturePluginInterface"); - QT_END_NAMESPACE +Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, QSensorGestureFactoryInterface_iid); #endif // QSENSORGESTUREPLUGININTERFACE_H diff --git a/src/sensors/qmobilitypluginsearch.h b/src/sensors/qmobilitypluginsearch.h deleted file mode 100644 index 045da296..00000000 --- a/src/sensors/qmobilitypluginsearch.h +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOBILITYPLUGINSEARCH_H -#define QMOBILITYPLUGINSEARCH_H - -#include -#include -#include -#include - -#if defined(Q_OS_SYMBIAN) -# include -#endif - -QT_BEGIN_NAMESPACE - -#if defined(Q_OS_SYMBIAN) -static inline bool qSymbian_CheckDir(const QDir& dir, RFs& rfs) -{ - bool pathFound = false; - // In Symbian, going cdUp() in a c:/private// will result in *platsec* error at fileserver (requires AllFiles capability) - // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should - // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp). - // Use native Symbian code to check for directory existence, because checking - // for files from under non-existent protected dir like E:/private/ using - // QDir::exists causes platform security violations on most apps. - QString nativePath = QDir::toNativeSeparators(dir.absolutePath()); - TPtrC ptr = TPtrC16(static_cast(nativePath.utf16()), nativePath.length()); - TUint attributes; - TInt err = rfs.Att(ptr, attributes); - if (err == KErrNone) { - // yes, the directory exists. - pathFound = true; - } - return pathFound; -} -#define CHECKDIR(dir) qSymbian_CheckDir(dir, rfs) -#else -#define CHECKDIR(dir) (dir).exists() -#endif - -inline QStringList mobilityPlugins(const QString& plugintype) -{ -#if !defined QT_NO_DEBUG - const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0; -#endif - - QStringList paths = QCoreApplication::libraryPaths(); -/*#ifdef QTM_PLUGIN_PATH - paths << QLatin1String(QTM_PLUGIN_PATH); -#endif*/ -#if !defined QT_NO_DEBUG - if (showDebug) - qDebug() << "Plugin paths:" << paths; -#endif - -#if defined(Q_OS_SYMBIAN) - RFs rfs; - qt_symbian_throwIfError(rfs.Connect()); -#endif - - // Temp variable to avoid multiple identical paths - // (we don't convert the list to set first, because that loses the order) - QSet processed; - - /* The list of discovered plugins */ - QStringList plugins; - - /* Enumerate our plugin paths */ - for (int i=0; i < paths.count(); i++) { - if (processed.contains(paths.at(i))) - continue; - processed.insert(paths.at(i)); - QDir pluginsDir(paths.at(i)); - if (!CHECKDIR(pluginsDir)) - continue; - -#if defined(Q_OS_WIN) - if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release")) - pluginsDir.cdUp(); -#elif defined(Q_OS_MAC) - if (pluginsDir.dirName() == QLatin1String("MacOS")) { - pluginsDir.cdUp(); - pluginsDir.cdUp(); - pluginsDir.cdUp(); - } -#endif - - QString subdir(QLatin1String("plugins/")); - subdir += plugintype; - if (pluginsDir.path().endsWith(QLatin1String("/plugins")) - || pluginsDir.path().endsWith(QLatin1String("/plugins/"))) - subdir = plugintype; - - if (CHECKDIR(QDir(pluginsDir.filePath(subdir)))) { - pluginsDir.cd(subdir); - QStringList files = pluginsDir.entryList(QDir::Files); - -#if !defined QT_NO_DEBUG - if (showDebug) - qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files; -#endif - - for (int j=0; j < files.count(); j++) { - plugins << pluginsDir.absoluteFilePath(files.at(j)); - } - } - } - - /* Add application path + plugintype */ - QDir appldir(QCoreApplication::applicationDirPath()); - if (appldir.cd(plugintype)) { - if (!processed.contains(appldir.absolutePath())){ - processed.insert(appldir.absolutePath()); - QStringList files = appldir.entryList(QDir::Files); -#if !defined QT_NO_DEBUG - if (showDebug) - qDebug() << "Looking for " << plugintype << " plugins in" << appldir.path() << files; -#endif - for (int j=0; j < files.count(); j++) { - plugins << appldir.absoluteFilePath(files.at(j)); - } - } - } - -#if defined(Q_OS_SYMBIAN) - rfs.Close(); -#endif - return plugins; -} - -QT_END_NAMESPACE - -#endif diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp index 1978e8c5..a7714508 100644 --- a/src/sensors/qsensormanager.cpp +++ b/src/sensors/qsensormanager.cpp @@ -84,6 +84,7 @@ public: bool sensorsChanged; QList changeListeners; + QSet seenPlugins; Q_SIGNALS: void availableSensorsChanged(); @@ -154,15 +155,21 @@ Q_SENSORS_EXPORT void sensors_unit_test_hook(int index) static void initPlugin(QObject *o) { if (!o) return; + QSensorManagerPrivate *d = sensorManagerPrivate(); + if (d->seenPlugins.contains(o)) + return; QSensorChangesInterface *changes = qobject_cast(o); if (changes) d->changeListeners << changes; QSensorPluginInterface *plugin = qobject_cast(o); - if (plugin) + + if (plugin) { + d->seenPlugins.insert(o); plugin->registerSensors(); + } } void QSensorManagerPrivate::loadPlugins() diff --git a/src/sensors/qsensorplugin.h b/src/sensors/qsensorplugin.h index 17308ca7..c2f417b5 100644 --- a/src/sensors/qsensorplugin.h +++ b/src/sensors/qsensorplugin.h @@ -50,10 +50,15 @@ QT_BEGIN_NAMESPACE -class Q_SENSORS_EXPORT QSensorPluginInterface +#define QSensorFactoryInterface_iid "com.nokia.Qt.QSensorPluginInterface/1.0" + +class Q_SENSORS_EXPORT QSensorPluginInterface : public QFactoryInterface { + public: virtual void registerSensors() = 0; + virtual QStringList keys() const = 0; + protected: ~QSensorPluginInterface() {} }; @@ -68,7 +73,7 @@ protected: QT_END_NAMESPACE -Q_DECLARE_INTERFACE(QSensorPluginInterface, "com.nokia.Qt.QSensorPluginInterface/1.0"); +Q_DECLARE_INTERFACE(QSensorPluginInterface, QSensorFactoryInterface_iid); Q_DECLARE_INTERFACE(QSensorChangesInterface, "com.nokia.Qt.QSensorChangesInterface/1.0"); #endif diff --git a/src/sensors/qsensorpluginloader.cpp b/src/sensors/qsensorpluginloader.cpp index 66012f49..7c9ab71f 100644 --- a/src/sensors/qsensorpluginloader.cpp +++ b/src/sensors/qsensorpluginloader.cpp @@ -43,12 +43,18 @@ #include #include #include +#include #include "qsensorplugin.h" -#include "qmobilitypluginsearch.h" QT_BEGIN_NAMESPACE + +#ifndef QT_NO_LIBRARY +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QSensorFactoryInterface_iid, QLatin1String("/sensors"))) +#endif + QSensorPluginLoader::QSensorPluginLoader() { load(); @@ -68,36 +74,25 @@ void QSensorPluginLoader::load() if (!m_plugins.isEmpty()) return; - QStringList plugins = mobilityPlugins(QLatin1String("sensors")); bool reportErrors = (qgetenv("QT_DEBUG_PLUGINS") == "1"); /* Now discover the dynamic plugins */ - for (int i = 0; i < plugins.count(); i++) { - QPluginLoader *loader = new QPluginLoader(plugins.at(i)); + QFactoryLoader *l = loader(); + foreach (const QString &key, l->keys()) { - QObject *o = loader->instance(); + QObject *o = l->instance(key); if (o != 0) { QSensorPluginInterface *p = qobject_cast(o); if (p != 0) { m_plugins << o; - m_loaders << loader; } else { if (reportErrors) { - qWarning() << plugins.at(i) << "is not a QSensorPluginInterface"; + qWarning() << key << "is not a QSensorPluginInterface"; } - loader->unload(); - delete loader; } continue; - } else { - if (reportErrors) { - qWarning() << loader->errorString(); - } } - delete o; - loader->unload(); - delete loader; } } diff --git a/src/sensors/qsensorpluginloader_p.h b/src/sensors/qsensorpluginloader_p.h index d51b5b7c..552b3264 100644 --- a/src/sensors/qsensorpluginloader_p.h +++ b/src/sensors/qsensorpluginloader_p.h @@ -72,7 +72,6 @@ private: void load(); QList m_plugins; - QList m_loaders; }; QT_END_NAMESPACE -- cgit v1.2.3