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
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
5
#
include
"qqmlenginecontrolclient_p.h"
6
#
include
"qqmlenginecontrolclient_p_p.h"
7
#
include
"qqmldebugconnection_p.h"
8
9
#
include
<
private
/
qpacket_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
QQmlEngineControlClient
::
QQmlEngineControlClient
(QQmlDebugConnection *connection) :
14
QQmlDebugClient(*(
new
QQmlEngineControlClientPrivate(connection)))
15
{
16
}
17
18
QQmlEngineControlClient
::
QQmlEngineControlClient
(
QQmlEngineControlClientPrivate
&dd) :
19
QQmlDebugClient
(dd)
20
{
21
}
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
*/
32
void
QQmlEngineControlClient
::
blockEngine
(
int
engineId)
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
*/
43
void
QQmlEngineControlClient
::
releaseEngine
(
int
engineId)
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) {
50
Q_ASSERT(state
.
releaseCommand
!=
QQmlEngineControlClientPrivate
::
InvalidCommand
);
51
d->sendCommand(state.releaseCommand, engineId);
52
d->blockedEngines.remove(engineId);
53
}
54
}
55
56
QList
<
int
>
QQmlEngineControlClient
::
blockedEngines
()
const
57
{
58
Q_D(
const
QQmlEngineControlClient);
59
return
d->blockedEngines.keys();
60
}
61
62
void
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);
79
Q_ASSERT(state
.
releaseCommand
==
QQmlEngineControlClientPrivate
::
InvalidCommand
);
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:
90
handleWaiting(
QQmlEngineControlClientPrivate
::
StartWaitingEngine
, [&](){
91
emit engineAboutToBeAdded(id, name);
92
});
93
break
;
94
case
QQmlEngineControlClientPrivate::EngineAdded:
95
emit engineAdded(id, name);
96
break
;
97
case
QQmlEngineControlClientPrivate::EngineAboutToBeRemoved:
98
handleWaiting(
QQmlEngineControlClientPrivate
::
StopWaitingEngine
, [&](){
99
emit engineAboutToBeRemoved(id, name);
100
});
101
break
;
102
case
QQmlEngineControlClientPrivate::EngineRemoved:
103
emit engineRemoved(id, name);
104
break
;
105
}
106
}
107
108
QQmlEngineControlClientPrivate
::
QQmlEngineControlClientPrivate
(
QQmlDebugConnection
*connection) :
109
QQmlDebugClientPrivate
(QLatin1String(
"EngineControl"
), connection)
110
{
111
}
112
113
void
QQmlEngineControlClientPrivate
::
sendCommand
(
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
122
QT_END_NAMESPACE
123
124
#
include
"moc_qqmlenginecontrolclient_p.cpp"
QQmlDebugClientPrivate
Definition
qqmldebugclient_p_p.h:27
QQmlDebugClient
Definition
qqmldebugclient_p.h:27
QQmlDebugConnection
Definition
qqmldebugconnection_p.h:28
QQmlEngineControlClientPrivate
Definition
qqmlenginecontrolclient_p_p.h:27
QQmlEngineControlClientPrivate::sendCommand
void sendCommand(CommandType command, int engineId)
Definition
qqmlenginecontrolclient.cpp:113
QQmlEngineControlClientPrivate::QQmlEngineControlClientPrivate
QQmlEngineControlClientPrivate(QQmlDebugConnection *connection)
Definition
qqmlenginecontrolclient.cpp:108
QQmlEngineControlClientPrivate::CommandType
CommandType
Definition
qqmlenginecontrolclient_p_p.h:37
QQmlEngineControlClientPrivate::StartWaitingEngine
@ StartWaitingEngine
Definition
qqmlenginecontrolclient_p_p.h:38
QQmlEngineControlClientPrivate::InvalidCommand
@ InvalidCommand
Definition
qqmlenginecontrolclient_p_p.h:40
QQmlEngineControlClientPrivate::StopWaitingEngine
@ StopWaitingEngine
Definition
qqmlenginecontrolclient_p_p.h:39
QQmlEngineControlClient
Definition
qqmlenginecontrolclient_p.h:25
QQmlEngineControlClient::QQmlEngineControlClient
QQmlEngineControlClient(QQmlEngineControlClientPrivate &dd)
Definition
qqmlenginecontrolclient.cpp:18
QQmlEngineControlClient::blockedEngines
QList< int > blockedEngines() const
Definition
qqmlenginecontrolclient.cpp:56
QQmlEngineControlClient::blockEngine
void blockEngine(int engineId)
Block the starting or stopping of the engine with id engineId for now.
Definition
qqmlenginecontrolclient.cpp:32
QQmlEngineControlClient::messageReceived
void messageReceived(const QByteArray &) override
Definition
qqmlenginecontrolclient.cpp:62
QQmlEngineControlClient::releaseEngine
void releaseEngine(int engineId)
Release the engine with id engineId.
Definition
qqmlenginecontrolclient.cpp:43
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QQmlEngineControlClientPrivate::EngineState
Definition
qqmlenginecontrolclient_p_p.h:47
QQmlEngineControlClientPrivate::EngineState::blockers
int blockers
Definition
qqmlenginecontrolclient_p_p.h:50
QQmlEngineControlClientPrivate::EngineState::releaseCommand
CommandType releaseCommand
Definition
qqmlenginecontrolclient_p_p.h:49
qtdeclarative
src
qmldebug
qqmlenginecontrolclient.cpp
Generated on
for Qt by
1.18.0