forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
|
|
||||||
struct QmlAdapterPrivate {
|
struct QmlAdapterPrivate {
|
||||||
@@ -49,6 +51,7 @@ struct QmlAdapterPrivate {
|
|||||||
int m_connectionAttempts;
|
int m_connectionAttempts;
|
||||||
int m_maxConnectionAttempts;
|
int m_maxConnectionAttempts;
|
||||||
QDeclarativeDebugConnection *m_conn;
|
QDeclarativeDebugConnection *m_conn;
|
||||||
|
QList<QByteArray> sendBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
QmlAdapterPrivate::QmlAdapterPrivate(DebuggerEngine *engine, QmlAdapter *q) :
|
QmlAdapterPrivate::QmlAdapterPrivate(DebuggerEngine *engine, QmlAdapter *q) :
|
||||||
@@ -133,6 +136,16 @@ bool QmlAdapter::connectToViewer()
|
|||||||
return true;
|
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)
|
void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError)
|
||||||
{
|
{
|
||||||
showConnectionErrorMessage(tr("Error: (%1) %2", "%1=error code, %2=error message")
|
showConnectionErrorMessage(tr("Error: (%1) %2", "%1=error code, %2=error message")
|
||||||
@@ -151,6 +164,9 @@ void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
logServiceStatusChange(serviceName, status);
|
logServiceStatusChange(serviceName, status);
|
||||||
|
|
||||||
|
if (status == QDeclarativeDebugClient::Enabled)
|
||||||
|
flushSendBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlAdapter::connectionStateChanged()
|
void QmlAdapter::connectionStateChanged()
|
||||||
@@ -199,7 +215,7 @@ void QmlAdapter::createDebuggerClient()
|
|||||||
connect(d->m_qmlClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
|
connect(d->m_qmlClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)),
|
||||||
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
|
this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status)));
|
||||||
connect(d->m_engine.data(), SIGNAL(sendMessage(QByteArray)),
|
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)),
|
connect(d->m_qmlClient, SIGNAL(messageWasReceived(QByteArray)),
|
||||||
d->m_engine.data(), SLOT(messageReceived(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
|
} // namespace Debugger
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ signals:
|
|||||||
void serviceConnectionError(const QString serviceName);
|
void serviceConnectionError(const QString serviceName);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void sendMessage(const QByteArray &msg);
|
||||||
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
|
void connectionErrorOccurred(QAbstractSocket::SocketError socketError);
|
||||||
void clientStatusChanged(QDeclarativeDebugClient::Status status);
|
void clientStatusChanged(QDeclarativeDebugClient::Status status);
|
||||||
void connectionStateChanged();
|
void connectionStateChanged();
|
||||||
@@ -94,6 +95,7 @@ private:
|
|||||||
void createDebuggerClient();
|
void createDebuggerClient();
|
||||||
void showConnectionStatusMessage(const QString &message);
|
void showConnectionStatusMessage(const QString &message);
|
||||||
void showConnectionErrorMessage(const QString &message);
|
void showConnectionErrorMessage(const QString &message);
|
||||||
|
void flushSendBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<QmlAdapterPrivate> d;
|
QScopedPointer<QmlAdapterPrivate> d;
|
||||||
|
|||||||
@@ -53,10 +53,5 @@ void QmlDebuggerClient::messageReceived(const QByteArray &data)
|
|||||||
emit messageWasReceived(data);
|
emit messageWasReceived(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlDebuggerClient::slotSendMessage(const QByteArray &message)
|
|
||||||
{
|
|
||||||
QDeclarativeDebugClient::sendMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Debugger
|
} // Debugger
|
||||||
|
|||||||
@@ -47,9 +47,6 @@ signals:
|
|||||||
void newStatus(QDeclarativeDebugClient::Status status);
|
void newStatus(QDeclarativeDebugClient::Status status);
|
||||||
void messageWasReceived(const QByteArray &data);
|
void messageWasReceived(const QByteArray &data);
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void slotSendMessage(const QByteArray &message);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void statusChanged(Status status);
|
virtual void statusChanged(Status status);
|
||||||
virtual void messageReceived(const QByteArray &data);
|
virtual void messageReceived(const QByteArray &data);
|
||||||
|
|||||||
Reference in New Issue
Block a user