836885db2a1be80ba5fffddf50de127a61514f79
[profile/ivi/qtdeclarative.git] / src / declarative / debugger / qdeclarativeenginedebug.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "private/qdeclarativeenginedebug_p.h"
43
44 #include "private/qdeclarativedebugclient_p.h"
45
46 #include <qdeclarativeenginedebugservice_p.h>
47
48 #include <private/qobject_p.h>
49
50 QT_BEGIN_NAMESPACE
51
52 class QDeclarativeEngineDebugClient : public QDeclarativeDebugClient
53 {
54 public:
55     QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client, QDeclarativeEngineDebugPrivate *p);
56
57 protected:
58     virtual void statusChanged(Status status);
59     virtual void messageReceived(const QByteArray &);
60
61 private:
62     QDeclarativeEngineDebugPrivate *priv;
63     friend class QDeclarativeEngineDebugPrivate;
64 };
65
66 class QDeclarativeEngineDebugPrivate : public QObjectPrivate
67 {
68     Q_DECLARE_PUBLIC(QDeclarativeEngineDebug)
69 public:
70     QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *);
71     ~QDeclarativeEngineDebugPrivate();
72
73     void statusChanged(QDeclarativeEngineDebug::Status status);
74     void message(const QByteArray &);
75
76     QDeclarativeEngineDebugClient *client;
77     int nextId;
78     int getId();
79
80     void decode(QDataStream &, QDeclarativeDebugContextReference &);
81     void decode(QDataStream &, QDeclarativeDebugObjectReference &, bool simple);
82
83     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugEnginesQuery *);
84     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugRootContextQuery *);
85     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugObjectQuery *);
86     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugExpressionQuery *);
87     static void remove(QDeclarativeEngineDebug *, QDeclarativeDebugWatch *);
88
89     QHash<int, QDeclarativeDebugEnginesQuery *> enginesQuery;
90     QHash<int, QDeclarativeDebugRootContextQuery *> rootContextQuery;
91     QHash<int, QDeclarativeDebugObjectQuery *> objectQuery;
92     QHash<int, QDeclarativeDebugExpressionQuery *> expressionQuery;
93
94     QHash<int, QDeclarativeDebugWatch *> watched;
95 };
96
97 QDeclarativeEngineDebugClient::QDeclarativeEngineDebugClient(QDeclarativeDebugConnection *client,
98                                                              QDeclarativeEngineDebugPrivate *p)
99     : QDeclarativeDebugClient(QLatin1String("QDeclarativeEngine"), client), priv(p)
100 {
101 }
102
103 void QDeclarativeEngineDebugClient::statusChanged(Status status)
104 {
105     if (priv)
106         priv->statusChanged(static_cast<QDeclarativeEngineDebug::Status>(status));
107 }
108
109 void QDeclarativeEngineDebugClient::messageReceived(const QByteArray &data)
110 {
111     if (priv)
112         priv->message(data);
113 }
114
115 QDeclarativeEngineDebugPrivate::QDeclarativeEngineDebugPrivate(QDeclarativeDebugConnection *c)
116     : client(new QDeclarativeEngineDebugClient(c, this)), nextId(0)
117 {
118 }
119
120 QDeclarativeEngineDebugPrivate::~QDeclarativeEngineDebugPrivate()
121 {
122     if (client)
123         client->priv = 0;
124     delete client;
125
126     QHash<int, QDeclarativeDebugEnginesQuery*>::iterator enginesIter = enginesQuery.begin();
127     for (; enginesIter != enginesQuery.end(); ++enginesIter) {
128         enginesIter.value()->m_client = 0;
129         if (enginesIter.value()->state() == QDeclarativeDebugQuery::Waiting)
130             enginesIter.value()->setState(QDeclarativeDebugQuery::Error);
131     }
132
133     QHash<int, QDeclarativeDebugRootContextQuery*>::iterator rootContextIter = rootContextQuery.begin();
134     for (; rootContextIter != rootContextQuery.end(); ++rootContextIter) {
135         rootContextIter.value()->m_client = 0;
136         if (rootContextIter.value()->state() == QDeclarativeDebugQuery::Waiting)
137             rootContextIter.value()->setState(QDeclarativeDebugQuery::Error);
138     }
139
140     QHash<int, QDeclarativeDebugObjectQuery*>::iterator objectIter = objectQuery.begin();
141     for (; objectIter != objectQuery.end(); ++objectIter) {
142         objectIter.value()->m_client = 0;
143         if (objectIter.value()->state() == QDeclarativeDebugQuery::Waiting)
144             objectIter.value()->setState(QDeclarativeDebugQuery::Error);
145     }
146
147     QHash<int, QDeclarativeDebugExpressionQuery*>::iterator exprIter = expressionQuery.begin();
148     for (; exprIter != expressionQuery.end(); ++exprIter) {
149         exprIter.value()->m_client = 0;
150         if (exprIter.value()->state() == QDeclarativeDebugQuery::Waiting)
151             exprIter.value()->setState(QDeclarativeDebugQuery::Error);
152     }
153
154     QHash<int, QDeclarativeDebugWatch*>::iterator watchIter = watched.begin();
155     for (; watchIter != watched.end(); ++watchIter) {
156         watchIter.value()->m_client = 0;
157         watchIter.value()->setState(QDeclarativeDebugWatch::Dead);
158     }
159 }
160
161 int QDeclarativeEngineDebugPrivate::getId()
162 {
163     return nextId++;
164 }
165
166 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugEnginesQuery *q)
167 {
168     if (c && q) {
169         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
170         p->enginesQuery.remove(q->m_queryId);
171     }
172 }
173
174 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, 
175                                             QDeclarativeDebugRootContextQuery *q)
176 {
177     if (c && q) {
178         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
179         p->rootContextQuery.remove(q->m_queryId);
180     }
181 }
182
183 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugObjectQuery *q)
184 {
185     if (c && q) {
186         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
187         p->objectQuery.remove(q->m_queryId);
188     }
189 }
190
191 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugExpressionQuery *q)
192 {
193     if (c && q) {
194         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
195         p->expressionQuery.remove(q->m_queryId);
196     }
197 }
198
199 void QDeclarativeEngineDebugPrivate::remove(QDeclarativeEngineDebug *c, QDeclarativeDebugWatch *w)
200 {
201     if (c && w) {
202         QDeclarativeEngineDebugPrivate *p = (QDeclarativeEngineDebugPrivate *)QObjectPrivate::get(c);
203         p->watched.remove(w->m_queryId);
204     }
205 }
206
207 void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugObjectReference &o,
208                                             bool simple)
209 {
210     QDeclarativeEngineDebugService::QDeclarativeObjectData data;
211     ds >> data;
212     o.m_debugId = data.objectId;
213     o.m_class = data.objectType;
214     o.m_idString = data.idString;
215     o.m_name = data.objectName;
216     o.m_source.m_url = data.url;
217     o.m_source.m_lineNumber = data.lineNumber;
218     o.m_source.m_columnNumber = data.columnNumber;
219     o.m_contextDebugId = data.contextId;
220
221     if (simple)
222         return;
223
224     int childCount;
225     bool recur;
226     ds >> childCount >> recur;
227
228     for (int ii = 0; ii < childCount; ++ii) {
229         o.m_children.append(QDeclarativeDebugObjectReference());
230         decode(ds, o.m_children.last(), !recur);
231     }
232
233     int propCount;
234     ds >> propCount;
235
236     for (int ii = 0; ii < propCount; ++ii) {
237         QDeclarativeEngineDebugService::QDeclarativeObjectProperty data;
238         ds >> data;
239         QDeclarativeDebugPropertyReference prop;
240         prop.m_objectDebugId = o.m_debugId;
241         prop.m_name = data.name;
242         prop.m_binding = data.binding;
243         prop.m_hasNotifySignal = data.hasNotifySignal;
244         prop.m_valueTypeName = data.valueTypeName;
245         switch (data.type) {
246         case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Basic:
247         case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::List:
248         case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::SignalProperty:
249         {
250             prop.m_value = data.value;
251             break;
252         }
253         case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Object:
254         {
255             QDeclarativeDebugObjectReference obj;
256             obj.m_debugId = prop.m_value.toInt();
257             prop.m_value = QVariant::fromValue(obj);
258             break;
259         }
260         case QDeclarativeEngineDebugService::QDeclarativeObjectProperty::Unknown:
261             break;
262         }
263         o.m_properties << prop;
264     }
265 }
266
267 void QDeclarativeEngineDebugPrivate::decode(QDataStream &ds, QDeclarativeDebugContextReference &c)
268 {
269     ds >> c.m_name >> c.m_debugId;
270
271     int contextCount;
272     ds >> contextCount;
273
274     for (int ii = 0; ii < contextCount; ++ii) {
275         c.m_contexts.append(QDeclarativeDebugContextReference());
276         decode(ds, c.m_contexts.last());
277     }
278
279     int objectCount;
280     ds >> objectCount;
281
282     for (int ii = 0; ii < objectCount; ++ii) {
283         QDeclarativeDebugObjectReference obj;
284         decode(ds, obj, true);
285
286         obj.m_contextDebugId = c.m_debugId;
287         c.m_objects << obj;
288     }
289 }
290
291 void QDeclarativeEngineDebugPrivate::statusChanged(QDeclarativeEngineDebug::Status status)
292 {
293     emit q_func()->statusChanged(status);
294 }
295
296 void QDeclarativeEngineDebugPrivate::message(const QByteArray &data)
297 {
298     QDataStream ds(data);
299
300     QByteArray type;
301     ds >> type;
302
303     //qDebug() << "QDeclarativeEngineDebugPrivate::message()" << type;
304
305     if (type == "LIST_ENGINES_R") {
306         int queryId;
307         ds >> queryId;
308
309         QDeclarativeDebugEnginesQuery *query = enginesQuery.value(queryId);
310         if (!query)
311             return;
312         enginesQuery.remove(queryId);
313
314         int count;
315         ds >> count;
316
317         for (int ii = 0; ii < count; ++ii) {
318             QDeclarativeDebugEngineReference ref;
319             ds >> ref.m_name;
320             ds >> ref.m_debugId;
321             query->m_engines << ref;
322         }
323
324         query->m_client = 0;
325         query->setState(QDeclarativeDebugQuery::Completed);
326     } else if (type == "LIST_OBJECTS_R") {
327         int queryId;
328         ds >> queryId;
329
330         QDeclarativeDebugRootContextQuery *query = rootContextQuery.value(queryId);
331         if (!query)
332             return;
333         rootContextQuery.remove(queryId);
334
335         if (!ds.atEnd())
336             decode(ds, query->m_context);
337
338         query->m_client = 0;
339         query->setState(QDeclarativeDebugQuery::Completed);
340     } else if (type == "FETCH_OBJECT_R") {
341         int queryId;
342         ds >> queryId;
343
344         QDeclarativeDebugObjectQuery *query = objectQuery.value(queryId);
345         if (!query)
346             return;
347         objectQuery.remove(queryId);
348
349         if (!ds.atEnd())
350             decode(ds, query->m_object, false);
351
352         query->m_client = 0;
353         query->setState(QDeclarativeDebugQuery::Completed);
354     } else if (type == "EVAL_EXPRESSION_R") {
355         int queryId;
356         QVariant result;
357         ds >> queryId >> result;
358
359         QDeclarativeDebugExpressionQuery *query = expressionQuery.value(queryId);
360         if (!query)
361             return;
362         expressionQuery.remove(queryId);
363
364         query->m_result = result;
365         query->m_client = 0;
366         query->setState(QDeclarativeDebugQuery::Completed);
367     } else if (type == "WATCH_PROPERTY_R") {
368         int queryId;
369         bool ok;
370         ds >> queryId >> ok;
371
372         QDeclarativeDebugWatch *watch = watched.value(queryId);
373         if (!watch)
374             return;
375
376         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
377     } else if (type == "WATCH_OBJECT_R") {
378         int queryId;
379         bool ok;
380         ds >> queryId >> ok;
381
382         QDeclarativeDebugWatch *watch = watched.value(queryId);
383         if (!watch)
384             return;
385
386         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
387     } else if (type == "WATCH_EXPR_OBJECT_R") {
388         int queryId;
389         bool ok;
390         ds >> queryId >> ok;
391
392         QDeclarativeDebugWatch *watch = watched.value(queryId);
393         if (!watch)
394             return;
395
396         watch->setState(ok ? QDeclarativeDebugWatch::Active : QDeclarativeDebugWatch::Inactive);
397     } else if (type == "UPDATE_WATCH") {
398         int queryId;
399         int debugId;
400         QByteArray name;
401         QVariant value;
402         ds >> queryId >> debugId >> name >> value;
403
404         QDeclarativeDebugWatch *watch = watched.value(queryId, 0);
405         if (!watch)
406             return;
407         emit watch->valueChanged(name, value);
408     } else if (type == "OBJECT_CREATED") {
409         emit q_func()->newObjects();
410     }
411 }
412
413 QDeclarativeEngineDebug::QDeclarativeEngineDebug(QDeclarativeDebugConnection *client, QObject *parent)
414     : QObject(*(new QDeclarativeEngineDebugPrivate(client)), parent)
415 {
416 }
417
418 QDeclarativeEngineDebug::Status QDeclarativeEngineDebug::status() const
419 {
420     Q_D(const QDeclarativeEngineDebug);
421
422     return static_cast<QDeclarativeEngineDebug::Status>(d->client->status());
423 }
424
425 QDeclarativeDebugPropertyWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugPropertyReference &property, QObject *parent)
426 {
427     Q_D(QDeclarativeEngineDebug);
428
429     QDeclarativeDebugPropertyWatch *watch = new QDeclarativeDebugPropertyWatch(parent);
430     if (d->client->status() == QDeclarativeDebugClient::Enabled) {
431         int queryId = d->getId();
432         watch->m_queryId = queryId;
433         watch->m_client = this;
434         watch->m_objectDebugId = property.objectDebugId();
435         watch->m_name = property.name();
436         d->watched.insert(queryId, watch);
437
438         QByteArray message;
439         QDataStream ds(&message, QIODevice::WriteOnly);
440         ds << QByteArray("WATCH_PROPERTY") << queryId << property.objectDebugId() << property.name().toUtf8();
441         d->client->sendMessage(message);
442     } else {
443         watch->m_state = QDeclarativeDebugWatch::Dead;
444     }
445
446     return watch;
447 }
448
449 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugContextReference &, const QString &, QObject *)
450 {
451     qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
452     return 0;
453 }
454
455 QDeclarativeDebugObjectExpressionWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, const QString &expr, QObject *parent)
456 {
457     Q_D(QDeclarativeEngineDebug);
458     QDeclarativeDebugObjectExpressionWatch *watch = new QDeclarativeDebugObjectExpressionWatch(parent);
459     if (d->client->status() == QDeclarativeDebugClient::Enabled) {
460         int queryId = d->getId();
461         watch->m_queryId = queryId;
462         watch->m_client = this;
463         watch->m_objectDebugId = object.debugId();
464         watch->m_expr = expr;
465         d->watched.insert(queryId, watch);
466
467         QByteArray message;
468         QDataStream ds(&message, QIODevice::WriteOnly);
469         ds << QByteArray("WATCH_EXPR_OBJECT") << queryId << object.debugId() << expr;
470         d->client->sendMessage(message);
471     } else {
472         watch->m_state = QDeclarativeDebugWatch::Dead;
473     }
474     return watch;
475 }
476
477 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugObjectReference &object, QObject *parent)
478 {
479     Q_D(QDeclarativeEngineDebug);
480
481     QDeclarativeDebugWatch *watch = new QDeclarativeDebugWatch(parent);
482     if (d->client->status() == QDeclarativeDebugClient::Enabled) {
483         int queryId = d->getId();
484         watch->m_queryId = queryId;
485         watch->m_client = this;
486         watch->m_objectDebugId = object.debugId();
487         d->watched.insert(queryId, watch);
488
489         QByteArray message;
490         QDataStream ds(&message, QIODevice::WriteOnly);
491         ds << QByteArray("WATCH_OBJECT") << queryId << object.debugId();
492         d->client->sendMessage(message);
493     } else {
494         watch->m_state = QDeclarativeDebugWatch::Dead;
495     }
496
497     return watch;
498 }
499
500 QDeclarativeDebugWatch *QDeclarativeEngineDebug::addWatch(const QDeclarativeDebugFileReference &, QObject *)
501 {
502     qWarning("QDeclarativeEngineDebug::addWatch(): Not implemented");
503     return 0;
504 }
505
506 void QDeclarativeEngineDebug::removeWatch(QDeclarativeDebugWatch *watch)
507 {
508     Q_D(QDeclarativeEngineDebug);
509
510     if (!watch || !watch->m_client)
511         return;
512
513     watch->m_client = 0;
514     watch->setState(QDeclarativeDebugWatch::Inactive);
515     
516     d->watched.remove(watch->queryId());
517
518     if (d->client && d->client->status() == QDeclarativeDebugClient::Enabled) {
519         QByteArray message;
520         QDataStream ds(&message, QIODevice::WriteOnly);
521         ds << QByteArray("NO_WATCH") << watch->queryId();
522         d->client->sendMessage(message);
523     }
524 }
525
526 QDeclarativeDebugEnginesQuery *QDeclarativeEngineDebug::queryAvailableEngines(QObject *parent)
527 {
528     Q_D(QDeclarativeEngineDebug);
529
530     QDeclarativeDebugEnginesQuery *query = new QDeclarativeDebugEnginesQuery(parent);
531     if (d->client->status() == QDeclarativeDebugClient::Enabled) {
532         query->m_client = this;
533         int queryId = d->getId();
534         query->m_queryId = queryId;
535         d->enginesQuery.insert(queryId, query);
536
537         QByteArray message;
538         QDataStream ds(&message, QIODevice::WriteOnly);
539         ds << QByteArray("LIST_ENGINES") << queryId;
540         d->client->sendMessage(message);
541     } else {
542         query->m_state = QDeclarativeDebugQuery::Error;
543     }
544
545     return query;
546 }
547
548 QDeclarativeDebugRootContextQuery *QDeclarativeEngineDebug::queryRootContexts(const QDeclarativeDebugEngineReference &engine, QObject *parent)
549 {
550     Q_D(QDeclarativeEngineDebug);
551
552     QDeclarativeDebugRootContextQuery *query = new QDeclarativeDebugRootContextQuery(parent);
553     if (d->client->status() == QDeclarativeDebugClient::Enabled && engine.debugId() != -1) {
554         query->m_client = this;
555         int queryId = d->getId();
556         query->m_queryId = queryId;
557         d->rootContextQuery.insert(queryId, query);
558
559         QByteArray message;
560         QDataStream ds(&message, QIODevice::WriteOnly);
561         ds << QByteArray("LIST_OBJECTS") << queryId << engine.debugId();
562         d->client->sendMessage(message);
563     } else {
564         query->m_state = QDeclarativeDebugQuery::Error;
565     }
566
567     return query;
568 }
569
570 QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObject(const QDeclarativeDebugObjectReference &object, QObject *parent)
571 {
572     Q_D(QDeclarativeEngineDebug);
573
574     QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
575     if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) {
576         query->m_client = this;
577         int queryId = d->getId();
578         query->m_queryId = queryId;
579         d->objectQuery.insert(queryId, query);
580
581         QByteArray message;
582         QDataStream ds(&message, QIODevice::WriteOnly);
583         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
584            << false << true;
585         d->client->sendMessage(message);
586     } else {
587         query->m_state = QDeclarativeDebugQuery::Error;
588     }
589
590     return query;
591 }
592
593 QDeclarativeDebugObjectQuery *QDeclarativeEngineDebug::queryObjectRecursive(const QDeclarativeDebugObjectReference &object, QObject *parent)
594 {
595     Q_D(QDeclarativeEngineDebug);
596
597     QDeclarativeDebugObjectQuery *query = new QDeclarativeDebugObjectQuery(parent);
598     if (d->client->status() == QDeclarativeDebugClient::Enabled && object.debugId() != -1) {
599         query->m_client = this;
600         int queryId = d->getId();
601         query->m_queryId = queryId;
602         d->objectQuery.insert(queryId, query);
603
604         QByteArray message;
605         QDataStream ds(&message, QIODevice::WriteOnly);
606         ds << QByteArray("FETCH_OBJECT") << queryId << object.debugId()
607            << true << true;
608         d->client->sendMessage(message);
609     } else {
610         query->m_state = QDeclarativeDebugQuery::Error;
611     }
612
613     return query;
614 }
615
616 QDeclarativeDebugExpressionQuery *QDeclarativeEngineDebug::queryExpressionResult(int objectDebugId, const QString &expr, QObject *parent)
617 {
618     Q_D(QDeclarativeEngineDebug);
619
620     QDeclarativeDebugExpressionQuery *query = new QDeclarativeDebugExpressionQuery(parent);
621     if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
622         query->m_client = this;
623         query->m_expr = expr;
624         int queryId = d->getId();
625         query->m_queryId = queryId;
626         d->expressionQuery.insert(queryId, query);
627
628         QByteArray message;
629         QDataStream ds(&message, QIODevice::WriteOnly);
630         ds << QByteArray("EVAL_EXPRESSION") << queryId << objectDebugId << expr;
631         d->client->sendMessage(message);
632     } else {
633         query->m_state = QDeclarativeDebugQuery::Error;
634     }
635
636     return query;
637 }
638
639 bool QDeclarativeEngineDebug::setBindingForObject(int objectDebugId, const QString &propertyName,
640                                                   const QVariant &bindingExpression,
641                                                   bool isLiteralValue,
642                                                   QString source, int line)
643 {
644     Q_D(QDeclarativeEngineDebug);
645
646     if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
647         QByteArray message;
648         QDataStream ds(&message, QIODevice::WriteOnly);
649         ds << QByteArray("SET_BINDING") << objectDebugId << propertyName << bindingExpression << isLiteralValue << source << line;
650         d->client->sendMessage(message);
651         return true;
652     } else {
653         return false;
654     }
655 }
656
657 bool QDeclarativeEngineDebug::resetBindingForObject(int objectDebugId, const QString &propertyName)
658 {
659     Q_D(QDeclarativeEngineDebug);
660
661     if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
662         QByteArray message;
663         QDataStream ds(&message, QIODevice::WriteOnly);
664         ds << QByteArray("RESET_BINDING") << objectDebugId << propertyName;
665         d->client->sendMessage(message);
666         return true;
667     } else {
668         return false;
669     }
670 }
671
672 bool QDeclarativeEngineDebug::setMethodBody(int objectDebugId, const QString &methodName,
673                                             const QString &methodBody)
674 {
675     Q_D(QDeclarativeEngineDebug);
676
677     if (d->client->status() == QDeclarativeDebugClient::Enabled && objectDebugId != -1) {
678         QByteArray message;
679         QDataStream ds(&message, QIODevice::WriteOnly);
680         ds << QByteArray("SET_METHOD_BODY") << objectDebugId << methodName << methodBody;
681         d->client->sendMessage(message);
682         return true;
683     } else {
684         return false;
685     }
686 }
687
688 QDeclarativeDebugWatch::QDeclarativeDebugWatch(QObject *parent)
689     : QObject(parent), m_state(Waiting), m_queryId(-1), m_client(0), m_objectDebugId(-1)
690 {
691 }
692
693 QDeclarativeDebugWatch::~QDeclarativeDebugWatch()
694 {
695     if (m_client && m_queryId != -1)
696         QDeclarativeEngineDebugPrivate::remove(m_client, this);
697 }
698
699 int QDeclarativeDebugWatch::queryId() const
700 {
701     return m_queryId;
702 }
703
704 int QDeclarativeDebugWatch::objectDebugId() const
705 {
706     return m_objectDebugId;
707 }
708
709 QDeclarativeDebugWatch::State QDeclarativeDebugWatch::state() const
710 {
711     return m_state;
712 }
713
714 void QDeclarativeDebugWatch::setState(State s)
715 {
716     if (m_state == s)
717         return;
718     m_state = s;
719     emit stateChanged(m_state);
720 }
721
722 QDeclarativeDebugPropertyWatch::QDeclarativeDebugPropertyWatch(QObject *parent)
723     : QDeclarativeDebugWatch(parent)
724 {
725 }
726
727 QString QDeclarativeDebugPropertyWatch::name() const
728 {
729     return m_name;
730 }
731
732
733 QDeclarativeDebugObjectExpressionWatch::QDeclarativeDebugObjectExpressionWatch(QObject *parent)
734     : QDeclarativeDebugWatch(parent)
735 {
736 }
737
738 QString QDeclarativeDebugObjectExpressionWatch::expression() const
739 {
740     return m_expr;
741 }
742
743
744 QDeclarativeDebugQuery::QDeclarativeDebugQuery(QObject *parent)
745     : QObject(parent), m_state(Waiting)
746 {
747 }
748
749 QDeclarativeDebugQuery::State QDeclarativeDebugQuery::state() const
750 {
751     return m_state;
752 }
753
754 bool QDeclarativeDebugQuery::isWaiting() const
755 {
756     return m_state == Waiting;
757 }
758
759 void QDeclarativeDebugQuery::setState(State s)
760 {
761     if (m_state == s)
762         return;
763     m_state = s;
764     emit stateChanged(m_state);
765 }
766
767 QDeclarativeDebugEnginesQuery::QDeclarativeDebugEnginesQuery(QObject *parent)
768     : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
769 {
770 }
771
772 QDeclarativeDebugEnginesQuery::~QDeclarativeDebugEnginesQuery()
773 {
774     if (m_client && m_queryId != -1)
775         QDeclarativeEngineDebugPrivate::remove(m_client, this);
776 }
777
778 QList<QDeclarativeDebugEngineReference> QDeclarativeDebugEnginesQuery::engines() const
779 {
780     return m_engines;
781 }
782
783 QDeclarativeDebugRootContextQuery::QDeclarativeDebugRootContextQuery(QObject *parent)
784     : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
785 {
786 }
787
788 QDeclarativeDebugRootContextQuery::~QDeclarativeDebugRootContextQuery()
789 {
790     if (m_client && m_queryId != -1)
791         QDeclarativeEngineDebugPrivate::remove(m_client, this);
792 }
793
794 QDeclarativeDebugContextReference QDeclarativeDebugRootContextQuery::rootContext() const
795 {
796     return m_context;
797 }
798
799 QDeclarativeDebugObjectQuery::QDeclarativeDebugObjectQuery(QObject *parent)
800     : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
801 {
802 }
803
804 QDeclarativeDebugObjectQuery::~QDeclarativeDebugObjectQuery()
805 {
806     if (m_client && m_queryId != -1)
807         QDeclarativeEngineDebugPrivate::remove(m_client, this);
808 }
809
810 QDeclarativeDebugObjectReference QDeclarativeDebugObjectQuery::object() const
811 {
812     return m_object;
813 }
814
815 QDeclarativeDebugExpressionQuery::QDeclarativeDebugExpressionQuery(QObject *parent)
816     : QDeclarativeDebugQuery(parent), m_client(0), m_queryId(-1)
817 {
818 }
819
820 QDeclarativeDebugExpressionQuery::~QDeclarativeDebugExpressionQuery()
821 {
822     if (m_client && m_queryId != -1)
823         QDeclarativeEngineDebugPrivate::remove(m_client, this);
824 }
825
826 QVariant QDeclarativeDebugExpressionQuery::expression() const
827 {
828     return m_expr;
829 }
830
831 QVariant QDeclarativeDebugExpressionQuery::result() const
832 {
833     return m_result;
834 }
835
836 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference()
837     : m_debugId(-1)
838 {
839 }
840
841 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(int debugId)
842     : m_debugId(debugId)
843 {
844 }
845
846 QDeclarativeDebugEngineReference::QDeclarativeDebugEngineReference(const QDeclarativeDebugEngineReference &o)
847     : m_debugId(o.m_debugId), m_name(o.m_name)
848 {
849 }
850
851 QDeclarativeDebugEngineReference &
852 QDeclarativeDebugEngineReference::operator=(const QDeclarativeDebugEngineReference &o)
853 {
854     m_debugId = o.m_debugId; m_name = o.m_name;
855     return *this;
856 }
857
858 int QDeclarativeDebugEngineReference::debugId() const
859 {
860     return m_debugId;
861 }
862
863 QString QDeclarativeDebugEngineReference::name() const
864 {
865     return m_name;
866 }
867
868 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference()
869     : m_debugId(-1), m_contextDebugId(-1)
870 {
871 }
872
873 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(int debugId)
874     : m_debugId(debugId), m_contextDebugId(-1)
875 {
876 }
877
878 QDeclarativeDebugObjectReference::QDeclarativeDebugObjectReference(const QDeclarativeDebugObjectReference &o)
879     : m_debugId(o.m_debugId), m_class(o.m_class), m_idString(o.m_idString),
880       m_name(o.m_name), m_source(o.m_source), m_contextDebugId(o.m_contextDebugId),
881       m_properties(o.m_properties), m_children(o.m_children)
882 {
883 }
884
885 QDeclarativeDebugObjectReference &
886 QDeclarativeDebugObjectReference::operator=(const QDeclarativeDebugObjectReference &o)
887 {
888     m_debugId = o.m_debugId; m_class = o.m_class; m_idString = o.m_idString;
889     m_name = o.m_name; m_source = o.m_source; m_contextDebugId = o.m_contextDebugId;
890     m_properties = o.m_properties; m_children = o.m_children;
891     return *this;
892 }
893
894 int QDeclarativeDebugObjectReference::debugId() const
895 {
896     return m_debugId;
897 }
898
899 QString QDeclarativeDebugObjectReference::className() const
900 {
901     return m_class;
902 }
903
904 QString QDeclarativeDebugObjectReference::idString() const
905 {
906     return m_idString;
907 }
908
909 QString QDeclarativeDebugObjectReference::name() const
910 {
911     return m_name;
912 }
913
914 QDeclarativeDebugFileReference QDeclarativeDebugObjectReference::source() const
915 {
916     return m_source;
917 }
918
919 int QDeclarativeDebugObjectReference::contextDebugId() const
920 {
921     return m_contextDebugId;
922 }
923
924 QList<QDeclarativeDebugPropertyReference> QDeclarativeDebugObjectReference::properties() const
925 {
926     return m_properties;
927 }
928
929 QList<QDeclarativeDebugObjectReference> QDeclarativeDebugObjectReference::children() const
930 {
931     return m_children;
932 }
933
934 QDeclarativeDebugContextReference::QDeclarativeDebugContextReference()
935     : m_debugId(-1)
936 {
937 }
938
939 QDeclarativeDebugContextReference::QDeclarativeDebugContextReference(const QDeclarativeDebugContextReference &o)
940     : m_debugId(o.m_debugId), m_name(o.m_name), m_objects(o.m_objects), m_contexts(o.m_contexts)
941 {
942 }
943
944 QDeclarativeDebugContextReference &QDeclarativeDebugContextReference::operator=(const QDeclarativeDebugContextReference &o)
945 {
946     m_debugId = o.m_debugId; m_name = o.m_name; m_objects = o.m_objects;
947     m_contexts = o.m_contexts;
948     return *this;
949 }
950
951 int QDeclarativeDebugContextReference::debugId() const
952 {
953     return m_debugId;
954 }
955
956 QString QDeclarativeDebugContextReference::name() const
957 {
958     return m_name;
959 }
960
961 QList<QDeclarativeDebugObjectReference> QDeclarativeDebugContextReference::objects() const
962 {
963     return m_objects;
964 }
965
966 QList<QDeclarativeDebugContextReference> QDeclarativeDebugContextReference::contexts() const
967 {
968     return m_contexts;
969 }
970
971 QDeclarativeDebugFileReference::QDeclarativeDebugFileReference()
972     : m_lineNumber(-1), m_columnNumber(-1)
973 {
974 }
975
976 QDeclarativeDebugFileReference::QDeclarativeDebugFileReference(const QDeclarativeDebugFileReference &o)
977     : m_url(o.m_url), m_lineNumber(o.m_lineNumber), m_columnNumber(o.m_columnNumber)
978 {
979 }
980
981 QDeclarativeDebugFileReference &QDeclarativeDebugFileReference::operator=(const QDeclarativeDebugFileReference &o)
982 {
983     m_url = o.m_url; m_lineNumber = o.m_lineNumber; m_columnNumber = o.m_columnNumber;
984     return *this;
985 }
986
987 QUrl QDeclarativeDebugFileReference::url() const
988 {
989     return m_url;
990 }
991
992 void QDeclarativeDebugFileReference::setUrl(const QUrl &u)
993 {
994     m_url = u;
995 }
996
997 int QDeclarativeDebugFileReference::lineNumber() const
998 {
999     return m_lineNumber;
1000 }
1001
1002 void QDeclarativeDebugFileReference::setLineNumber(int l)
1003 {
1004     m_lineNumber = l;
1005 }
1006
1007 int QDeclarativeDebugFileReference::columnNumber() const
1008 {
1009     return m_columnNumber;
1010 }
1011
1012 void QDeclarativeDebugFileReference::setColumnNumber(int c)
1013 {
1014     m_columnNumber = c;
1015 }
1016
1017 QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference()
1018     : m_objectDebugId(-1), m_hasNotifySignal(false)
1019 {
1020 }
1021
1022 QDeclarativeDebugPropertyReference::QDeclarativeDebugPropertyReference(const QDeclarativeDebugPropertyReference &o)
1023     : m_objectDebugId(o.m_objectDebugId), m_name(o.m_name), m_value(o.m_value),
1024       m_valueTypeName(o.m_valueTypeName), m_binding(o.m_binding),
1025       m_hasNotifySignal(o.m_hasNotifySignal)
1026 {
1027 }
1028
1029 QDeclarativeDebugPropertyReference &QDeclarativeDebugPropertyReference::operator=(const QDeclarativeDebugPropertyReference &o)
1030 {
1031     m_objectDebugId = o.m_objectDebugId; m_name = o.m_name; m_value = o.m_value;
1032     m_valueTypeName = o.m_valueTypeName; m_binding = o.m_binding;
1033     m_hasNotifySignal = o.m_hasNotifySignal;
1034     return *this;
1035 }
1036
1037 int QDeclarativeDebugPropertyReference::objectDebugId() const
1038 {
1039     return m_objectDebugId;
1040 }
1041
1042 QString QDeclarativeDebugPropertyReference::name() const
1043 {
1044     return m_name;
1045 }
1046
1047 QString QDeclarativeDebugPropertyReference::valueTypeName() const
1048 {
1049     return m_valueTypeName;
1050 }
1051
1052 QVariant QDeclarativeDebugPropertyReference::value() const
1053 {
1054     return m_value;
1055 }
1056
1057 QString QDeclarativeDebugPropertyReference::binding() const
1058 {
1059     return m_binding;
1060 }
1061
1062 bool QDeclarativeDebugPropertyReference::hasNotifySignal() const
1063 {
1064     return m_hasNotifySignal;
1065 }
1066
1067 QT_END_NAMESPACE
1068