Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlenginecontrolclient.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
8
9#include <private/qpacket_p.h>
10
12
13QQmlEngineControlClient::QQmlEngineControlClient(QQmlDebugConnection *connection) :
14 QQmlDebugClient(*(new QQmlEngineControlClientPrivate(connection)))
15{
16}
17
22
23/*!
24 * Block the starting or stopping of the engine with id \a engineId for now. By calling
25 * releaseEngine later the block can be lifted again. In the debugged application the engine control
26 * server waits until a message is received before continuing. So by not sending a message here we
27 * delay the process. Blocks add up. You have to call releaseEngine() as often as you've called
28 * blockEngine before. The intention of that is to allow different debug clients to use the same
29 * engine control and communicate with their respective counterparts before the QML engine starts or
30 * shuts down.
31 */
33{
34 Q_D(QQmlEngineControlClient);
35 Q_ASSERT(d->blockedEngines.contains(engineId));
36 d->blockedEngines[engineId].blockers++;
37}
38
39/*!
40 * Release the engine with id \a engineId. If no other blocks are present, depending on what the
41 * engine is waiting for, the start or stop command is sent to the process being debugged.
42 */
44{
45 Q_D(QQmlEngineControlClient);
46 Q_ASSERT(d->blockedEngines.contains(engineId));
47
48 QQmlEngineControlClientPrivate::EngineState &state = d->blockedEngines[engineId];
49 if (--state.blockers == 0) {
51 d->sendCommand(state.releaseCommand, engineId);
52 d->blockedEngines.remove(engineId);
53 }
54}
55
57{
58 Q_D(const QQmlEngineControlClient);
59 return d->blockedEngines.keys();
60}
61
62void QQmlEngineControlClient::messageReceived(const QByteArray &data)
63{
64 Q_D(QQmlEngineControlClient);
65 QPacket stream(d->connection->currentDataStreamVersion(), data);
66 qint32 message;
67 qint32 id;
68 QString name;
69
70 stream >> message >> id;
71
72 if (!stream.atEnd())
73 stream >> name;
74
75 auto handleWaiting = [&](
76 QQmlEngineControlClientPrivate::CommandType command, std::function<void()> emitter) {
77 QQmlEngineControlClientPrivate::EngineState &state = d->blockedEngines[id];
78 Q_ASSERT(state.blockers == 0);
80 state.releaseCommand = command;
81 emitter();
82 if (state.blockers == 0) {
83 d->sendCommand(state.releaseCommand, id);
84 d->blockedEngines.remove(id);
85 }
86 };
87
88 switch (message) {
89 case QQmlEngineControlClientPrivate::EngineAboutToBeAdded:
91 emit engineAboutToBeAdded(id, name);
92 });
93 break;
94 case QQmlEngineControlClientPrivate::EngineAdded:
95 emit engineAdded(id, name);
96 break;
97 case QQmlEngineControlClientPrivate::EngineAboutToBeRemoved:
99 emit engineAboutToBeRemoved(id, name);
100 });
101 break;
102 case QQmlEngineControlClientPrivate::EngineRemoved:
103 emit engineRemoved(id, name);
104 break;
105 }
106}
107
109 QQmlDebugClientPrivate(QLatin1String("EngineControl"), connection)
110{
111}
112
114 QQmlEngineControlClientPrivate::CommandType command, int engineId)
115{
116 Q_Q(QQmlEngineControlClient);
117 QPacket stream(connection->currentDataStreamVersion());
118 stream << static_cast<qint32>(command) << engineId;
119 q->sendMessage(stream.data());
120}
121
122QT_END_NAMESPACE
123
124#include "moc_qqmlenginecontrolclient_p.cpp"
void sendCommand(CommandType command, int engineId)
QQmlEngineControlClientPrivate(QQmlDebugConnection *connection)
QQmlEngineControlClient(QQmlEngineControlClientPrivate &dd)
QList< int > blockedEngines() const
void blockEngine(int engineId)
Block the starting or stopping of the engine with id engineId for now.
void messageReceived(const QByteArray &) override
void releaseEngine(int engineId)
Release the engine with id engineId.
Combined button and popup list for selecting options.