QmlJSDebugClient: Update library to latest changes in qt

Protocol / classes changed with commit fd9771c29d

Reviewed-by: Christiaan Janssen
This commit is contained in:
Kai Koehne
2010-09-27 12:45:56 +02:00
parent 9a49ad003a
commit 141ca58827
6 changed files with 242 additions and 129 deletions

View File

@@ -51,18 +51,22 @@ public:
QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p); QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
protected: protected:
virtual void statusChanged(Status status);
virtual void messageReceived(const QByteArray &); virtual void messageReceived(const QByteArray &);
private: private:
QDeclarativeEngineDebugPrivate *priv; QDeclarativeEngineDebugPrivate *priv;
friend class QDeclarativeEngineDebugPrivate;
}; };
class QDeclarativeEngineDebugPrivate class QDeclarativeEngineDebugPrivate
{ {
// Q_DECLARE_PUBLIC(QDeclarativeEngineDebug) // Q_DECLARE_PUBLIC(QDeclarativeEngineDebug)
public: public:
QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *); QDeclarativeEngineDebugPrivate(QDeclarativeEngineDebug *, QDeclarativeDebugConnection *);
~QDeclarativeEngineDebugPrivate();
void statusChanged(QDeclarativeEngineDebug::Status status);
void message(const QByteArray &); void message(const QByteArray &);
QDeclarativeEngineDebugClient *client; QDeclarativeEngineDebugClient *client;
@@ -90,19 +94,31 @@ QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugCo
QDeclarativeEngineDebugPrivate *p) QDeclarativeEngineDebugPrivate *p)
: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(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) void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
{ {
priv->message(data); if (priv)
priv->message(data);
} }
QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c) QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeEngineDebug *q, QDeclarativeDebugConnection *c)
: client(new QDeclarativeEngineDebugClient(c, this)), nextId(0) : client(new QDeclarativeEngineDebugClient(c, this)), q_ptr(q), nextId(0)
{ {
} }
QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate()
{
if (client)
client->priv = 0;
}
int QDeclarativeEngineDebugPrivate::getId() int QDeclarativeEngineDebugPrivate::getId()
{ {
return nextId++; return nextId++;
@@ -116,7 +132,7 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara
} }
} }
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
QDeclarativeDebugRootContextQuery *q) QDeclarativeDebugRootContextQuery *q)
{ {
if (c && q) { if (c && q) {
@@ -125,6 +141,44 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c,
} }
} }
// from qdeclarativeenginedebug_p.h
struct QDeclarativeObjectData {
QUrl url;
int lineNumber;
int columnNumber;
QString idString;
QString objectName;
QString objectType;
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;
QString name;
QVariant value;
QString valueTypeName;
QString binding;
bool hasNotifySignal;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
{
int type;
ds >> type >> data.name >> data.value >> data.valueTypeName
>> data.binding >> data.hasNotifySignal;
data.type = (QDeclarativeObjectProperty::Type)type;
return ds;
}
void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q) void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
{ {
if (c && q) { if (c && q) {
@@ -141,41 +195,6 @@ void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclara
} }
} }
//from qdeclarativeenginedebug.cpp
struct QDeclarativeObjectData {
QUrl url;
int lineNumber;
int columnNumber;
QString idString;
QString objectName;
QString objectType;
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;
QString name;
QVariant value;
QString valueTypeName;
QString binding;
bool hasNotifySignal;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
{
int type;
ds >> type >> data.name >> data.value >> data.valueTypeName
>> data.binding >> data.hasNotifySignal;
data.type = (QDeclarativeObjectProperty::Type)type;
return ds;
}
void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o, void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
bool simple) 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) void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
{ {
QDataStream ds(data); QDataStream ds(data);
@@ -378,18 +402,25 @@ void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
} }
QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent) 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) QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
{ {
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent); QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
if (d->client->isConnected()) { if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId(); int queryId = d->getId();
watch->m_queryId = queryId; watch->m_queryId = queryId;
watch->m_client = this; watch->m_client = this;
@@ -418,7 +449,7 @@ QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const
{ {
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent); QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
if (d->client->isConnected()) { if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId(); int queryId = d->getId();
watch->m_queryId = queryId; watch->m_queryId = queryId;
watch->m_client = this; watch->m_client = this;
@@ -441,7 +472,7 @@ QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebu
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent); QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
if (d->client->isConnected()) { if (d->client->status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId(); int queryId = d->getId();
watch->m_queryId = queryId; watch->m_queryId = queryId;
watch->m_client = this; watch->m_client = this;
@@ -477,7 +508,7 @@ void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch)
d->watched.remove(watch->queryId()); d->watched.remove(watch->queryId());
if (d->client && d->client->isConnected()) { if (d->client && d->client->status() == QDeclarativeDebugClient::Enabled) {
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("NO_WATCH") << watch->queryId(); ds << QByteArray("NO_WATCH") << watch->queryId();
@@ -490,7 +521,7 @@ QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QO
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent); QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
if (d->client->isConnected()) { if (d->client->status() == QDeclarativeDebugClient::Enabled) {
query->m_client = this; query->m_client = this;
int queryId = d->getId(); int queryId = d->getId();
query->m_queryId = queryId; query->m_queryId = queryId;
@@ -512,7 +543,7 @@ QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(co
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent); 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; query->m_client = this;
int queryId = d->getId(); int queryId = d->getId();
query->m_queryId = queryId; query->m_queryId = queryId;
@@ -534,7 +565,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclar
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); 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; query->m_client = this;
int queryId = d->getId(); int queryId = d->getId();
query->m_queryId = queryId; query->m_queryId = queryId;
@@ -557,7 +588,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(cons
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent); 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; query->m_client = this;
int queryId = d->getId(); int queryId = d->getId();
query->m_queryId = queryId; query->m_queryId = queryId;
@@ -566,9 +597,7 @@ QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(cons
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId() ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
<< true << true; // Note: dumping all the properties is slow, and make noticable lags. << true << true;
// TODO: Find an alternative to this when they are needed by the live preview
d->client->sendMessage(message); d->client->sendMessage(message);
} else { } else {
query->m_state = QDeclarativeDebugQuery::Error; query->m_state = QDeclarativeDebugQuery::Error;
@@ -582,7 +611,7 @@ QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent); 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_client = this;
query->m_expr = expr; query->m_expr = expr;
int queryId = d->getId(); int queryId = d->getId();
@@ -606,7 +635,7 @@ bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QStri
{ {
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) { if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue; ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue;
@@ -621,7 +650,7 @@ bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QSt
{ {
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) { if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName; ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
@@ -637,7 +666,7 @@ bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &me
{ {
Q_D(QDeclarativeEngineDebug); Q_D(QDeclarativeEngineDebug);
if (d->client->isConnected() && objectDebugId != -1) { if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
QByteArray message; QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly); QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody; ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
@@ -701,6 +730,7 @@ QString QDeclarativeDebugObjectExpressionWatch::expression() const
return m_expr; return m_expr;
} }
QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent) QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent)
: QObject(parent), m_state(Waiting) : QObject(parent), m_state(Waiting)
{ {
@@ -1025,4 +1055,3 @@ bool QDeclarativeDebugPropertyReference::hasNotifySignal() const
} }
} }

View File

@@ -63,15 +63,18 @@ class QDeclarativeDebugObjectReference;
class QDeclarativeDebugFileReference; class QDeclarativeDebugFileReference;
class QDeclarativeDebugEngineReference; class QDeclarativeDebugEngineReference;
class QDeclarativeEngineDebugPrivate; class QDeclarativeEngineDebugPrivate;
class QDeclarativeEngineDebug;
class QDeclarativeEngineDebug : public QObject class QDeclarativeEngineDebug : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Status { NotConnected, Unavailable, Enabled };
explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0); explicit QDeclarativeEngineDebug(QDeclarativeDebugConnection *, QObject * = 0);
~QDeclarativeEngineDebug(); ~QDeclarativeEngineDebug();
Status status() const;
QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &, QDeclarativeDebugPropertyWatch *addWatch(const QDeclarativeDebugPropertyReference &,
QObject *parent = 0); QObject *parent = 0);
QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &, QDeclarativeDebugWatch *addWatch(const QDeclarativeDebugContextReference &, const QString &,
@@ -100,16 +103,15 @@ public:
bool resetBindingForObject(int objectDebugId, const QString &propertyName); bool resetBindingForObject(int objectDebugId, const QString &propertyName);
bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody); bool setMethodBody(int objectDebugId, const QString &methodName, const QString &methodBody);
signals: Q_SIGNALS:
void newObjects(); void newObjects();
void statusChanged(Status status);
private: private:
Q_DECLARE_PRIVATE(QDeclarativeEngineDebug) Q_DECLARE_PRIVATE(QDeclarativeEngineDebug)
Q_DISABLE_COPY(QDeclarativeEngineDebug)
QScopedPointer<QDeclarativeEngineDebugPrivate> d_ptr; QScopedPointer<QDeclarativeEngineDebugPrivate> d_ptr;
}; };
class QDeclarativeDebugWatch : public QObject class QDeclarativeDebugWatch : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -368,7 +370,6 @@ private:
int m_queryId; int m_queryId;
QVariant m_expr; QVariant m_expr;
QVariant m_result; QVariant m_result;
}; };
} }
@@ -378,6 +379,5 @@ Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugObjectReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugContextReference)
Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference) Q_DECLARE_METATYPE(QmlJsDebugClient::QDeclarativeDebugPropertyReference)
QT_END_HEADER
#endif // QDECLARATIVEDEBUG_H #endif // QDECLARATIVEDEBUG_H

