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#ifndef QBLUETOOTHSERVICEINFO_H
5#define QBLUETOOTHSERVICEINFO_H
6
7#include <QtBluetooth/qtbluetoothglobal.h>
8
9#include <QtBluetooth/QBluetoothUuid>
10#include <QtBluetooth/QBluetoothAddress>
11
12#include <QtCore/QMetaType>
13#include <QtCore/QList>
14#include <QtCore/QSharedPointer>
15#include <QtCore/QVariant>
16
17#include <QtCore/QDebug>
18
19QT_BEGIN_NAMESPACE
20
21class QBluetoothServiceInfoPrivate;
22class QBluetoothDeviceInfo;
23
24class Q_BLUETOOTH_EXPORT QBluetoothServiceInfo
25{
26public:
27 enum AttributeId {
28 ServiceRecordHandle = 0x0000,
29 ServiceClassIds = 0x0001,
30 ServiceRecordState = 0x0002,
31 ServiceId = 0x0003,
32 ProtocolDescriptorList = 0x0004,
33 BrowseGroupList = 0x0005,
34 LanguageBaseAttributeIdList = 0x0006,
35 ServiceInfoTimeToLive = 0x0007,
36 ServiceAvailability = 0x0008,
37 BluetoothProfileDescriptorList = 0x0009,
38 DocumentationUrl = 0x000A,
39 ClientExecutableUrl = 0x000B,
40 IconUrl = 0x000C,
41 AdditionalProtocolDescriptorList = 0x000D,
42 PrimaryLanguageBase = 0x0100,
43 ServiceName = PrimaryLanguageBase + 0x0000,
44 ServiceDescription = PrimaryLanguageBase + 0x0001,
45 ServiceProvider = PrimaryLanguageBase + 0x0002
46 };
47
48 enum Protocol {
49 UnknownProtocol,
50 L2capProtocol,
51 RfcommProtocol
52 };
53
54 class Sequence : public QList<QVariant>
55 {
56 public:
57 Sequence() { }
58 Sequence(const QList<QVariant> &list) : QList<QVariant>(list) { }
59 };
60
61 class Alternative : public QList<QVariant>
62 {
63 public:
64 Alternative() { }
65 Alternative(const QList<QVariant> &list) : QList<QVariant>(list) { }
66 };
67
68 QBluetoothServiceInfo();
69 QBluetoothServiceInfo(const QBluetoothServiceInfo &other);
70 ~QBluetoothServiceInfo();
71
72 bool isValid() const;
73 bool isComplete() const;
74
75 void setDevice(const QBluetoothDeviceInfo &info);
76 QBluetoothDeviceInfo device() const;
77
78 void setAttribute(quint16 attributeId, const QVariant &value);
79 void setAttribute(quint16 attributeId, const QBluetoothUuid &value);
80 void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value);
81 void setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value);
82 QVariant attribute(quint16 attributeId) const;
83 QList<quint16> attributes() const;
84 bool contains(quint16 attributeId) const;
85 void removeAttribute(quint16 attributeId);
86
87 inline void setServiceName(const QString &name);
88 inline QString serviceName() const;
89 inline void setServiceDescription(const QString &description);
90 inline QString serviceDescription() const;
91 inline void setServiceProvider(const QString &provider);
92 inline QString serviceProvider() const;
93
94 QBluetoothServiceInfo::Protocol socketProtocol() const;
95 int protocolServiceMultiplexer() const;
96 int serverChannel() const;
97
98 QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const;
99
100 inline void setServiceAvailability(quint8 availability);
101 inline quint8 serviceAvailability() const;
102
103 inline void setServiceUuid(const QBluetoothUuid &uuid);
104 inline QBluetoothUuid serviceUuid() const;
105
106 QList<QBluetoothUuid> serviceClassUuids() const;
107
108 QBluetoothServiceInfo &operator=(const QBluetoothServiceInfo &other);
109
110 bool isRegistered() const;
111 bool registerService(const QBluetoothAddress &localAdapter = QBluetoothAddress());
112 bool unregisterService();
113
114private:
115#ifndef QT_NO_DEBUG_STREAM
116 friend QDebug operator<<(QDebug d, const QBluetoothServiceInfo &i)
117 {
118 return streamingOperator(d, i);
119 }
120 static QDebug streamingOperator(QDebug, const QBluetoothServiceInfo &);
121#endif
122protected:
123 QSharedPointer<QBluetoothServiceInfoPrivate> d_ptr;
124};
125
126QT_END_NAMESPACE
127
128QT_DECL_METATYPE_EXTERN(QBluetoothServiceInfo, Q_BLUETOOTH_EXPORT)
129QT_DECL_METATYPE_EXTERN_TAGGED(QBluetoothServiceInfo::Sequence, QBluetoothServiceInfo__Sequence,
130 Q_BLUETOOTH_EXPORT)
131QT_DECL_METATYPE_EXTERN_TAGGED(QBluetoothServiceInfo::Alternative,
132 QBluetoothServiceInfo__Alternative,
133 Q_BLUETOOTH_EXPORT)
134
135QT_BEGIN_NAMESPACE
136
137inline void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothUuid &value)
138{
139 setAttribute(attributeId, value: QVariant::fromValue(value));
140}
141
142inline void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Sequence &value)
143{
144 setAttribute(attributeId, value: QVariant::fromValue(value));
145}
146
147inline void QBluetoothServiceInfo::setAttribute(quint16 attributeId, const QBluetoothServiceInfo::Alternative &value)
148{
149 setAttribute(attributeId, value: QVariant::fromValue(value));
150}
151
152inline void QBluetoothServiceInfo::setServiceName(const QString &name)
153{
154 setAttribute(attributeId: ServiceName, value: QVariant::fromValue(value: name));
155}
156
157inline QString QBluetoothServiceInfo::serviceName() const
158{
159 return attribute(attributeId: ServiceName).toString();
160}
161
162inline void QBluetoothServiceInfo::setServiceDescription(const QString &description)
163{
164 setAttribute(attributeId: ServiceDescription, value: QVariant::fromValue(value: description));
165}
166
167inline QString QBluetoothServiceInfo::serviceDescription() const
168{
169 return attribute(attributeId: ServiceDescription).toString();
170}
171
172inline void QBluetoothServiceInfo::setServiceProvider(const QString &provider)
173{
174 setAttribute(attributeId: ServiceProvider, value: QVariant::fromValue(value: provider));
175}
176
177inline QString QBluetoothServiceInfo::serviceProvider() const
178{
179 return attribute(attributeId: ServiceProvider).toString();
180}
181
182inline void QBluetoothServiceInfo::setServiceAvailability(quint8 availability)
183{
184 setAttribute(attributeId: ServiceAvailability, value: QVariant::fromValue(value: availability));
185}
186
187inline quint8 QBluetoothServiceInfo::serviceAvailability() const
188{
189 return attribute(attributeId: ServiceAvailability).toUInt();
190}
191
192inline void QBluetoothServiceInfo::setServiceUuid(const QBluetoothUuid &uuid)
193{
194 setAttribute(attributeId: ServiceId, value: uuid);
195}
196
197inline QBluetoothUuid QBluetoothServiceInfo::serviceUuid() const
198{
199 return attribute(attributeId: ServiceId).value<QBluetoothUuid>();
200}
201QT_END_NAMESPACE
202
203#endif
204

source code of qtconnectivity/src/bluetooth/qbluetoothserviceinfo.h