summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-15 18:37:40 +0200
committerKent Hansen <khansen@trolltech.com>2009-06-15 18:37:40 +0200
commit84b7c9a9433f3536b327fd2fd560c20c20ca4cba (patch)
tree2a23489c9031fcfe357bded5b205ffd21727ab3c
parent17ff2c10d9aa77af31d3921e60f74250493b09c8 (diff)
implement QScriptRemoteTargetDebugger::listen()
-rw-r--r--src/qscriptdebuggerengine.cpp4
-rw-r--r--src/qscriptremotetargetdebugger.cpp89
-rw-r--r--src/qscriptremotetargetdebugger.h1
3 files changed, 70 insertions, 24 deletions
diff --git a/src/qscriptdebuggerengine.cpp b/src/qscriptdebuggerengine.cpp
index 54fabc1..b6cf264 100644
--- a/src/qscriptdebuggerengine.cpp
+++ b/src/qscriptdebuggerengine.cpp
@@ -97,7 +97,7 @@ void QScriptRemoteTargetDebuggerBackend::connectToDebugger(const QHostAddress &a
if (!m_socket) {
m_socket = new QTcpSocket(this);
QObject::connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
- this, SLOT(onSocketSateChanged(QAbstractSocket::SocketState)));
+ this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
QObject::connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(onSocketError(QAbstractSocket::SocketError)));
QObject::connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
@@ -117,7 +117,7 @@ bool QScriptRemoteTargetDebuggerBackend::listen(const QHostAddress &address, qui
if (m_socket)
return false;
if (!m_server) {
- m_server = new QTcpServer();
+ m_server = new QTcpServer(this);
QObject::connect(m_server, SIGNAL(newConnection()),
this, SLOT(onNewConnection()));
}
diff --git a/src/qscriptremotetargetdebugger.cpp b/src/qscriptremotetargetdebugger.cpp
index f6b26c5..be38491 100644
--- a/src/qscriptremotetargetdebugger.cpp
+++ b/src/qscriptremotetargetdebugger.cpp
@@ -20,6 +20,7 @@
****************************************************************************/
#include "qscriptremotetargetdebugger.h"
+#include <QtNetwork/qtcpserver.h>
#include <QtNetwork/qtcpsocket.h>
#include <QtGui>
@@ -50,6 +51,7 @@ public:
void attachTo(const QHostAddress &address, quint16 port);
void detach();
+ bool listen(const QHostAddress &address, quint16 port);
Q_SIGNALS:
void attached();
@@ -63,9 +65,14 @@ private Q_SLOTS:
void onSocketStateChanged(QAbstractSocket::SocketState);
void onSocketError(QAbstractSocket::SocketError);
void onReadyRead();
+ void onNewConnection();
+
+private:
+ void initiateHandshake();
private:
State m_state;
+ QTcpServer *m_server;
QTcpSocket *m_socket;
int m_blockSize;
@@ -73,7 +80,7 @@ private:
};
QScriptRemoteTargetDebuggerFrontend::QScriptRemoteTargetDebuggerFrontend()
- : m_state(UnattachedState), m_socket(0), m_blockSize(0)
+ : m_state(UnattachedState), m_server(0), m_socket(0), m_blockSize(0)
{
}
@@ -100,6 +107,18 @@ void QScriptRemoteTargetDebuggerFrontend::detach()
Q_ASSERT_X(false, Q_FUNC_INFO, "implement me");
}
+bool QScriptRemoteTargetDebuggerFrontend::listen(const QHostAddress &address, quint16 port)
+{
+ if (m_socket)
+ return false;
+ if (!m_server) {
+ m_server = new QTcpServer(this);
+ QObject::connect(m_server, SIGNAL(newConnection()),
+ this, SLOT(onNewConnection()));
+ }
+ return m_server->listen(address, port);
+}
+
void QScriptRemoteTargetDebuggerFrontend::onSocketStateChanged(QAbstractSocket::SocketState state)
{
switch (state) {
@@ -110,14 +129,9 @@ void QScriptRemoteTargetDebuggerFrontend::onSocketStateChanged(QAbstractSocket::
case QAbstractSocket::ConnectingState:
m_state = ConnectingState;
break;
- case QAbstractSocket::ConnectedState: {
- m_state = HandshakingState;
- QByteArray handshakeData("QtScriptDebug-Handshake");
-#ifdef DEBUG_DEBUGGER
- qDebug("writing handshake data");
-#endif
- m_socket->write(handshakeData);
- } break;
+ case QAbstractSocket::ConnectedState:
+ initiateHandshake();
+ break;
case QAbstractSocket::BoundState:
break;
case QAbstractSocket::ClosingState:
@@ -231,6 +245,22 @@ void QScriptRemoteTargetDebuggerFrontend::onReadyRead()
}
}
+void QScriptRemoteTargetDebuggerFrontend::onNewConnection()
+{
+ qDebug("received connection");
+ m_socket = m_server->nextPendingConnection();
+ m_server->close();
+ QObject::connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+ this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
+ QObject::connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(onSocketError(QAbstractSocket::SocketError)));
+ QObject::connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
+ initiateHandshake();
+}
+
+/*!
+ \reimp
+*/
void QScriptRemoteTargetDebuggerFrontend::processCommand(int id, const QScriptDebuggerCommand &command)
{
Q_ASSERT(m_state == AttachedState);
@@ -248,6 +278,16 @@ void QScriptRemoteTargetDebuggerFrontend::processCommand(int id, const QScriptDe
m_socket->write(block);
}
+void QScriptRemoteTargetDebuggerFrontend::initiateHandshake()
+{
+ m_state = HandshakingState;
+ QByteArray handshakeData("QtScriptDebug-Handshake");
+#ifdef DEBUG_DEBUGGER
+ qDebug("writing handshake data");
+#endif
+ m_socket->write(handshakeData);
+}
+
QScriptRemoteTargetDebugger::QScriptRemoteTargetDebugger(QObject *parent)
: QObject(parent), m_frontend(0), m_debugger(0), m_autoShow(true),
m_standardWindow(0)
@@ -262,18 +302,8 @@ QScriptRemoteTargetDebugger::~QScriptRemoteTargetDebugger()
void QScriptRemoteTargetDebugger::attachTo(const QHostAddress &address, quint16 port)
{
- createDebugger();
- if (!m_frontend) {
- m_frontend = new QScriptRemoteTargetDebuggerFrontend();
- QObject::connect(m_frontend, SIGNAL(attached()),
- this, SIGNAL(attached()), Qt::QueuedConnection);
- QObject::connect(m_frontend, SIGNAL(detached()),
- this, SIGNAL(detached()), Qt::QueuedConnection);
- QObject::connect(m_frontend, SIGNAL(error(QScriptRemoteTargetDebugger::Error)),
- this, SIGNAL(error(QScriptRemoteTargetDebugger::Error)));
- }
+ createFrontend();
m_frontend->attachTo(address, port);
- m_debugger->setFrontend(m_frontend);
}
void QScriptRemoteTargetDebugger::detach()
@@ -284,8 +314,8 @@ void QScriptRemoteTargetDebugger::detach()
bool QScriptRemoteTargetDebugger::listen(const QHostAddress &address, quint16 port)
{
- Q_ASSERT_X(false, Q_FUNC_INFO, "implement me");
- return false;
+ createFrontend();
+ return m_frontend->listen(address, port);
}
void QScriptRemoteTargetDebugger::createDebugger()
@@ -304,6 +334,21 @@ void QScriptRemoteTargetDebugger::createDebugger()
}
}
+void QScriptRemoteTargetDebugger::createFrontend()
+{
+ if (!m_frontend) {
+ m_frontend = new QScriptRemoteTargetDebuggerFrontend();
+ QObject::connect(m_frontend, SIGNAL(attached()),
+ this, SIGNAL(attached()), Qt::QueuedConnection);
+ QObject::connect(m_frontend, SIGNAL(detached()),
+ this, SIGNAL(detached()), Qt::QueuedConnection);
+ QObject::connect(m_frontend, SIGNAL(error(QScriptRemoteTargetDebugger::Error)),
+ this, SIGNAL(error(QScriptRemoteTargetDebugger::Error)));
+ createDebugger();
+ m_debugger->setFrontend(m_frontend);
+ }
+}
+
QMainWindow *QScriptRemoteTargetDebugger::standardWindow() const
{
if (m_standardWindow)
diff --git a/src/qscriptremotetargetdebugger.h b/src/qscriptremotetargetdebugger.h
index 458cce9..4b56af0 100644
--- a/src/qscriptremotetargetdebugger.h
+++ b/src/qscriptremotetargetdebugger.h
@@ -108,6 +108,7 @@ private Q_SLOTS:
private:
void createDebugger();
+ void createFrontend();
private:
QScriptRemoteTargetDebuggerFrontend *m_frontend;