Skip to content

Commit

Permalink
Debugger: Add optional 'host' argument to -qmljsdebugger
Browse files Browse the repository at this point in the history
Change-Id: I5bb2e48e2ad2019b8a92f6f8842b88027fcd2d28
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
  • Loading branch information
Simjees Abraham authored and Qt by Nokia committed Mar 19, 2012
1 parent 5c05f5d commit e0e81d6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/plugins/qmltooling/qmldbg_ost/qmlostplugin.cpp
Expand Up @@ -115,10 +115,11 @@ bool QmlOstPlugin::waitForMessage()
return d->protocol->waitForReadyRead(-1);
}

void QmlOstPlugin::setPort(int port, bool block)
void QmlOstPlugin::setPort(int port, bool block, const QString &hostaddress)
{
Q_UNUSED(port);
Q_UNUSED(block);
Q_UNUSED(hostaddress);

Q_D(QmlOstPlugin);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/qmltooling/qmldbg_ost/qmlostplugin.h
Expand Up @@ -63,7 +63,7 @@ class QmlOstPlugin : public QObject, public QQmlDebugServerConnection
~QmlOstPlugin();

void setServer(QQmlDebugServer *server);
void setPort(int port, bool bock);
void setPort(int port, bool bock, const QString &hostaddress);

bool isConnected() const;
void send(const QByteArray &message);
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.cpp
Expand Up @@ -56,6 +56,7 @@ class QTcpServerConnectionPrivate {

int port;
bool block;
QString hostaddress;
QTcpSocket *socket;
QPacketProtocol *protocol;
QTcpServer *tcpServer;
Expand Down Expand Up @@ -129,11 +130,12 @@ bool QTcpServerConnection::waitForMessage()
return d->protocol->waitForReadyRead(-1);
}

void QTcpServerConnection::setPort(int port, bool block)
void QTcpServerConnection::setPort(int port, bool block, const QString &hostaddress)
{
Q_D(QTcpServerConnection);
d->port = port;
d->block = block;
d->hostaddress = hostaddress;

listen();
if (block)
Expand All @@ -146,7 +148,17 @@ void QTcpServerConnection::listen()

d->tcpServer = new QTcpServer(this);
QObject::connect(d->tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
if (d->tcpServer->listen(QHostAddress::Any, d->port))
QHostAddress hostaddress;
if (!d->hostaddress.isEmpty()) {
if (!hostaddress.setAddress(d->hostaddress)) {
hostaddress = QHostAddress::Any;
qDebug("QML Debugger: Incorrect host address provided. So accepting connections "
"from any host.");
}
} else {
hostaddress = QHostAddress::Any;
}
if (d->tcpServer->listen(hostaddress, d->port))
qDebug("QML Debugger: Waiting for connection on port %d...", d->port);
else
qWarning("QML Debugger: Unable to listen to port %d.", d->port);
Expand Down Expand Up @@ -194,4 +206,3 @@ void QTcpServerConnection::invalidPacket()
}

QT_END_NAMESPACE

2 changes: 1 addition & 1 deletion src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnection.h
Expand Up @@ -62,7 +62,7 @@ class QTcpServerConnection : public QObject, public QQmlDebugServerConnection
~QTcpServerConnection();

void setServer(QQmlDebugServer *server);
void setPort(int port, bool bock);
void setPort(int port, bool bock, const QString &hostaddress);

bool isConnected() const;
void send(const QList<QByteArray> &messages);
Expand Down
35 changes: 22 additions & 13 deletions src/qml/debugger/qqmldebugserver.cpp
Expand Up @@ -117,9 +117,10 @@ class QQmlDebugServerThread : public QThread
m_pluginName = pluginName;
}

void setPort(int port, bool block) {
void setPort(int port, bool block, QString &hostAddress) {
m_port = port;
m_block = block;
m_hostAddress = hostAddress;
}

void run();
Expand All @@ -128,6 +129,7 @@ class QQmlDebugServerThread : public QThread
QString m_pluginName;
int m_port;
bool m_block;
QString m_hostAddress;
};

QQmlDebugServerPrivate::QQmlDebugServerPrivate() :
Expand Down Expand Up @@ -214,7 +216,7 @@ void QQmlDebugServerThread::run()
= server->d_func()->loadConnectionPlugin(m_pluginName);
if (connection) {
connection->setServer(QQmlDebugServer::instance());
connection->setPort(m_port, m_block);
connection->setPort(m_port, m_block, m_hostAddress);
} else {
QCoreApplicationPrivate *appD = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp));
qWarning() << QString(QLatin1String("QML Debugger: Ignoring \"-qmljsdebugger=%1\". "
Expand Down Expand Up @@ -258,8 +260,9 @@ QQmlDebugServer *QQmlDebugServer::instance()
int port = 0;
bool block = false;
bool ok = false;
QString hostAddress;

// format: qmljsdebugger=port:3768[,block] OR qmljsdebugger=ost[,block]
// format: qmljsdebugger=port:3768[,host:<ip address>][,block] OR qmljsdebugger=ost[,block]
if (!appD->qmljsDebugArgumentsString().isEmpty()) {
if (!QQmlEnginePrivate::qml_debugging_enabled) {
qWarning() << QString(QLatin1String(
Expand All @@ -270,24 +273,30 @@ QQmlDebugServer *QQmlDebugServer::instance()
}

QString pluginName;
if (appD->qmljsDebugArgumentsString().indexOf(QLatin1String("port:")) == 0) {
int separatorIndex = appD->qmljsDebugArgumentsString().indexOf(QLatin1Char(','));
port = appD->qmljsDebugArgumentsString().mid(5, separatorIndex - 5).toInt(&ok);
pluginName = QStringLiteral("qmldbg_tcp");
} else if (appD->qmljsDebugArgumentsString().contains(QLatin1String("ost"))) {
pluginName = QStringLiteral("qmldbg_ost");
ok = true;
QStringList lstjsDebugArguments = appD->qmljsDebugArgumentsString()
.split(QLatin1Char(','));
foreach (const QString &strArgument, lstjsDebugArguments) {
if (strArgument.startsWith(QLatin1String("port:"))) {
port = strArgument.mid(5).toInt(&ok);
pluginName = QLatin1String("qmldbg_tcp");
} else if (strArgument.startsWith(QLatin1String("host:"))) {
hostAddress = strArgument.mid(5);
} else if (strArgument == QLatin1String("block")) {
block = true;
} else {
qWarning() << QString::fromLatin1("QML Debugger: Invalid argument '%1' "
"detected. Ignoring the same.")
.arg(strArgument);
}
}

block = appD->qmljsDebugArgumentsString().contains(QLatin1String("block"));

if (ok) {
qQmlDebugServer = new QQmlDebugServer();
QQmlDebugServerThread *thread = new QQmlDebugServerThread;
qQmlDebugServer->d_func()->thread = thread;
qQmlDebugServer->moveToThread(thread);
thread->setPluginName(pluginName);
thread->setPort(port, block);
thread->setPort(port, block, hostAddress);
thread->start();

if (block) {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/debugger/qqmldebugserverconnection_p.h
Expand Up @@ -69,7 +69,7 @@ class Q_QML_EXPORT QQmlDebugServerConnection
virtual ~QQmlDebugServerConnection() {}

virtual void setServer(QQmlDebugServer *server) = 0;
virtual void setPort(int port, bool bock) = 0;
virtual void setPort(int port, bool bock, const QString &hostaddress) = 0;
virtual bool isConnected() const = 0;
virtual void send(const QList<QByteArray> &messages) = 0;
virtual void disconnect() = 0;
Expand Down
Expand Up @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
char **_argv = new char*[_argc];
for (int i = 0; i < argc; ++i)
_argv[i] = argv[i];
char arg[] = "-qmljsdebugger=port:" STR_PORT;
char arg[] = "-qmljsdebugger=port:" STR_PORT ",host:127.0.0.1";
_argv[_argc - 1] = arg;

QGuiApplication app(_argc, _argv);
Expand Down

0 comments on commit e0e81d6

Please sign in to comment.