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
qbluetoothservicediscoveryagent_p.h
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
4#ifndef QBLUETOOTHSERVICEDISCOVERYAGENT_P_H
5#define QBLUETOOTHSERVICEDISCOVERYAGENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
22
23#include <QStack>
24#include <QStringList>
25
26#if QT_CONFIG(bluez)
27
28namespace QtBluetoothPrivate {
29
30class OrgBluezManagerInterface;
31class OrgBluezAdapterInterface;
32class OrgBluezDeviceInterface;
33class OrgFreedesktopDBusObjectManagerInterface;
34
35} // namespace QtBluetoothPrivate
36
37#include <QtCore/qprocess.h>
38
39QT_BEGIN_NAMESPACE
40class QDBusPendingCallWatcher;
41class QXmlStreamReader;
42QT_END_NAMESPACE
43#endif
44
45#ifdef QT_WINRT_BLUETOOTH
46#include <QtCore/QPointer>
47#endif
48
49#ifdef QT_OSX_BLUETOOTH
50#include "darwin/btdelegates_p.h"
51#include "darwin/btraii_p.h"
52#endif
53
54#ifdef QT_ANDROID_BLUETOOTH
55#include <QtCore/QJniObject>
56#include <QtBluetooth/QBluetoothLocalDevice>
57#endif
58
59// intentionally outside of Qt namespace
60class tst_QBluetoothServiceDiscoveryAgent;
61
62QT_BEGIN_NAMESPACE
63
64class QBluetoothDeviceDiscoveryAgent;
65#ifdef QT_ANDROID_BLUETOOTH
66class ServiceDiscoveryBroadcastReceiver;
67class LocalDeviceBroadcastReceiver;
68#endif
69
70#ifdef QT_WINRT_BLUETOOTH
71class QWinRTBluetoothServiceDiscoveryWorker;
72#endif
73
75#if defined(QT_WINRT_BLUETOOTH)
76 : public QObject
77{
78 Q_OBJECT
79#elif defined(QT_OSX_BLUETOOTH)
80 : public QObject, public DarwinBluetooth::SDPInquiryDelegate
81{
82#else
83{
84#endif
85 Q_DECLARE_PUBLIC(QBluetoothServiceDiscoveryAgent)
86 friend class ::tst_QBluetoothServiceDiscoveryAgent;
87
88public:
89 // Best-guess value. Should be enough for all real usecases.
90 static constexpr int kMaxSdpRecursionDepth = 64;
91
97
98 QBluetoothServiceDiscoveryAgentPrivate(QBluetoothServiceDiscoveryAgent *qp,
101
103 void stopDeviceDiscovery();
106
107 void setDiscoveryState(DiscoveryState s) { state = s; }
108 inline DiscoveryState discoveryState() { return state; }
109
110 void setDiscoveryMode(QBluetoothServiceDiscoveryAgent::DiscoveryMode m) { mode = m; }
112
114 void _q_deviceDiscovered(const QBluetoothDeviceInfo &info);
117#if QT_CONFIG(bluez)
118 void _q_sdpScannerDone(int exitCode, QProcess::ExitStatus status);
119 void _q_finishSdpScan(QBluetoothServiceDiscoveryAgent::Error errorCode,
120 const QString &errorDescription,
121 const QStringList &xmlRecords);
122#endif
123#ifdef QT_ANDROID_BLUETOOTH
124 void _q_processFetchedUuids(const QBluetoothAddress &address, const QList<QBluetoothUuid> &uuids);
125
126 void populateDiscoveredServices(const QBluetoothDeviceInfo &remoteDevice,
127 const QList<QBluetoothUuid> &uuids);
128 void _q_fetchUuidsTimeout();
129 void _q_hostModeStateChanged(QBluetoothLocalDevice::HostMode state);
130#endif
131
132private:
133 void start(const QBluetoothAddress &address);
134 void stop();
135 bool isDuplicatedService(const QBluetoothServiceInfo &serviceInfo) const;
136
137#if QT_CONFIG(bluez)
138 void startBluez5(const QBluetoothAddress &address);
139 void runExternalSdpScan(const QBluetoothAddress &remoteAddress,
140 const QBluetoothAddress &localAddress);
141 void sdpScannerDone(int exitCode, QProcess::ExitStatus exitStatus);
142 QVariant readAttributeValue(QXmlStreamReader &xml, int depth = 0);
143 QBluetoothServiceInfo parseServiceXml(const QString& xml);
144 void performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress);
145#endif
146
147public:
148 QBluetoothServiceDiscoveryAgent::Error error;
150 QBluetoothAddress deviceAddress;
153 QBluetoothAddress m_deviceAdapterAddress;
154
155private:
156 DiscoveryState state;
157 QList<QBluetoothUuid> uuidFilter;
158
159 QBluetoothDeviceDiscoveryAgent *deviceDiscoveryAgent = nullptr;
160
161 QBluetoothServiceDiscoveryAgent::DiscoveryMode mode;
162
163 bool singleDevice;
164#if QT_CONFIG(bluez)
165 QString foundHostAdapterPath;
166 QtBluetoothPrivate::OrgFreedesktopDBusObjectManagerInterface *manager = nullptr;
167 QProcess *sdpScannerProcess = nullptr;
168#endif
169
170#ifdef QT_ANDROID_BLUETOOTH
171 ServiceDiscoveryBroadcastReceiver *receiver = nullptr;
172 LocalDeviceBroadcastReceiver *localDeviceReceiver = nullptr;
173
174 QJniObject btAdapter;
175 // The sdpCache caches service discovery results while it is running, and is
176 // cleared once finished. The cache is used as we may (or may not) get more accurate
177 // results after the first result. This temporary caching allows to send the
178 // serviceDiscovered() signal once per service and with the most accurate information.
179 // Partial cache clearing may occur already during the scan if the second (more accurate)
180 // scan result is received.
181 QMap<QBluetoothAddress,QPair<QBluetoothDeviceInfo,QList<QBluetoothUuid> > > sdpCache;
182#endif
183
184#ifdef QT_WINRT_BLUETOOTH
185private slots:
186 void processFoundService(quint64 deviceAddress, const QBluetoothServiceInfo &info);
187 void onScanFinished(quint64 deviceAddress);
188 void onError();
189
190private:
191 void releaseWorker();
192 QPointer<QWinRTBluetoothServiceDiscoveryWorker> worker;
193#endif
194
195#ifdef QT_OSX_BLUETOOTH
196 // SDPInquiryDelegate:
197 void SDPInquiryFinished(void *device) override;
198 void SDPInquiryError(void *device, IOReturn errorCode) override;
199
200 void performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress);
201 //void serviceDiscoveryFinished();
202
203 bool serviceHasMatchingUuid(const QBluetoothServiceInfo &serviceInfo) const;
204
205 DarwinBluetooth::ScopedPointer serviceInquiry;
206#endif // QT_OSX_BLUETOOTH
207
208protected:
209 QBluetoothServiceDiscoveryAgent *q_ptr;
210};
211
212QT_END_NAMESPACE
213
214#endif
void _q_deviceDiscovered(const QBluetoothDeviceInfo &info)
void setDiscoveryMode(QBluetoothServiceDiscoveryAgent::DiscoveryMode m)
void _q_deviceDiscoveryFinished()
Called when device discovery finishes.
void startServiceDiscovery()
Starts service discovery for the next device.
QBluetoothServiceDiscoveryAgent::DiscoveryMode DiscoveryMode()
void _q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)
void qt_test_iobluetooth_runloop()
Definition btutility.mm:125