4#include <private/qqmldebugserverconnection_p.h>
6#include <QtCore/qplugin.h>
7#include <QtNetwork/qlocalsocket.h>
8#include <private/qqmldebugserver_p.h>
10Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
15class QLocalClientConnection :
public QQmlDebugServerConnection
18 Q_DISABLE_COPY(QLocalClientConnection)
21 QLocalClientConnection();
22 ~QLocalClientConnection() override;
24 void setServer(QQmlDebugServer *server) override;
25 bool setPortRange(
int portFrom,
int portTo,
bool block,
const QString &hostaddress) override;
26 bool setFileName(
const QString &filename,
bool block) override;
28 bool isConnected()
const override;
29 void disconnect() override;
31 void waitForConnection() override;
32 void flush() override;
35 void connectionEstablished();
36 bool connectToServer();
40 QLocalSocket *m_socket =
nullptr;
41 QQmlDebugServer *m_debugServer =
nullptr;
44QLocalClientConnection::QLocalClientConnection() { }
46QLocalClientConnection::~QLocalClientConnection()
52void QLocalClientConnection::setServer(QQmlDebugServer *server)
54 m_debugServer = server;
57bool QLocalClientConnection::isConnected()
const
59 return m_socket && m_socket->state() == QLocalSocket::ConnectedState;
62void QLocalClientConnection::disconnect()
64 while (m_socket && m_socket->bytesToWrite() > 0)
65 m_socket->waitForBytesWritten();
67 m_socket->deleteLater();
71bool QLocalClientConnection::setPortRange(
int portFrom,
int portTo,
bool block,
72 const QString &hostaddress)
77 Q_UNUSED(hostaddress);
81bool QLocalClientConnection::setFileName(
const QString &filename,
bool block)
83 m_filename = filename;
85 return connectToServer();
88void QLocalClientConnection::waitForConnection()
90 m_socket->waitForConnected(-1);
93bool QLocalClientConnection::connectToServer()
95 m_socket =
new QLocalSocket;
96 m_socket->setParent(
this);
97 connect(m_socket, &QLocalSocket::connected,
98 this, &QLocalClientConnection::connectionEstablished);
99 connect(m_socket,
static_cast<
void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(
100 &QLocalSocket::errorOccurred), m_socket, [
this](QLocalSocket::LocalSocketError) {
101 m_socket->disconnectFromServer();
102 m_socket->connectToServer(m_filename);
103 }, Qt::QueuedConnection);
105 m_socket->connectToServer(m_filename);
106 qDebug(
"QML Debugger: Connecting to socket %s...", m_filename.toLatin1().constData());
110void QLocalClientConnection::flush()
116void QLocalClientConnection::connectionEstablished()
118 m_debugServer->setDevice(m_socket);
124 Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE
"qlocalclientconnection.json")
132 return (key == QLatin1String(
"QLocalClientConnection") ?
new QLocalClientConnection :
nullptr);
137#include "qlocalclientconnection.moc"