Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmldebug/qqmlenginecontrolclient.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 "qqmlenginecontrolclient_p.h" | - | ||||||
41 | #include "qqmlenginecontrolclient_p_p.h" | - | ||||||
42 | #include "qqmldebugconnection_p.h" | - | ||||||
43 | - | |||||||
44 | #include <private/qpacket_p.h> | - | ||||||
45 | - | |||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||
47 | - | |||||||
48 | QQmlEngineControlClient::QQmlEngineControlClient(QQmlDebugConnection *connection) : | - | ||||||
49 | QQmlDebugClient(*(new QQmlEngineControlClientPrivate(connection))) | - | ||||||
50 | { | - | ||||||
51 | } executed 44 times by 2 tests: end of block Executed by:
| 44 | ||||||
52 | - | |||||||
53 | QQmlEngineControlClient::QQmlEngineControlClient(QQmlEngineControlClientPrivate &dd) : | - | ||||||
54 | QQmlDebugClient(dd) | - | ||||||
55 | { | - | ||||||
56 | } never executed: end of block | 0 | ||||||
57 | - | |||||||
58 | /*! | - | ||||||
59 | * Block the starting or stopping of the engine with id \a engineId for now. By calling | - | ||||||
60 | * releaseEngine later the block can be lifted again. In the debugged application the engine control | - | ||||||
61 | * server waits until a message is received before continuing. So by not sending a message here we | - | ||||||
62 | * delay the process. Blocks add up. You have to call releaseEngine() as often as you've called | - | ||||||
63 | * blockEngine before. The intention of that is to allow different debug clients to use the same | - | ||||||
64 | * engine control and communicate with their respective counterparts before the QML engine starts or | - | ||||||
65 | * shuts down. | - | ||||||
66 | */ | - | ||||||
67 | void QQmlEngineControlClient::blockEngine(int engineId) | - | ||||||
68 | { | - | ||||||
69 | Q_D(QQmlEngineControlClient); | - | ||||||
70 | Q_ASSERT(d->blockedEngines.contains(engineId)); | - | ||||||
71 | d->blockedEngines[engineId].blockers++; | - | ||||||
72 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||
73 | - | |||||||
74 | /*! | - | ||||||
75 | * Release the engine with id \a engineId. If no other blocks are present, depending on what the | - | ||||||
76 | * engine is waiting for, the start or stop command is sent to the process being debugged. | - | ||||||
77 | */ | - | ||||||
78 | void QQmlEngineControlClient::releaseEngine(int engineId) | - | ||||||
79 | { | - | ||||||
80 | Q_D(QQmlEngineControlClient); | - | ||||||
81 | Q_ASSERT(d->blockedEngines.contains(engineId)); | - | ||||||
82 | - | |||||||
83 | QQmlEngineControlClientPrivate::EngineState &state = d->blockedEngines[engineId]; | - | ||||||
84 | if (--state.blockers == 0) {
| 0-16 | ||||||
85 | Q_ASSERT(state.releaseCommand != QQmlEngineControlClientPrivate::InvalidCommand); | - | ||||||
86 | d->sendCommand(state.releaseCommand, engineId); | - | ||||||
87 | d->blockedEngines.remove(engineId); | - | ||||||
88 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||
89 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||
90 | - | |||||||
91 | QList<int> QQmlEngineControlClient::blockedEngines() const | - | ||||||
92 | { | - | ||||||
93 | Q_D(const QQmlEngineControlClient); | - | ||||||
94 | return d->blockedEngines.keys(); executed 108 times by 2 tests: return d->blockedEngines.keys(); Executed by:
| 108 | ||||||
95 | } | - | ||||||
96 | - | |||||||
97 | void QQmlEngineControlClient::messageReceived(const QByteArray &data) | - | ||||||
98 | { | - | ||||||
99 | Q_D(QQmlEngineControlClient); | - | ||||||
100 | QPacket stream(d->connection->currentDataStreamVersion(), data); | - | ||||||
101 | qint32 message; | - | ||||||
102 | qint32 id; | - | ||||||
103 | QString name; | - | ||||||
104 | - | |||||||
105 | stream >> message >> id; | - | ||||||
106 | - | |||||||
107 | if (!stream.atEnd())
| 0-92 | ||||||
108 | stream >> name; never executed: stream >> name; | 0 | ||||||
109 | - | |||||||
110 | auto handleWaiting = [&]( | - | ||||||
111 | QQmlEngineControlClientPrivate::CommandType command, std::function<void()> emitter) { | - | ||||||
112 | QQmlEngineControlClientPrivate::EngineState &state = d->blockedEngines[id]; | - | ||||||
113 | Q_ASSERT(state.blockers == 0); | - | ||||||
114 | Q_ASSERT(state.releaseCommand == QQmlEngineControlClientPrivate::InvalidCommand); | - | ||||||
115 | state.releaseCommand = command; | - | ||||||
116 | emitter(); | - | ||||||
117 | if (state.blockers == 0) {
| 16-30 | ||||||
118 | d->sendCommand(state.releaseCommand, id); | - | ||||||
119 | d->blockedEngines.remove(id); | - | ||||||
120 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||
121 | }; executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||
122 | - | |||||||
123 | switch (message) { | - | ||||||
124 | case QQmlEngineControlClientPrivate::EngineAboutToBeAdded: executed 36 times by 2 tests: case QQmlEngineControlClientPrivate::EngineAboutToBeAdded: Executed by:
| 36 | ||||||
125 | handleWaiting(QQmlEngineControlClientPrivate::StartWaitingEngine, [&](){ | - | ||||||
126 | emit engineAboutToBeAdded(id, name); | - | ||||||
127 | }); executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||
128 | break; executed 36 times by 2 tests: break; Executed by:
| 36 | ||||||
129 | case QQmlEngineControlClientPrivate::EngineAdded: executed 36 times by 2 tests: case QQmlEngineControlClientPrivate::EngineAdded: Executed by:
| 36 | ||||||
130 | emit engineAdded(id, name); | - | ||||||
131 | break; executed 36 times by 2 tests: break; Executed by:
| 36 | ||||||
132 | case QQmlEngineControlClientPrivate::EngineAboutToBeRemoved: executed 10 times by 2 tests: case QQmlEngineControlClientPrivate::EngineAboutToBeRemoved: Executed by:
| 10 | ||||||
133 | handleWaiting(QQmlEngineControlClientPrivate::StopWaitingEngine, [&](){ | - | ||||||
134 | emit engineAboutToBeRemoved(id, name); | - | ||||||
135 | }); executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||
136 | break; executed 10 times by 2 tests: break; Executed by:
| 10 | ||||||
137 | case QQmlEngineControlClientPrivate::EngineRemoved: executed 10 times by 2 tests: case QQmlEngineControlClientPrivate::EngineRemoved: Executed by:
| 10 | ||||||
138 | emit engineRemoved(id, name); | - | ||||||
139 | break; executed 10 times by 2 tests: break; Executed by:
| 10 | ||||||
140 | } | - | ||||||
141 | } executed 92 times by 2 tests: end of block Executed by:
| 92 | ||||||
142 | - | |||||||
143 | QQmlEngineControlClientPrivate::QQmlEngineControlClientPrivate(QQmlDebugConnection *connection) : | - | ||||||
144 | QQmlDebugClientPrivate(QLatin1String("EngineControl"), connection) | - | ||||||
145 | { | - | ||||||
146 | } executed 44 times by 2 tests: end of block Executed by:
| 44 | ||||||
147 | - | |||||||
148 | void QQmlEngineControlClientPrivate::sendCommand( | - | ||||||
149 | QQmlEngineControlClientPrivate::CommandType command, int engineId) | - | ||||||
150 | { | - | ||||||
151 | Q_Q(QQmlEngineControlClient); | - | ||||||
152 | QPacket stream(connection->currentDataStreamVersion()); | - | ||||||
153 | stream << static_cast<qint32>(command) << engineId; | - | ||||||
154 | q->sendMessage(stream.data()); | - | ||||||
155 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||
156 | - | |||||||
157 | QT_END_NAMESPACE | - | ||||||
158 | - | |||||||
159 | #include "moc_qqmlenginecontrolclient_p.cpp" | - | ||||||
Source code | Switch to Preprocessed file |