Commit 4cd2e326 authored by Aurindam Jana's avatar Aurindam Jana
Browse files

QmlEngineDebugClient: Simplify the client and utility classes



Change-Id: I86033bdbdef94c6f17e706f8e13ce390969171c6
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 8966d82a
......@@ -33,120 +33,7 @@
namespace QmlJsDebugClient {
class QmlEngineDebugClientPrivate
{
public:
QmlEngineDebugClientPrivate(QmlEngineDebugClient *);
~QmlEngineDebugClientPrivate();
void statusChanged(QDeclarativeDebugClient::Status status);
void message(const QByteArray &);
QmlEngineDebugClient *q;
int nextId;
int getId();
void decode(QDataStream &, QDeclarativeDebugContextReference &);
void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple);
static void remove(QmlEngineDebugClient *, QDeclarativeDebugEnginesQuery *);
static void remove(QmlEngineDebugClient *, QDeclarativeDebugRootContextQuery *);
static void remove(QmlEngineDebugClient *, QDeclarativeDebugObjectQuery *);
static void remove(QmlEngineDebugClient *, QDeclarativeDebugExpressionQuery *);
static void remove(QmlEngineDebugClient *, QDeclarativeDebugWatch *);
QHash<int, QDeclarativeDebugEnginesQuery *> enginesQuery;
QHash<int, QDeclarativeDebugRootContextQuery *> rootContextQuery;
QHash<int, QDeclarativeDebugObjectQuery *> objectQuery;
QHash<int, QDeclarativeDebugExpressionQuery *> expressionQuery;
QHash<int, QDeclarativeDebugWatch *> watched;
};
void QmlEngineDebugClient::statusChanged(Status status)
{
emit newStatus(status);
}
void QmlEngineDebugClient::messageReceived(const QByteArray &data)
{
d->message(data);
}
QmlEngineDebugClientPrivate::QmlEngineDebugClientPrivate(QmlEngineDebugClient *q)
: q(q), nextId(0)
{
}
QmlEngineDebugClientPrivate::~QmlEngineDebugClientPrivate()
{
QHash<int, QDeclarativeDebugEnginesQuery*>::iterator enginesIter = enginesQuery.begin();
for (; enginesIter != enginesQuery.end(); ++enginesIter) {
enginesIter.value()->m_client = 0;
if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting)
enginesIter.value()->setState(QDeclarativeDebugQuery::Error);
}
QHash<int, QDeclarativeDebugRootContextQuery*>::iterator rootContextIter = rootContextQuery.begin();
for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) {
rootContextIter.value()->m_client = 0;
if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting)
rootContextIter.value()->setState(QDeclarativeDebugQuery::Error);
}
QHash<int, QDeclarativeDebugObjectQuery*>::iterator objectIter = objectQuery.begin();
for (; objectIter != objectQuery.end(); ++objectIter) {
objectIter.value()->m_client = 0;
if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting)
objectIter.value()->setState(QDeclarativeDebugQuery::Error);
}
QHash<int, QDeclarativeDebugExpressionQuery*>::iterator exprIter = expressionQuery.begin();
for (; exprIter != expressionQuery.end(); ++exprIter) {
exprIter.value()->m_client = 0;
if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting)
exprIter.value()->setState(QDeclarativeDebugQuery::Error);
}
QHash<int, QDeclarativeDebugWatch*>::iterator watchIter = watched.begin();
for (; watchIter != watched.end(); ++watchIter) {
watchIter.value()->m_client = 0;
watchIter.value()->setState(QDeclarativeDebugWatch::Dead);
}
}
int QmlEngineDebugClientPrivate::getId()
{
return nextId++;
}
void QmlEngineDebugClientPrivate::remove(QmlEngineDebugClient *c, QDeclarativeDebugEnginesQuery *q)
{
if (c && q) {
QmlEngineDebugClientPrivate *p = c->priv();
p->enginesQuery.remove(q->m_queryId);
}
}
void QmlEngineDebugClientPrivate::remove(QmlEngineDebugClient *c,
QDeclarativeDebugRootContextQuery *q)
{
if (c && q) {
QmlEngineDebugClientPrivate *p = c->priv();
p->rootContextQuery.remove(q->m_queryId);
}
}
void QmlEngineDebugClientPrivate::remove(QmlEngineDebugClient *c, QDeclarativeDebugWatch *w)
{
if (c && w) {
QmlEngineDebugClientPrivate *p = c->priv();
p->watched.remove(w->m_queryId);
}
}
// from qdeclarativeenginedebug_p.h
struct QDeclarativeObjectData {
struct QmlObjectData {
QUrl url;
int lineNumber;
int columnNumber;
......@@ -157,14 +44,14 @@ struct QDeclarativeObjectData {
int contextId;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectData &data)
QDataStream &operator>>(QDataStream &ds, QmlObjectData &data)
{
ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString
>> data.objectName >> data.objectType >> data.objectId >> data.contextId;
return ds;
}
struct QDeclarativeObjectProperty {
struct QmlObjectProperty {
enum Type { Unknown, Basic, Object, List, SignalProperty };
Type type;
QString name;
......@@ -174,38 +61,23 @@ struct QDeclarativeObjectProperty {
bool hasNotifySignal;
};
QDataStream &operator>>(QDataStream &ds, QDeclarativeObjectProperty &data)
QDataStream &operator>>(QDataStream &ds, QmlObjectProperty &data)
{
int type;
ds >> type >> data.name >> data.value >> data.valueTypeName
>> data.binding >> data.hasNotifySignal;
data.type = (QDeclarativeObjectProperty::Type)type;
data.type = (QmlObjectProperty::Type)type;
return ds;
}
void QmlEngineDebugClientPrivate::remove(QmlEngineDebugClient *c, QDeclarativeDebugObjectQuery *q)
{
if (c && q) {
QmlEngineDebugClientPrivate *p = c->priv();
p->objectQuery.remove(q->m_queryId);
}
}
void QmlEngineDebugClientPrivate::remove(QmlEngineDebugClient *c, QDeclarativeDebugExpressionQuery *q)
{
if (c && q) {
QmlEngineDebugClientPrivate *p = c->priv();
p->expressionQuery.remove(q->m_queryId);
}
}
void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
bool simple)
void QmlEngineDebugClient::decode(QDataStream &ds,
QmlDebugObjectReference &o,
bool simple)
{
QDeclarativeObjectData data;
QmlObjectData data;
ds >> data;
o.m_debugId = data.objectId;
o.m_class = data.objectType;
o.m_className = data.objectType;
o.m_idString = data.idString;
o.m_name = data.objectName;
o.m_source.m_url = data.url;
......@@ -221,7 +93,7 @@ void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugObjec
ds >> childCount >> recur;
for (int ii = 0; ii < childCount; ++ii) {
o.m_children.append(QDeclarativeDebugObjectReference());
o.m_children.append(QmlDebugObjectReference());
decode(ds, o.m_children.last(), !recur);
}
......@@ -229,37 +101,38 @@ void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugObjec
ds >> propCount;
for (int ii = 0; ii < propCount; ++ii) {
QDeclarativeObjectProperty data;
QmlObjectProperty data;
ds >> data;
QDeclarativeDebugPropertyReference prop;
QmlDebugPropertyReference prop;
prop.m_objectDebugId = o.m_debugId;
prop.m_name = data.name;
prop.m_binding = data.binding;
prop.m_hasNotifySignal = data.hasNotifySignal;
prop.m_valueTypeName = data.valueTypeName;
switch (data.type) {
case QDeclarativeObjectProperty::Basic:
case QDeclarativeObjectProperty::List:
case QDeclarativeObjectProperty::SignalProperty:
case QmlObjectProperty::Basic:
case QmlObjectProperty::List:
case QmlObjectProperty::SignalProperty:
{
prop.m_value = data.value;
break;
}
case QDeclarativeObjectProperty::Object:
case QmlObjectProperty::Object:
{
QDeclarativeDebugObjectReference obj;
QmlDebugObjectReference obj;
obj.m_debugId = prop.m_value.toInt();
prop.m_value = qVariantFromValue(obj);
break;
}
case QDeclarativeObjectProperty::Unknown:
case QmlObjectProperty::Unknown:
break;
}
o.m_properties << prop;
}
}
void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c)
void QmlEngineDebugClient::decode(QDataStream &ds,
QmlDebugContextReference &c)
{
ds >> c.m_name >> c.m_debugId;
......@@ -267,7 +140,7 @@ void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugConte
ds >> contextCount;
for (int ii = 0; ii < contextCount; ++ii) {
c.m_contexts.append(QDeclarativeDebugContextReference());
c.m_contexts.append(QmlDebugContextReference());
decode(ds, c.m_contexts.last());
}
......@@ -275,764 +148,259 @@ void QmlEngineDebugClientPrivate::decode(QDataStream &ds, QDeclarativeDebugConte
ds >> objectCount;
for (int ii = 0; ii < objectCount; ++ii) {
QDeclarativeDebugObjectReference obj;
QmlDebugObjectReference obj;
decode(ds, obj, true);
obj.m_contextDebugId = c.m_debugId;
c.m_objects << obj;
}
}
void QmlEngineDebugClientPrivate::statusChanged(QDeclarativeDebugClient::Status status)
void QmlEngineDebugClient::statusChanged(Status status)
{
emit q->statusChanged(status);
emit newStatus(status);
}
void QmlEngineDebugClientPrivate::message(const QByteArray &data)
void QmlEngineDebugClient::messageReceived(const QByteArray &data)
{
QDataStream ds(data);
int queryId;
QByteArray type;
ds >> type;
//qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type;
if (type == "LIST_ENGINES_R") {
int queryId;
ds >> queryId;
if (type == "OBJECT_CREATED") {
emit newObjects();
return;
}
QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId);
if (!query)
return;
enginesQuery.remove(queryId);
ds >> queryId;
if (type == "LIST_ENGINES_R") {
int count;
ds >> count;
QmlDebugEngineReferenceList engines;
for (int ii = 0; ii < count; ++ii) {
QDeclarativeDebugEngineReference ref;
ds >> ref.m_name;
ds >> ref.m_debugId;
query->m_engines << ref;
QmlDebugEngineReference eng;
ds >> eng.m_name;
ds >> eng.m_debugId;
engines << eng;
}
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
emit result(queryId, QVariant::fromValue(engines));
} else if (type == "LIST_OBJECTS_R") {
int queryId;
ds >> queryId;
QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId);
if (!query)
return;
rootContextQuery.remove(queryId);
QmlDebugContextReference rootContext;
if (!ds.atEnd())
decode(ds, query->m_context);
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
decode(ds, rootContext);
emit result(queryId, QVariant::fromValue(rootContext));
} else if (type == "FETCH_OBJECT_R") {
int queryId;
ds >> queryId;
QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId);
if (!query)
return;
objectQuery.remove(queryId);
QmlDebugObjectReference object;
if (!ds.atEnd())
decode(ds, query->m_object, false);
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "EVAL_EXPRESSION_R") {
int queryId;
QVariant result;
ds >> queryId >> result;
QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId);
if (!query)
return;
expressionQuery.remove(queryId);
query->m_result = result;
query->m_client = 0;
query->setState(QDeclarativeDebugQuery::Completed);
} else if (type == "WATCH_PROPERTY_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
} else if (type == "WATCH_OBJECT_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
} else if (type == "WATCH_EXPR_OBJECT_R") {
int queryId;
bool ok;
ds >> queryId >> ok;
QDeclarativeDebugWatch *watch = watched.value(queryId);
if (!watch)
return;
watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
decode(ds, object, false);
emit result(queryId, QVariant::fromValue(object));
} else if (type == "EVAL_EXPRESSION_R") {;
QVariant exprResult;
ds >> exprResult;
emit result(queryId, exprResult);
} else if (type == "WATCH_PROPERTY_R" ||
type == "WATCH_OBJECT_R" ||
type == "WATCH_EXPR_OBJECT_R") {
bool valid;
ds >> valid;
emit result(queryId, valid);
} else if (type == "UPDATE_WATCH") {
int queryId;
int debugId;
QByteArray name;
QVariant value;
ds >> queryId >> debugId >> name >> value;
QDeclarativeDebugWatch *watch = watched.value(queryId, 0);
if (!watch)
return;
emit watch->valueChanged(name, value);
} else if (type == "OBJECT_CREATED") {
emit q->newObjects();
ds >> debugId >> name >> value;
emit valueChanged(debugId, name, value);
}
}
QmlEngineDebugClient::QmlEngineDebugClient(QDeclarativeDebugConnection *client)
: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client),
d(new QmlEngineDebugClientPrivate(this))
{
}
QmlEngineDebugClient::~QmlEngineDebugClient()
QmlEngineDebugClient::QmlEngineDebugClient(
QDeclarativeDebugConnection *connection)
: QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), connection),
m_nextId(1)
{
delete d;
}
QDeclarativeDebugPropertyWatch *QmlEngineDebugClient::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
quint32 QmlEngineDebugClient::addWatch(const QmlDebugPropertyReference &property)
{
QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
quint32 id;
if (status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = property.objectDebugId();
watch->m_name = property.name();
d->watched.insert(queryId, watch);
id = getId();
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8();
ds << QByteArray("WATCH_PROPERTY") << id << property.m_objectDebugId
<< property.m_name.toUtf8();
sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
return id;
}
QDeclarativeDebugWatch *QmlEngineDebugClient::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *)
quint32 QmlEngineDebugClient::addWatch(const QmlDebugContextReference &/*context*/,
const QString &/*id*/)
{
qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
qWarning("QmlEngineDebugClient::addWatch(): Not implemented");
return 0;
}
QDeclarativeDebugObjectExpressionWatch *QmlEngineDebugClient::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent)
quint32 QmlEngineDebugClient::addWatch(const QmlDebugObjectReference &object,
const QString &expr)
{
QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
quint32 id = 0;
if (status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = object.debugId();
watch->m_expr = expr;
d->watched.insert(queryId, watch);
id = getId();
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr;
ds << QByteArray("WATCH_EXPR_OBJECT") << id << object.m_debugId << expr;
sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
return id;
}
QDeclarativeDebugWatch *QmlEngineDebugClient::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent)
quint32 QmlEngineDebugClient::addWatch(const QmlDebugObjectReference &object)
{
QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
quint32 id = 0;
if (status() == QDeclarativeDebugClient::Enabled) {
int queryId = d->getId();
watch->m_queryId = queryId;
watch->m_client = this;
watch->m_objectDebugId = object.debugId();
d->watched.insert(queryId, watch);
id = getId();
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId();
ds << QByteArray("WATCH_OBJECT") << id << object.m_debugId;
sendMessage(message);
} else {
watch->m_state = QDeclarativeDebugWatch::Dead;
}
return watch;
return id;
}
QDeclarativeDebugWatch *QmlEngineDebugClient::addWatch(const QDeclarativeDebugFileReference &, QObject *)
quint32 QmlEngineDebugClient::addWatch(const QmlDebugFileReference &/*file*/)
{
qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
qWarning("QmlEngineDebugClient::addWatch(): Not implemented");
return 0;
}
void QmlEngineDebugClient::removeWatch(QDeclarativeDebugWatch *watch)
void QmlEngineDebugClient::removeWatch(quint32 id)
{
if (!watch || !watch->m_client)
return;
watch->m_client = 0;
watch->setState(QDeclarativeDebugWatch::Inactive);
d->watched.remove(watch->queryId());
if (status() == QDeclarativeDebugClient::Enabled) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("NO_WATCH") << watch->queryId();
ds << QByteArray("NO_WATCH") << id;
sendMessage(message);
}
}
QDeclarativeDebugEnginesQuery *QmlEngineDebugClient::queryAvailableEngines(QObject *parent)
quint32 QmlEngineDebugClient::queryAvailableEngines()
{
QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
quint32 id = 0;
if (status() == QDeclarativeDebugClient::Enabled) {
query->m_client = this;
int queryId = d->getId();
query->m_queryId = queryId;
d->enginesQuery.insert(queryId, query);
id = getId();
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("LIST_ENGINES") << queryId;
ds << QByteArray("LIST_ENGINES") << id;
sendMessage(message);
} else {
query->m_state = QDeclarativeDebugQuery::Error;
}
return query;
return id;
}
QDeclarativeDebugRootContextQuery *QmlEngineDebugClient::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent)
quint32 QmlEngineDebugClient::queryRootContexts(const QmlDebugEngineReference &engine)
{
QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent);
if (status() == QDeclarativeDebugClient::Enabled && engine.debugId() != -1) {
query->m_cli