Commit 1bca3e96 authored by Kai Koehne's avatar Kai Koehne

QmlJSDebugger: Merge back changes done to the files in qtdeclarative

Change-Id: I722b191035757c60ce103edf74517f5348a91955
Reviewed-on: http://codereview.qt.nokia.com/3945Reviewed-by: default avatarAurindam Jana <aurindam.jana@nokia.com>
parent 7fa9e52d
......@@ -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();
......
......@@ -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 };
......
......@@ -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
{
......
......@@ -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
......@@ -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);
}
/*!
......@@ -440,6 +487,14 @@ bool QPacket::isEmpty() const
return b.isEmpty();
}
/*!
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
......@@ -471,7 +526,7 @@ void QPacket::clear()
\internal
*/
QPacketAutoSend::QPacketAutoSend(QPacketProtocol * _p)
QPacketAutoSend::QPacketAutoSend(QPacketProtocol *_p)
: QPacket(), p(_p)
{
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment