From 0a0b8dcafc0a681966f2a9ce8982e5f3c6be2c81 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 14 Apr 2011 17:19:28 +0200 Subject: [PATCH] QmlProfiler: Reinstantiate a QDDClient for every new connection --- src/plugins/qmlprofiler/qmlprofilertool.cpp | 94 +++++++++++++++------ src/plugins/qmlprofiler/qmlprofilertool.h | 2 + 2 files changed, 69 insertions(+), 27 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 03ca9767dfd..f06bf4a0be6 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -52,6 +52,7 @@ #include #include +#include #include #include #include @@ -145,8 +146,8 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) QmlProfilerTool::~QmlProfilerTool() { - if (d->m_client->isConnected()) - d->m_client->close(); + if (d->m_client) + delete d->m_client; delete d->m_tabbed; delete d->m_outputPaneAdapter; @@ -206,8 +207,6 @@ void QmlProfilerTool::initialize(ExtensionSystem::IPlugin * /*plugin*/) qmlRegisterType("Monitor", 1, 0,"TimelineView"); - d->m_client = new QDeclarativeDebugConnection; - d->m_tabbed = new QTabWidget(); d->m_traceWindow = new TraceWindow(d->m_tabbed); @@ -293,41 +292,33 @@ QWidget *QmlProfilerTool::createTimeLineWidget() void QmlProfilerTool::connectClient() { + QTC_ASSERT(!d->m_client, return;) + d->m_client = new QDeclarativeDebugConnection; + connect(d->m_client, SIGNAL(stateChanged(QAbstractSocket::SocketState)), + this, SLOT(connectionStateChanged())); d->m_connectionTimer.start(); } void QmlProfilerTool::connectToClient() { - QDeclarativeDebugConnection *newClient = new QDeclarativeDebugConnection; - d->m_traceWindow->reset(newClient); - delete d->m_client; - d->m_client = newClient; + if (!d->m_client || d->m_client->state() != QAbstractSocket::UnconnectedState) + return; + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: Connecting to %s:%d ...", qPrintable(d->m_host), d->m_port); + d->m_client->connectToHost(d->m_host, d->m_port); - - if (d->m_client->isConnected()) { - d->m_traceWindow->setRecording(d->m_recordingEnabled); - if (QmlProfilerPlugin::debugOutput) - qWarning("QmlProfiler: connected and running"); - } else { - d->m_traceWindow->setRecording(false); - if (QmlProfilerPlugin::debugOutput) - qWarning("QmlProfiler: Failed to connect: %s", qPrintable(d->m_client->errorString())); - emit connectionFailed(); - } - - if (d->m_traceWindow->isRecording()) - clearDisplay(); } void QmlProfilerTool::disconnectClient() { - d->m_client->close(); + delete d->m_client; + d->m_client = 0; } void QmlProfilerTool::startRecording() { - if (d->m_client->isConnected()) { + if (d->m_client && d->m_client->isConnected()) { clearDisplay(); d->m_traceWindow->setRecording(true); } @@ -432,15 +423,64 @@ void QmlProfilerTool::tryToConnect() { ++d->m_connectionAttempts; - if (d->m_client->isConnected()) { + if (d->m_client && d->m_client->isConnected()) { d->m_connectionTimer.stop(); d->m_connectionAttempts = 0; } else if (d->m_connectionAttempts == 50) { d->m_connectionTimer.stop(); d->m_connectionAttempts = 0; - // TODO: Warn user that connection failed - //emit connectionStartupFailed(); + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: Failed to connect: %s", qPrintable(d->m_client->errorString())); + emit connectionFailed(); } else { connectToClient(); } } + +void QmlProfilerTool::connectionStateChanged() +{ + if (!d->m_client) + return; + switch (d->m_client->state()) { + case QAbstractSocket::UnconnectedState: + { + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: disconnected"); + break; + } + case QAbstractSocket::HostLookupState: + break; + case QAbstractSocket::ConnectingState: { + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: Connecting to debug server ..."); + break; + } + case QAbstractSocket::ConnectedState: + { + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: connected and running"); + resetWindow(); + break; + } + case QAbstractSocket::ClosingState: + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: closing ..."); + break; + case QAbstractSocket::BoundState: + case QAbstractSocket::ListeningState: + break; + } +} + +void QmlProfilerTool::resetWindow() +{ + d->m_traceWindow->reset(d->m_client); + if (d->m_client->isConnected()) { + d->m_traceWindow->setRecording(d->m_recordingEnabled); + } else { + d->m_traceWindow->setRecording(false); + } + + if (d->m_traceWindow->isRecording()) + clearDisplay(); +} diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index 58a6242b1a5..ff3f4d63d59 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -86,9 +86,11 @@ private slots: void attach(); void updateAttachAction(); void tryToConnect(); + void connectionStateChanged(); private: void connectToClient(); + void resetWindow(); class QmlProfilerToolPrivate; QmlProfilerToolPrivate *d;