From 2f190e21c82c7b20f6cf1b9e5671316cd831f684 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 15 Jul 2015 15:19:50 +0200 Subject: Use QQmlDebugPluginManager for loading connection plugins Also remove all the hacks that deal with static builds, QT_NO_LIBRARY and friends. QQmlDebugPluginManager handles those cases. Change-Id: I62f13b787292108fa25d09fabc775332394989be Reviewed-by: Simon Hausmann --- .../qmldbg_local/qlocalclientconnection.cpp | 5 ++ .../qmldbg_local/qlocalclientconnection.h | 11 +++- .../qmldbg_local/qlocalclientconnection.json | 3 + .../qmltooling/qmldbg_local/qmldbg_local.pro | 5 +- .../qmltooling/qmldbg_server/qqmldebugserver.cpp | 77 +++------------------- src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro | 5 +- .../qmltooling/qmldbg_tcp/qtcpserverconnection.cpp | 5 ++ .../qmltooling/qmldbg_tcp/qtcpserverconnection.h | 11 +++- .../qmldbg_tcp/qtcpserverconnection.json | 3 + .../qmltooling/shared/qqmldebugserverconnection.h | 10 ++- 10 files changed, 58 insertions(+), 77 deletions(-) create mode 100644 src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.json create mode 100644 src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.json (limited to 'src/plugins') diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp index cf4512cc6e..993bafcf9f 100644 --- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp +++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp @@ -142,4 +142,9 @@ void QLocalClientConnection::connectionEstablished() d->debugServer->setDevice(d->socket); } +QQmlDebugServerConnection *QLocalClientConnectionFactory::create(const QString &key) +{ + return (key == QLatin1String("QLocalClientConnection") ? new QLocalClientConnection : 0); +} + QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h index 4d20b8db2f..119f29921b 100644 --- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h +++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h @@ -44,8 +44,6 @@ class QLocalClientConnection : public QObject, public QQmlDebugServerConnection Q_OBJECT Q_DECLARE_PRIVATE(QLocalClientConnection) Q_DISABLE_COPY(QLocalClientConnection) - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlDebugServerConnection") - Q_INTERFACES(QQmlDebugServerConnection) public: QLocalClientConnection(); @@ -70,6 +68,15 @@ private: QLocalClientConnectionPrivate *d_ptr; }; +class QLocalClientConnectionFactory : public QQmlDebugServerConnectionFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE "qlocalclientconnection.json") + Q_INTERFACES(QQmlDebugServerConnectionFactory) +public: + QQmlDebugServerConnection *create(const QString &key); +}; + QT_END_NAMESPACE #endif // QLOCALCLIENTCONNECTION_H diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.json b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.json new file mode 100644 index 0000000000..5f8fd49296 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QLocalClientConnection" ] +} diff --git a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro index 4fa05234e6..f190368441 100644 --- a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro +++ b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro @@ -2,7 +2,7 @@ TARGET = qmldbg_local QT = qml-private PLUGIN_TYPE = qmltooling -PLUGIN_CLASS_NAME = QLocalClientConnection +PLUGIN_CLASS_NAME = QLocalClientConnectionFactory load(qt_plugin) SOURCES += \ @@ -15,3 +15,6 @@ HEADERS += \ INCLUDEPATH += $$PWD \ $$PWD/../shared + +OTHER_FILES += \ + $$PWD/qlocalclientconnection.json diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp index 4a4af77064..2d79777c2c 100644 --- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp +++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -49,10 +50,6 @@ #include #include -#if defined(QT_STATIC) && !defined(QT_NO_LIBRARY) -#include "../../plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h" -#endif - QT_BEGIN_NAMESPACE /* @@ -77,12 +74,11 @@ QT_BEGIN_NAMESPACE Everything send with a header different to "QDeclarativeDebugServer" is sent to the appropriate plugin. */ -const int protocolVersion = 1; +Q_QML_DEBUG_PLUGIN_LOADER(QQmlDebugServerConnection) +Q_QML_IMPORT_DEBUG_PLUGIN(QTcpServerConnectionFactory) +Q_QML_IMPORT_DEBUG_PLUGIN(QLocalClientConnectionFactory) -// print detailed information about loading of plugins -#ifndef QT_NO_LIBRARY -DEFINE_BOOL_CONFIG_OPTION(qmlDebugVerbose, QML_DEBUGGER_VERBOSE) -#endif +const int protocolVersion = 1; class QQmlDebugServerThread; class QQmlDebugServerImpl : public QQmlDebugServer @@ -143,7 +139,6 @@ private: bool canSendMessage(const QString &name); void doSendMessage(const QString &name, const QByteArray &message); - QQmlDebugServerConnection *loadConnectionPlugin(const QString &pluginName); QQmlDebugServerConnection *m_connection; QHash m_plugins; @@ -157,9 +152,6 @@ private: QWaitCondition m_helloCondition; QQmlDebugServerThread *m_thread; QPacketProtocol *m_protocol; -#ifndef QT_NO_LIBRARY - QPluginLoader m_loader; -#endif QAtomicInt m_changeServiceStateCalls; }; @@ -209,7 +201,7 @@ struct StartTcpServerAction { bool operator()(QQmlDebugServerImpl *d) { - if (!d->init(QLatin1String("qmldbg_tcp"), block)) + if (!d->init(QLatin1String("QTcpServerConnection"), block)) return false; d->m_thread->setPortRange(portFrom, portTo == -1 ? portFrom : portTo, block, hostAddress); return true; @@ -225,7 +217,7 @@ struct ConnectToLocalAction { bool operator()(QQmlDebugServerImpl *d) { - if (!d->init(QLatin1String("qmldbg_local"), block)) + if (!d->init(QLatin1String("QLocalClientConnection"), block)) return false; d->m_thread->setFileName(fileName, block); return true; @@ -263,63 +255,10 @@ void QQmlDebugServerImpl::cleanup() } } -QQmlDebugServerConnection *QQmlDebugServerImpl::loadConnectionPlugin(const QString &pluginName) -{ -#ifndef QT_NO_LIBRARY - QStringList pluginCandidates; - const QStringList paths = QCoreApplication::libraryPaths(); - foreach (const QString &libPath, paths) { - const QDir dir(libPath + QLatin1String("/qmltooling")); - if (dir.exists()) { - QStringList plugins(dir.entryList(QDir::Files)); - foreach (const QString &pluginPath, plugins) { - if (QFileInfo(pluginPath).fileName().contains(pluginName)) - pluginCandidates << dir.absoluteFilePath(pluginPath); - } - } - } - - QQmlDebugServerConnection *loadedConnection = 0; - foreach (const QString &pluginPath, pluginCandidates) { - if (qmlDebugVerbose()) - qDebug() << "QML Debugger: Trying to load plugin " << pluginPath << "..."; - - m_loader.setFileName(pluginPath); - if (!m_loader.load()) { - if (qmlDebugVerbose()) - qDebug() << "QML Debugger: Error while loading: " << m_loader.errorString(); - continue; - } - if (QObject *instance = m_loader.instance()) - loadedConnection = qobject_cast(instance); - - if (loadedConnection) { - if (qmlDebugVerbose()) - qDebug() << "QML Debugger: Plugin successfully loaded."; - - return loadedConnection; - } - - if (qmlDebugVerbose()) - qDebug() << "QML Debugger: Plugin does not implement interface QQmlDebugServerConnection."; - - m_loader.unload(); - } -#else - Q_UNUSED(pluginName); -#endif - return 0; -} - void QQmlDebugServerThread::run() { Q_ASSERT_X(m_server != 0, Q_FUNC_INFO, "There should always be a debug server available here."); -#if defined(QT_STATIC) && !defined(QT_NO_LIBRARY) - QQmlDebugServerConnection *connection - = new QTcpServerConnection; -#else - QQmlDebugServerConnection *connection = m_server->loadConnectionPlugin(m_pluginName); -#endif + QQmlDebugServerConnection *connection = loadQQmlDebugServerConnection(m_pluginName); if (connection) { connection->setServer(m_server); diff --git a/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro b/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro index 15ba7c730a..b6d25e0e9e 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro +++ b/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro @@ -2,7 +2,7 @@ TARGET = qmldbg_tcp QT = qml-private network PLUGIN_TYPE = qmltooling -PLUGIN_CLASS_NAME = QTcpServerConnection +PLUGIN_CLASS_NAME = QTcpServerConnectionFactory load(qt_plugin) SOURCES += \ @@ -15,3 +15,6 @@ HEADERS += \ INCLUDEPATH += $$PWD \ $$PWD/../shared + +OTHER_FILES += \ + $$PWD/qtcpserverconnection.json diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp index 7734e5ed0d..689c98f2b9 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp +++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp @@ -189,4 +189,9 @@ void QTcpServerConnection::newConnection() d->debugServer->setDevice(d->socket); } +QQmlDebugServerConnection *QTcpServerConnectionFactory::create(const QString &key) +{ + return (key == QLatin1String("QTcpServerConnection") ? new QTcpServerConnection : 0); +} + QT_END_NAMESPACE diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h index 8b2aed0b55..f405e83aac 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h +++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h @@ -44,8 +44,6 @@ class QTcpServerConnection : public QObject, public QQmlDebugServerConnection Q_OBJECT Q_DECLARE_PRIVATE(QTcpServerConnection) Q_DISABLE_COPY(QTcpServerConnection) - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlDebugServerConnection") - Q_INTERFACES(QQmlDebugServerConnection) public: QTcpServerConnection(); @@ -70,6 +68,15 @@ private: QTcpServerConnectionPrivate *d_ptr; }; +class QTcpServerConnectionFactory : public QQmlDebugServerConnectionFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE "qtcpserverconnection.json") + Q_INTERFACES(QQmlDebugServerConnectionFactory) +public: + QQmlDebugServerConnection *create(const QString &key); +}; + QT_END_NAMESPACE #endif // QTCPSERVERCONNECTION_H diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.json b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.json new file mode 100644 index 0000000000..201a1b3fcb --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "QTcpServerConnection" ] +} diff --git a/src/plugins/qmltooling/shared/qqmldebugserverconnection.h b/src/plugins/qmltooling/shared/qqmldebugserverconnection.h index 04e4c056ac..03cbe19321 100644 --- a/src/plugins/qmltooling/shared/qqmldebugserverconnection.h +++ b/src/plugins/qmltooling/shared/qqmldebugserverconnection.h @@ -66,9 +66,15 @@ public: virtual void flush() = 0; }; -#define QQmlDebugServerConnection_iid "org.qt-project.Qt.QQmlDebugServerConnection" +class QQmlDebugServerConnectionFactory : public QObject +{ + Q_OBJECT +public: + virtual QQmlDebugServerConnection *create(const QString &key) = 0; +}; -Q_DECLARE_INTERFACE(QQmlDebugServerConnection, QQmlDebugServerConnection_iid) +#define QQmlDebugServerConnectionFactory_iid "org.qt-project.Qt.QQmlDebugServerConnectionFactory" +Q_DECLARE_INTERFACE(QQmlDebugServerConnectionFactory, QQmlDebugServerConnectionFactory_iid) QT_END_NAMESPACE -- cgit v1.2.3