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#include "qqmldebugclient_p_p.h"
5#include "qqmldebugconnection_p.h"
6
7#include <QtCore/qdebug.h>
8#include <QtCore/qpointer.h>
9
10QT_BEGIN_NAMESPACE
11
12QQmlDebugClient::QQmlDebugClient(const QString &name, QQmlDebugConnection *parent) :
13 QObject(*(new QQmlDebugClientPrivate(name, parent)), parent)
14{
15 Q_D(QQmlDebugClient);
16 d->addToConnection();
17}
18
19QQmlDebugClient::QQmlDebugClient(QQmlDebugClientPrivate &dd) :
20 QObject(dd, dd.connection.data())
21{
22 Q_D(QQmlDebugClient);
23 d->addToConnection();
24}
25
26QQmlDebugClient::~QQmlDebugClient()
27{
28 Q_D(QQmlDebugClient);
29 if (d->connection && !d->connection->removeClient(name: d->name))
30 qWarning() << "QQmlDebugClient: Plugin not registered" << d->name;
31}
32
33QQmlDebugClientPrivate::QQmlDebugClientPrivate(const QString &name,
34 QQmlDebugConnection *connection) :
35 name(name), connection(connection)
36{
37}
38
39void QQmlDebugClientPrivate::addToConnection()
40{
41 Q_Q(QQmlDebugClient);
42 if (connection && !connection->addClient(name, client: q)) {
43 qWarning() << "QQmlDebugClient: Conflicting plugin name" << name;
44 connection = nullptr;
45 }
46}
47
48QString QQmlDebugClient::name() const
49{
50 Q_D(const QQmlDebugClient);
51 return d->name;
52}
53
54float QQmlDebugClient::serviceVersion() const
55{
56 Q_D(const QQmlDebugClient);
57 return d->connection->serviceVersion(serviceName: d->name);
58}
59
60QQmlDebugClient::State QQmlDebugClient::state() const
61{
62 Q_D(const QQmlDebugClient);
63 if (!d->connection || !d->connection->isConnected())
64 return NotConnected;
65
66 if (d->connection->serviceVersion(serviceName: d->name) != -1)
67 return Enabled;
68
69 return Unavailable;
70}
71
72void QQmlDebugClient::sendMessage(const QByteArray &message)
73{
74 Q_D(QQmlDebugClient);
75 d->connection->sendMessage(name: d->name, message);
76}
77
78QQmlDebugConnection *QQmlDebugClient::connection() const
79{
80 Q_D(const QQmlDebugClient);
81 return d->connection;
82}
83
84void QQmlDebugClient::messageReceived(const QByteArray &message)
85{
86 Q_UNUSED(message);
87}
88
89QT_END_NAMESPACE
90
91#include "moc_qqmldebugclient_p.cpp"
92

source code of qtdeclarative/src/qmldebug/qqmldebugclient.cpp