Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmldebug/qqmldebugconnection.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qqmldebugconnection_p.h" | - | ||||||||||||
41 | #include "qqmldebugclient_p.h" | - | ||||||||||||
42 | - | |||||||||||||
43 | #include <private/qpacketprotocol_p.h> | - | ||||||||||||
44 | #include <private/qpacket_p.h> | - | ||||||||||||
45 | #include <private/qobject_p.h> | - | ||||||||||||
46 | - | |||||||||||||
47 | #include <QtCore/qeventloop.h> | - | ||||||||||||
48 | #include <QtCore/qtimer.h> | - | ||||||||||||
49 | #include <QtCore/qdatastream.h> | - | ||||||||||||
50 | #include <QtNetwork/qlocalserver.h> | - | ||||||||||||
51 | #include <QtNetwork/qlocalsocket.h> | - | ||||||||||||
52 | #include <QtNetwork/qtcpsocket.h> | - | ||||||||||||
53 | - | |||||||||||||
54 | QT_BEGIN_NAMESPACE | - | ||||||||||||
55 | - | |||||||||||||
56 | static const int protocolVersion = 1; | - | ||||||||||||
57 | static const QString serverId = QLatin1String("QDeclarativeDebugServer"); | - | ||||||||||||
58 | static const QString clientId = QLatin1String("QDeclarativeDebugClient"); | - | ||||||||||||
59 | - | |||||||||||||
60 | class QQmlDebugConnectionPrivate : public QObjectPrivate | - | ||||||||||||
61 | { | - | ||||||||||||
62 | Q_DECLARE_PUBLIC(QQmlDebugConnection) | - | ||||||||||||
63 | - | |||||||||||||
64 | public: | - | ||||||||||||
65 | QQmlDebugConnectionPrivate(); | - | ||||||||||||
66 | QPacketProtocol *protocol = nullptr; | - | ||||||||||||
67 | QIODevice *device = nullptr; | - | ||||||||||||
68 | QLocalServer *server = nullptr; | - | ||||||||||||
69 | QEventLoop handshakeEventLoop; | - | ||||||||||||
70 | QTimer handshakeTimer; | - | ||||||||||||
71 | - | |||||||||||||
72 | bool gotHello = false; | - | ||||||||||||
73 | int currentDataStreamVersion = QDataStream::Qt_4_7; | - | ||||||||||||
74 | int maximumDataStreamVersion = QDataStream::Qt_DefaultCompiledVersion; | - | ||||||||||||
75 | QHash <QString, float> serverPlugins; | - | ||||||||||||
76 | QHash<QString, QQmlDebugClient *> plugins; | - | ||||||||||||
77 | QStringList removedPlugins; | - | ||||||||||||
78 | - | |||||||||||||
79 | void advertisePlugins(); | - | ||||||||||||
80 | void createProtocol(); | - | ||||||||||||
81 | void flush(); | - | ||||||||||||
82 | }; | - | ||||||||||||
83 | - | |||||||||||||
84 | QQmlDebugConnectionPrivate::QQmlDebugConnectionPrivate() | - | ||||||||||||
85 | { | - | ||||||||||||
86 | handshakeTimer.setSingleShot(true); | - | ||||||||||||
87 | handshakeTimer.setInterval(3000); | - | ||||||||||||
88 | } executed 550 times by 11 tests: end of block Executed by:
| 550 | ||||||||||||
89 | - | |||||||||||||
90 | void QQmlDebugConnectionPrivate::advertisePlugins() | - | ||||||||||||
91 | { | - | ||||||||||||
92 | Q_Q(QQmlDebugConnection); | - | ||||||||||||
93 | if (!q->isConnected())
| 3192-3208 | ||||||||||||
94 | return; executed 3192 times by 9 tests: return; Executed by:
| 3192 | ||||||||||||
95 | - | |||||||||||||
96 | QPacket pack(currentDataStreamVersion); | - | ||||||||||||
97 | pack << serverId << 1 << plugins.keys(); | - | ||||||||||||
98 | protocol->send(pack.data()); | - | ||||||||||||
99 | flush(); | - | ||||||||||||
100 | } executed 3208 times by 11 tests: end of block Executed by:
| 3208 | ||||||||||||
101 | - | |||||||||||||
102 | void QQmlDebugConnection::socketConnected() | - | ||||||||||||
103 | { | - | ||||||||||||
104 | Q_D(QQmlDebugConnection); | - | ||||||||||||
105 | QPacket pack(d->currentDataStreamVersion); | - | ||||||||||||
106 | pack << serverId << 0 << protocolVersion << d->plugins.keys() << d->maximumDataStreamVersion | - | ||||||||||||
107 | << true; // We accept multiple messages per packet | - | ||||||||||||
108 | d->protocol->send(pack.data()); | - | ||||||||||||
109 | d->flush(); | - | ||||||||||||
110 | } executed 547 times by 11 tests: end of block Executed by:
| 547 | ||||||||||||
111 | - | |||||||||||||
112 | void QQmlDebugConnection::socketDisconnected() | - | ||||||||||||
113 | { | - | ||||||||||||
114 | Q_D(QQmlDebugConnection); | - | ||||||||||||
115 | d->gotHello = false; | - | ||||||||||||
116 | emit disconnected(); | - | ||||||||||||
117 | } executed 11 times by 3 tests: end of block Executed by:
| 11 | ||||||||||||
118 | - | |||||||||||||
119 | void QQmlDebugConnection::protocolReadyRead() | - | ||||||||||||
120 | { | - | ||||||||||||
121 | Q_D(QQmlDebugConnection); | - | ||||||||||||
122 | if (!d->gotHello) {
| 544-7394 | ||||||||||||
123 | QPacket pack(d->currentDataStreamVersion, d->protocol->read()); | - | ||||||||||||
124 | QString name; | - | ||||||||||||
125 | - | |||||||||||||
126 | pack >> name; | - | ||||||||||||
127 | - | |||||||||||||
128 | bool validHello = false; | - | ||||||||||||
129 | if (name == clientId) {
| 0-544 | ||||||||||||
130 | int op = -1; | - | ||||||||||||
131 | pack >> op; | - | ||||||||||||
132 | if (op == 0) {
| 0-544 | ||||||||||||
133 | int version = -1; | - | ||||||||||||
134 | pack >> version; | - | ||||||||||||
135 | if (version == protocolVersion) {
| 0-544 | ||||||||||||
136 | QStringList pluginNames; | - | ||||||||||||
137 | QList<float> pluginVersions; | - | ||||||||||||
138 | pack >> pluginNames; | - | ||||||||||||
139 | if (!pack.atEnd())
| 0-544 | ||||||||||||
140 | pack >> pluginVersions; executed 544 times by 11 tests: pack >> pluginVersions; Executed by:
| 544 | ||||||||||||
141 | - | |||||||||||||
142 | const int pluginNamesSize = pluginNames.size(); | - | ||||||||||||
143 | const int pluginVersionsSize = pluginVersions.size(); | - | ||||||||||||
144 | for (int i = 0; i < pluginNamesSize; ++i) {
| 544-3274 | ||||||||||||
145 | float pluginVersion = 1.0; | - | ||||||||||||
146 | if (i < pluginVersionsSize)
| 0-3274 | ||||||||||||
147 | pluginVersion = pluginVersions.at(i); executed 3274 times by 11 tests: pluginVersion = pluginVersions.at(i); Executed by:
| 3274 | ||||||||||||
148 | d->serverPlugins.insert(pluginNames.at(i), pluginVersion); | - | ||||||||||||
149 | } executed 3274 times by 11 tests: end of block Executed by:
| 3274 | ||||||||||||
150 | - | |||||||||||||
151 | pack >> d->currentDataStreamVersion; | - | ||||||||||||
152 | validHello = true; | - | ||||||||||||
153 | } executed 544 times by 11 tests: end of block Executed by:
| 544 | ||||||||||||
154 | } executed 544 times by 11 tests: end of block Executed by:
| 544 | ||||||||||||
155 | } executed 544 times by 11 tests: end of block Executed by:
| 544 | ||||||||||||
156 | - | |||||||||||||
157 | if (!validHello) {
| 0-544 | ||||||||||||
158 | qWarning("QQmlDebugConnection: Invalid hello message"); | - | ||||||||||||
159 | close(); | - | ||||||||||||
160 | return; never executed: return; | 0 | ||||||||||||
161 | } | - | ||||||||||||
162 | d->gotHello = true; | - | ||||||||||||
163 | emit connected(); | - | ||||||||||||
164 | - | |||||||||||||
165 | QHash<QString, QQmlDebugClient *>::Iterator iter = d->plugins.begin(); | - | ||||||||||||
166 | for (; iter != d->plugins.end(); ++iter) {
| 544-3166 | ||||||||||||
167 | QQmlDebugClient::State newState = QQmlDebugClient::Unavailable; | - | ||||||||||||
168 | if (d->serverPlugins.contains(iter.key()))
| 384-2782 | ||||||||||||
169 | newState = QQmlDebugClient::Enabled; executed 2782 times by 9 tests: newState = QQmlDebugClient::Enabled; Executed by:
| 2782 | ||||||||||||
170 | iter.value()->stateChanged(newState); | - | ||||||||||||
171 | } executed 3166 times by 9 tests: end of block Executed by:
| 3166 | ||||||||||||
172 | - | |||||||||||||
173 | d->handshakeTimer.stop(); | - | ||||||||||||
174 | d->handshakeEventLoop.quit(); | - | ||||||||||||
175 | } executed 544 times by 11 tests: end of block Executed by:
| 544 | ||||||||||||
176 | - | |||||||||||||
177 | while (d->protocol->packetsAvailable()) {
| 7394-7938 | ||||||||||||
178 | QPacket pack(d->currentDataStreamVersion, d->protocol->read()); | - | ||||||||||||
179 | QString name; | - | ||||||||||||
180 | pack >> name; | - | ||||||||||||
181 | - | |||||||||||||
182 | if (name == clientId) {
| 0-7394 | ||||||||||||
183 | int op = -1; | - | ||||||||||||
184 | pack >> op; | - | ||||||||||||
185 | - | |||||||||||||
186 | if (op == 1) {
| 0 | ||||||||||||
187 | // Service Discovery | - | ||||||||||||
188 | QHash<QString, float> oldServerPlugins = d->serverPlugins; | - | ||||||||||||
189 | d->serverPlugins.clear(); | - | ||||||||||||
190 | - | |||||||||||||
191 | QStringList pluginNames; | - | ||||||||||||
192 | QList<float> pluginVersions; | - | ||||||||||||
193 | pack >> pluginNames; | - | ||||||||||||
194 | if (!pack.atEnd())
| 0 | ||||||||||||
195 | pack >> pluginVersions; never executed: pack >> pluginVersions; | 0 | ||||||||||||
196 | - | |||||||||||||
197 | const int pluginNamesSize = pluginNames.size(); | - | ||||||||||||
198 | const int pluginVersionsSize = pluginVersions.size(); | - | ||||||||||||
199 | for (int i = 0; i < pluginNamesSize; ++i) {
| 0 | ||||||||||||
200 | float pluginVersion = 1.0; | - | ||||||||||||
201 | if (i < pluginVersionsSize)
| 0 | ||||||||||||
202 | pluginVersion = pluginVersions.at(i); never executed: pluginVersion = pluginVersions.at(i); | 0 | ||||||||||||
203 | d->serverPlugins.insert(pluginNames.at(i), pluginVersion); | - | ||||||||||||
204 | } never executed: end of block | 0 | ||||||||||||
205 | - | |||||||||||||
206 | QHash<QString, QQmlDebugClient *>::Iterator iter = d->plugins.begin(); | - | ||||||||||||
207 | for (; iter != d->plugins.end(); ++iter) {
| 0 | ||||||||||||
208 | const QString pluginName = iter.key(); | - | ||||||||||||
209 | QQmlDebugClient::State newSate = QQmlDebugClient::Unavailable; | - | ||||||||||||
210 | if (d->serverPlugins.contains(pluginName))
| 0 | ||||||||||||
211 | newSate = QQmlDebugClient::Enabled; never executed: newSate = QQmlDebugClient::Enabled; | 0 | ||||||||||||
212 | - | |||||||||||||
213 | if (oldServerPlugins.contains(pluginName)
| 0 | ||||||||||||
214 | != d->serverPlugins.contains(pluginName)) {
| 0 | ||||||||||||
215 | iter.value()->stateChanged(newSate); | - | ||||||||||||
216 | } never executed: end of block | 0 | ||||||||||||
217 | } never executed: end of block | 0 | ||||||||||||
218 | } else { never executed: end of block | 0 | ||||||||||||
219 | qWarning() << "QQmlDebugConnection: Unknown control message id" << op; | - | ||||||||||||
220 | } never executed: end of block | 0 | ||||||||||||
221 | } else { | - | ||||||||||||
222 | QHash<QString, QQmlDebugClient *>::Iterator iter = d->plugins.find(name); | - | ||||||||||||
223 | if (iter == d->plugins.end()) {
| 409-6985 | ||||||||||||
224 | // We can get more messages for plugins we have removed because it takes time to | - | ||||||||||||
225 | // send the advertisement message but the removal is instant locally. | - | ||||||||||||
226 | if (!d->removedPlugins.contains(name))
| 0-409 | ||||||||||||
227 | qWarning() << "QQmlDebugConnection: Message received for missing plugin" never executed: QMessageLogger(__FILE__, 227, __PRETTY_FUNCTION__).warning() << "QQmlDebugConnection: Message received for missing plugin" << name; | 0 | ||||||||||||
228 | << name; never executed: QMessageLogger(__FILE__, 227, __PRETTY_FUNCTION__).warning() << "QQmlDebugConnection: Message received for missing plugin" << name; | 0 | ||||||||||||
229 | } else { executed 409 times by 4 tests: end of block Executed by:
| 409 | ||||||||||||
230 | QQmlDebugClient *client = *iter; | - | ||||||||||||
231 | QByteArray message; | - | ||||||||||||
232 | while (!pack.atEnd()) {
| 3697-6985 | ||||||||||||
233 | pack >> message; | - | ||||||||||||
234 | client->messageReceived(message); | - | ||||||||||||
235 | } executed 3697 times by 11 tests: end of block Executed by:
| 3697 | ||||||||||||
236 | } executed 6985 times by 11 tests: end of block Executed by:
| 6985 | ||||||||||||
237 | } | - | ||||||||||||
238 | } | - | ||||||||||||
239 | } executed 7938 times by 11 tests: end of block Executed by:
| 7938 | ||||||||||||
240 | - | |||||||||||||
241 | void QQmlDebugConnection::handshakeTimeout() | - | ||||||||||||
242 | { | - | ||||||||||||
243 | Q_D(QQmlDebugConnection); | - | ||||||||||||
244 | if (!d->gotHello) {
| 0-3 | ||||||||||||
245 | qWarning() << "QQmlDebugConnection: Did not get handshake answer in time"; | - | ||||||||||||
246 | d->handshakeEventLoop.quit(); | - | ||||||||||||
247 | } executed 3 times by 2 tests: end of block Executed by:
| 3 | ||||||||||||
248 | } executed 3 times by 2 tests: end of block Executed by:
| 3 | ||||||||||||
249 | - | |||||||||||||
250 | QQmlDebugConnection::QQmlDebugConnection(QObject *parent) : | - | ||||||||||||
251 | QObject(*(new QQmlDebugConnectionPrivate), parent) | - | ||||||||||||
252 | { | - | ||||||||||||
253 | Q_D(QQmlDebugConnection); | - | ||||||||||||
254 | connect(&d->handshakeTimer, &QTimer::timeout, this, &QQmlDebugConnection::handshakeTimeout); | - | ||||||||||||
255 | } executed 550 times by 11 tests: end of block Executed by:
| 550 | ||||||||||||
256 | - | |||||||||||||
257 | QQmlDebugConnection::~QQmlDebugConnection() | - | ||||||||||||
258 | { | - | ||||||||||||
259 | Q_D(QQmlDebugConnection); | - | ||||||||||||
260 | QHash<QString, QQmlDebugClient*>::iterator iter = d->plugins.begin(); | - | ||||||||||||
261 | for (; iter != d->plugins.end(); ++iter)
| 4-550 | ||||||||||||
262 | emit iter.value()->stateChanged(QQmlDebugClient::NotConnected); executed 4 times by 2 tests: iter.value()->stateChanged(QQmlDebugClient::NotConnected); Executed by:
| 4 | ||||||||||||
263 | } executed 550 times by 11 tests: end of block Executed by:
| 550 | ||||||||||||
264 | - | |||||||||||||
265 | int QQmlDebugConnection::currentDataStreamVersion() const | - | ||||||||||||
266 | { | - | ||||||||||||
267 | Q_D(const QQmlDebugConnection); | - | ||||||||||||
268 | return d->currentDataStreamVersion; executed 5415 times by 8 tests: return d->currentDataStreamVersion; Executed by:
| 5415 | ||||||||||||
269 | } | - | ||||||||||||
270 | - | |||||||||||||
271 | void QQmlDebugConnection::setMaximumDataStreamVersion(int maximumVersion) | - | ||||||||||||
272 | { | - | ||||||||||||
273 | Q_D(QQmlDebugConnection); | - | ||||||||||||
274 | d->maximumDataStreamVersion = maximumVersion; | - | ||||||||||||
275 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
276 | - | |||||||||||||
277 | bool QQmlDebugConnection::isConnected() const | - | ||||||||||||
278 | { | - | ||||||||||||
279 | Q_D(const QQmlDebugConnection); | - | ||||||||||||
280 | return d->gotHello; executed 26853 times by 11 tests: return d->gotHello; Executed by:
| 26853 | ||||||||||||
281 | } | - | ||||||||||||
282 | - | |||||||||||||
283 | bool QQmlDebugConnection::isConnecting() const | - | ||||||||||||
284 | { | - | ||||||||||||
285 | Q_D(const QQmlDebugConnection); | - | ||||||||||||
286 | return !d->gotHello && d->device; never executed: return !d->gotHello && d->device; | 0 | ||||||||||||
287 | } | - | ||||||||||||
288 | - | |||||||||||||
289 | void QQmlDebugConnection::close() | - | ||||||||||||
290 | { | - | ||||||||||||
291 | Q_D(QQmlDebugConnection); | - | ||||||||||||
292 | if (d->gotHello) {
| 0-2 | ||||||||||||
293 | d->gotHello = false; | - | ||||||||||||
294 | d->device->close(); | - | ||||||||||||
295 | - | |||||||||||||
296 | QHash<QString, QQmlDebugClient*>::iterator iter = d->plugins.begin(); | - | ||||||||||||
297 | for (; iter != d->plugins.end(); ++iter)
| 0-2 | ||||||||||||
298 | emit iter.value()->stateChanged(QQmlDebugClient::NotConnected); never executed: iter.value()->stateChanged(QQmlDebugClient::NotConnected); | 0 | ||||||||||||
299 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
300 | - | |||||||||||||
301 | if (d->device) {
| 0-2 | ||||||||||||
302 | d->device->deleteLater(); | - | ||||||||||||
303 | d->device = nullptr; | - | ||||||||||||
304 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
305 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
306 | - | |||||||||||||
307 | bool QQmlDebugConnection::waitForConnected(int msecs) | - | ||||||||||||
308 | { | - | ||||||||||||
309 | Q_D(QQmlDebugConnection); | - | ||||||||||||
310 | QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device); | - | ||||||||||||
311 | if (!socket) {
| 2-67 | ||||||||||||
312 | if (!d->server || (!d->server->hasPendingConnections() &&
| 0-2 | ||||||||||||
313 | !d->server->waitForNewConnection(msecs)))
| 0-2 | ||||||||||||
314 | return false; never executed: return false; | 0 | ||||||||||||
315 | } else if (!socket->waitForConnected(msecs)) { executed 2 times by 1 test: end of block Executed by:
| 0-67 | ||||||||||||
316 | return false; never executed: return false; | 0 | ||||||||||||
317 | } | - | ||||||||||||
318 | // wait for handshake | - | ||||||||||||
319 | d->handshakeTimer.start(); | - | ||||||||||||
320 | d->handshakeEventLoop.exec(); | - | ||||||||||||
321 | return d->gotHello; executed 69 times by 6 tests: return d->gotHello; Executed by:
| 69 | ||||||||||||
322 | } | - | ||||||||||||
323 | - | |||||||||||||
324 | QQmlDebugClient *QQmlDebugConnection::client(const QString &name) const | - | ||||||||||||
325 | { | - | ||||||||||||
326 | Q_D(const QQmlDebugConnection); | - | ||||||||||||
327 | return d->plugins.value(name, 0); executed 3696 times by 8 tests: return d->plugins.value(name, 0); Executed by:
| 3696 | ||||||||||||
328 | } | - | ||||||||||||
329 | - | |||||||||||||
330 | bool QQmlDebugConnection::addClient(const QString &name, QQmlDebugClient *client) | - | ||||||||||||
331 | { | - | ||||||||||||
332 | Q_D(QQmlDebugConnection); | - | ||||||||||||
333 | if (d->plugins.contains(name))
| 4-3202 | ||||||||||||
334 | return false; executed 4 times by 2 tests: return false; Executed by:
| 4 | ||||||||||||
335 | d->removedPlugins.removeAll(name); | - | ||||||||||||
336 | d->plugins.insert(name, client); | - | ||||||||||||
337 | d->advertisePlugins(); | - | ||||||||||||
338 | return true; executed 3202 times by 11 tests: return true; Executed by:
| 3202 | ||||||||||||
339 | } | - | ||||||||||||
340 | - | |||||||||||||
341 | bool QQmlDebugConnection::removeClient(const QString &name) | - | ||||||||||||
342 | { | - | ||||||||||||
343 | Q_D(QQmlDebugConnection); | - | ||||||||||||
344 | if (!d->plugins.contains(name))
| 0-3198 | ||||||||||||
345 | return false; never executed: return false; | 0 | ||||||||||||
346 | d->plugins.remove(name); | - | ||||||||||||
347 | d->removedPlugins.append(name); | - | ||||||||||||
348 | d->advertisePlugins(); | - | ||||||||||||
349 | return true; executed 3198 times by 11 tests: return true; Executed by:
| 3198 | ||||||||||||
350 | } | - | ||||||||||||
351 | - | |||||||||||||
352 | float QQmlDebugConnection::serviceVersion(const QString &serviceName) const | - | ||||||||||||
353 | { | - | ||||||||||||
354 | Q_D(const QQmlDebugConnection); | - | ||||||||||||
355 | return d->serverPlugins.value(serviceName, -1); executed 18603 times by 11 tests: return d->serverPlugins.value(serviceName, -1); Executed by:
| 18603 | ||||||||||||
356 | } | - | ||||||||||||
357 | - | |||||||||||||
358 | bool QQmlDebugConnection::sendMessage(const QString &name, const QByteArray &message) | - | ||||||||||||
359 | { | - | ||||||||||||
360 | Q_D(QQmlDebugConnection); | - | ||||||||||||
361 | if (!isConnected() || !d->serverPlugins.contains(name))
| 0-1782 | ||||||||||||
362 | return false; never executed: return false; | 0 | ||||||||||||
363 | - | |||||||||||||
364 | QPacket pack(d->currentDataStreamVersion); | - | ||||||||||||
365 | pack << name << message; | - | ||||||||||||
366 | d->protocol->send(pack.data()); | - | ||||||||||||
367 | d->flush(); | - | ||||||||||||
368 | - | |||||||||||||
369 | return true; executed 1782 times by 9 tests: return true; Executed by:
| 1782 | ||||||||||||
370 | } | - | ||||||||||||
371 | - | |||||||||||||
372 | void QQmlDebugConnectionPrivate::flush() | - | ||||||||||||
373 | { | - | ||||||||||||
374 | if (QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(device))
| 18-5519 | ||||||||||||
375 | socket->flush(); executed 5519 times by 10 tests: socket->flush(); Executed by:
| 5519 | ||||||||||||
376 | else if (QLocalSocket *socket = qobject_cast<QLocalSocket *>(device))
| 0-18 | ||||||||||||
377 | socket->flush(); executed 18 times by 1 test: socket->flush(); Executed by:
| 18 | ||||||||||||
378 | } executed 5537 times by 11 tests: end of block Executed by:
| 5537 | ||||||||||||
379 | - | |||||||||||||
380 | void QQmlDebugConnection::connectToHost(const QString &hostName, quint16 port) | - | ||||||||||||
381 | { | - | ||||||||||||
382 | Q_D(QQmlDebugConnection); | - | ||||||||||||
383 | if (d->gotHello)
| 0-545 | ||||||||||||
384 | close(); never executed: close(); | 0 | ||||||||||||
385 | QTcpSocket *socket = new QTcpSocket(this); | - | ||||||||||||
386 | d->device = socket; | - | ||||||||||||
387 | d->createProtocol(); | - | ||||||||||||
388 | connect(socket, &QAbstractSocket::disconnected, this, &QQmlDebugConnection::socketDisconnected); | - | ||||||||||||
389 | connect(socket, &QAbstractSocket::connected, this, &QQmlDebugConnection::socketConnected); | - | ||||||||||||
390 | connect(socket, static_cast<void(QAbstractSocket::*)(QAbstractSocket::SocketError)>( | - | ||||||||||||
391 | &QAbstractSocket::error), this, &QQmlDebugConnection::socketError); | - | ||||||||||||
392 | connect(socket, &QAbstractSocket::stateChanged, this, &QQmlDebugConnection::socketStateChanged); | - | ||||||||||||
393 | socket->connectToHost(hostName, port); | - | ||||||||||||
394 | } executed 545 times by 10 tests: end of block Executed by:
| 545 | ||||||||||||
395 | - | |||||||||||||
396 | void QQmlDebugConnection::startLocalServer(const QString &fileName) | - | ||||||||||||
397 | { | - | ||||||||||||
398 | Q_D(QQmlDebugConnection); | - | ||||||||||||
399 | if (d->gotHello)
| 0-2 | ||||||||||||
400 | close(); never executed: close(); | 0 | ||||||||||||
401 | if (d->server)
| 0-2 | ||||||||||||
402 | d->server->deleteLater(); never executed: d->server->deleteLater(); | 0 | ||||||||||||
403 | d->server = new QLocalServer(this); | - | ||||||||||||
404 | // QueuedConnection so that waitForNewConnection() returns true. | - | ||||||||||||
405 | connect(d->server, &QLocalServer::newConnection, | - | ||||||||||||
406 | this, &QQmlDebugConnection::newConnection, Qt::QueuedConnection); | - | ||||||||||||
407 | d->server->listen(fileName); | - | ||||||||||||
408 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
409 | - | |||||||||||||
410 | class LocalSocketSignalTranslator : public QObject | - | ||||||||||||
411 | { | - | ||||||||||||
412 | Q_OBJECT | - | ||||||||||||
413 | public: | - | ||||||||||||
414 | LocalSocketSignalTranslator(QLocalSocket *parent) : QObject(parent) | - | ||||||||||||
415 | { | - | ||||||||||||
416 | connect(parent, &QLocalSocket::stateChanged, | - | ||||||||||||
417 | this, &LocalSocketSignalTranslator::onStateChanged); | - | ||||||||||||
418 | connect(parent, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>( | - | ||||||||||||
419 | &QLocalSocket::error), this, &LocalSocketSignalTranslator::onError); | - | ||||||||||||
420 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
421 | - | |||||||||||||
422 | void onError(QLocalSocket::LocalSocketError error) | - | ||||||||||||
423 | { | - | ||||||||||||
424 | emit socketError(static_cast<QAbstractSocket::SocketError>(error)); | - | ||||||||||||
425 | } never executed: end of block | 0 | ||||||||||||
426 | - | |||||||||||||
427 | void onStateChanged(QLocalSocket::LocalSocketState state) | - | ||||||||||||
428 | { | - | ||||||||||||
429 | emit socketStateChanged(static_cast<QAbstractSocket::SocketState>(state)); | - | ||||||||||||
430 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
431 | - | |||||||||||||
432 | signals: | - | ||||||||||||
433 | void socketError(QAbstractSocket::SocketError error); | - | ||||||||||||
434 | void socketStateChanged(QAbstractSocket::SocketState state); | - | ||||||||||||
435 | }; | - | ||||||||||||
436 | - | |||||||||||||
437 | void QQmlDebugConnection::newConnection() | - | ||||||||||||
438 | { | - | ||||||||||||
439 | Q_D(QQmlDebugConnection); | - | ||||||||||||
440 | delete d->device; | - | ||||||||||||
441 | QLocalSocket *socket = d->server->nextPendingConnection(); | - | ||||||||||||
442 | d->server->close(); | - | ||||||||||||
443 | d->device = socket; | - | ||||||||||||
444 | d->createProtocol(); | - | ||||||||||||
445 | connect(socket, &QLocalSocket::disconnected, this, &QQmlDebugConnection::socketDisconnected); | - | ||||||||||||
446 | LocalSocketSignalTranslator *translator = new LocalSocketSignalTranslator(socket); | - | ||||||||||||
447 | - | |||||||||||||
448 | connect(translator, &LocalSocketSignalTranslator::socketError, | - | ||||||||||||
449 | this, &QQmlDebugConnection::socketError); | - | ||||||||||||
450 | connect(translator, &LocalSocketSignalTranslator::socketStateChanged, | - | ||||||||||||
451 | this, &QQmlDebugConnection::socketStateChanged); | - | ||||||||||||
452 | socketConnected(); | - | ||||||||||||
453 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
454 | - | |||||||||||||
455 | void QQmlDebugConnectionPrivate::createProtocol() | - | ||||||||||||
456 | { | - | ||||||||||||
457 | Q_Q(QQmlDebugConnection); | - | ||||||||||||
458 | delete protocol; | - | ||||||||||||
459 | protocol = new QPacketProtocol(device, q); | - | ||||||||||||
460 | QObject::connect(protocol, &QPacketProtocol::readyRead, | - | ||||||||||||
461 | q, &QQmlDebugConnection::protocolReadyRead); | - | ||||||||||||
462 | } executed 547 times by 11 tests: end of block Executed by:
| 547 | ||||||||||||
463 | - | |||||||||||||
464 | QT_END_NAMESPACE | - | ||||||||||||
465 | - | |||||||||||||
466 | #include <qqmldebugconnection.moc> | - | ||||||||||||
467 | - | |||||||||||||
468 | #include "moc_qqmldebugconnection_p.cpp" | - | ||||||||||||
Source code | Switch to Preprocessed file |