From 07f19d36347d69c330e092e3cb4fc351a8815d5c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 15 Jul 2015 15:42:10 +0200 Subject: 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 --- .../qmltooling/qmldbg_tcp/qtcpserverconnection.cpp | 134 +++++++++++---------- 1 file changed, 69 insertions(+), 65 deletions(-) (limited to 'src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp') diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp index 689c98f2b9..c8010a4aa9 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 @@ -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" -- cgit v1.2.3