diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-07-15 15:42:10 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-08-04 13:34:55 +0000 |
commit | 07f19d36347d69c330e092e3cb4fc351a8815d5c (patch) | |
tree | 621e882a9f11d8d89760e327e32d1a3574404394 /src/plugins | |
parent | 2f190e21c82c7b20f6cf1b9e5671316cd831f684 (diff) | |
download | qtdeclarative-07f19d36347d69c330e092e3cb4fc351a8815d5c.tar.gz qtdeclarative-07f19d36347d69c330e092e3cb4fc351a8815d5c.tar.bz2 qtdeclarative-07f19d36347d69c330e092e3cb4fc351a8815d5c.zip |
Remove pimpl from debug server connections
Now that they are self-contained plugins there is no reason for the
indirection anymore.
Change-Id: Ic2e2fe2075796c758057235e12981c8d40ce97c2
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp | 95 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h (renamed from src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h) | 36 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro | 2 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro | 2 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp | 134 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h (renamed from src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h) | 36 | ||||
-rw-r--r-- | src/plugins/qmltooling/shared/qqmldebugserverconnection.h | 7 |
7 files changed, 132 insertions, 180 deletions
diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp index 993bafcf9..057bf9523 100644 --- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp +++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp @@ -31,7 +31,7 @@ ** ****************************************************************************/ -#include "qlocalclientconnection.h" +#include "qlocalclientconnectionfactory.h" #include "qpacketprotocol.h" #include "qqmldebugserver.h" @@ -40,25 +40,42 @@ QT_BEGIN_NAMESPACE -class QLocalClientConnectionPrivate { + +class QLocalClientConnection : public QQmlDebugServerConnection +{ + Q_OBJECT + Q_DISABLE_COPY(QLocalClientConnection) + public: - QLocalClientConnectionPrivate(); + QLocalClientConnection(); + ~QLocalClientConnection(); - bool block; - QString filename; - QLocalSocket *socket; - QQmlDebugServer *debugServer; -}; + void setServer(QQmlDebugServer *server); + bool setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress); + bool setFileName(const QString &filename, bool block); -QLocalClientConnectionPrivate::QLocalClientConnectionPrivate() : - block(false), - socket(0), - debugServer(0) -{ -} + bool isConnected() const; + void disconnect(); + + void waitForConnection(); + void flush(); + +private slots: + void connectionEstablished(); + +private: + bool connectToServer(); + + bool m_block; + QString m_filename; + QLocalSocket *m_socket; + QQmlDebugServer *m_debugServer; +}; QLocalClientConnection::QLocalClientConnection() : - d_ptr(new QLocalClientConnectionPrivate) + m_block(false), + m_socket(0), + m_debugServer(0) { } @@ -66,30 +83,25 @@ QLocalClientConnection::~QLocalClientConnection() { if (isConnected()) disconnect(); - delete d_ptr; } void QLocalClientConnection::setServer(QQmlDebugServer *server) { - Q_D(QLocalClientConnection); - d->debugServer = server; + m_debugServer = server; } bool QLocalClientConnection::isConnected() const { - Q_D(const QLocalClientConnection); - return d->socket && d->socket->state() == QLocalSocket::ConnectedState; + return m_socket && m_socket->state() == QLocalSocket::ConnectedState; } void QLocalClientConnection::disconnect() { - Q_D(QLocalClientConnection); - - while (d->socket && d->socket->bytesToWrite() > 0) - d->socket->waitForBytesWritten(); + while (m_socket && m_socket->bytesToWrite() > 0) + m_socket->waitForBytesWritten(); - d->socket->deleteLater(); - d->socket = 0; + m_socket->deleteLater(); + m_socket = 0; } bool QLocalClientConnection::setPortRange(int portFrom, int portTo, bool block, @@ -104,42 +116,35 @@ bool QLocalClientConnection::setPortRange(int portFrom, int portTo, bool block, bool QLocalClientConnection::setFileName(const QString &filename, bool block) { - Q_D(QLocalClientConnection); - d->filename = filename; - d->block = block; + m_filename = filename; + m_block = block; return connectToServer(); } void QLocalClientConnection::waitForConnection() { - Q_D(QLocalClientConnection); - d->socket->waitForConnected(-1); + m_socket->waitForConnected(-1); } bool QLocalClientConnection::connectToServer() { - Q_D(QLocalClientConnection); - - d->socket = new QLocalSocket; - d->socket->setParent(this); - QObject::connect(d->socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); - d->socket->connectToServer(d->filename); - qDebug("QML Debugger: Connecting to socket %s...", - d->filename.toLatin1().constData()); + m_socket = new QLocalSocket; + m_socket->setParent(this); + QObject::connect(m_socket, SIGNAL(connected()), this, SLOT(connectionEstablished())); + m_socket->connectToServer(m_filename); + qDebug("QML Debugger: Connecting to socket %s...", m_filename.toLatin1().constData()); return true; } void QLocalClientConnection::flush() { - Q_D(QLocalClientConnection); - if (d->socket) - d->socket->flush(); + if (m_socket) + m_socket->flush(); } void QLocalClientConnection::connectionEstablished() { - Q_D(QLocalClientConnection); - d->debugServer->setDevice(d->socket); + m_debugServer->setDevice(m_socket); } QQmlDebugServerConnection *QLocalClientConnectionFactory::create(const QString &key) @@ -148,3 +153,5 @@ QQmlDebugServerConnection *QLocalClientConnectionFactory::create(const QString & } QT_END_NAMESPACE + +#include "qlocalclientconnection.moc" diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h index 119f29921..110e0c239 100644 --- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.h +++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h @@ -31,43 +31,13 @@ ** ****************************************************************************/ -#ifndef QLOCALCLIENTCONNECTION_H -#define QLOCALCLIENTCONNECTION_H +#ifndef QLOCALCLIENTCONNECTIONFACTORY_H +#define QLOCALCLIENTCONNECTIONFACTORY_H #include "qqmldebugserverconnection.h" QT_BEGIN_NAMESPACE -class QLocalClientConnectionPrivate; -class QLocalClientConnection : public QObject, public QQmlDebugServerConnection -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QLocalClientConnection) - Q_DISABLE_COPY(QLocalClientConnection) - -public: - QLocalClientConnection(); - ~QLocalClientConnection(); - - void setServer(QQmlDebugServer *server); - bool setPortRange(int portFrom, int portTo, bool bock, const QString &hostaddress); - bool setFileName(const QString &filename, bool block); - - bool isConnected() const; - void disconnect(); - - void waitForConnection(); - void flush(); - -private Q_SLOTS: - void connectionEstablished(); - -private: - bool connectToServer(); - - QLocalClientConnectionPrivate *d_ptr; -}; - class QLocalClientConnectionFactory : public QQmlDebugServerConnectionFactory { Q_OBJECT @@ -79,4 +49,4 @@ public: QT_END_NAMESPACE -#endif // QLOCALCLIENTCONNECTION_H +#endif // QLOCALCLIENTCONNECTIONFACTORY_H diff --git a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro index f19036844..491be04b1 100644 --- a/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro +++ b/src/plugins/qmltooling/qmldbg_local/qmldbg_local.pro @@ -9,7 +9,7 @@ SOURCES += \ $$PWD/qlocalclientconnection.cpp HEADERS += \ - $$PWD/qlocalclientconnection.h \ + $$PWD/qlocalclientconnectionfactory.h \ $$PWD/../shared/qqmldebugserver.h \ $$PWD/../shared/qqmldebugserverconnection.h diff --git a/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro b/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro index b6d25e0e9..fd419aeb5 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro +++ b/src/plugins/qmltooling/qmldbg_tcp/qmldbg_tcp.pro @@ -9,7 +9,7 @@ SOURCES += \ $$PWD/qtcpserverconnection.cpp HEADERS += \ - $$PWD/qtcpserverconnection.h \ + $$PWD/qtcpserverconnectionfactory.h \ $$PWD/../shared/qqmldebugserver.h \ $$PWD/../shared/qqmldebugserverconnection.h diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp index 689c98f2b..c8010a4aa 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp +++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp @@ -31,7 +31,7 @@ ** ****************************************************************************/ -#include "qtcpserverconnection.h" +#include "qtcpserverconnectionfactory.h" #include "qqmldebugserver.h" #include <QtCore/qplugin.h> @@ -40,79 +40,87 @@ QT_BEGIN_NAMESPACE -class QTcpServerConnectionPrivate { +class QTcpServerConnection : public QQmlDebugServerConnection +{ + Q_OBJECT + Q_DISABLE_COPY(QTcpServerConnection) + public: - QTcpServerConnectionPrivate(); + QTcpServerConnection(); + ~QTcpServerConnection(); - int portFrom; - int portTo; - bool block; - QString hostaddress; - QTcpSocket *socket; - QTcpServer *tcpServer; + void setServer(QQmlDebugServer *server); + bool setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress); + bool setFileName(const QString &fileName, bool block); - QQmlDebugServer *debugServer; -}; + bool isConnected() const; + void disconnect(); -QTcpServerConnectionPrivate::QTcpServerConnectionPrivate() : - portFrom(0), - portTo(0), - block(false), - socket(0), - tcpServer(0), - debugServer(0) -{ -} + void waitForConnection(); + void flush(); + +private slots: + void newConnection(); + +private: + bool listen(); + + int m_portFrom; + int m_portTo; + bool m_block; + QString m_hostaddress; + QTcpSocket *m_socket; + QTcpServer *m_tcpServer; + QQmlDebugServer *m_debugServer; +}; QTcpServerConnection::QTcpServerConnection() : - d_ptr(new QTcpServerConnectionPrivate) + m_portFrom(0), + m_portTo(0), + m_block(false), + m_socket(0), + m_tcpServer(0), + m_debugServer(0) { - } QTcpServerConnection::~QTcpServerConnection() { if (isConnected()) disconnect(); - delete d_ptr; } void QTcpServerConnection::setServer(QQmlDebugServer *server) { - Q_D(QTcpServerConnection); - d->debugServer = server; + m_debugServer = server; } bool QTcpServerConnection::isConnected() const { - Q_D(const QTcpServerConnection); - return d->socket && d->socket->state() == QTcpSocket::ConnectedState; + return m_socket && m_socket->state() == QTcpSocket::ConnectedState; } void QTcpServerConnection::disconnect() { - Q_D(QTcpServerConnection); - - while (d->socket && d->socket->bytesToWrite() > 0) { - if (!d->socket->waitForBytesWritten()) { + while (m_socket && m_socket->bytesToWrite() > 0) { + if (!m_socket->waitForBytesWritten()) { qWarning("QML Debugger: Failed to send remaining %lld bytes on disconnect.", - d->socket->bytesToWrite()); + m_socket->bytesToWrite()); break; } } - d->socket->deleteLater(); - d->socket = 0; + m_socket->deleteLater(); + m_socket = 0; } bool QTcpServerConnection::setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress) { - Q_D(QTcpServerConnection); - d->portFrom = portFrom; - d->portTo = portTo; - d->block = block; - d->hostaddress = hostaddress; + m_portFrom = portFrom; + m_portTo = portTo; + m_block = block; + m_hostaddress = hostaddress; return listen(); } @@ -126,26 +134,22 @@ bool QTcpServerConnection::setFileName(const QString &fileName, bool block) void QTcpServerConnection::waitForConnection() { - Q_D(QTcpServerConnection); - d->tcpServer->waitForNewConnection(-1); + m_tcpServer->waitForNewConnection(-1); } void QTcpServerConnection::flush() { - Q_D(QTcpServerConnection); - if (d->socket) - d->socket->flush(); + if (m_socket) + m_socket->flush(); } bool QTcpServerConnection::listen() { - Q_D(QTcpServerConnection); - - d->tcpServer = new QTcpServer(this); - QObject::connect(d->tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection())); + m_tcpServer = new QTcpServer(this); + QObject::connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection())); QHostAddress hostaddress; - if (!d->hostaddress.isEmpty()) { - if (!hostaddress.setAddress(d->hostaddress)) { + if (!m_hostaddress.isEmpty()) { + if (!hostaddress.setAddress(m_hostaddress)) { hostaddress = QHostAddress::Any; qDebug("QML Debugger: Incorrect host address provided. So accepting connections " "from any host."); @@ -153,19 +157,19 @@ bool QTcpServerConnection::listen() } else { hostaddress = QHostAddress::Any; } - int port = d->portFrom; + int port = m_portFrom; do { - if (d->tcpServer->listen(hostaddress, port)) { + if (m_tcpServer->listen(hostaddress, port)) { qDebug("QML Debugger: Waiting for connection on port %d...", port); break; } ++port; - } while (port <= d->portTo); - if (port > d->portTo) { - if (d->portFrom == d->portTo) - qWarning("QML Debugger: Unable to listen to port %d.", d->portFrom); + } while (port <= m_portTo); + if (port > m_portTo) { + if (m_portFrom == m_portTo) + qWarning("QML Debugger: Unable to listen to port %d.", m_portFrom); else - qWarning("QML Debugger: Unable to listen to ports %d - %d.", d->portFrom, d->portTo); + qWarning("QML Debugger: Unable to listen to ports %d - %d.", m_portFrom, m_portTo); return false; } else { return true; @@ -174,19 +178,17 @@ bool QTcpServerConnection::listen() void QTcpServerConnection::newConnection() { - Q_D(QTcpServerConnection); - - if (d->socket && d->socket->peerPort()) { + if (m_socket && m_socket->peerPort()) { qWarning("QML Debugger: Another client is already connected."); - QTcpSocket *faultyConnection = d->tcpServer->nextPendingConnection(); + QTcpSocket *faultyConnection = m_tcpServer->nextPendingConnection(); delete faultyConnection; return; } - delete d->socket; - d->socket = d->tcpServer->nextPendingConnection(); - d->socket->setParent(this); - d->debugServer->setDevice(d->socket); + delete m_socket; + m_socket = m_tcpServer->nextPendingConnection(); + m_socket->setParent(this); + m_debugServer->setDevice(m_socket); } QQmlDebugServerConnection *QTcpServerConnectionFactory::create(const QString &key) @@ -195,3 +197,5 @@ QQmlDebugServerConnection *QTcpServerConnectionFactory::create(const QString &ke } QT_END_NAMESPACE + +#include "qtcpserverconnection.moc" diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h index f405e83aa..97dde0308 100644 --- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h +++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h @@ -31,43 +31,13 @@ ** ****************************************************************************/ -#ifndef QTCPSERVERCONNECTION_H -#define QTCPSERVERCONNECTION_H +#ifndef QTCPSERVERCONNECTIONFACTORY_H +#define QTCPSERVERCONNECTIONFACTORY_H #include "qqmldebugserverconnection.h" QT_BEGIN_NAMESPACE -class QTcpServerConnectionPrivate; -class QTcpServerConnection : public QObject, public QQmlDebugServerConnection -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QTcpServerConnection) - Q_DISABLE_COPY(QTcpServerConnection) - -public: - QTcpServerConnection(); - ~QTcpServerConnection(); - - void setServer(QQmlDebugServer *server); - bool setPortRange(int portFrom, int portTo, bool bock, const QString &hostaddress); - bool setFileName(const QString &fileName, bool block); - - bool isConnected() const; - void disconnect(); - - void waitForConnection(); - void flush(); - -private Q_SLOTS: - void newConnection(); - -private: - bool listen(); - - QTcpServerConnectionPrivate *d_ptr; -}; - class QTcpServerConnectionFactory : public QQmlDebugServerConnectionFactory { Q_OBJECT @@ -79,4 +49,4 @@ public: QT_END_NAMESPACE -#endif // QTCPSERVERCONNECTION_H +#endif // QTCPSERVERCONNECTIONFACTORY_H diff --git a/src/plugins/qmltooling/shared/qqmldebugserverconnection.h b/src/plugins/qmltooling/shared/qqmldebugserverconnection.h index 03cbe1932..9bdb1bcc8 100644 --- a/src/plugins/qmltooling/shared/qqmldebugserverconnection.h +++ b/src/plugins/qmltooling/shared/qqmldebugserverconnection.h @@ -52,13 +52,14 @@ QT_BEGIN_NAMESPACE class QQmlDebugServer; -class QQmlDebugServerConnection +class QQmlDebugServerConnection : public QObject { + Q_OBJECT public: - virtual ~QQmlDebugServerConnection() {} + QQmlDebugServerConnection(QObject *parent = 0) : QObject(parent) {} virtual void setServer(QQmlDebugServer *server) = 0; - virtual bool setPortRange(int portFrom, int portTo, bool bock, const QString &hostaddress) = 0; + virtual bool setPortRange(int portFrom, int portTo, bool block, const QString &hostaddress) = 0; virtual bool setFileName(const QString &fileName, bool block) = 0; virtual bool isConnected() const = 0; virtual void disconnect() = 0; |