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