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 QBLUETOOTHLOCALDEVICE_H
5#define QBLUETOOTHLOCALDEVICE_H
6
7#include <QtBluetooth/qtbluetoothglobal.h>
8
9#include <QtCore/QObject>
10#include <QtCore/QList>
11#include <QtCore/QString>
12
13#include <QtBluetooth/QBluetoothHostInfo>
14
15QT_BEGIN_NAMESPACE
16
17class QBluetoothLocalDevicePrivate;
18
19class Q_BLUETOOTH_EXPORT QBluetoothLocalDevice : public QObject
20{
21 Q_OBJECT
22
23public:
24 enum Pairing {
25 Unpaired,
26 Paired,
27 AuthorizedPaired
28 };
29 Q_ENUM(Pairing)
30
31 enum HostMode {
32 HostPoweredOff,
33 HostConnectable,
34 HostDiscoverable,
35 HostDiscoverableLimitedInquiry
36 };
37 Q_ENUM(HostMode)
38
39 enum Error {
40 NoError,
41 PairingError,
42 MissingPermissionsError,
43 UnknownError = 100
44 };
45 Q_ENUM(Error)
46
47 explicit QBluetoothLocalDevice(QObject *parent = nullptr);
48 explicit QBluetoothLocalDevice(const QBluetoothAddress &address, QObject *parent = nullptr);
49 virtual ~QBluetoothLocalDevice();
50
51 bool isValid() const;
52
53 void requestPairing(const QBluetoothAddress &address, Pairing pairing);
54 Pairing pairingStatus(const QBluetoothAddress &address) const;
55
56 void setHostMode(QBluetoothLocalDevice::HostMode mode);
57 HostMode hostMode() const;
58 QList<QBluetoothAddress> connectedDevices() const;
59
60 void powerOn();
61
62 QString name() const;
63 QBluetoothAddress address() const;
64
65 static QList<QBluetoothHostInfo> allDevices();
66
67Q_SIGNALS:
68 void hostModeStateChanged(QBluetoothLocalDevice::HostMode state);
69 void deviceConnected(const QBluetoothAddress &address);
70 void deviceDisconnected(const QBluetoothAddress &address);
71 void pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing);
72
73 void errorOccurred(QBluetoothLocalDevice::Error error);
74
75private:
76 Q_DECLARE_PRIVATE(QBluetoothLocalDevice)
77 QBluetoothLocalDevicePrivate *d_ptr;
78};
79
80QT_END_NAMESPACE
81
82QT_DECL_METATYPE_EXTERN_TAGGED(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice__Pairing,
83 Q_BLUETOOTH_EXPORT)
84QT_DECL_METATYPE_EXTERN_TAGGED(QBluetoothLocalDevice::HostMode, QBluetoothLocalDevice__HostMode,
85 Q_BLUETOOTH_EXPORT)
86QT_DECL_METATYPE_EXTERN_TAGGED(QBluetoothLocalDevice::Error, QBluetoothLocalDevice__Error,
87 Q_BLUETOOTH_EXPORT)
88
89#endif // QBLUETOOTHLOCALDEVICE_H
90

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