diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2011-08-31 12:55:08 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2011-09-01 08:53:39 +0200 |
commit | 1bca3e966dbe2ebe841765d90c84554fab41334d (patch) | |
tree | 9b8d55964672e3a7deff855a61e4187c7fa435e9 | |
parent | 7fa9e52d709ce3e7e3166ea37e3e42528a1c8c72 (diff) | |
download | qt-creator-1bca3e966dbe2ebe841765d90c84554fab41334d.tar.gz |
QmlJSDebugger: Merge back changes done to the files in qtdeclarative
Change-Id: I722b191035757c60ce103edf74517f5348a91955
Reviewed-on: http://codereview.qt.nokia.com/3945
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
6 files changed, 83 insertions, 18 deletions
diff --git a/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp b/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp index e11eadfbaf..f12eaf6937 100644 --- a/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp +++ b/src/libs/qmljsdebugclient/qdeclarativedebugclient.cpp @@ -246,6 +246,14 @@ void QDeclarativeDebugConnection::close() } } +bool QDeclarativeDebugConnection::waitForConnected(int msecs) +{ + QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device); + if (socket) + return socket->waitForConnected(msecs); + return false; +} + // For ease of refactoring we use QAbstractSocket's states even if we're actually using a OstChannel underneath // since serial ports have a subset of the socket states afaics QAbstractSocket::SocketState QDeclarativeDebugConnection::state() const @@ -350,7 +358,7 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name, QDeclarativeDebugClient::~QDeclarativeDebugClient() { - Q_D(QDeclarativeDebugClient); + Q_D(const QDeclarativeDebugClient); if (d->connection && d->connection->d) { d->connection->d->plugins.remove(d->name); d->connection->d->advertisePlugins(); diff --git a/src/libs/qmljsdebugclient/qdeclarativedebugclient.h b/src/libs/qmljsdebugclient/qdeclarativedebugclient.h index 170ee51acc..fe118de535 100644 --- a/src/libs/qmljsdebugclient/qdeclarativedebugclient.h +++ b/src/libs/qmljsdebugclient/qdeclarativedebugclient.h @@ -41,7 +41,7 @@ class QDeclarativeDebugConnectionPrivate; class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugConnection : public QIODevice { Q_OBJECT - + Q_DISABLE_COPY(QDeclarativeDebugConnection) public: QDeclarativeDebugConnection(QObject * = 0); ~QDeclarativeDebugConnection(); @@ -55,13 +55,14 @@ public: 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); -private: +protected: qint64 readData(char *data, qint64 maxSize); qint64 writeData(const char *data, qint64 maxSize); @@ -76,6 +77,7 @@ class QMLJSDEBUGCLIENT_EXPORT QDeclarativeDebugClient : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativeDebugClient) + Q_DISABLE_COPY(QDeclarativeDebugClient) public: enum Status { NotConnected, Unavailable, Enabled }; diff --git a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp index 9dab585217..db3f4a7781 100644 --- a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp +++ b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.cpp @@ -39,7 +39,6 @@ class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient { public: QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p); - ~QDeclarativeEngineDebugClient(); protected: virtual void statusChanged(Status status); @@ -88,10 +87,6 @@ QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugCo { } -QDeclarativeEngineDebugClient::~QDeclarativeEngineDebugClient() -{ -} - void QDeclarativeEngineDebugClient::statusChanged(Status status) { if (priv) @@ -445,7 +440,9 @@ QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *cl { } -QDeclarativeEngineDebug::~QDeclarativeEngineDebug() { } +QDeclarativeEngineDebug::~QDeclarativeEngineDebug() +{ +} QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const { diff --git a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h index 51d3120ad3..ed941a5e3b 100644 --- a/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h +++ b/src/libs/qmljsdebugclient/qdeclarativeenginedebug.h @@ -29,8 +29,8 @@ ** **************************************************************************/ -#ifndef QDECLARATIVEDEBUG_H -#define QDECLARATIVEDEBUG_H +#ifndef QDECLARATIVEENGINEDEBUG_H +#define QDECLARATIVEENGINEDEBUG_H #include "qmljsdebugclient_global.h" #include <QtCore/qobject.h> @@ -368,4 +368,4 @@ Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugObjectReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference) -#endif // QDECLARATIVEDEBUG_H +#endif // QDECLARATIVEENGINEDEBUG_H diff --git a/src/libs/qmljsdebugclient/qpacketprotocol.cpp b/src/libs/qmljsdebugclient/qpacketprotocol.cpp index 2bae0758ab..d19d666d05 100644 --- a/src/libs/qmljsdebugclient/qpacketprotocol.cpp +++ b/src/libs/qmljsdebugclient/qpacketprotocol.cpp @@ -31,7 +31,8 @@ #include "qpacketprotocol.h" -#include <QtCore/QBuffer> +#include <QtCore/qbuffer.h> +#include <QtCore/qelapsedtimer.h> namespace QmlJsDebugClient { @@ -105,7 +106,7 @@ class QPacketProtocolPrivate : public QObject public: QPacketProtocolPrivate(QPacketProtocol *parent, QIODevice *_dev) : QObject(parent), inProgressSize(-1), maxPacketSize(MAX_PACKET_SIZE), - dev(_dev) + waitingForPacket(false), dev(_dev) { Q_ASSERT(4 == sizeof(qint32)); @@ -189,6 +190,7 @@ public Q_SLOTS: inProgressSize = -1; inProgress.clear(); + waitingForPacket = false; emit readyRead(); } else return; @@ -202,14 +204,15 @@ public: QByteArray inProgress; qint32 inProgressSize; qint32 maxPacketSize; - QIODevice * dev; + bool waitingForPacket; + QIODevice *dev; }; /*! Construct a QPacketProtocol instance that works on \a dev with the specified \a parent. */ -QPacketProtocol::QPacketProtocol(QIODevice * dev, QObject * parent) +QPacketProtocol::QPacketProtocol(QIODevice *dev, QObject *parent) : QObject(parent), d(new QPacketProtocolPrivate(this, dev)) { Q_ASSERT(dev); @@ -313,10 +316,53 @@ QPacket QPacketProtocol::read() return rv; } + +/* + Returns the difference between msecs and elapsed. If msecs is -1, + however, -1 is returned. +*/ +static int qt_timeout_value(int msecs, int elapsed) +{ + if (msecs == -1) + return -1; + + int timeout = msecs - elapsed; + return timeout < 0 ? 0 : timeout; +} + +/*! + This function locks until a new packet is available for reading and the + \l{QIODevice::}{readyRead()} signal has been emitted. The function + will timeout after \a msecs milliseconds; the default timeout is + 30000 milliseconds. + + The function returns true if the readyRead() signal is emitted and + there is new data available for reading; otherwise it returns false + (if an error occurred or the operation timed out). + */ + +bool QPacketProtocol::waitForReadyRead(int msecs) +{ + if (!d->packets.isEmpty()) + return true; + + QElapsedTimer stopWatch; + stopWatch.start(); + + d->waitingForPacket = true; + do { + if (!d->dev->waitForReadyRead(msecs)) + return false; + if (!d->waitingForPacket) + return true; + msecs = qt_timeout_value(msecs, stopWatch.elapsed()); + } while (true); +} + /*! Return the QIODevice passed to the QPacketProtocol constructor. */ -QIODevice * QPacketProtocol::device() +QIODevice *QPacketProtocol::device() { return d->dev; } @@ -396,6 +442,7 @@ QPacket::QPacket() buf = new QBuffer(&b); buf->open(QIODevice::WriteOnly); setDevice(buf); + setVersion(QDataStream::Qt_4_7); } /*! @@ -441,6 +488,14 @@ bool QPacket::isEmpty() const } /*! + Returns raw packet data. + */ +QByteArray QPacket::data() const +{ + return b; +} + +/*! Clears data in the packet. This is useful for reusing one writable packet. For example \code @@ -471,7 +526,7 @@ void QPacket::clear() \internal */ -QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p) +QPacketAutoSend::QPacketAutoSend(QPacketProtocol *_p) : QPacket(), p(_p) { } diff --git a/src/libs/qmljsdebugclient/qpacketprotocol.h b/src/libs/qmljsdebugclient/qpacketprotocol.h index 05bc28f800..2a75f2b365 100644 --- a/src/libs/qmljsdebugclient/qpacketprotocol.h +++ b/src/libs/qmljsdebugclient/qpacketprotocol.h @@ -64,6 +64,8 @@ public: qint64 packetsAvailable() const; QPacket read(); + bool waitForReadyRead(int msecs = 3000); + void clear(); QIODevice *device(); @@ -87,6 +89,7 @@ public: void clear(); bool isEmpty() const; + QByteArray data() const; protected: friend class QPacketProtocol; |