From: Kai Koehne Date: Wed, 31 Aug 2011 10:41:04 +0000 (+0200) Subject: Debugger: Merge back changes from Qt Creator copy X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d3c58815a37a311c1bd743a102368e03fd07fee1;p=konrad%2Fqtdeclarative.git Debugger: Merge back changes from Qt Creator copy Apply changes done to the Qt Creator copy. In Qt Creator we also support connecting via OST, which we don't do inside QtDeclarative because it would pull in dependencies. Anyhow, make the code align nevertheless. Change-Id: I98f0be5ed3e136374e163cf1400df100128497ee Reviewed-on: http://codereview.qt.nokia.com/3943 Reviewed-by: Qt Sanity Bot Reviewed-by: Aurindam Jana --- diff --git a/src/declarative/debugger/qdeclarativedebugclient.cpp b/src/declarative/debugger/qdeclarativedebugclient.cpp index 9853a9f..606ad2d 100644 --- a/src/declarative/debugger/qdeclarativedebugclient.cpp +++ b/src/declarative/debugger/qdeclarativedebugclient.cpp @@ -45,6 +45,7 @@ #include #include +#include #include @@ -71,20 +72,23 @@ public: QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c); QDeclarativeDebugConnection *q; QPacketProtocol *protocol; + QIODevice *device; bool gotHello; QStringList serverPlugins; QHash plugins; void advertisePlugins(); + void connectDeviceSignals(); public Q_SLOTS: void connected(); void readyRead(); + void deviceAboutToClose(); }; QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c) - : QObject(c), q(c), protocol(0), gotHello(false) + : QObject(c), q(c), protocol(0), device(0), gotHello(false) { protocol = new QPacketProtocol(q, this); QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); @@ -137,7 +141,6 @@ void QDeclarativeDebugConnectionPrivate::readyRead() QObject::disconnect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead())); return; } - gotHello = true; QHash::Iterator iter = plugins.begin(); @@ -193,8 +196,15 @@ void QDeclarativeDebugConnectionPrivate::readyRead() } } +void QDeclarativeDebugConnectionPrivate::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(); +} + QDeclarativeDebugConnection::QDeclarativeDebugConnection(QObject *parent) - : QTcpSocket(parent), d(new QDeclarativeDebugConnectionPrivate(this)) + : QIODevice(parent), d(new QDeclarativeDebugConnectionPrivate(this)) { } @@ -209,9 +219,92 @@ QDeclarativeDebugConnection::~QDeclarativeDebugConnection() bool QDeclarativeDebugConnection::isConnected() const { - return state() == ConnectedState; + return state() == QAbstractSocket::ConnectedState; +} + +qint64 QDeclarativeDebugConnection::readData(char *data, qint64 maxSize) +{ + return d->device->read(data, maxSize); +} + +qint64 QDeclarativeDebugConnection::writeData(const char *data, qint64 maxSize) +{ + return d->device->write(data, maxSize); +} + +qint64 QDeclarativeDebugConnection::bytesAvailable() const +{ + return d->device->bytesAvailable(); +} + +bool QDeclarativeDebugConnection::isSequential() const +{ + return true; } +void QDeclarativeDebugConnection::close() +{ + if (isOpen()) { + QIODevice::close(); + d->device->close(); + emit stateChanged(QAbstractSocket::UnconnectedState); + + QHash::iterator iter = d->plugins.begin(); + for (; iter != d->plugins.end(); ++iter) { + iter.value()->statusChanged(QDeclarativeDebugClient::NotConnected); + } + } +} + +bool QDeclarativeDebugConnection::waitForConnected(int msecs) +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) + return socket->waitForConnected(msecs); + return false; +} + +QAbstractSocket::SocketState QDeclarativeDebugConnection::state() const +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) + return socket->state(); + + return QAbstractSocket::UnconnectedState; +} + +void QDeclarativeDebugConnection::flush() +{ + QAbstractSocket *socket = qobject_cast(d->device); + if (socket) { + socket->flush(); + return; + } +} + +void QDeclarativeDebugConnection::connectToHost(const QString &hostName, quint16 port) +{ + QTcpSocket *socket = new QTcpSocket(d); + socket->setProxy(QNetworkProxy::NoProxy); + d->device = socket; + d->connectDeviceSignals(); + d->gotHello = false; + connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(stateChanged(QAbstractSocket::SocketState))); + 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 QDeclarativeDebugConnectionPrivate::connectDeviceSignals() +{ + connect(device, SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64))); + connect(device, SIGNAL(readyRead()), q, SIGNAL(readyRead())); + connect(device, SIGNAL(aboutToClose()), this, SLOT(deviceAboutToClose())); +} + +// + QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate() : connection(0) { @@ -239,7 +332,7 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name, QDeclarativeDebugClient::~QDeclarativeDebugClient() { - Q_D(const QDeclarativeDebugClient); + Q_D(QDeclarativeDebugClient); if (d->connection && d->connection->d) { d->connection->d->plugins.remove(d->name); d->connection->d->advertisePlugins(); @@ -269,14 +362,13 @@ QDeclarativeDebugClient::Status QDeclarativeDebugClient::status() const void QDeclarativeDebugClient::sendMessage(const QByteArray &message) { Q_D(QDeclarativeDebugClient); - if (status() != Enabled) return; QPacket pack; pack << d->name << message; d->connection->d->protocol->send(pack); - d->connection->d->q->flush(); + d->connection->flush(); } void QDeclarativeDebugClient::statusChanged(Status) diff --git a/src/declarative/debugger/qdeclarativedebugclient_p.h b/src/declarative/debugger/qdeclarativedebugclient_p.h index 5b5d670..5b21935 100644 --- a/src/declarative/debugger/qdeclarativedebugclient_p.h +++ b/src/declarative/debugger/qdeclarativedebugclient_p.h @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QDeclarativeDebugConnectionPrivate; -class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugConnection : public QTcpSocket +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeDebugConnection : public QIODevice { Q_OBJECT Q_DISABLE_COPY(QDeclarativeDebugConnection) @@ -72,7 +72,25 @@ public: QDeclarativeDebugConnection(QObject * = 0); ~QDeclarativeDebugConnection(); + void connectToHost(const QString &hostName, quint16 port); + + qint64 bytesAvailable() const; bool isConnected() const; + QAbstractSocket::SocketState state() const; + void flush(); + bool isSequential() const; + void close(); + bool waitForConnected(int msecs = 30000); + +signals: + void connected(); + void stateChanged(QAbstractSocket::SocketState socketState); + void error(QAbstractSocket::SocketError socketError); + +protected: + qint64 readData(char *data, qint64 maxSize); + qint64 writeData(const char *data, qint64 maxSize); + private: QDeclarativeDebugConnectionPrivate *d; friend class QDeclarativeDebugClient; @@ -96,7 +114,7 @@ public: Status status() const; - void sendMessage(const QByteArray &); + virtual void sendMessage(const QByteArray &); protected: virtual void statusChanged(Status);