Commit a03e7572 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlDebugger: Buffer messages in QmlAdapter until client is ready

Don't 'loose' messages at startup because the client is not enabled
yet / sendMessage will silently fail.

Reviewed-by: Christiaan Janssen
parent 226a82d3
......@@ -36,6 +36,8 @@
#include <QtCore/QTimer>
#include <QtCore/QDebug>
#include <utils/qtcassert.h>
namespace Debugger {
struct QmlAdapterPrivate {
......@@ -49,6 +51,7 @@ struct QmlAdapterPrivate {
int m_connectionAttempts;
int m_maxConnectionAttempts;
QDeclarativeDebugConnection *m_conn;
QList<QByteArray> sendBuffer;
};
QmlAdapterPrivate::QmlAdapterPrivate(DebuggerEngine *engine, QmlAdapter *q) :
......@@ -133,6 +136,16 @@ bool QmlAdapter::connectToViewer()
return true;
}
void QmlAdapter::sendMessage(const QByteArray &msg)
{
if (d->m_qmlClient->status() == QDeclarativeDebugClient::Enabled) {
flushSendBuffer();
d->m_qmlClient->sendMessage(msg);
} else {
d->sendBuffer.append(msg);
}
}
void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError)
{
showConnectionErrorMessage(tr("Error: (%1) %2", "%1=error code, %2=error message")
......@@ -151,6 +164,9 @@ void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status)
}
logServiceStatusChange(serviceName, status);
if (status == QDeclarativeDebugClient::Enabled)
flushSendBuffer();
}
void QmlAdapter::connectionStateChanged()
......@@ -199,7 +215,7 @@ void QmlAdapter::createDebuggerClient()
connect(d->m_qmlClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
connect(d->m_engine.data(), SIGNAL(sendMessage(QByteArray)),
d->m_qmlClient, SLOT(slotSendMessage(QByteArray)));
this, SLOT(sendMessage(QByteArray)));
connect(d->m_qmlClient, SIGNAL(messageWasReceived(QByteArray)),
d->m_engine.data(), SLOT(messageReceived(QByteArray)));
......@@ -272,4 +288,13 @@ void QmlAdapter::logServiceStatusChange(const QString &service, QDeclarativeDebu
}
}
void QmlAdapter::flushSendBuffer()
{
QTC_ASSERT(d->m_qmlClient->status() == QDeclarativeDebugClient::Enabled, return);
foreach (const QByteArray &msg, d->sendBuffer) {
d->m_qmlClient->sendMessage(msg);
}
d->sendBuffer.clear();
}
} // namespace Debugger
......@@ -84,6 +84,7 @@ signals:
void serviceConnectionError(const QString serviceName);
private slots:
void sendMessage(const QByteArray &msg);
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
void clientStatusChanged(QDeclarativeDebugClient::Status status);
void connectionStateChanged();
......@@ -94,6 +95,7 @@ private:
void createDebuggerClient();
void showConnectionStatusMessage(const QString &message);
void showConnectionErrorMessage(const QString &message);
void flushSendBuffer();
private:
QScopedPointer<QmlAdapterPrivate> d;
......
......@@ -53,10 +53,5 @@ void QmlDebuggerClient::messageReceived(const QByteArray &data)
emit messageWasReceived(data);
}
void QmlDebuggerClient::slotSendMessage(const QByteArray &message)
{
QDeclarativeDebugClient::sendMessage(message);
}
} // Internal
} // Debugger
......@@ -47,9 +47,6 @@ signals:
void newStatus(QDeclarativeDebugClient::Status status);
void messageWasReceived(const QByteArray &data);
private Q_SLOTS:
void slotSendMessage(const QByteArray &message);
protected:
virtual void statusChanged(Status status);
virtual void messageReceived(const QByteArray &data);
......
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