diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-11-26 15:22:47 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-02-14 14:28:04 (GMT) |
commit | 9d21531d218347342e22842289265f0bee2b322e (patch) | |
tree | fd5e0ec9e9d84befdcc45a918a11147cdf96eaa1 | |
parent | cddc9c443d7422a6d1f4e43e9094faa94b8f4958 (diff) | |
download | Qt-9d21531d218347342e22842289265f0bee2b322e.zip Qt-9d21531d218347342e22842289265f0bee2b322e.tar.gz Qt-9d21531d218347342e22842289265f0bee2b322e.tar.bz2 |
QDeclarativeDebug: Move Tcp server to separate plugin
Reviewed-by: Christiaan Janssen
(cherry picked from commit 21016c3b28674029a2a205da38f54e362e3635b9)
-rw-r--r-- | src/declarative/debugger/debugger.pri | 4 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugserver.cpp | 50 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugserver_p.h | 2 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugserverconnection_p.h | 9 | ||||
-rw-r--r-- | src/declarative/debugger/qpacketprotocol_p.h | 4 | ||||
-rw-r--r-- | src/plugins/plugins.pro | 3 | ||||
-rw-r--r-- | src/plugins/qmldebugging/qmldebugging.pro | 4 | ||||
-rw-r--r-- | src/plugins/qmldebugging/tcpserver/qtcpserverconnection.cpp (renamed from src/declarative/debugger/qdeclarativedebugservertcpconnection.cpp) | 74 | ||||
-rw-r--r-- | src/plugins/qmldebugging/tcpserver/qtcpserverconnection.h (renamed from src/declarative/debugger/qdeclarativedebugservertcpconnection_p.h) | 36 | ||||
-rw-r--r-- | src/plugins/qmldebugging/tcpserver/tcpserver.pro | 18 |
10 files changed, 136 insertions, 68 deletions
diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index e7354dc..9152677 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -8,8 +8,7 @@ SOURCES += \ $$PWD/qdeclarativedebug.cpp \ $$PWD/qdeclarativedebugtrace.cpp \ $$PWD/qdeclarativedebughelper.cpp \ - $$PWD/qdeclarativedebugserver.cpp \ - $$PWD/qdeclarativedebugservertcpconnection.cpp + $$PWD/qdeclarativedebugserver.cpp HEADERS += \ $$PWD/qdeclarativedebuggerstatus_p.h \ @@ -22,5 +21,4 @@ HEADERS += \ $$PWD/qdeclarativedebughelper_p.h \ $$PWD/qdeclarativedebugserverplugin_p.h \ $$PWD/qdeclarativedebugserver_p.h \ - $$PWD/qdeclarativedebugservertcpconnection_p.h \ debugger/qdeclarativedebugserverconnection_p.h diff --git a/src/declarative/debugger/qdeclarativedebugserver.cpp b/src/declarative/debugger/qdeclarativedebugserver.cpp index 6085e3e..a269984 100644 --- a/src/declarative/debugger/qdeclarativedebugserver.cpp +++ b/src/declarative/debugger/qdeclarativedebugserver.cpp @@ -42,9 +42,10 @@ #include "private/qdeclarativedebugserver_p.h" #include "private/qdeclarativedebugservice_p.h" #include "private/qdeclarativedebugservice_p_p.h" -#include "private/qdeclarativedebugservertcpconnection_p.h" #include "private/qdeclarativeengine_p.h" +#include <QtCore/QDir> +#include <QtCore/QPluginLoader> #include <QtCore/QStringList> #include <private/qobject_p.h> @@ -89,6 +90,8 @@ public: QHash<QString, QDeclarativeDebugService *> plugins; QStringList clientPlugins; bool gotHello; + + static QDeclarativeDebugServerConnection *loadConnectionPlugin(); }; QDeclarativeDebugServerPrivate::QDeclarativeDebugServerPrivate() : @@ -110,6 +113,36 @@ void QDeclarativeDebugServerPrivate::advertisePlugins() connection->send(message); } +QDeclarativeDebugServerConnection *QDeclarativeDebugServerPrivate::loadConnectionPlugin() +{ + QStringList pluginCandidates; + const QStringList paths = QCoreApplication::libraryPaths(); + foreach (const QString &libPath, paths) { + const QDir dir(libPath + QLatin1String("/qmldebugging")); + if (dir.exists()) { + QStringList plugins(dir.entryList(QDir::Files)); + foreach (const QString &pluginPath, plugins) { + pluginCandidates << dir.absoluteFilePath(pluginPath); + } + } + } + + foreach (const QString &pluginPath, pluginCandidates) { + QPluginLoader loader(pluginPath); + if (!loader.load()) { + continue; + } + QDeclarativeDebugServerConnection *connection = 0; + if (QObject *instance = loader.instance()) + connection = qobject_cast<QDeclarativeDebugServerConnection*>(instance); + + if (connection) + return connection; + loader.unload(); + } + return 0; +} + bool QDeclarativeDebugServer::hasDebuggingClient() const { Q_D(const QDeclarativeDebugServer); @@ -153,15 +186,18 @@ QDeclarativeDebugServer *QDeclarativeDebugServer::instance() if (ok) { server = new QDeclarativeDebugServer(); - QDeclarativeDebugServerTcpConnection *tcpConnection - = new QDeclarativeDebugServerTcpConnection(port, server); + QDeclarativeDebugServerConnection *connection + = QDeclarativeDebugServerPrivate::loadConnectionPlugin(); + if (connection) { + server->d_func()->connection = connection; - tcpConnection->listen(); - if (block) { - tcpConnection->waitForConnection(); + connection->setServer(server); + connection->setPort(port, block); + } else { + qWarning() << QString::fromAscii("QDeclarativeDebugServer: Ignoring\"-qmljsdebugger=%1\". " + "Remote debugger plugin has not been found.").arg(appD->qmljsDebugArgumentsString()); } - server->d_func()->connection = tcpConnection; } else { qWarning(QString::fromAscii("QDeclarativeDebugServer: Ignoring \"-qmljsdebugger=%1\". " "Format is -qmljsdebugger=port:<port>[,block]").arg( diff --git a/src/declarative/debugger/qdeclarativedebugserver_p.h b/src/declarative/debugger/qdeclarativedebugserver_p.h index 93ab10b..ec3e60f 100644 --- a/src/declarative/debugger/qdeclarativedebugserver_p.h +++ b/src/declarative/debugger/qdeclarativedebugserver_p.h @@ -54,7 +54,7 @@ QT_MODULE(Declarative) class QDeclarativeDebugService; class QDeclarativeDebugServerPrivate; -class QDeclarativeDebugServer : public QObject +class Q_DECLARATIVE_EXPORT QDeclarativeDebugServer : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeDebugServer) diff --git a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h index 4175126..631da74 100644 --- a/src/declarative/debugger/qdeclarativedebugserverconnection_p.h +++ b/src/declarative/debugger/qdeclarativedebugserverconnection_p.h @@ -42,7 +42,7 @@ #ifndef QDECLARATIVEDEBUGSERVERCONNECTION_H #define QDECLARATIVEDEBUGSERVERCONNECTION_H -#include <private/qdeclarativeglobal_p.h> +#include <QtDeclarative/private/qdeclarativeglobal_p.h> QT_BEGIN_HEADER @@ -50,17 +50,22 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeDebugServerConnection +class QDeclarativeDebugServer; +class Q_DECLARATIVE_EXPORT QDeclarativeDebugServerConnection { public: QDeclarativeDebugServerConnection() {} virtual ~QDeclarativeDebugServerConnection() {} + virtual void setServer(QDeclarativeDebugServer *server) = 0; + virtual void setPort(int port, bool bock) = 0; virtual bool isConnected() const = 0; virtual void send(const QByteArray &message) = 0; virtual void disconnect() = 0; }; +Q_DECLARE_INTERFACE(QDeclarativeDebugServerConnection, "com.trolltech.Qt.QDeclarativeDebugServerConnection/1.0") + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/debugger/qpacketprotocol_p.h b/src/declarative/debugger/qpacketprotocol_p.h index bcf4fe4..accb8ef 100644 --- a/src/declarative/debugger/qpacketprotocol_p.h +++ b/src/declarative/debugger/qpacketprotocol_p.h @@ -59,7 +59,7 @@ class QPacket; class QPacketAutoSend; class QPacketProtocolPrivate; -class Q_DECLARATIVE_PRIVATE_EXPORT QPacketProtocol : public QObject +class Q_DECLARATIVE_EXPORT QPacketProtocol : public QObject { Q_OBJECT public: @@ -89,7 +89,7 @@ private: }; -class Q_DECLARATIVE_PRIVATE_EXPORT QPacket : public QDataStream +class Q_DECLARATIVE_EXPORT QPacket : public QDataStream { public: QPacket(); diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 722979d..07825d9 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -14,5 +14,4 @@ embedded:SUBDIRS *= gfxdrivers decorations mousedrivers kbddrivers symbian:SUBDIRS += s60 contains(QT_CONFIG, phonon): SUBDIRS *= phonon contains(QT_CONFIG, multimedia): SUBDIRS *= audio - - +contains(QT_CONFIG, declarative): SUBDIRS *= qmldebugging diff --git a/src/plugins/qmldebugging/qmldebugging.pro b/src/plugins/qmldebugging/qmldebugging.pro new file mode 100644 index 0000000..01cf1a9 --- /dev/null +++ b/src/plugins/qmldebugging/qmldebugging.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS = tcpserver + diff --git a/src/declarative/debugger/qdeclarativedebugservertcpconnection.cpp b/src/plugins/qmldebugging/tcpserver/qtcpserverconnection.cpp index 223c875..69c1ef5 100644 --- a/src/declarative/debugger/qdeclarativedebugservertcpconnection.cpp +++ b/src/plugins/qmldebugging/tcpserver/qtcpserverconnection.cpp @@ -39,20 +39,19 @@ ** ****************************************************************************/ -#include "qdeclarativedebugservertcpconnection_p.h" - -#include "qdeclarativedebugserver_p.h" -#include "private/qpacketprotocol_p.h" +#include "qtcpserverconnection.h" #include <QtNetwork/qtcpserver.h> #include <QtNetwork/qtcpsocket.h> +#include <private/qdeclarativedebugserver_p.h> +#include <private/qpacketprotocol_p.h> QT_BEGIN_NAMESPACE -class QDeclarativeDebugServerTcpConnectionPrivate { +class QTcpServerConnectionPrivate { public: - QDeclarativeDebugServerTcpConnectionPrivate(); + QTcpServerConnectionPrivate(); int port; QTcpSocket *socket; @@ -62,7 +61,7 @@ public: QDeclarativeDebugServer *debugServer; }; -QDeclarativeDebugServerTcpConnectionPrivate::QDeclarativeDebugServerTcpConnectionPrivate() : +QTcpServerConnectionPrivate::QTcpServerConnectionPrivate() : port(0), socket(0), protocol(0), @@ -71,29 +70,32 @@ QDeclarativeDebugServerTcpConnectionPrivate::QDeclarativeDebugServerTcpConnectio { } -QDeclarativeDebugServerTcpConnection::QDeclarativeDebugServerTcpConnection(int port, QDeclarativeDebugServer *server) : - QObject(server), - d_ptr(new QDeclarativeDebugServerTcpConnectionPrivate) +QTcpServerConnection::QTcpServerConnection() : + d_ptr(new QTcpServerConnectionPrivate) { - Q_D(QDeclarativeDebugServerTcpConnection); - d->port = port; - d->debugServer = server; + } -QDeclarativeDebugServerTcpConnection::~QDeclarativeDebugServerTcpConnection() +QTcpServerConnection::~QTcpServerConnection() { delete d_ptr; } -bool QDeclarativeDebugServerTcpConnection::isConnected() const +void QTcpServerConnection::setServer(QDeclarativeDebugServer *server) { - Q_D(const QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); + d->debugServer = server; +} + +bool QTcpServerConnection::isConnected() const +{ + Q_D(const QTcpServerConnection); return d->socket && d->socket->state() == QTcpSocket::ConnectedState; } -void QDeclarativeDebugServerTcpConnection::send(const QByteArray &message) +void QTcpServerConnection::send(const QByteArray &message) { - Q_D(QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); if (!isConnected()) return; @@ -105,9 +107,9 @@ void QDeclarativeDebugServerTcpConnection::send(const QByteArray &message) d->socket->flush(); } -void QDeclarativeDebugServerTcpConnection::disconnect() +void QTcpServerConnection::disconnect() { - Q_D(QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); delete d->protocol; d->protocol = 0; @@ -115,9 +117,19 @@ void QDeclarativeDebugServerTcpConnection::disconnect() d->socket = 0; } -void QDeclarativeDebugServerTcpConnection::listen() +void QTcpServerConnection::setPort(int port, bool block) { - Q_D(QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); + d->port = port; + + listen(); + if (block) + d->tcpServer->waitForNewConnection(-1); +} + +void QTcpServerConnection::listen() +{ + Q_D(QTcpServerConnection); d->tcpServer = new QTcpServer(this); QObject::connect(d->tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection())); @@ -127,27 +139,22 @@ void QDeclarativeDebugServerTcpConnection::listen() qWarning("QDeclarativeDebugServer: Unable to listen on port %d", d->port); } -void QDeclarativeDebugServerTcpConnection::waitForConnection() -{ - Q_D(QDeclarativeDebugServerTcpConnection); - d->tcpServer->waitForNewConnection(-1); -} -void QDeclarativeDebugServerTcpConnection::readyRead() +void QTcpServerConnection::readyRead() { - Q_D(QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); QPacket packet = d->protocol->read(); QByteArray content = packet.data(); d->debugServer->receiveMessage(content); } -void QDeclarativeDebugServerTcpConnection::newConnection() +void QTcpServerConnection::newConnection() { - Q_D(QDeclarativeDebugServerTcpConnection); + Q_D(QTcpServerConnection); if (d->socket) { - qWarning("QDeclarativeDebugServer error: another client is already connected"); + qWarning("QDeclarativeDebugServer: Another client is already connected"); QTcpSocket *faultyConnection = d->tcpServer->nextPendingConnection(); delete faultyConnection; return; @@ -160,4 +167,7 @@ void QDeclarativeDebugServerTcpConnection::newConnection() } +Q_EXPORT_PLUGIN2(tcpserver, QTcpServerConnection) + QT_END_NAMESPACE + diff --git a/src/declarative/debugger/qdeclarativedebugservertcpconnection_p.h b/src/plugins/qmldebugging/tcpserver/qtcpserverconnection.h index f1c749ef..a6e17e6 100644 --- a/src/declarative/debugger/qdeclarativedebugservertcpconnection_p.h +++ b/src/plugins/qmldebugging/tcpserver/qtcpserverconnection.h @@ -39,30 +39,30 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEDEBUGSERVERTCPCONNECTION_H -#define QDECLARATIVEDEBUGSERVERTCPCONNECTION_H +#ifndef QTCPSERVERCONNECTION_H +#define QTCPSERVERCONNECTION_H -#include <private/qdeclarativeglobal_p.h> - -QT_BEGIN_HEADER +#include <QtGui/QStylePlugin> +#include <QtDeclarative/private/qdeclarativedebugserverconnection_p.h> QT_BEGIN_NAMESPACE -QT_MODULE(Declarative) - -#include <qdeclarativedebugserverconnection_p.h> - class QDeclarativeDebugServer; -class QDeclarativeDebugServerTcpConnectionPrivate; -class QDeclarativeDebugServerTcpConnection : public QObject, public QDeclarativeDebugServerConnection +class QTcpServerConnectionPrivate; +class QTcpServerConnection : public QObject, public QDeclarativeDebugServerConnection { Q_OBJECT - Q_DECLARE_PRIVATE(QDeclarativeDebugServerTcpConnection) - Q_DISABLE_COPY(QDeclarativeDebugServerTcpConnection) + Q_DECLARE_PRIVATE(QTcpServerConnection) + Q_DISABLE_COPY(QTcpServerConnection) + Q_INTERFACES(QDeclarativeDebugServerConnection) + public: - QDeclarativeDebugServerTcpConnection(int port, QDeclarativeDebugServer *server); - ~QDeclarativeDebugServerTcpConnection(); + QTcpServerConnection(); + ~QTcpServerConnection(); + + void setServer(QDeclarativeDebugServer *server); + void setPort(int port, bool bock); bool isConnected() const; void send(const QByteArray &message); @@ -76,11 +76,9 @@ private Q_SLOTS: void newConnection(); private: - QDeclarativeDebugServerTcpConnectionPrivate *d_ptr; + QTcpServerConnectionPrivate *d_ptr; }; QT_END_NAMESPACE -QT_END_HEADER - -#endif // QDECLARATIVEDEBUGSERVERTCPCONNECTION_H +#endif // QTCPSERVERCONNECTION_H diff --git a/src/plugins/qmldebugging/tcpserver/tcpserver.pro b/src/plugins/qmldebugging/tcpserver/tcpserver.pro new file mode 100644 index 0000000..e90fb34 --- /dev/null +++ b/src/plugins/qmldebugging/tcpserver/tcpserver.pro @@ -0,0 +1,18 @@ +TARGET = tcpserver +QT += declarative network + +include(../../qpluginbase.pri) + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/qmldebugging +QTDIR_build:REQUIRES += "contains(QT_CONFIG, declarative)" + +SOURCES += \ + qtcpserverconnection.cpp + +HEADERS += \ + qtcpserverconnection.h + +target.path += $$[QT_INSTALL_PLUGINS]/qmldebugging +INSTALLS += target + +symbian:TARGET.UID3=0x20031E90
\ No newline at end of file |