summaryrefslogtreecommitdiff
path: root/src/libs/qmldebug/qmldebugclient.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@digia.com>2014-04-04 13:31:02 +0200
committerUlf Hermann <ulf.hermann@digia.com>2014-05-05 18:13:21 +0200
commitc71137c25808e77d4803606b84ddf73f2ce01a9e (patch)
treed58dbfd28daa4f2db461168fda844cde70b57811 /src/libs/qmldebug/qmldebugclient.cpp
parent60ccb2a425c2b55d15b8db75aa7b775e6752c02e (diff)
downloadqt-creator-c71137c25808e77d4803606b84ddf73f2ce01a9e.tar.gz
QmlDebug: simplify the qml debug connection
We're using exactly one method of the QIODevice API in QmlDebugConnection: errorString(), and that is just passing the error string of the internal QTcpSocket. It's hard to justify all the boilerplate code to implement QIODevice and the hackery around close() for that. Change-Id: I90b90c67c60faa73e288c1bbcd962ea64db8f76a Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/libs/qmldebug/qmldebugclient.cpp')
-rw-r--r--src/libs/qmldebug/qmldebugclient.cpp61
1 files changed, 7 insertions, 54 deletions
diff --git a/src/libs/qmldebug/qmldebugclient.cpp b/src/libs/qmldebug/qmldebugclient.cpp
index c689e1ed50..7c7d0130d5 100644
--- a/src/libs/qmldebug/qmldebugclient.cpp
+++ b/src/libs/qmldebug/qmldebugclient.cpp
@@ -67,7 +67,6 @@ public:
QHash<QString, QmlDebugClient *> plugins;
void advertisePlugins();
- void connectDeviceSignals();
public Q_SLOTS:
void connected();
@@ -78,9 +77,7 @@ public Q_SLOTS:
QmlDebugConnectionPrivate::QmlDebugConnectionPrivate(QmlDebugConnection *c)
: QObject(c), q(c), protocol(0), device(0), gotHello(false)
{
- protocol = new QPacketProtocol(q, this);
QObject::connect(c, SIGNAL(connected()), this, SLOT(connected()));
- QObject::connect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
}
void QmlDebugConnectionPrivate::advertisePlugins()
@@ -219,15 +216,8 @@ void QmlDebugConnectionPrivate::readyRead()
}
}
-void QmlDebugConnectionPrivate::deviceAboutToClose()
-{
- // This is nasty syntax but we want to emit our own aboutToClose signal (by calling QIODevice::close())
- // without calling the underlying device close fn as that would cause an infinite loop
- q->QIODevice::close();
-}
-
QmlDebugConnection::QmlDebugConnection(QObject *parent)
- : QIODevice(parent), d(new QmlDebugConnectionPrivate(this))
+ : QObject(parent), d(new QmlDebugConnectionPrivate(this))
{
}
@@ -245,36 +235,9 @@ bool QmlDebugConnection::isConnected() const
return state() == QAbstractSocket::ConnectedState;
}
-qint64 QmlDebugConnection::readData(char *data, qint64 maxSize)
-{
- return d->device->read(data, maxSize);
-}
-
-qint64 QmlDebugConnection::writeData(const char *data, qint64 maxSize)
-{
- return d->device->write(data, maxSize);
-}
-
-void QmlDebugConnection::internalError(QAbstractSocket::SocketError socketError)
-{
- setErrorString(d->device->errorString());
- emit error(socketError);
-}
-
-qint64 QmlDebugConnection::bytesAvailable() const
-{
- return d->device->bytesAvailable();
-}
-
-bool QmlDebugConnection::isSequential() const
-{
- return true;
-}
-
void QmlDebugConnection::close()
{
- if (isOpen()) {
- QIODevice::close();
+ if (d->device->isOpen()) {
d->device->close();
emit stateChanged(QAbstractSocket::UnconnectedState);
@@ -285,12 +248,9 @@ void QmlDebugConnection::close()
}
}
-bool QmlDebugConnection::waitForConnected(int msecs)
+QString QmlDebugConnection::errorString() const
{
- QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device);
- if (socket)
- return socket->waitForConnected(msecs);
- return false;
+ return d->device->errorString();
}
// For ease of refactoring we use QAbstractSocket's states even if we're actually using a OstChannel underneath
@@ -318,20 +278,13 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
QTcpSocket *socket = new QTcpSocket(d);
socket->setProxy(QNetworkProxy::NoProxy);
d->device = socket;
- d->connectDeviceSignals();
+ d->protocol = new QPacketProtocol(d->device, this);
+ connect(d->protocol, SIGNAL(readyRead()), d, SLOT(readyRead()));
d->gotHello = false;
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(stateChanged(QAbstractSocket::SocketState)));
- connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(internalError(QAbstractSocket::SocketError)));
+ connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(error(QAbstractSocket::SocketError)));
connect(socket, SIGNAL(connected()), this, SIGNAL(connected()));
socket->connectToHost(hostName, port);
- QIODevice::open(ReadWrite | Unbuffered);
-}
-
-void QmlDebugConnectionPrivate::connectDeviceSignals()
-{
- connect(device, SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64)));
- connect(device, SIGNAL(readyRead()), q, SIGNAL(readyRead()));
- connect(device, SIGNAL(aboutToClose()), this, SLOT(deviceAboutToClose()));
}
//