diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-08-13 10:47:48 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-08-18 19:59:29 +0000 |
commit | 1f437e7540cbdfca8adcad0b69ae26237846ab23 (patch) | |
tree | 283142e8668103c0025d0d31884a2438638394b8 /src/corelib/plugin | |
parent | 0b1f439cb294eb4c6e1fe2855b68534e683a165f (diff) |
Reorder code in qfactoryloader.cpp
This allows us to introduce loading of static plugins with
QT_NO_LIBRARY set, using a minimal number of #ifdefs.
Also, drop the unused unloadPath() declaration.
Change-Id: Ifb1c096e5d349f17cfa51d44bfd917e1d4d2d27e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 87 |
1 files changed, 41 insertions, 46 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index cc5aa1394a..daecf0d3b0 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -50,10 +50,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders) - -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive)) - namespace { // avoid duplicate QStringLiteral data: @@ -69,18 +65,20 @@ class QFactoryLoaderPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QFactoryLoader) public: QFactoryLoaderPrivate(){} + QByteArray iid; ~QFactoryLoaderPrivate(); mutable QMutex mutex; - QByteArray iid; QList<QLibraryPrivate*> libraryList; QMap<QString,QLibraryPrivate*> keyMap; QString suffix; Qt::CaseSensitivity cs; QStringList loadedPaths; - - void unloadPath(const QString &path); }; +Q_GLOBAL_STATIC(QList<QFactoryLoader *>, qt_factory_loaders) + +Q_GLOBAL_STATIC_WITH_ARGS(QMutex, qt_factoryloader_mutex, (QMutex::Recursive)) + QFactoryLoaderPrivate::~QFactoryLoaderPrivate() { for (int i = 0; i < libraryList.count(); ++i) { @@ -90,25 +88,6 @@ QFactoryLoaderPrivate::~QFactoryLoaderPrivate() } } -QFactoryLoader::QFactoryLoader(const char *iid, - const QString &suffix, - Qt::CaseSensitivity cs) - : QObject(*new QFactoryLoaderPrivate) -{ - moveToThread(QCoreApplicationPrivate::mainThread()); - Q_D(QFactoryLoader); - d->iid = iid; - d->cs = cs; - d->suffix = suffix; - - - QMutexLocker locker(qt_factoryloader_mutex()); - update(); - qt_factory_loaders()->append(this); -} - - - void QFactoryLoader::update() { #ifdef QT_SHARED @@ -229,11 +208,45 @@ QFactoryLoader::~QFactoryLoader() qt_factory_loaders()->removeAll(this); } +#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) +QLibraryPrivate *QFactoryLoader::library(const QString &key) const +{ + Q_D(const QFactoryLoader); + return d->keyMap.value(d->cs ? key : key.toLower()); +} +#endif + +void QFactoryLoader::refreshAll() +{ + QMutexLocker locker(qt_factoryloader_mutex()); + QList<QFactoryLoader *> *loaders = qt_factory_loaders(); + for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin(); + it != loaders->constEnd(); ++it) { + (*it)->update(); + } +} + +QFactoryLoader::QFactoryLoader(const char *iid, + const QString &suffix, + Qt::CaseSensitivity cs) + : QObject(*new QFactoryLoaderPrivate) +{ + moveToThread(QCoreApplicationPrivate::mainThread()); + Q_D(QFactoryLoader); + d->iid = iid; + d->cs = cs; + d->suffix = suffix; + + QMutexLocker locker(qt_factoryloader_mutex()); + update(); + qt_factory_loaders()->append(this); +} + QList<QJsonObject> QFactoryLoader::metaData() const { Q_D(const QFactoryLoader); - QMutexLocker locker(&d->mutex); QList<QJsonObject> metaData; + QMutexLocker locker(&d->mutex); for (int i = 0; i < d->libraryList.size(); ++i) metaData.append(d->libraryList.at(i)->metaData); @@ -266,8 +279,8 @@ QObject *QFactoryLoader::instance(int index) const } return 0; } - index -= d->libraryList.size(); + QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins(); for (int i = 0; i < staticPlugins.count(); ++i) { const QJsonObject object = staticPlugins.at(i).metaData(); @@ -282,24 +295,6 @@ QObject *QFactoryLoader::instance(int index) const return 0; } -#if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) -QLibraryPrivate *QFactoryLoader::library(const QString &key) const -{ - Q_D(const QFactoryLoader); - return d->keyMap.value(d->cs ? key : key.toLower()); -} -#endif - -void QFactoryLoader::refreshAll() -{ - QMutexLocker locker(qt_factoryloader_mutex()); - QList<QFactoryLoader *> *loaders = qt_factory_loaders(); - for (QList<QFactoryLoader *>::const_iterator it = loaders->constBegin(); - it != loaders->constEnd(); ++it) { - (*it)->update(); - } -} - QMultiMap<int, QString> QFactoryLoader::keyMap() const { QMultiMap<int, QString> result; |