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
4
5#ifndef QQMLCONFIGURABLEDEBUGSEVICE_P_H
6#define QQMLCONFIGURABLEDEBUGSEVICE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qqmldebugservice_p.h"
20#include "qqmldebugconnector_p.h"
21
22#include <QtCore/qmutex.h>
23
24QT_BEGIN_NAMESPACE
25
26template <class Base>
27class QQmlConfigurableDebugService : public Base
28{
29protected:
30 QQmlConfigurableDebugService(float version, QObject *parent = nullptr) :
31 Base(version, parent)
32 {
33 init();
34 }
35
36 void stopWaiting()
37 {
38 QMutexLocker lock(&m_configMutex);
39 m_waitingForConfiguration = false;
40 for (QJSEngine *engine : std::as_const(t&: m_waitingEngines))
41 Q_EMIT Base::attachedToEngine(engine);
42 m_waitingEngines.clear();
43 }
44
45 void init()
46 {
47 QMutexLocker lock(&m_configMutex);
48 // If we're not enabled or not blocking, don't wait for configuration
49 m_waitingForConfiguration = (Base::state() == QQmlDebugService::Enabled &&
50 QQmlDebugConnector::instance()->blockingMode());
51 }
52
53 void stateChanged(QQmlDebugService::State newState) override
54 {
55 if (newState != QQmlDebugService::Enabled)
56 stopWaiting();
57 else
58 init();
59 }
60
61 void engineAboutToBeAdded(QJSEngine *engine) override
62 {
63 QMutexLocker lock(&m_configMutex);
64 if (m_waitingForConfiguration)
65 m_waitingEngines.append(t: engine);
66 else
67 Q_EMIT Base::attachedToEngine(engine);
68 }
69
70 QRecursiveMutex m_configMutex;
71 QList<QJSEngine *> m_waitingEngines;
72 bool m_waitingForConfiguration;
73};
74
75QT_END_NAMESPACE
76
77#endif // QQMLCONFIGURABLEDEBUGSEVICE_P_H
78

source code of qtdeclarative/src/qml/debugger/qqmlconfigurabledebugservice_p.h