View File

@@ -48,6 +48,20 @@
namespace QmlJsDebugClient { 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 class QDeclarativeDebugConnectionPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -56,40 +70,123 @@ public:
QDeclarativeDebugConnection *q; QDeclarativeDebugConnection *q;
QPacketProtocol *protocol; QPacketProtocol *protocol;
QStringList enabled; bool gotHello;
QStringList serverPlugins;
QHash<QString, QDeclarativeDebugClient *> plugins; QHash<QString, QDeclarativeDebugClient *> plugins;
void advertisePlugins();
public Q_SLOTS: public Q_SLOTS:
void connected(); void connected();
void readyRead(); void readyRead();
}; };
QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c) QDeclarativeDebugConnectionPrivate::QDeclarativeDebugConnectionPrivate(QDeclarativeDebugConnection *c)
: QObject(c), q(c), protocol(0) : QObject(c), q(c), protocol(0), gotHello(false)
{ {
protocol = new QPacketProtocol(q, this); protocol = new QPacketProtocol(q, this);
QObject::connect(c, SIGNAL(connected()), this, SLOT(connected())); QObject::connect(c, SIGNAL(connected()), this, SLOT(connected()));
QObject::connect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead())); 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() void QDeclarativeDebugConnectionPrivate::connected()
{ {
QPacket pack; QPacket pack;
pack << QString(QLatin1String("QDeclarativeDebugServer")) << enabled; pack << serverId << 0 << protocolVersion << plugins.keys();
protocol->send(pack); protocol->send(pack);
q->flush();
} }
void QDeclarativeDebugConnectionPrivate::readyRead() void QDeclarativeDebugConnectionPrivate::readyRead()
{ {
QPacket pack = protocol->read(); if (!gotHello) {
QString name; QByteArray message; QPacket pack = protocol->read();
pack >> name >> message; QString name;
QHash<QString, QDeclarativeDebugClient *>::Iterator iter = pack >> name;
plugins.find(name);
if (iter == plugins.end()) { bool validHello = false;
qWarning() << "QDeclarativeDebugConnection: Message received for missing plugin" << name; if (name == clientId) {
} else { int op = -1;
(*iter)->messageReceived(message); 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)
{ {
} }
QDeclarativeDebugConnection::~QDeclarativeDebugConnection()
{
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);
}
}
bool QDeclarativeDebugConnection::isConnected() const bool QDeclarativeDebugConnection::isConnected() const
{ {
return state() == ConnectedState; return state() == ConnectedState;
} }
class QDeclarativeDebugClientPrivate
{
public:
QDeclarativeDebugClientPrivate();
QString name;
QDeclarativeDebugConnection *client;
bool enabled;
};
QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate() QDeclarativeDebugClientPrivate::QDeclarativeDebugClientPrivate()
: client(0), enabled(false) : client(0)
{ {
} }
QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name, QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name,
QDeclarativeDebugConnection *parent) QDeclarativeDebugConnection *parent)
: QObject(parent), d(new QDeclarativeDebugClientPrivate) : QObject(parent), d(new QDeclarativeDebugClientPrivate())
{ {
d->name = name; d->name = name;
d->client = parent; d->client = parent;
@@ -133,60 +229,49 @@ QDeclarativeDebugClient::QDeclarativeDebugClient(const QString &name,
d->client = 0; d->client = 0;
} else { } else {
d->client->d->plugins.insert(name, this); 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 QString QDeclarativeDebugClient::name() const
{ {
return d->name; 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 (d->client->d->serverPlugins.contains(d->name))
{ return Enabled;
if (e == d->enabled)
return;
d->enabled = e; return Unavailable;
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;
d->client->d->protocol->send(pack);
}
}
}
bool QDeclarativeDebugClient::isConnected() const
{
if (!d->client)
return false;
return d->client->isConnected();
} }
void QDeclarativeDebugClient::sendMessage(const QByteArray &message) void QDeclarativeDebugClient::sendMessage(const QByteArray &message)
{ {
if (!d->client || !d->client->isConnected()) if (status() != Enabled)
return; return;
QPacket pack; QPacket pack;
pack << d->name << message; pack << d->name << message;
d->client->d->protocol->send(pack); d->client->d->protocol->send(pack);
d->client->flush();
}
void QDeclarativeDebugClient::statusChanged(Status)
{
} }
void QDeclarativeDebugClient::messageReceived(const QByteArray &) void QDeclarativeDebugClient::messageReceived(const QByteArray &)

View File

@@ -55,6 +55,7 @@ class QDeclarativeDebugConnection : public QTcpSocket
Q_DISABLE_COPY(QDeclarativeDebugConnection) Q_DISABLE_COPY(QDeclarativeDebugConnection)
public: public:
QDeclarativeDebugConnection(QObject * = 0); QDeclarativeDebugConnection(QObject * = 0);
~QDeclarativeDebugConnection();
bool isConnected() const; bool isConnected() const;
private: private:
@@ -71,19 +72,19 @@ class QDeclarativeDebugClient : public QObject
Q_DISABLE_COPY(QDeclarativeDebugClient) Q_DISABLE_COPY(QDeclarativeDebugClient)
public: public:
enum Status { NotConnected, Unavailable, Enabled };
QDeclarativeDebugClient(const QString &, QDeclarativeDebugConnection *parent); QDeclarativeDebugClient(const QString &, QDeclarativeDebugConnection *parent);
~QDeclarativeDebugClient(); ~QDeclarativeDebugClient();
QString name() const; QString name() const;
bool isEnabled() const; Status status() const;
void setEnabled(bool);
bool isConnected() const;
void sendMessage(const QByteArray &); void sendMessage(const QByteArray &);
protected: protected:
virtual void statusChanged(Status);
virtual void messageReceived(const QByteArray &); virtual void messageReceived(const QByteArray &);
private: private:

View File

@@ -37,7 +37,6 @@ namespace Internal {
QmlDebuggerClient::QmlDebuggerClient(QmlJsDebugClient::QDeclarativeDebugConnection* client) QmlDebuggerClient::QmlDebuggerClient(QmlJsDebugClient::QDeclarativeDebugConnection* client)
: QDeclarativeDebugClient(QLatin1String("JSDebugger"), client) : QDeclarativeDebugClient(QLatin1String("JSDebugger"), client)
{ {
setEnabled(true);
} }
QmlDebuggerClient::~QmlDebuggerClient() QmlDebuggerClient::~QmlDebuggerClient()

View File

@@ -53,7 +53,6 @@ QmlJSObserverClient::QmlJSObserverClient(QDeclarativeDebugConnection *client,
: QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), client) , : QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), client) ,
m_connection(client) m_connection(client)
{ {
setEnabled(true);
} }
void QmlJSObserverClient::messageReceived(const QByteArray &message) void QmlJSObserverClient::messageReceived(const QByteArray &message)