1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QBLUETOOTHDEVICEDISCOVERYAGENT_H
41#define QBLUETOOTHDEVICEDISCOVERYAGENT_H
42
43#include <QtBluetooth/qtbluetoothglobal.h>
44
45#include <QtCore/QObject>
46#include <QtBluetooth/QBluetoothDeviceInfo>
47#include <QtBluetooth/QBluetoothAddress>
48
49QT_BEGIN_NAMESPACE
50
51class QBluetoothDeviceDiscoveryAgentPrivate;
52
53class Q_BLUETOOTH_EXPORT QBluetoothDeviceDiscoveryAgent : public QObject
54{
55 Q_OBJECT
56 Q_PROPERTY(QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType
57 READ inquiryType WRITE setInquiryType)
58
59public:
60 // FIXME: add more errors
61 // FIXME: add bluez error handling
62 enum Error {
63 NoError,
64 InputOutputError,
65 PoweredOffError,
66 InvalidBluetoothAdapterError,
67 UnsupportedPlatformError,
68 UnsupportedDiscoveryMethod,
69 UnknownError = 100 // New errors must be added before Unknown error
70 };
71 Q_ENUM(Error)
72
73 enum InquiryType {
74 GeneralUnlimitedInquiry,
75 LimitedInquiry
76 };
77 Q_ENUM(InquiryType)
78
79 enum DiscoveryMethod
80 {
81 NoMethod = 0x0,
82 ClassicMethod = 0x01,
83 LowEnergyMethod = 0x02,
84 };
85 Q_DECLARE_FLAGS(DiscoveryMethods, DiscoveryMethod)
86 Q_FLAG(DiscoveryMethods)
87
88 explicit QBluetoothDeviceDiscoveryAgent(QObject *parent = nullptr);
89 explicit QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter,
90 QObject *parent = nullptr);
91 ~QBluetoothDeviceDiscoveryAgent();
92
93 // TODO Remove inquiry type in Qt 6 -> not really used anywhere
94 QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType() const;
95 void setInquiryType(QBluetoothDeviceDiscoveryAgent::InquiryType type);
96
97 bool isActive() const;
98
99 Error error() const;
100 QString errorString() const;
101
102 QList<QBluetoothDeviceInfo> discoveredDevices() const;
103
104 void setLowEnergyDiscoveryTimeout(int msTimeout);
105 int lowEnergyDiscoveryTimeout() const;
106
107 static DiscoveryMethods supportedDiscoveryMethods();
108public Q_SLOTS:
109 void start();
110 void start(DiscoveryMethods method);
111 void stop();
112
113Q_SIGNALS:
114 void deviceDiscovered(const QBluetoothDeviceInfo &info);
115 void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields);
116 void finished();
117 void error(QBluetoothDeviceDiscoveryAgent::Error error);
118 void canceled();
119
120private:
121 Q_DECLARE_PRIVATE(QBluetoothDeviceDiscoveryAgent)
122 QBluetoothDeviceDiscoveryAgentPrivate *d_ptr;
123};
124
125Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods)
126
127QT_END_NAMESPACE
128
129#endif
130