5#include <private/qqmldebugserverconnection_p.h>
7#include <QtCore/qplugin.h>
8#include <QtNetwork/qlocalsocket.h>
9#include <private/qqmldebugserver_p.h>
11Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
16class QLocalClientConnection :
public QQmlDebugServerConnection
19 Q_DISABLE_COPY(QLocalClientConnection)
22 QLocalClientConnection();
23 ~QLocalClientConnection() override;
25 void setServer(QQmlDebugServer *server) override;
26 bool setPortRange(
int portFrom,
int portTo,
bool block,
const QString &hostaddress) override;
27 bool setFileName(
const QString &filename,
bool block) override;
29 bool isConnected()
const override;
30 void disconnect() override;
32 void waitForConnection() override;
33 void flush() override;
36 void connectionEstablished();
37 bool connectToServer();
41 QLocalSocket *m_socket =
nullptr;
42 QQmlDebugServer *m_debugServer =
nullptr;
45QLocalClientConnection::QLocalClientConnection() { }
47QLocalClientConnection::~QLocalClientConnection()
53void QLocalClientConnection::setServer(QQmlDebugServer *server)
55 m_debugServer = server;
58bool QLocalClientConnection::isConnected()
const
60 return m_socket && m_socket->state() == QLocalSocket::ConnectedState;
63void QLocalClientConnection::disconnect()
65 while (m_socket && m_socket->bytesToWrite() > 0)
66 m_socket->waitForBytesWritten();
68 m_socket->deleteLater();
72bool QLocalClientConnection::setPortRange(
int portFrom,
int portTo,
bool block,
73 const QString &hostaddress)
78 Q_UNUSED(hostaddress);
82bool QLocalClientConnection::setFileName(
const QString &filename,
bool block)
84 m_filename = filename;
86 return connectToServer();
89void QLocalClientConnection::waitForConnection()
91 m_socket->waitForConnected(-1);
94bool QLocalClientConnection::connectToServer()
96 m_socket =
new QLocalSocket;
97 m_socket->setParent(
this);
98 connect(m_socket, &QLocalSocket::connected,
99 this, &QLocalClientConnection::connectionEstablished);
100 connect(m_socket,
static_cast<
void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(
101 &QLocalSocket::errorOccurred), m_socket, [
this](QLocalSocket::LocalSocketError) {
102 m_socket->disconnectFromServer();
103 m_socket->connectToServer(m_filename);
104 }, Qt::QueuedConnection);
106 m_socket->connectToServer(m_filename);
107 qDebug(
"QML Debugger: Connecting to socket %s...", m_filename.toLatin1().constData());
111void QLocalClientConnection::flush()
117void QLocalClientConnection::connectionEstablished()
119 m_debugServer->setDevice(m_socket);
125 Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE
"qlocalclientconnection.json")
133 return (key == QLatin1String(
"QLocalClientConnection") ?
new QLocalClientConnection :
nullptr);
138#include "qlocalclientconnection.moc"