Skip to content

Commit

Permalink
QmlEngineDebugService: Rename service to QmlDebugger
Browse files Browse the repository at this point in the history
Rename service from QDeclarativeEngine to QmlDebugger.
Send a response for each query.

Change-Id: I01cfeaf3e4116bfd7029d170ee228c159973947c
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
  • Loading branch information
Aurindam Jana authored and Qt by Nokia committed Mar 19, 2012
1 parent e0e81d6 commit bfedb27
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 45 deletions.
86 changes: 51 additions & 35 deletions src/qml/debugger/qqmlenginedebugservice.cpp
Expand Up @@ -67,7 +67,7 @@ QQmlEngineDebugService *QQmlEngineDebugService::instance()
}

QQmlEngineDebugService::QQmlEngineDebugService(QObject *parent)
: QQmlDebugService(QStringLiteral("QDeclarativeEngine"), 1, parent),
: QQmlDebugService(QStringLiteral("QmlDebugger"), 1, parent),
m_watch(new QQmlWatcher(this)),
m_statesDelegate(0)
{
Expand Down Expand Up @@ -396,12 +396,10 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)
QDataStream ds(message);

QByteArray type;
ds >> type;
int queryId;
ds >> type >> queryId;

if (type == "LIST_ENGINES") {
int queryId;
ds >> queryId;

QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("LIST_ENGINES_R");
Expand All @@ -418,9 +416,8 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)

sendMessage(reply);
} else if (type == "LIST_OBJECTS") {
int queryId;
int engineId = -1;
ds >> queryId >> engineId;
ds >> engineId;

QQmlEngine *engine =
qobject_cast<QQmlEngine *>(QQmlDebugService::objectForId(engineId));
Expand All @@ -445,12 +442,11 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)

sendMessage(reply);
} else if (type == "FETCH_OBJECT") {
int queryId;
int objectId;
bool recurse;
bool dumpProperties = true;

ds >> queryId >> objectId >> recurse >> dumpProperties;
ds >> objectId >> recurse >> dumpProperties;

QObject *object = QQmlDebugService::objectForId(objectId);

Expand All @@ -466,10 +462,9 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)

sendMessage(reply);
} else if (type == "WATCH_OBJECT") {
int queryId;
int objectId;

ds >> queryId >> objectId;
ds >> objectId;
bool ok = m_watch->addWatch(queryId, objectId);

QByteArray reply;
Expand All @@ -478,11 +473,10 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)

sendMessage(reply);
} else if (type == "WATCH_PROPERTY") {
int queryId;
int objectId;
QByteArray property;

ds >> queryId >> objectId >> property;
ds >> objectId >> property;
bool ok = m_watch->addWatch(queryId, objectId, property);

QByteArray reply;
Expand All @@ -491,28 +485,28 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)

sendMessage(reply);
} else if (type == "WATCH_EXPR_OBJECT") {
int queryId;
int debugId;
QString expr;

ds >> queryId >> debugId >> expr;
ds >> debugId >> expr;
bool ok = m_watch->addWatch(queryId, debugId, expr);

QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("WATCH_EXPR_OBJECT_R") << queryId << ok;
sendMessage(reply);
} else if (type == "NO_WATCH") {
int queryId;
bool ok = m_watch->removeWatch(queryId);

ds >> queryId;
m_watch->removeWatch(queryId);
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("NO_WATCH_R") << queryId << ok;
sendMessage(reply);
} else if (type == "EVAL_EXPRESSION") {
int queryId;
int objectId;
QString expr;

ds >> queryId >> objectId >> expr;
ds >> objectId >> expr;

QObject *object = QQmlDebugService::objectForId(objectId);
QQmlContext *context = qmlContext(object);
Expand Down Expand Up @@ -541,33 +535,51 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)
bool isLiteralValue;
QString filename;
int line;
ds >> objectId >> propertyName >> expr >> isLiteralValue;
if (!ds.atEnd()) { // backward compatibility from 2.1, 2.2
ds >> filename >> line;
}
setBinding(objectId, propertyName, expr, isLiteralValue, filename, line);
ds >> objectId >> propertyName >> expr >> isLiteralValue >>
filename >> line;
bool ok = setBinding(objectId, propertyName, expr, isLiteralValue,
filename, line);

QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("SET_BINDING_R") << queryId << ok;

sendMessage(reply);
} else if (type == "RESET_BINDING") {
int objectId;
QString propertyName;
ds >> objectId >> propertyName;
resetBinding(objectId, propertyName);
bool ok = resetBinding(objectId, propertyName);

QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("RESET_BINDING_R") << queryId << ok;

sendMessage(reply);
} else if (type == "SET_METHOD_BODY") {
int objectId;
QString methodName;
QString methodBody;
ds >> objectId >> methodName >> methodBody;
setMethodBody(objectId, methodName, methodBody);
bool ok = setMethodBody(objectId, methodName, methodBody);

QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("SET_METHOD_BODY_R") << queryId << ok;

sendMessage(reply);
}
}

void QQmlEngineDebugService::setBinding(int objectId,
bool QQmlEngineDebugService::setBinding(int objectId,
const QString &propertyName,
const QVariant &expression,
bool isLiteralValue,
QString filename,
int line,
int column)
{
bool ok = true;
QObject *object = objectForId(objectId);
QQmlContext *context = qmlContext(object);

Expand Down Expand Up @@ -596,22 +608,23 @@ void QQmlEngineDebugService::setBinding(int objectId,
oldBinding->destroy();
binding->update();
} else {
ok = false;
qWarning() << "QQmlEngineDebugService::setBinding: unable to set property" << propertyName << "on object" << object;
}
}

} else {
// not a valid property
bool ok = false;
if (m_statesDelegate)
ok = m_statesDelegate->setBindingForInvalidProperty(object, propertyName, expression, isLiteralValue);
if (!ok)
qWarning() << "QQmlEngineDebugService::setBinding: unable to set property" << propertyName << "on object" << object;
}
}
return ok;
}

void QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyName)
bool QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyName)
{
QObject *object = objectForId(objectId);
QQmlContext *context = qmlContext(object);
Expand Down Expand Up @@ -653,24 +666,25 @@ void QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyN
m_statesDelegate->resetBindingForInvalidProperty(object, propertyName);
}
}
return true;
}

void QQmlEngineDebugService::setMethodBody(int objectId, const QString &method, const QString &body)
bool QQmlEngineDebugService::setMethodBody(int objectId, const QString &method, const QString &body)
{
QObject *object = objectForId(objectId);
QQmlContext *context = qmlContext(object);
if (!object || !context || !context->engine())
return;
return false;
QQmlContextData *contextData = QQmlContextData::get(context);
if (!contextData)
return;
return false;

QQmlPropertyData dummy;
QQmlPropertyData *prop =
QQmlPropertyCache::property(context->engine(), object, method, dummy);

if (!prop || !prop->isVMEFunction())
return;
return false;

QMetaMethod metaMethod = object->metaObject()->method(prop->coreIndex);
QList<QByteArray> paramNames = metaMethod.parameterNames();
Expand All @@ -692,6 +706,7 @@ void QQmlEngineDebugService::setMethodBody(int objectId, const QString &method,

int lineNumber = vmeMetaObject->vmeMethodLineNumber(prop->coreIndex);
vmeMetaObject->setVmeMethod(prop->coreIndex, QQmlExpressionPrivate::evalFunction(contextData, object, jsfunction, contextData->url.toString(), lineNumber));
return true;
}

void QQmlEngineDebugService::propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value)
Expand Down Expand Up @@ -731,7 +746,8 @@ void QQmlEngineDebugService::objectCreated(QQmlEngine *engine, QObject *object)
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);

rs << QByteArray("OBJECT_CREATED") << engineId << objectId;
//unique queryId -1
rs << QByteArray("OBJECT_CREATED") << -1 << engineId << objectId;
sendMessage(reply);
}

