diff options
Diffstat (limited to 'src/declarative/debugger/qdeclarativedebugserver.cpp')
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugserver.cpp | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugserver.cpp b/src/declarative/debugger/qdeclarativedebugserver.cpp index 5112af0..4343870 100644 --- a/src/declarative/debugger/qdeclarativedebugserver.cpp +++ b/src/declarative/debugger/qdeclarativedebugserver.cpp @@ -90,7 +90,11 @@ public: QHash<QString, QDeclarativeDebugService *> plugins; QStringList clientPlugins; bool gotHello; + QString waitingForMsgFromService; +private: + // private slot + void _q_deliverMessage(const QString &serviceName, const QByteArray &message); static QDeclarativeDebugServerConnection *loadConnectionPlugin(const QString &pluginName); }; @@ -237,7 +241,6 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) QDataStream in(message); if (!d->gotHello) { - QString name; int op; in >> name >> op; @@ -252,6 +255,17 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) int version; in >> version >> d->clientPlugins; + // Send the hello answer immediately, since it needs to arrive before + // the plugins below start sending messages. + QByteArray helloAnswer; + { + QDataStream out(&helloAnswer, QIODevice::WriteOnly); + out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << d->plugins.keys(); + } + d->connection->send(helloAnswer); + + d->gotHello = true; + QHash<QString, QDeclarativeDebugService*>::Iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) { QDeclarativeDebugService::Status newStatus = QDeclarativeDebugService::Unavailable; @@ -261,14 +275,6 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) iter.value()->statusChanged(newStatus); } - QByteArray helloAnswer; - { - QDataStream out(&helloAnswer, QIODevice::WriteOnly); - out << QString(QLatin1String("QDeclarativeDebugClient")) << 0 << protocolVersion << d->plugins.keys(); - } - d->connection->send(helloAnswer); - - d->gotHello = true; qWarning("QDeclarativeDebugServer: Connection established"); } else { @@ -306,17 +312,33 @@ void QDeclarativeDebugServer::receiveMessage(const QByteArray &message) QByteArray message; in >> message; - QHash<QString, QDeclarativeDebugService *>::Iterator iter = - d->plugins.find(name); - if (iter == d->plugins.end()) { - qWarning() << "QDeclarativeDebugServer: Message received for missing plugin" << name; + if (d->waitingForMsgFromService == name) { + // deliver directly so that it is delivered before waitForMessage is returning. + d->_q_deliverMessage(name, message); + d->waitingForMsgFromService.clear(); } else { - (*iter)->messageReceived(message); + // deliver message in next event loop run. + // Fixes the case that the service does start it's own event loop ..., + // but the networking code doesn't deliver any new messages because readyRead + // hasn't returned. + QMetaObject::invokeMethod(this, "_q_deliverMessage", Qt::QueuedConnection, + Q_ARG(QString, name), + Q_ARG(QByteArray, message)); } } } } +void QDeclarativeDebugServerPrivate::_q_deliverMessage(const QString &serviceName, const QByteArray &message) +{ + QHash<QString, QDeclarativeDebugService *>::Iterator iter = plugins.find(serviceName); + if (iter == plugins.end()) { + qWarning() << "QDeclarativeDebugServer: Message received for missing plugin" << serviceName; + } else { + (*iter)->messageReceived(message); + } +} + QList<QDeclarativeDebugService*> QDeclarativeDebugServer::services() const { const Q_D(QDeclarativeDebugServer); @@ -374,4 +396,23 @@ void QDeclarativeDebugServer::sendMessage(QDeclarativeDebugService *service, d->connection->send(msg); } +bool QDeclarativeDebugServer::waitForMessage(QDeclarativeDebugService *service) +{ + Q_D(QDeclarativeDebugServer); + + if (!service + || !d->plugins.contains(service->name()) + || !d->waitingForMsgFromService.isEmpty()) + return false; + + d->waitingForMsgFromService = service->name(); + + do { + d->connection->waitForMessage(); + } while (!d->waitingForMsgFromService.isEmpty()); + return true; +} + QT_END_NAMESPACE + +#include "moc_qdeclarativedebugserver_p.cpp" |