Commit 141ca588 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlJSDebugClient: Update library to latest changes in qt

Protocol / classes changed with commit fd9771c29d

Reviewed-by: Christiaan Janssen
parent 9a49ad00
......@@ -51,18 +51,22 @@ public:
QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
protected:
virtual void statusChanged(Status status);
virtual void messageReceived(const QByteArray &);
private:
QDeclarativeEngineDebugPrivate *priv;
friend class QDeclarativeEngineDebugPrivate;
};
class QDeclarativeEngineDebugPrivate
{
// Q_DECLARE_PUBLIC(QDeclarativeEngineDebug)
public:
QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *);
QDeclarativeEngineDebugPrivate(QDeclarativeEngineDebug *, QDeclarativeDebugConnection *);
~QDeclarativeEngineDebugPrivate();
void statusChanged(QDeclarativeEngineDebug::Status status);
void message(const QByteArray &);
QDeclarativeEngineDebugClient *client;
......@@ -90,19 +94,31 @@ QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugCo
QDeclarativeEngineDebugPrivate *p)
: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
{
setEnabled(true);
}
void QDeclarativeEngineDebugClient::statusChanged(Status status)
{
if (priv)
priv->statusChanged(static_cast<QDeclarativeEngineDebug::Status>(status));
}
void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
{
priv->message(data);
if (priv)
priv->message(data);
}
QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c)
: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0)
QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeEngineDebug *q, QDeclarativeDebugConnection *c)
: client(new QDeclarativeEngineDebugClient(c, this)), q_ptr(q), nextId(0)
{
}
QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate()
{
if (client)
client->priv = 0;
}
int QDeclarativeEngineDebugPrivate::getId()
{
return nextId++;
......@@ -116,7 +132,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
QDeclarativeDebugRootContextQuery *q)
{
if (c && q) {
......@@ -125,23 +141,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = c->d_func();
p->objectQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = c->d_func();
p->expressionQuery.remove(q->m_queryId);
}
}
//from qdeclarativeenginedebug.cpp
// from qdeclarativeenginedebug_p.h
struct QDeclarativeObjectData {
QUrl url;
int lineNumber;
......@@ -152,12 +152,14 @@ struct QDeclarativeObjectData {
int objectId;
int contextId;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectData &data)
{
ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString
>> data.objectName >> data.objectType >> data.objectId >> data.contextId;
return ds;
}
struct QDeclarativeObjectProperty {
enum Type { Unknown, Basic, Object, List, SignalProperty };
Type type;
......@@ -167,6 +169,7 @@ struct QDeclarativeObjectProperty {
QString binding;
bool hasNotifySignal;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
{
int type;
......@@ -176,6 +179,22 @@ QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
return ds;
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = c->d_func();
p->objectQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q)
{
if (c && q) {
QDeclarativeEngineDebugPrivate *p = c->d_func();
p->expressionQuery.remove(q->m_queryId);
}
}
void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
bool simple)
{
......@@ -260,6 +279,11 @@ void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugCo
}
}
void QDeclarativeEngineDebugPrivate::statusChanged(QDeclarativeEngineDebug::Status status)
{
emit q_ptr->statusChanged(status);
}
void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
{
QDataStream ds(data);
......@@ -378,18 +402,25 @@ void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
}
QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent)
: QObject(parent), d_ptr(new QDeclarativeEngineDebugPrivate(client))
: QObject(parent), d_ptr(new QDeclarativeEngineDebugPrivate(this, client))
{
d_ptr->q_ptr = this;
}
QDeclarativeEngineDebug::~QDeclarativeEngineDebug() {}
QDeclarativeEngineDebug::~QDeclarativeEngineDebug() { }
QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const
{
Q_D(const QDeclarativeEngineDebug);
return static_cast<QDeclarativeEngineDebug::Status>(d->client->status());
}
QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
if (d->client->isConnected()) {
if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
......@@ -418,7 +449,7 @@ QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const
{
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
if (d->client->isConnected()) {
if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
......@@ -441,7 +472,7 @@ QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebu
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
if (d->client->isConnected()) {
if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
......@@ -477,7 +508,7 @@ void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch)
d->watched.remove(watch->queryId());
if (d->client && d->client->isConnected()) {
if (d->client && d->client->status() == QDeclarativeDebugClient::Enabled) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("NO_WATCH") << watch->queryId();
......@@ -490,7 +521,7 @@ QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QO
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
if (d->client->isConnected()) {
if (d->client->status() == QDeclarativeDebugClient::Enabled) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
......@@ -512,7 +543,7 @@ QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(co
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent);
if (d->client->isConnected() && engine.debugId() != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && engine.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
......@@ -534,7 +565,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclar
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
if (d->client->isConnected() && object.debugId() != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
......@@ -557,7 +588,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(cons
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
if (d->client->isConnected() && object.debugId() != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
......@@ -566,9 +597,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(cons
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
<< true << true; // Note: dumping all the properties is slow, and make noticable lags.
// TODO: Find an alternative to this when they are needed by the live preview
<< true << true;
d->client->sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
......@@ -582,7 +611,7 @@ QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult
Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent);
if (d->client->isConnected() && objectDebugId != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
query->m_client = this;
query->m_expr = expr;
int queryId = d->getId();
......@@ -606,7 +635,7 @@ bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QStri
{
Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue;
......@@ -621,7 +650,7 @@ bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QSt
{
Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
......@@ -637,7 +666,7 @@ bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &me
{
Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) {
if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
......@@ -701,6 +730,7 @@ QString QDeclarativeDebugObjectExpressionWatch::expression() const
return m_expr;
}
QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent)
: QObject(parent), m_state(Waiting)
{
......@@ -1025,4 +1055,3 @@ bool QDeclarativeDebugPropertyReference::hasNotifySignal() const
}
}
......@@ -63,15 +63,18 @@ class QDeclarativeDebugObjectReference;
class QDeclarativeDebugFileReference;
class QDeclarativeDebugEngineReference;
class QDeclarativeEngineDebugPrivate;
class QDeclarativeEngineDebug;
class QDeclarativeEngineDebug : public QObject
{
Q_OBJECT
public:
enum Status { NotConnected, Unavailable, Enabled };
explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0);
~QDeclarativeEngineDebug();
Status status() const;
QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &,
QObject *parent = 0);
QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &,
......@@ -100,16 +103,15 @@ public:
bool resetBindingForObject(int objectDebugId, const QString &propertyName);
bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody);
signals:
Q_SIGNALS:
void newObjects();
void statusChanged(Status status);
private:
Q_DECLARE_PRIVATE(QDeclarativeEngineDebug)
Q_DISABLE_COPY(QDeclarativeEngineDebug)
QScopedPointer<QDeclarativeEngineDebugPrivate> d_ptr;
};
class QDeclarativeDebugWatch : public QObject
{
Q_OBJECT
......@@ -368,7 +370,6 @@ private:
int m_queryId;
QVariant m_expr;
QVariant m_result;
};
}
......@@ -378,6 +379,5 @@ Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugObjectReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference)
QT_END_HEADER
#endif // QDECLARATIVEDEBUG_H
......@@ -48,6 +48,20 @@
namespace QmlJsDebugClient {
const int protocolVersion = 1;
const QString serverId = QLatin1String("QDeclarativeDebugServer");
const QString clientId = QLatin1String("QDeclarativeDebugClient");
class QDeclarativeDebugClientPrivate
{
// Q_DECLARE_PUBLIC(QDeclarativeDebugClient)
public:
QDeclarativeDebugClientPrivate();
QString name;
QDeclarativeDebugConnection *client;
};
class QDeclarativeDebugConnectionPrivate : public QObject
{
Q_OBJECT
......@@ -56,40 +70,123 @@ public:
QDeclarativeDebugConnection *q;
QPacketProtocol *protocol;
QStringList enabled;
bool gotHello;
QStringList serverPlugins;
QHash<QString, QDeclarativeDebugClient *> plugins;
void advertisePlugins();
public Q_SLOTS:
void connected();
void readyRead();
};
QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c)
: QObject(c), q(c), protocol(0)
: QObject(c), q(c), protocol(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 QDeclarativeDebugConnectionPrivate::advertisePlugins()
{
if (!q->isConnected() || !gotHello)
return;
QPacket pack;
pack << serverId << 1 << plugins.keys();
protocol->send(pack);
q->flush();
}
void QDeclarativeDebugConnectionPrivate::connected()
{
QPacket pack;
pack << QString(QLatin1String("QDeclarativeDebugServer")) << enabled;
pack << serverId << 0 << protocolVersion << plugins.keys();
protocol->send(pack);
q->flush();
}
void QDeclarativeDebugConnectionPrivate::readyRead()
{
QPacket pack = protocol->read();
QString name; QByteArray message;
pack >> name >> message;
if (!gotHello) {
QPacket pack = protocol->read();
QString name;
QHash<QString, QDeclarativeDebugClient *>::Iterator iter =
plugins.find(name);
if (iter == plugins.end()) {
qWarning() << "QDeclarativeDebugConnection: Message received for missing plugin" << name;
} else {
(*iter)->messageReceived(message);
pack >> name;
bool validHello = false;
if (name == clientId) {
int op = -1;
pack >> op;
if (op == 0) {
int version = -1;
pack >> version;
if (version == protocolVersion) {
pack >> serverPlugins;
validHello = true;
}
}
}
if (!validHello) {
qWarning("QDeclarativeDebugConnection: Invalid hello message");
QObject::disconnect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
return;
}
gotHello = true;
QHash<QString, QDeclarativeDebugClient *>::Iterator iter = plugins.begin();
for (; iter != plugins.end(); ++iter) {
QDeclarativeDebugClient::Status newStatus = QDeclarativeDebugClient::Unavailable;
if (serverPlugins.contains(iter.key()))
newStatus = QDeclarativeDebugClient::Enabled;
iter.value()->statusChanged(newStatus);
}
}
while (protocol->packetsAvailable()) {
QPacket pack = protocol->read();
QString name;
pack >> name;
if (name == clientId) {
int op = -1;
pack >> op;
if (op == 1) {
// Service Discovery
QStringList oldServerPlugins = serverPlugins;
pack >> serverPlugins;
QHash<QString, QDeclarativeDebugClient *>::Iterator iter = plugins.begin();
for (; iter != plugins.end(); ++iter) {
const QString pluginName = iter.key();
QDeclarativeDebugClient::Status newStatus = QDeclarativeDebugClient::Unavailable;
if (serverPlugins.contains(pluginName))
newStatus = QDeclarativeDebugClient::Enabled;
if (oldServerPlugins.contains(pluginName)
!= serverPlugins.contains(pluginName)) {
iter.value()->statusChanged(newStatus);
}
}
} else {
qWarning() << "QDeclarativeDebugConnection: Unknown control message id" << op;
}
} else {
QByteArray message;
pack >> message;
QHash<QString, QDeclarativeDebugClient *>::Iterator iter =
plugins.find(name);
if (iter == plugins.end()) {
qWarning() << "QDeclarativeDebugConnection: Message received for missing plugin" << name;
} else {
(*iter)->messageReceived(message);
}
}
}
}
......@@ -98,29 +195,28 @@ QDeclarativeDebugConnection::QDeclarativeDebugConnection(QObject *parent)
{
}
bool QDeclarativeDebugConnection::isConnected() const
QDeclarativeDebugConnection::~QDeclarativeDebugConnection()
{
return state() == ConnectedState;
QHash<QString, QDeclarativeDebugClient*>::iterator iter = d->plugins.begin();
for (; iter != d->plugins.end(); ++iter) {
iter.value()->d_func()->client = 0;
iter.value()->statusChanged(QDeclarativeDebugClient::NotConnected);
}
}
class QDeclarativeDebugClientPrivate
bool QDeclarativeDebugConnection::isConnected() const
{
public:
QDeclarativeDebugClientPrivate();
QString name;
QDeclarativeDebugConnection *client;
bool enabled;
};
return state() == ConnectedState;
}
QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate()
: client(0), enabled(false)
: client(0)
{
}
QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name,
QDeclarativeDebugConnection *parent)
: QObject(parent), d(new QDeclarativeDebugClientPrivate)
: QObject(parent), d(new QDeclarativeDebugClientPrivate())
{
d->name = name;
d->client = parent;
......@@ -133,60 +229,49 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name,
d->client = 0;
} else {
d->client->d->plugins.insert(name, this);
d->client->d->advertisePlugins();
}
}
QDeclarativeDebugClient::~QDeclarativeDebugClient() {}
QDeclarativeDebugClient::~QDeclarativeDebugClient()
{
if (d->client && d->client->d) {
d->client->d->plugins.remove(d->name);
d->client->d->advertisePlugins();
}
}
QString QDeclarativeDebugClient::name() const
{
return d->name;
}
bool QDeclarativeDebugClient::isEnabled() const
QDeclarativeDebugClient::Status QDeclarativeDebugClient::status() const
{
return d->enabled;
}
if (!d->client
|| !d->client->isConnected()
|| !d->client->d->gotHello)
return NotConnected;
void QDeclarativeDebugClient::setEnabled(bool e)
{
if (e == d->enabled)
return;
if (d->client->d->serverPlugins.contains(d->name))
return Enabled;
d->enabled = e;
if (d->client) {
if (e)
d->client->d->enabled.append(d->name);
else
d->client->d->enabled.removeAll(d->name);
if (d->client->state() == QTcpSocket::ConnectedState) {
QPacket pack;
pack << QString(QLatin1String("QDeclarativeDebugServer"));
if (e) pack << (int)1;
else pack << (int)2;
pack << d->name;