Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qlocalclientconnection.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
include
<
private
/
qqmldebugserverconnection_p
.
h
>
6
7
#
include
<
QtCore
/
qplugin
.
h
>
8
#
include
<
QtNetwork
/
qlocalsocket
.
h
>
9
#
include
<
private
/
qqmldebugserver_p
.
h
>
10
11
Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
12
13
QT_BEGIN_NAMESPACE
14
15
16
class
QLocalClientConnection :
public
QQmlDebugServerConnection
17
{
18
Q_OBJECT
19
Q_DISABLE_COPY(QLocalClientConnection)
20
21
public
:
22
QLocalClientConnection();
23
~QLocalClientConnection() override;
24
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;
28
29
bool
isConnected()
const
override;
30
void
disconnect() override;
31
32
void
waitForConnection() override;
33
void
flush() override;
34
35
private
:
36
void
connectionEstablished();
37
bool
connectToServer();
38
39
bool
m_block =
false
;
40
QString m_filename;
41
QLocalSocket *m_socket =
nullptr
;
42
QQmlDebugServer *m_debugServer =
nullptr
;
43
};
44
45
QLocalClientConnection::QLocalClientConnection() { }
46
47
QLocalClientConnection::~QLocalClientConnection()
48
{
49
if
(isConnected())
50
disconnect();
51
}
52
53
void
QLocalClientConnection::setServer(QQmlDebugServer *server)
54
{
55
m_debugServer = server;
56
}
57
58
bool
QLocalClientConnection::isConnected()
const
59
{
60
return
m_socket && m_socket->state() == QLocalSocket::ConnectedState;
61
}
62
63
void
QLocalClientConnection::disconnect()
64
{
65
while
(m_socket && m_socket->bytesToWrite() > 0)
66
m_socket->waitForBytesWritten();
67
68
m_socket->deleteLater();
69
m_socket =
nullptr
;
70
}
71
72
bool
QLocalClientConnection::setPortRange(
int
portFrom,
int
portTo,
bool
block,
73
const
QString &hostaddress)
74
{
75
Q_UNUSED(portFrom);
76
Q_UNUSED(portTo);
77
Q_UNUSED(block);
78
Q_UNUSED(hostaddress);
79
return
false
;
80
}
81
82
bool
QLocalClientConnection::setFileName(
const
QString &filename,
bool
block)
83
{
84
m_filename = filename;
85
m_block = block;
86
return
connectToServer();
87
}
88
89
void
QLocalClientConnection::waitForConnection()
90
{
91
m_socket->waitForConnected(-1);
92
}
93
94
bool
QLocalClientConnection::connectToServer()
95
{
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);
105
106
m_socket->connectToServer(m_filename);
107
qDebug(
"QML Debugger: Connecting to socket %s..."
, m_filename.toLatin1().constData());
108
return
true
;
109
}
110
111
void
QLocalClientConnection::flush()
112
{
113
if
(m_socket)
114
m_socket->flush();
115
}
116
117
void
QLocalClientConnection::connectionEstablished()
118
{
119
m_debugServer->setDevice(m_socket);
120
}
121
122
class
QLocalClientConnectionFactory
:
public
QQmlDebugServerConnectionFactory
123
{
124
Q_OBJECT
125
Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE
"qlocalclientconnection.json"
)
126
Q_INTERFACES
(
QQmlDebugServerConnectionFactory
)
127
public
:
128
QQmlDebugServerConnection
*
create
(
const
QString
&
key
)
override
;
129
};
130
131
QQmlDebugServerConnection *
QLocalClientConnectionFactory
::create(
const
QString &key)
132
{
133
return
(key == QLatin1String(
"QLocalClientConnection"
) ?
new
QLocalClientConnection :
nullptr
);
134
}
135
136
QT_END_NAMESPACE
137
138
#
include
"qlocalclientconnection.moc"
QLocalClientConnectionFactory
Definition
qlocalclientconnection.cpp:123
qtdeclarative
src
plugins
qmltooling
qmldbg_local
qlocalclientconnection.cpp
Generated on
for Qt by
1.18.0