Commit bfedb278 authored by Aurindam Jana's avatar Aurindam Jana Committed by Qt by Nokia

QmlEngineDebugService: Rename service to QmlDebugger

Rename service from QDeclarativeEngine to QmlDebugger.
Send a response for each query.

Change-Id: I01cfeaf3e4116bfd7029d170ee228c159973947c
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent e0e81d6f
......@@ -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)
{
......@@ -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");
......@@ -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));
......@@ -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);
......@@ -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;
......@@ -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;
......@@ -491,11 +485,10 @@ 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;
......@@ -503,16 +496,17 @@ void QQmlEngineDebugService::processMessage(const QByteArray &message)
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);
......@@ -541,26 +535,43 @@ 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,
......@@ -568,6 +579,7 @@ void QQmlEngineDebugService::setBinding(int objectId,
int line,
int column)
{
bool ok = true;
QObject *object = objectForId(objectId);
QQmlContext *context = qmlContext(object);
......@@ -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);
......@@ -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();
......@@ -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)
......@@ -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);
}
......
......@@ -119,9 +119,9 @@ private:
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;
......
......@@ -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)
......
......@@ -77,7 +77,7 @@ public:
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);
......
......@@ -127,7 +127,7 @@ public:
QQmlEngineDebugClient::QQmlEngineDebugClient(QQmlDebugConnection *client,
QQmlEngineDebugPrivate *p)
: QQmlDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
: QQmlDebugClient(QLatin1String("QmlDebugger"), client), priv(p)
{
}
......@@ -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;
}
}
......@@ -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 {
......@@ -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 {
......@@ -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 {
......
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