diff options
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 106 | ||||
-rw-r--r-- | src/corelib/plugin/qfactoryloader_p.h | 21 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 4 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary_p.h | 25 | ||||
-rw-r--r-- | src/corelib/plugin/qpluginloader.cpp | 15 | ||||
-rw-r--r-- | src/corelib/plugin/qpluginloader.h | 15 |
6 files changed, 106 insertions, 80 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index cc5aa1394a..f7545b5bcb 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -33,7 +33,7 @@ #include "qfactoryloader_p.h" -#ifndef QT_NO_LIBRARY +#ifndef QT_NO_QOBJECT #include "qfactoryinterface.h" #include "qmap.h" #include <qdir.h> @@ -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,24 @@ class QFactoryLoaderPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QFactoryLoader) public: QFactoryLoaderPrivate(){} + QByteArray iid; +#ifndef QT_NO_LIBRARY ~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); +#endif }; +#ifndef QT_NO_LIBRARY + +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 +92,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,13 +212,56 @@ 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(); + } +} + +#endif // QT_NO_LIBRARY + +QFactoryLoader::QFactoryLoader(const char *iid, + const QString &suffix, + Qt::CaseSensitivity cs) + : QObject(*new QFactoryLoaderPrivate) +{ + moveToThread(QCoreApplicationPrivate::mainThread()); + Q_D(QFactoryLoader); + d->iid = iid; +#ifndef QT_NO_LIBRARY + d->cs = cs; + d->suffix = suffix; + + QMutexLocker locker(qt_factoryloader_mutex()); + update(); + qt_factory_loaders()->append(this); +#else + Q_UNUSED(suffix); + Q_UNUSED(cs); +#endif +} + QList<QJsonObject> QFactoryLoader::metaData() const { Q_D(const QFactoryLoader); - QMutexLocker locker(&d->mutex); QList<QJsonObject> metaData; +#ifndef QT_NO_LIBRARY + QMutexLocker locker(&d->mutex); for (int i = 0; i < d->libraryList.size(); ++i) metaData.append(d->libraryList.at(i)->metaData); +#endif foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) { const QJsonObject object = plugin.metaData(); @@ -252,6 +278,7 @@ QObject *QFactoryLoader::instance(int index) const if (index < 0) return 0; +#ifndef QT_NO_LIBRARY if (index < d->libraryList.size()) { QLibraryPrivate *library = d->libraryList.at(index); if (library->instance || library->loadPlugin()) { @@ -266,8 +293,9 @@ QObject *QFactoryLoader::instance(int index) const } return 0; } - index -= d->libraryList.size(); +#endif + QVector<QStaticPlugin> staticPlugins = QPluginLoader::staticPlugins(); for (int i = 0; i < staticPlugins.count(); ++i) { const QJsonObject object = staticPlugins.at(i).metaData(); @@ -282,24 +310,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; @@ -335,4 +345,4 @@ int QFactoryLoader::indexOf(const QString &needle) const QT_END_NAMESPACE -#endif // QT_NO_LIBRARY +#endif // QT_NO_QOBJECT diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h index 1c48491b0d..ee07084180 100644 --- a/src/corelib/plugin/qfactoryloader_p.h +++ b/src/corelib/plugin/qfactoryloader_p.h @@ -45,17 +45,18 @@ // We mean it. // +#include "QtCore/qglobal.h" +#ifndef QT_NO_QOBJECT + #include "QtCore/qobject.h" #include "QtCore/qstringlist.h" #include "QtCore/qjsonobject.h" #include "QtCore/qmap.h" #include "private/qlibrary_p.h" -#ifndef QT_NO_LIBRARY QT_BEGIN_NAMESPACE class QFactoryLoaderPrivate; - class Q_CORE_EXPORT QFactoryLoader : public QObject { Q_OBJECT @@ -65,21 +66,23 @@ public: explicit QFactoryLoader(const char *iid, const QString &suffix = QString(), Qt::CaseSensitivity = Qt::CaseSensitive); + +#ifndef QT_NO_LIBRARY ~QFactoryLoader(); - QList<QJsonObject> metaData() const; - QObject *instance(int index) const; + void update(); + static void refreshAll(); #if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) QLibraryPrivate *library(const QString &key) const; -#endif +#endif // Q_OS_UNIX && !Q_OS_MAC +#endif // !QT_NO_LIBRARY QMultiMap<int, QString> keyMap() const; int indexOf(const QString &needle) const; - void update(); - - static void refreshAll(); + QList<QJsonObject> metaData() const; + QObject *instance(int index) const; }; template <class PluginInterface, class FactoryInterface> @@ -112,6 +115,6 @@ PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, QT_END_NAMESPACE -#endif // QT_NO_LIBRARY +#endif // QT_NO_QOBJECT #endif // QFACTORYLOADER_P_H diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 920e02ae5a..763f0fb1e9 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -302,7 +302,7 @@ static bool findPatternUnloaded(const QString &library, QLibraryPrivate *lib) if (pos >= 0) { if (hasMetaData) { const char *data = filedata + pos; - QJsonDocument doc = QLibraryPrivate::fromRawMetaData(data); + QJsonDocument doc = qJsonFromRawLibraryMetaData(data); lib->metaData = doc.object(); if (qt_debug_component()) qWarning("Found metadata in lib %s, metadata=\n%s\n", @@ -677,7 +677,7 @@ static bool qt_get_metadata(QtPluginQueryVerificationDataFunction pfn, QLibraryP if (!szData) return false; - QJsonDocument doc = QLibraryPrivate::fromRawMetaData(szData); + QJsonDocument doc = qJsonFromRawLibraryMetaData(szData); if (doc.isNull()) return false; priv->metaData = doc.object(); diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h index ada90d7bfd..11b0cb1eb9 100644 --- a/src/corelib/plugin/qlibrary_p.h +++ b/src/corelib/plugin/qlibrary_p.h @@ -57,9 +57,20 @@ # include "QtCore/qt_windows.h" #endif +QT_BEGIN_NAMESPACE + +// Needed also in case of QT_NO_LIBRARY, for static plugin loading. +inline QJsonDocument qJsonFromRawLibraryMetaData(const char *raw) +{ + raw += strlen("QTMETADATA "); + // the size of the embedded JSON object can be found 8 bytes into the data (see qjson_p.h), + // but doesn't include the size of the header (8 bytes) + QByteArray json(raw, qFromLittleEndian<uint>(*(const uint *)(raw + 8)) + 8); + return QJsonDocument::fromBinaryData(json); +} + #ifndef QT_NO_LIBRARY -QT_BEGIN_NAMESPACE bool qt_debug_component(); @@ -104,14 +115,6 @@ public: void updatePluginState(); bool isPlugin(); - static inline QJsonDocument fromRawMetaData(const char *raw) { - raw += strlen("QTMETADATA "); - // the size of the embedded JSON object can be found 8 bytes into the data (see qjson_p.h), - // but doesn't include the size of the header (8 bytes) - QByteArray json(raw, qFromLittleEndian<uint>(*(const uint *)(raw + 8)) + 8); - return QJsonDocument::fromBinaryData(json); - } - private: explicit QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints); ~QLibraryPrivate(); @@ -132,8 +135,8 @@ private: friend class QLibraryStore; }; -QT_END_NAMESPACE - #endif // QT_NO_LIBRARY +QT_END_NAMESPACE + #endif // QLIBRARY_P_H diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index 24101be87b..8264a27842 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -41,10 +41,10 @@ #include "qdebug.h" #include "qdir.h" -#ifndef QT_NO_LIBRARY - QT_BEGIN_NAMESPACE +#ifndef QT_NO_LIBRARY + /*! \class QPluginLoader \inmodule QtCore @@ -382,9 +382,6 @@ QString QPluginLoader::errorString() const return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; } -typedef QVector<QStaticPlugin> StaticPluginList; -Q_GLOBAL_STATIC(StaticPluginList, staticPluginList) - /*! \since 4.4 \property QPluginLoader::loadHints @@ -413,6 +410,11 @@ QLibrary::LoadHints QPluginLoader::loadHints() const return d ? d->loadHints() : QLibrary::LoadHints(); } +#endif // QT_NO_LIBRARY + +typedef QVector<QStaticPlugin> StaticPluginList; +Q_GLOBAL_STATIC(StaticPluginList, staticPluginList) + /*! \relates QPluginLoader \since 5.0 @@ -465,9 +467,8 @@ QVector<QStaticPlugin> QPluginLoader::staticPlugins() */ QJsonObject QStaticPlugin::metaData() const { - return QLibraryPrivate::fromRawMetaData(rawMetaData()).object(); + return qJsonFromRawLibraryMetaData(rawMetaData()).object(); } QT_END_NAMESPACE -#endif // QT_NO_LIBRARY diff --git a/src/corelib/plugin/qpluginloader.h b/src/corelib/plugin/qpluginloader.h index 0ab25bbb07..5dc7d1b66c 100644 --- a/src/corelib/plugin/qpluginloader.h +++ b/src/corelib/plugin/qpluginloader.h @@ -37,10 +37,10 @@ #include <QtCore/qlibrary.h> #include <QtCore/qplugin.h> -#ifndef QT_NO_LIBRARY - QT_BEGIN_NAMESPACE +#ifndef QT_NO_LIBRARY + class QLibraryPrivate; class QJsonObject; @@ -78,8 +78,17 @@ private: Q_DISABLE_COPY(QPluginLoader) }; -QT_END_NAMESPACE +#else + +class Q_CORE_EXPORT QPluginLoader +{ +public: + static QObjectList staticInstances(); + static QVector<QStaticPlugin> staticPlugins(); +}; #endif // QT_NO_LIBRARY +QT_END_NAMESPACE + #endif //QPLUGINLOADER_H |