Expand Down
6 changes: 3 additions & 3 deletions src/qml/debugger/qqmlenginedebugservice_p.h
Expand Up @@ -119,9 +119,9 @@ private Q_SLOTS:
QQmlObjectData objectData(QObject *);
QQmlObjectProperty propertyData(QObject *, int);
QVariant valueContents(const QVariant &defaultValue) const;
void setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1, int column = 0);
void resetBinding(int objectId, const QString &propertyName);
void setMethodBody(int objectId, const QString &method, const QString &body);
bool setBinding(int objectId, const QString &propertyName, const QVariant &expression, bool isLiteralValue, QString filename = QString(), int line = -1, int column = 0);
bool resetBinding(int objectId, const QString &propertyName);
bool setMethodBody(int objectId, const QString &method, const QString &body);

QList<QQmlEngine *> m_engines;
QQmlWatcher *m_watch;
Expand Down
5 changes: 3 additions & 2 deletions src/qml/qml/qqmlwatcher.cpp
Expand Up @@ -166,13 +166,14 @@ bool QQmlWatcher::addWatch(int id, quint32 objectId, const QString &expr)
return false;
}

void QQmlWatcher::removeWatch(int id)
bool QQmlWatcher::removeWatch(int id)
{
if (!m_proxies.contains(id))
return;
return false;

QList<QPointer<QQmlWatchProxy> > proxies = m_proxies.take(id);
qDeleteAll(proxies);
return true;
}

void QQmlWatcher::addPropertyWatch(int id, QObject *object, quint32 debugId, const QMetaProperty &property)
Expand Down
2 changes: 1 addition & 1 deletion src/qml/qml/qqmlwatcher_p.h
Expand Up @@ -77,7 +77,7 @@ class QQmlWatcher : public QObject
bool addWatch(int id, quint32 objectId, const QByteArray &property);
bool addWatch(int id, quint32 objectId, const QString &expr);

void removeWatch(int id);
bool removeWatch(int id);

Q_SIGNALS:
void propertyChanged(int id, int objectId, const QMetaProperty &property, const QVariant &value);
Expand Down
14 changes: 10 additions & 4 deletions tests/auto/qml/debugger/shared/qqmlenginedebug.cpp
Expand Up @@ -127,7 +127,7 @@ class QQmlEngineDebugPrivate

QQmlEngineDebugClient::QQmlEngineDebugClient(QQmlDebugConnection *client,
QQmlEngineDebugPrivate *p)
: QQmlDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
: QQmlDebugClient(QLatin1String("QmlDebugger"), client), priv(p)
{
}

Expand Down Expand Up @@ -439,6 +439,12 @@ void QQmlEngineDebugPrivate::message(const QByteArray &data)
emit watch->valueChanged(name, value);
} else if (type == "OBJECT_CREATED") {
emit q->newObjects();
} else if (type == "SET_BINDING_R" ||
type == "RESET_BINDING_R" ||
type == "SET_METHOD_BODY_R" ||
type == "NO_WATCH_R") {
bool valid;
ds >> valid;
}
}

Expand Down Expand Up @@ -663,7 +669,7 @@ bool QQmlEngineDebug::setBindingForObject(int objectDebugId, const QString &prop
if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line;
ds << QByteArray("SET_BINDING") << d->getId() << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line;
d->client->sendMessage(message);
return true;
} else {
Expand All @@ -676,7 +682,7 @@ bool QQmlEngineDebug::resetBindingForObject(int objectDebugId, const QString &pr
if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
ds << QByteArray("RESET_BINDING") << d->getId() << objectDebugId << propertyName;
d->client->sendMessage(message);
return true;
} else {
Expand All @@ -690,7 +696,7 @@ bool QQmlEngineDebug::setMethodBody(int objectDebugId, const QString &methodName
if (d->client->state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
QByteArray message;
QDataStream ds(&message, QIODevice::WriteOnly);
ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
ds << QByteArray("SET_METHOD_BODY") << d->getId() << objectDebugId << methodName << methodBody;
d->client->sendMessage(message);
return true;
} else {
Expand Down

0 comments on commit bfedb27

Please sign in to comment.