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_H
5#define QBLUETOOTHSERVICEDISCOVERYAGENT_H
6
7#include <QtBluetooth/qtbluetoothglobal.h>
8
9#include <QtCore/QObject>
10#include <QtCore/QVariant>
11
12#include <QtBluetooth/QBluetoothServiceInfo>
13#include <QtBluetooth/QBluetoothUuid>
14#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
15
16#if QT_CONFIG(bluez)
17#include <QtCore/qprocess.h>
18#endif
19
20QT_BEGIN_NAMESPACE
21
22class QBluetoothAddress;
23class QBluetoothServiceDiscoveryAgentPrivate;
24
25class Q_BLUETOOTH_EXPORT QBluetoothServiceDiscoveryAgent : public QObject
26{
27 Q_OBJECT
28 Q_DECLARE_PRIVATE(QBluetoothServiceDiscoveryAgent)
29
30public:
31 enum Error {
32 NoError = QBluetoothDeviceDiscoveryAgent::NoError,
33 InputOutputError = QBluetoothDeviceDiscoveryAgent::InputOutputError,
34 PoweredOffError = QBluetoothDeviceDiscoveryAgent::PoweredOffError,
35 InvalidBluetoothAdapterError = QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
36 MissingPermissionsError = QBluetoothDeviceDiscoveryAgent::MissingPermissionsError,
37 UnknownError = QBluetoothDeviceDiscoveryAgent::UnknownError //=100
38 //New Errors must be added after Unknown Error the space before UnknownError is reserved
39 //for future device discovery errors
40 };
41 Q_ENUM(Error)
42
43 enum DiscoveryMode {
44 MinimalDiscovery,
45 FullDiscovery
46 };
47 Q_ENUM(DiscoveryMode)
48
49 explicit QBluetoothServiceDiscoveryAgent(QObject *parent = nullptr);
50 explicit QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = nullptr);
51 ~QBluetoothServiceDiscoveryAgent();
52
53 bool isActive() const;
54
55 Error error() const;
56 QString errorString() const;
57
58 QList<QBluetoothServiceInfo> discoveredServices() const;
59
60 void setUuidFilter(const QList<QBluetoothUuid> &uuids);
61 void setUuidFilter(const QBluetoothUuid &uuid);
62 QList<QBluetoothUuid> uuidFilter() const;
63 bool setRemoteAddress(const QBluetoothAddress &address);
64 QBluetoothAddress remoteAddress() const;
65
66public Q_SLOTS:
67 void start(DiscoveryMode mode = MinimalDiscovery);
68 void stop();
69 void clear();
70
71Q_SIGNALS:
72 void serviceDiscovered(const QBluetoothServiceInfo &info);
73 void finished();
74 void canceled();
75 void errorOccurred(QBluetoothServiceDiscoveryAgent::Error error);
76
77private:
78 QBluetoothServiceDiscoveryAgentPrivate *d_ptr;
79};
80
81QT_END_NAMESPACE
82
83#endif
84

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