| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com> | 
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 4 |  | 
| 5 | #ifndef QBLUETOOTHDEVICEDISCOVERYAGENT_H | 
| 6 | #define QBLUETOOTHDEVICEDISCOVERYAGENT_H | 
| 7 |  | 
| 8 | #include <QtBluetooth/qtbluetoothglobal.h> | 
| 9 |  | 
| 10 | #include <QtCore/QObject> | 
| 11 | #include <QtBluetooth/QBluetoothDeviceInfo> | 
| 12 | #include <QtBluetooth/QBluetoothAddress> | 
| 13 |  | 
| 14 | QT_BEGIN_NAMESPACE | 
| 15 |  | 
| 16 | class QBluetoothDeviceDiscoveryAgentPrivate; | 
| 17 |  | 
| 18 | class Q_BLUETOOTH_EXPORT QBluetoothDeviceDiscoveryAgent : public QObject | 
| 19 | { | 
| 20 |     Q_OBJECT | 
| 21 |  | 
| 22 | public: | 
| 23 |     // FIXME: add more errors | 
| 24 |     // FIXME: add bluez error handling | 
| 25 |     enum Error { | 
| 26 |         NoError, | 
| 27 |         InputOutputError, | 
| 28 |         PoweredOffError, | 
| 29 |         InvalidBluetoothAdapterError, | 
| 30 |         UnsupportedPlatformError, | 
| 31 |         UnsupportedDiscoveryMethod, | 
| 32 |         LocationServiceTurnedOffError, | 
| 33 |         MissingPermissionsError, | 
| 34 |         UnknownError = 100 // New errors must be added before Unknown error | 
| 35 |     }; | 
| 36 |     Q_ENUM(Error) | 
| 37 |  | 
| 38 |     enum DiscoveryMethod | 
| 39 |     { | 
| 40 |         NoMethod = 0x0, | 
| 41 |         ClassicMethod = 0x01, | 
| 42 |         LowEnergyMethod = 0x02, | 
| 43 |     }; | 
| 44 |     Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod) | 
| 45 |     Q_FLAG(DiscoveryMethods) | 
| 46 |  | 
| 47 |     explicit QBluetoothDeviceDiscoveryAgent(QObject *parent = nullptr); | 
| 48 |     explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, | 
| 49 |                                             QObject *parent = nullptr); | 
| 50 |     ~QBluetoothDeviceDiscoveryAgent(); | 
| 51 |  | 
| 52 |     bool isActive() const; | 
| 53 |  | 
| 54 |     Error error() const; | 
| 55 |     QString errorString() const; | 
| 56 |  | 
| 57 |     QList<QBluetoothDeviceInfo> discoveredDevices() const; | 
| 58 |  | 
| 59 |     void setLowEnergyDiscoveryTimeout(int msTimeout); | 
| 60 |     int lowEnergyDiscoveryTimeout() const; | 
| 61 |  | 
| 62 |     static DiscoveryMethods supportedDiscoveryMethods(); | 
| 63 | public Q_SLOTS: | 
| 64 |     void start(); | 
| 65 |     void start(DiscoveryMethods method); | 
| 66 |     void stop(); | 
| 67 |  | 
| 68 | Q_SIGNALS: | 
| 69 |     void deviceDiscovered(const QBluetoothDeviceInfo &info); | 
| 70 |     void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields); | 
| 71 |     void finished(); | 
| 72 |     void errorOccurred(QBluetoothDeviceDiscoveryAgent::Error error); | 
| 73 |     void canceled(); | 
| 74 |  | 
| 75 | private: | 
| 76 |     Q_DECLARE_PRIVATE(QBluetoothDeviceDiscoveryAgent) | 
| 77 |     QBluetoothDeviceDiscoveryAgentPrivate *d_ptr; | 
| 78 | }; | 
| 79 |  | 
| 80 | Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods) | 
| 81 |  | 
| 82 | QT_END_NAMESPACE | 
| 83 |  | 
| 84 | #endif | 
| 85 |  |