2010-08-13 14:18:10 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-08-13 14:18:10 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-08-13 14:18:10 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-08-13 14:18:10 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-08-13 14:18:10 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmladapter.h"
|
2011-01-10 10:14:23 +01:00
|
|
|
|
2011-07-26 16:22:49 +02:00
|
|
|
#include "qmlengine.h"
|
2012-04-18 14:20:54 +02:00
|
|
|
#include "qmlv8debuggerclient.h"
|
|
|
|
|
#include "qscriptdebuggerclient.h"
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
#include <qmldebug/qdebugmessageclient.h>
|
2012-04-18 14:20:54 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-12-20 16:12:38 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
using namespace QmlDebug;
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
namespace Debugger {
|
2011-01-12 13:51:26 +01:00
|
|
|
namespace Internal {
|
2010-09-13 13:30:35 +02:00
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent)
|
2012-04-18 14:20:54 +02:00
|
|
|
: QObject(parent)
|
|
|
|
|
, m_engine(engine)
|
|
|
|
|
, m_qmlClient(0)
|
|
|
|
|
, m_conn(0)
|
|
|
|
|
, m_msgClient(0)
|
2010-09-13 13:30:35 +02:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
m_connectionTimer.setInterval(4000);
|
|
|
|
|
m_connectionTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_connectionTimer, SIGNAL(timeout()), SLOT(checkConnectionState()));
|
|
|
|
|
|
|
|
|
|
m_conn = new QmlDebugConnection(this);
|
|
|
|
|
connect(m_conn, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
2011-02-08 16:35:40 +01:00
|
|
|
SLOT(connectionStateChanged()));
|
2012-04-18 14:20:54 +02:00
|
|
|
connect(m_conn, SIGNAL(error(QAbstractSocket::SocketError)),
|
2011-02-08 16:35:40 +01:00
|
|
|
SLOT(connectionErrorOccurred(QAbstractSocket::SocketError)));
|
|
|
|
|
|
2011-09-14 16:58:10 +02:00
|
|
|
createDebuggerClients();
|
2012-04-18 14:20:54 +02:00
|
|
|
m_msgClient = new QDebugMessageClient(m_conn);
|
2012-05-10 10:29:11 +02:00
|
|
|
connect(m_msgClient, SIGNAL(newStatus(QmlDebug::ClientStatus)),
|
|
|
|
|
this, SLOT(clientStatusChanged(QmlDebug::ClientStatus)));
|
2012-04-18 14:20:54 +02:00
|
|
|
|
2010-09-13 13:30:35 +02:00
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2010-09-13 13:30:35 +02:00
|
|
|
QmlAdapter::~QmlAdapter()
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-21 15:47:55 +01:00
|
|
|
void QmlAdapter::beginConnectionTcp(const QString &address, quint16 port)
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (m_engine.isNull()
|
|
|
|
|
|| (m_conn && m_conn->state() != QAbstractSocket::UnconnectedState))
|
2011-02-08 16:35:40 +01:00
|
|
|
return;
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2012-02-21 15:47:55 +01:00
|
|
|
showConnectionStatusMessage(tr("Connecting to debug server %1:%2").arg(address).arg(
|
|
|
|
|
QString::number(port)));
|
2012-04-18 14:20:54 +02:00
|
|
|
m_conn->connectToHost(address, port);
|
2012-02-21 15:47:55 +01:00
|
|
|
|
|
|
|
|
//A timeout to check the connection state
|
2012-04-18 14:20:54 +02:00
|
|
|
m_connectionTimer.start();
|
2012-02-21 15:47:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlAdapter::beginConnectionOst(const QString &channel)
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (m_engine.isNull()
|
|
|
|
|
|| (m_conn && m_conn->state() != QAbstractSocket::UnconnectedState))
|
2012-02-21 15:47:55 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
showConnectionStatusMessage(tr("Connecting to debug server on %1").arg(channel));
|
2012-04-18 14:20:54 +02:00
|
|
|
m_conn->connectToOst(channel);
|
2011-09-14 16:58:10 +02:00
|
|
|
|
|
|
|
|
//A timeout to check the connection state
|
2012-04-18 14:20:54 +02:00
|
|
|
m_connectionTimer.start();
|
2011-09-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlAdapter::closeConnection()
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (m_connectionTimer.isActive()) {
|
|
|
|
|
m_connectionTimer.stop();
|
2011-09-14 16:58:10 +02:00
|
|
|
} else {
|
2012-04-18 14:20:54 +02:00
|
|
|
if (m_conn) {
|
|
|
|
|
m_conn->close();
|
2011-09-14 16:58:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-27 13:11:55 +02:00
|
|
|
void QmlAdapter::connectionErrorOccurred(QAbstractSocket::SocketError socketError)
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2010-12-16 16:20:21 +01:00
|
|
|
showConnectionStatusMessage(tr("Error: (%1) %2", "%1=error code, %2=error message")
|
2012-04-18 14:20:54 +02:00
|
|
|
.arg(socketError).arg(m_conn->errorString()));
|
2010-08-13 14:18:10 +02:00
|
|
|
|
|
|
|
|
// this is only an error if we are already connected and something goes wrong.
|
2011-09-14 16:58:10 +02:00
|
|
|
if (isConnected()) {
|
2010-08-27 13:11:55 +02:00
|
|
|
emit connectionError(socketError);
|
2011-09-14 16:58:10 +02:00
|
|
|
} else {
|
2012-04-18 14:20:54 +02:00
|
|
|
m_connectionTimer.stop();
|
2011-09-14 16:58:10 +02:00
|
|
|
emit connectionStartupFailed();
|
|
|
|
|
}
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
void QmlAdapter::clientStatusChanged(QmlDebug::ClientStatus status)
|
2010-09-30 14:05:20 +02:00
|
|
|
{
|
|
|
|
|
QString serviceName;
|
2012-04-10 16:54:08 +02:00
|
|
|
float version = 0;
|
2012-04-18 12:06:10 +02:00
|
|
|
if (QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender())) {
|
2010-09-30 14:05:20 +02:00
|
|
|
serviceName = client->name();
|
2012-04-10 16:54:08 +02:00
|
|
|
version = client->serviceVersion();
|
|
|
|
|
}
|
2010-09-30 14:05:20 +02:00
|
|
|
|
2012-04-10 16:54:08 +02:00
|
|
|
logServiceStatusChange(serviceName, version, status);
|
2011-12-20 16:12:38 +01:00
|
|
|
}
|
2010-09-30 15:03:42 +02:00
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
void QmlAdapter::debugClientStatusChanged(QmlDebug::ClientStatus status)
|
2011-12-20 16:12:38 +01:00
|
|
|
{
|
2012-05-10 10:29:11 +02:00
|
|
|
if (status != QmlDebug::Enabled)
|
2012-01-12 10:18:25 +01:00
|
|
|
return;
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugClient *client = qobject_cast<QmlDebugClient*>(sender());
|
2011-12-20 16:12:38 +01:00
|
|
|
QTC_ASSERT(client, return);
|
|
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
m_qmlClient = qobject_cast<BaseQmlDebuggerClient *>(client);
|
2012-04-18 14:20:54 +02:00
|
|
|
m_qmlClient->startSession();
|
2010-09-30 14:05:20 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
void QmlAdapter::connectionStateChanged()
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
switch (m_conn->state()) {
|
2011-02-17 15:57:26 +01:00
|
|
|
case QAbstractSocket::UnconnectedState:
|
|
|
|
|
{
|
|
|
|
|
showConnectionStatusMessage(tr("disconnected.\n\n"));
|
|
|
|
|
emit disconnected();
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2011-02-17 15:57:26 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QAbstractSocket::HostLookupState:
|
|
|
|
|
showConnectionStatusMessage(tr("resolving host..."));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ConnectingState:
|
|
|
|
|
showConnectionStatusMessage(tr("connecting to debug server..."));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ConnectedState:
|
|
|
|
|
{
|
|
|
|
|
showConnectionStatusMessage(tr("connected.\n"));
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
m_connectionTimer.stop();
|
2011-07-26 16:22:49 +02:00
|
|
|
|
2011-02-17 15:57:26 +01:00
|
|
|
//reloadEngines();
|
|
|
|
|
emit connected();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QAbstractSocket::ClosingState:
|
|
|
|
|
showConnectionStatusMessage(tr("closing..."));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::BoundState:
|
|
|
|
|
case QAbstractSocket::ListeningState:
|
|
|
|
|
break;
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-14 16:58:10 +02:00
|
|
|
void QmlAdapter::checkConnectionState()
|
|
|
|
|
{
|
|
|
|
|
if (!isConnected()) {
|
|
|
|
|
closeConnection();
|
|
|
|
|
emit connectionStartupFailed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-26 16:22:49 +02:00
|
|
|
void QmlAdapter::createDebuggerClients()
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2012-05-09 14:56:04 +02:00
|
|
|
QScriptDebuggerClient *debugClient1 = new QScriptDebuggerClient(m_conn);
|
2012-05-10 10:29:11 +02:00
|
|
|
connect(debugClient1, SIGNAL(newStatus(QmlDebug::Status)),
|
|
|
|
|
this, SLOT(clientStatusChanged(QmlDebug::Status)));
|
|
|
|
|
connect(debugClient1, SIGNAL(newStatus(QmlDebug::Status)),
|
|
|
|
|
this, SLOT(debugClientStatusChanged(QmlDebug::Status)));
|
2011-07-26 16:22:49 +02:00
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
QmlV8DebuggerClient *debugClient2 = new QmlV8DebuggerClient(m_conn);
|
2012-05-10 10:29:11 +02:00
|
|
|
connect(debugClient2, SIGNAL(newStatus(QmlDebug::Status)),
|
|
|
|
|
this, SLOT(clientStatusChanged(QmlDebug::Status)));
|
|
|
|
|
connect(debugClient2, SIGNAL(newStatus(QmlDebug::Status)),
|
|
|
|
|
this, SLOT(debugClientStatusChanged(QmlDebug::Status)));
|
2011-07-26 16:22:49 +02:00
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
m_debugClients.insert(debugClient1->name(),debugClient1);
|
|
|
|
|
m_debugClients.insert(debugClient2->name(),debugClient2);
|
2011-07-26 16:22:49 +02:00
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
debugClient1->setEngine((QmlEngine*)(m_engine.data()));
|
|
|
|
|
debugClient2->setEngine((QmlEngine*)(m_engine.data()));
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlAdapter::isConnected() const
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_conn && m_qmlClient && m_conn->state() == QAbstractSocket::ConnectedState;
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnection *QmlAdapter::connection() const
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_conn;
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-29 11:39:41 +01:00
|
|
|
DebuggerEngine *QmlAdapter::debuggerEngine() const
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_engine.data();
|
2011-11-29 11:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
void QmlAdapter::showConnectionStatusMessage(const QString &message)
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (!m_engine.isNull())
|
|
|
|
|
m_engine.data()->showMessage(QLatin1String("QML Debugger: ") + message, LogStatus);
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlAdapter::showConnectionErrorMessage(const QString &message)
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (!m_engine.isNull())
|
|
|
|
|
m_engine.data()->showMessage(QLatin1String("QML Debugger: ") + message, LogError);
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2011-01-24 16:30:34 +01:00
|
|
|
bool QmlAdapter::disableJsDebugging(bool block)
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (m_engine.isNull())
|
2011-01-24 16:30:34 +01:00
|
|
|
return block;
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
bool isBlocked = m_engine.data()->state() == InferiorRunOk;
|
2011-01-24 16:30:34 +01:00
|
|
|
|
|
|
|
|
if (isBlocked == block)
|
|
|
|
|
return block;
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
if (block)
|
|
|
|
|
m_engine.data()->continueInferior();
|
|
|
|
|
else
|
|
|
|
|
m_engine.data()->requestInterruptInferior();
|
2011-01-24 16:30:34 +01:00
|
|
|
|
|
|
|
|
return isBlocked;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
BaseQmlDebuggerClient *QmlAdapter::activeDebuggerClient() const
|
2011-07-26 16:22:49 +02:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_qmlClient;
|
2011-07-26 16:22:49 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-09 14:56:04 +02:00
|
|
|
QHash<QString, BaseQmlDebuggerClient*> QmlAdapter::debuggerClients() const
|
2011-07-26 16:22:49 +02:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_debugClients;
|
2011-10-06 17:38:28 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 13:31:36 +02:00
|
|
|
QDebugMessageClient *QmlAdapter::messageClient() const
|
2011-12-20 16:12:38 +01:00
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
return m_msgClient;
|
2011-10-06 17:38:28 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-10 16:54:08 +02:00
|
|
|
void QmlAdapter::logServiceStatusChange(const QString &service, float version,
|
2012-05-10 10:29:11 +02:00
|
|
|
QmlDebug::ClientStatus newStatus)
|
2010-09-30 14:05:20 +02:00
|
|
|
{
|
|
|
|
|
switch (newStatus) {
|
2012-05-10 10:29:11 +02:00
|
|
|
case QmlDebug::Unavailable: {
|
2012-04-10 16:54:08 +02:00
|
|
|
showConnectionStatusMessage(tr("Status of '%1' Version: %2 changed to 'unavailable'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
2010-09-30 14:05:20 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2012-05-10 10:29:11 +02:00
|
|
|
case QmlDebug::Enabled: {
|
2012-04-10 16:54:08 +02:00
|
|
|
showConnectionStatusMessage(tr("Status of '%1' Version: %2 changed to 'enabled'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
2010-09-30 14:05:20 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-10 10:29:11 +02:00
|
|
|
case QmlDebug::NotConnected: {
|
2012-04-10 16:54:08 +02:00
|
|
|
showConnectionStatusMessage(tr("Status of '%1' Version: %2 changed to 'not connected'.").
|
|
|
|
|
arg(service).arg(QString::number(version)));
|
2010-09-30 14:05:20 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-16 17:26:25 +01:00
|
|
|
void QmlAdapter::logServiceActivity(const QString &service, const QString &logMessage)
|
|
|
|
|
{
|
2012-04-18 14:20:54 +02:00
|
|
|
if (!m_engine.isNull())
|
|
|
|
|
m_engine.data()->showMessage(service + QLatin1Char(' ') + logMessage, LogDebug);
|
2010-12-16 17:26:25 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 14:20:54 +02:00
|
|
|
} // namespace Internal
|
2010-08-13 14:18:10 +02:00
|
|
|
} // namespace Debugger
|