2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-07-29 14:15:12 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-07-29 14:15:12 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-07-29 14:15:12 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-07-29 14:15:12 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
2011-04-13 08:42:33 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-07-29 14:15:12 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
#include "qmldebugclient.h"
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2011-08-05 10:18:32 +02:00
|
|
|
#include "qpacketprotocol.h"
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <qdebug.h>
|
|
|
|
|
#include <qstringlist.h>
|
|
|
|
|
#include <qnetworkproxy.h>
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
namespace QmlDebug {
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-09-27 12:45:56 +02:00
|
|
|
const int protocolVersion = 1;
|
2013-11-01 09:58:44 +01:00
|
|
|
int QmlDebugClient::s_dataStreamVersion = QDataStream::Qt_4_7;
|
|
|
|
|
|
2010-09-27 12:45:56 +02:00
|
|
|
const QString serverId = QLatin1String("QDeclarativeDebugServer");
|
|
|
|
|
const QString clientId = QLatin1String("QDeclarativeDebugClient");
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
class QmlDebugClientPrivate
|
2010-09-27 12:45:56 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
// Q_DECLARE_PUBLIC(QmlDebugClient)
|
2010-09-27 12:45:56 +02:00
|
|
|
public:
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugClientPrivate();
|
2010-09-27 12:45:56 +02:00
|
|
|
|
|
|
|
|
QString name;
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnection *connection;
|
2010-09-27 12:45:56 +02:00
|
|
|
};
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
class QmlDebugConnectionPrivate : public QObject
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnectionPrivate(QmlDebugConnection *c);
|
|
|
|
|
QmlDebugConnection *q;
|
2010-07-29 14:15:12 +02:00
|
|
|
QPacketProtocol *protocol;
|
2012-08-22 13:27:25 +02:00
|
|
|
QIODevice *device; // Currently a QTcpSocket
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-09-27 12:45:56 +02:00
|
|
|
bool gotHello;
|
2011-12-15 17:56:58 +01:00
|
|
|
QHash <QString, float> serverPlugins;
|
2012-04-18 12:06:10 +02:00
|
|
|
QHash<QString, QmlDebugClient *> plugins;
|
2010-09-27 12:45:56 +02:00
|
|
|
|
|
|
|
|
void advertisePlugins();
|
2014-05-05 17:34:03 +02:00
|
|
|
void flush();
|
2010-09-27 12:45:56 +02:00
|
|
|
|
2010-07-29 14:15:12 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
|
void connected();
|
2014-05-05 17:18:11 +02:00
|
|
|
void disconnected();
|
|
|
|
|
void error(QAbstractSocket::SocketError error);
|
2010-07-29 14:15:12 +02:00
|
|
|
void readyRead();
|
2014-05-05 17:18:11 +02:00
|
|
|
void stateChanged(QAbstractSocket::SocketState state);
|
2010-07-29 14:15:12 +02:00
|
|
|
};
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnectionPrivate::QmlDebugConnectionPrivate(QmlDebugConnection *c)
|
2011-08-05 10:18:32 +02:00
|
|
|
: QObject(c), q(c), protocol(0), device(0), gotHello(false)
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugConnectionPrivate::advertisePlugins()
|
2010-09-27 12:45:56 +02:00
|
|
|
{
|
2014-05-05 18:01:02 +02:00
|
|
|
if (!q->isOpen())
|
2010-09-27 12:45:56 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QPacket pack;
|
|
|
|
|
pack << serverId << 1 << plugins.keys();
|
|
|
|
|
protocol->send(pack);
|
2014-05-05 17:34:03 +02:00
|
|
|
flush();
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugConnectionPrivate::connected()
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
QPacket pack;
|
2013-11-01 09:58:44 +01:00
|
|
|
QDataStream str;
|
|
|
|
|
pack << serverId << 0 << protocolVersion << plugins.keys() << QDataStream().version();
|
2010-07-29 14:15:12 +02:00
|
|
|
protocol->send(pack);
|
2014-05-05 17:34:03 +02:00
|
|
|
flush();
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:18:11 +02:00
|
|
|
void QmlDebugConnectionPrivate::disconnected()
|
|
|
|
|
{
|
|
|
|
|
if (gotHello) {
|
|
|
|
|
gotHello = false;
|
|
|
|
|
QHash<QString, QmlDebugClient*>::iterator iter = plugins.begin();
|
|
|
|
|
for (; iter != plugins.end(); ++iter)
|
|
|
|
|
iter.value()->stateChanged(QmlDebugClient::NotConnected);
|
|
|
|
|
emit q->closed();
|
|
|
|
|
}
|
|
|
|
|
delete protocol;
|
|
|
|
|
protocol = 0;
|
|
|
|
|
if (device) {
|
|
|
|
|
// Don't immediately delete it as it may do some cleanup on returning from a signal.
|
|
|
|
|
device->deleteLater();
|
|
|
|
|
device = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlDebugConnectionPrivate::error(QAbstractSocket::SocketError socketError)
|
|
|
|
|
{
|
|
|
|
|
//: %1=error code, %2=error message
|
|
|
|
|
emit q->errorMessage(tr("Error: (%1) %2").arg(socketError)
|
|
|
|
|
.arg(device ? device->errorString() : tr("<device is gone>")));
|
|
|
|
|
if (socketError == QAbstractSocket::RemoteHostClosedError)
|
|
|
|
|
emit q->error(QDebugSupport::RemoteClosedConnectionError);
|
|
|
|
|
else
|
|
|
|
|
emit q->error(QDebugSupport::UnknownError);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugConnectionPrivate::readyRead()
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2010-09-27 12:45:56 +02:00
|
|
|
if (!gotHello) {
|
|
|
|
|
QPacket pack = protocol->read();
|
|
|
|
|
QString name;
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-09-27 12:45:56 +02:00
|
|
|
pack >> name;
|
|
|
|
|
|
|
|
|
|
bool validHello = false;
|
|
|
|
|
if (name == clientId) {
|
|
|
|
|
int op = -1;
|
|
|
|
|
pack >> op;
|
|
|
|
|
if (op == 0) {
|
|
|
|
|
int version = -1;
|
|
|
|
|
pack >> version;
|
|
|
|
|
if (version == protocolVersion) {
|
2011-12-15 17:56:58 +01:00
|
|
|
QStringList pluginNames;
|
|
|
|
|
QList<float> pluginVersions;
|
|
|
|
|
pack >> pluginNames;
|
|
|
|
|
if (!pack.isEmpty())
|
|
|
|
|
pack >> pluginVersions;
|
|
|
|
|
|
|
|
|
|
const int pluginNamesSize = pluginNames.size();
|
|
|
|
|
const int pluginVersionsSize = pluginVersions.size();
|
|
|
|
|
for (int i = 0; i < pluginNamesSize; ++i) {
|
|
|
|
|
float pluginVersion = 1.0;
|
|
|
|
|
if (i < pluginVersionsSize)
|
|
|
|
|
pluginVersion = pluginVersions.at(i);
|
|
|
|
|
serverPlugins.insert(pluginNames.at(i), pluginVersion);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-08 14:30:21 +01:00
|
|
|
if (!pack.atEnd()) {
|
2013-11-01 09:58:44 +01:00
|
|
|
pack >> QmlDebugClient::s_dataStreamVersion;
|
|
|
|
|
if (QmlDebugClient::s_dataStreamVersion
|
|
|
|
|
> QDataStream().version())
|
|
|
|
|
qWarning() << "Server returned invalid data stream version!";
|
|
|
|
|
}
|
2010-09-27 12:45:56 +02:00
|
|
|
validHello = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!validHello) {
|
2012-04-18 12:06:10 +02:00
|
|
|
qWarning("QML Debug Client: Invalid hello message");
|
2010-09-27 12:45:56 +02:00
|
|
|
QObject::disconnect(protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
gotHello = true;
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QHash<QString, QmlDebugClient *>::Iterator iter = plugins.begin();
|
2010-09-27 12:45:56 +02:00
|
|
|
for (; iter != plugins.end(); ++iter) {
|
2014-05-05 16:11:43 +02:00
|
|
|
QmlDebugClient::State newState = QmlDebugClient::Unavailable;
|
2010-09-27 12:45:56 +02:00
|
|
|
if (serverPlugins.contains(iter.key()))
|
2014-05-05 16:11:43 +02:00
|
|
|
newState = QmlDebugClient::Enabled;
|
|
|
|
|
iter.value()->stateChanged(newState);
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
2014-05-05 17:18:11 +02:00
|
|
|
emit q->opened();
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (protocol->packetsAvailable()) {
|
|
|
|
|
QPacket pack = protocol->read();
|
|
|
|
|
QString name;
|
|
|
|
|
pack >> name;
|
|
|
|
|
|
|
|
|
|
if (name == clientId) {
|
|
|
|
|
int op = -1;
|
|
|
|
|
pack >> op;
|
|
|
|
|
|
|
|
|
|
if (op == 1) {
|
|
|
|
|
// Service Discovery
|
2011-12-15 17:56:58 +01:00
|
|
|
QHash<QString, float> oldServerPlugins = serverPlugins;
|
|
|
|
|
serverPlugins.clear();
|
|
|
|
|
|
|
|
|
|
QStringList pluginNames;
|
|
|
|
|
QList<float> pluginVersions;
|
|
|
|
|
pack >> pluginNames;
|
|
|
|
|
if (!pack.isEmpty())
|
|
|
|
|
pack >> pluginVersions;
|
|
|
|
|
|
|
|
|
|
const int pluginNamesSize = pluginNames.size();
|
|
|
|
|
const int pluginVersionsSize = pluginVersions.size();
|
|
|
|
|
for (int i = 0; i < pluginNamesSize; ++i) {
|
|
|
|
|
float pluginVersion = 1.0;
|
|
|
|
|
if (i < pluginVersionsSize)
|
|
|
|
|
pluginVersion = pluginVersions.at(i);
|
|
|
|
|
serverPlugins.insert(pluginNames.at(i), pluginVersion);
|
|
|
|
|
}
|
2010-09-27 12:45:56 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QHash<QString, QmlDebugClient *>::Iterator iter = plugins.begin();
|
2010-09-27 12:45:56 +02:00
|
|
|
for (; iter != plugins.end(); ++iter) {
|
|
|
|
|
const QString pluginName = iter.key();
|
2014-05-05 16:11:43 +02:00
|
|
|
QmlDebugClient::State newState = QmlDebugClient::Unavailable;
|
2010-09-27 12:45:56 +02:00
|
|
|
if (serverPlugins.contains(pluginName))
|
2014-05-05 16:11:43 +02:00
|
|
|
newState = QmlDebugClient::Enabled;
|
2010-09-27 12:45:56 +02:00
|
|
|
|
|
|
|
|
if (oldServerPlugins.contains(pluginName)
|
|
|
|
|
!= serverPlugins.contains(pluginName)) {
|
2014-05-05 16:11:43 +02:00
|
|
|
iter.value()->stateChanged(newState);
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-04-18 12:06:10 +02:00
|
|
|
qWarning() << "QML Debug Client: Unknown control message id" << op;
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QByteArray message;
|
|
|
|
|
pack >> message;
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QHash<QString, QmlDebugClient *>::Iterator iter =
|
2011-08-05 10:18:32 +02:00
|
|
|
plugins.find(name);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (iter == plugins.end())
|
2012-04-18 12:06:10 +02:00
|
|
|
qWarning() << "QML Debug Client: Message received for missing plugin" << name;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-09-27 12:45:56 +02:00
|
|
|
(*iter)->messageReceived(message);
|
|
|
|
|
}
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:18:11 +02:00
|
|
|
void QmlDebugConnectionPrivate::stateChanged(QAbstractSocket::SocketState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state) {
|
|
|
|
|
case QAbstractSocket::UnconnectedState:
|
|
|
|
|
emit q->stateMessage(tr("Network connection dropped"));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::HostLookupState:
|
|
|
|
|
emit q->stateMessage(tr("Resolving host"));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ConnectingState:
|
|
|
|
|
emit q->stateMessage(tr("Establishing network connection ..."));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ConnectedState:
|
|
|
|
|
emit q->stateMessage(tr("Network connection established"));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ClosingState:
|
|
|
|
|
emit q->stateMessage(tr("Network connection closing"));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::BoundState:
|
|
|
|
|
emit q->errorMessage(tr("Socket state changed to BoundState. This should not happen!"));
|
|
|
|
|
break;
|
|
|
|
|
case QAbstractSocket::ListeningState:
|
|
|
|
|
emit q->errorMessage(tr("Socket state changed to ListeningState. This should not happen!"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnection::QmlDebugConnection(QObject *parent)
|
2014-04-04 13:31:02 +02:00
|
|
|
: QObject(parent), d(new QmlDebugConnectionPrivate(this))
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugConnection::~QmlDebugConnection()
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2014-05-05 17:18:11 +02:00
|
|
|
d->disconnected();
|
2012-04-18 12:06:10 +02:00
|
|
|
QHash<QString, QmlDebugClient*>::iterator iter = d->plugins.begin();
|
2014-05-05 17:18:11 +02:00
|
|
|
for (; iter != d->plugins.end(); ++iter)
|
2011-08-05 10:18:32 +02:00
|
|
|
iter.value()->d_func()->connection = 0;
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-05 18:01:02 +02:00
|
|
|
bool QmlDebugConnection::isOpen() const
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2014-05-05 17:18:11 +02:00
|
|
|
// gotHello can only be set if the connection is open.
|
|
|
|
|
return d->gotHello;
|
2011-02-23 12:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugConnection::close()
|
2011-02-23 12:10:51 +01:00
|
|
|
{
|
2014-05-05 17:18:11 +02:00
|
|
|
if (d->device && d->device->isOpen())
|
|
|
|
|
d->device->close(); // will trigger disconnected() at some point.
|
2011-02-23 12:10:51 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:34:03 +02:00
|
|
|
void QmlDebugConnectionPrivate::flush()
|
2011-02-23 12:10:51 +01:00
|
|
|
{
|
2014-05-05 17:34:03 +02:00
|
|
|
QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(device);
|
2011-02-23 12:10:51 +01:00
|
|
|
if (socket) {
|
|
|
|
|
socket->flush();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
|
2011-02-23 12:10:51 +01:00
|
|
|
{
|
2014-05-05 17:18:11 +02:00
|
|
|
d->disconnected();
|
|
|
|
|
emit stateMessage(tr("Connecting to debug server at %1:%2 ...")
|
|
|
|
|
.arg(hostName).arg(QString::number(port)));
|
2011-02-23 12:10:51 +01:00
|
|
|
QTcpSocket *socket = new QTcpSocket(d);
|
2011-08-11 09:57:44 +02:00
|
|
|
socket->setProxy(QNetworkProxy::NoProxy);
|
2011-02-23 12:10:51 +01:00
|
|
|
d->device = socket;
|
2014-04-04 13:31:02 +02:00
|
|
|
d->protocol = new QPacketProtocol(d->device, this);
|
|
|
|
|
connect(d->protocol, SIGNAL(readyRead()), d, SLOT(readyRead()));
|
2014-05-05 17:18:11 +02:00
|
|
|
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
|
|
|
|
|
d, SLOT(stateChanged(QAbstractSocket::SocketState)));
|
|
|
|
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
|
|
|
|
|
d, SLOT(error(QAbstractSocket::SocketError)));
|
|
|
|
|
connect(socket, SIGNAL(connected()), d, SLOT(connected()));
|
|
|
|
|
connect(socket, SIGNAL(disconnected()), d, SLOT(disconnected()));
|
2011-02-23 12:10:51 +01:00
|
|
|
socket->connectToHost(hostName, port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugClientPrivate::QmlDebugClientPrivate()
|
2011-08-05 10:18:32 +02:00
|
|
|
: connection(0)
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugClient::QmlDebugClient(const QString &name,
|
|
|
|
|
QmlDebugConnection *parent)
|
|
|
|
|
: QObject(parent), d_ptr(new QmlDebugClientPrivate())
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(QmlDebugClient);
|
2010-07-29 14:15:12 +02:00
|
|
|
d->name = name;
|
2010-11-15 17:09:28 +01:00
|
|
|
d->connection = parent;
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-11-15 17:09:28 +01:00
|
|
|
if (!d->connection)
|
2010-07-29 14:15:12 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-11-15 17:09:28 +01:00
|
|
|
if (d->connection->d->plugins.contains(name)) {
|
2012-04-18 12:06:10 +02:00
|
|
|
qWarning() << "QML Debug Client: Conflicting plugin name" << name;
|
2010-11-15 17:09:28 +01:00
|
|
|
d->connection = 0;
|
2010-07-29 14:15:12 +02:00
|
|
|
} else {
|
2010-11-15 17:09:28 +01:00
|
|
|
d->connection->d->plugins.insert(name, this);
|
|
|
|
|
d->connection->d->advertisePlugins();
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QmlDebugClient::~QmlDebugClient()
|
2010-09-27 12:45:56 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(const QmlDebugClient);
|
2010-11-15 17:09:28 +01:00
|
|
|
if (d->connection && d->connection->d) {
|
|
|
|
|
d->connection->d->plugins.remove(d->name);
|
|
|
|
|
d->connection->d->advertisePlugins();
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
QString QmlDebugClient::name() const
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(const QmlDebugClient);
|
2010-07-29 14:15:12 +02:00
|
|
|
return d->name;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 17:40:53 +02:00
|
|
|
int QmlDebugClient::remoteVersion() const
|
2011-12-15 17:56:58 +01:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(const QmlDebugClient);
|
2014-05-05 17:40:53 +02:00
|
|
|
// The version is internally saved as float for compatibility reasons. Exposing that to clients
|
|
|
|
|
// is a bad idea because floats cannot be properly compared. IEEE 754 floats represent integers
|
|
|
|
|
// exactly up to about 2^24, so the cast shouldn't be a problem for any realistic version
|
|
|
|
|
// numbers.
|
2012-04-13 10:48:53 +02:00
|
|
|
if (d->connection && d->connection->d->serverPlugins.contains(d->name))
|
2014-05-05 17:40:53 +02:00
|
|
|
return static_cast<int>(d->connection->d->serverPlugins.value(d->name));
|
2011-12-15 17:56:58 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 16:11:43 +02:00
|
|
|
QmlDebugClient::State QmlDebugClient::state() const
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(const QmlDebugClient);
|
2014-05-05 18:01:02 +02:00
|
|
|
if (!d->connection || !d->connection->isOpen())
|
2010-09-27 12:45:56 +02:00
|
|
|
return NotConnected;
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-11-15 17:09:28 +01:00
|
|
|
if (d->connection->d->serverPlugins.contains(d->name))
|
2010-09-27 12:45:56 +02:00
|
|
|
return Enabled;
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2010-09-27 12:45:56 +02:00
|
|
|
return Unavailable;
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugClient::sendMessage(const QByteArray &message)
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
2012-04-18 12:06:10 +02:00
|
|
|
Q_D(QmlDebugClient);
|
2014-05-05 16:11:43 +02:00
|
|
|
if (state() != Enabled)
|
2010-07-29 14:15:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QPacket pack;
|
|
|
|
|
pack << d->name << message;
|
2010-11-15 17:09:28 +01:00
|
|
|
d->connection->d->protocol->send(pack);
|
2014-05-05 17:34:03 +02:00
|
|
|
d->connection->d->flush();
|
2010-09-27 12:45:56 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-05 16:11:43 +02:00
|
|
|
void QmlDebugClient::stateChanged(State)
|
2010-09-27 12:45:56 +02:00
|
|
|
{
|
2010-07-29 14:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
void QmlDebugClient::messageReceived(const QByteArray &)
|
2010-07-29 14:15:12 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 09:58:44 +01:00
|
|
|
QmlDebugStream::QmlDebugStream()
|
|
|
|
|
: QDataStream()
|
|
|
|
|
{
|
|
|
|
|
setVersion(QmlDebugClient::s_dataStreamVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlDebugStream::QmlDebugStream(QIODevice *d)
|
|
|
|
|
: QDataStream(d)
|
|
|
|
|
{
|
|
|
|
|
setVersion(QmlDebugClient::s_dataStreamVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlDebugStream::QmlDebugStream(QByteArray *ba, QIODevice::OpenMode flags)
|
|
|
|
|
: QDataStream(ba, flags)
|
|
|
|
|
{
|
|
|
|
|
setVersion(QmlDebugClient::s_dataStreamVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QmlDebugStream::QmlDebugStream(const QByteArray &ba)
|
|
|
|
|
: QDataStream(ba)
|
|
|
|
|
{
|
|
|
|
|
setVersion(QmlDebugClient::s_dataStreamVersion);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
} // namespace QmlDebug
|
2010-07-29 14:15:12 +02:00
|
|
|
|
2012-04-18 12:06:10 +02:00
|
|
|
#include <qmldebugclient.moc>
|