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
qbluetoothlocaldevice_p.h
Go to the documentation of this file.
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 QBLUETOOTHLOCALDEVICE_P_H
6#define QBLUETOOTHLOCALDEVICE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtBluetooth/qtbluetoothglobal.h>
20
22
23#if QT_CONFIG(bluez)
24#include <QObject>
25#include <QDBusObjectPath>
26#include <QDBusMessage>
27#include <QSet>
28#include "bluez/bluez5_helper_p.h"
29
30namespace QtBluetoothPrivate {
31
32class OrgBluezAdapter1Interface;
33class OrgFreedesktopDBusPropertiesInterface;
34class OrgFreedesktopDBusObjectManagerInterface;
35class OrgBluezDevice1Interface;
36
37} // namespace QtBluetoothPrivate
38
39QT_BEGIN_NAMESPACE
40class QDBusPendingCallWatcher;
41QT_END_NAMESPACE
42#endif
43
44#ifdef QT_WINRT_BLUETOOTH
45#include "qbluetoothutils_winrt_p.h"
46#include <winrt/Windows.Devices.Bluetooth.h>
47QT_BEGIN_NAMESPACE
48struct PairingWorker;
49QT_END_NAMESPACE
50#endif
51
52#ifdef QT_ANDROID_BLUETOOTH
53#include <jni.h>
54#include <QtCore/QJniEnvironment>
55#include <QtCore/QJniObject>
56#include <QtCore/QPair>
57#endif
58
59QT_BEGIN_NAMESPACE
60
61extern void registerQBluetoothLocalDeviceMetaType();
62
63class QBluetoothAddress;
64
65#ifdef QT_ANDROID_BLUETOOTH
66class LocalDeviceBroadcastReceiver;
67class QBluetoothLocalDevicePrivate : public QObject
68{
69 Q_OBJECT
70public:
71 QBluetoothLocalDevicePrivate(
72 QBluetoothLocalDevice *q, const QBluetoothAddress &address = QBluetoothAddress());
73 ~QBluetoothLocalDevicePrivate();
74
75 QJniObject *adapter();
76 void initialize(const QBluetoothAddress &address);
77 static bool startDiscovery();
78 static bool cancelDiscovery();
79 static bool isDiscovering();
80 bool isValid() const;
81
82private slots:
83 void processHostModeChange(QBluetoothLocalDevice::HostMode newMode);
84 void processPairingStateChanged(const QBluetoothAddress &address,
85 QBluetoothLocalDevice::Pairing pairing);
86 void processConnectDeviceChanges(const QBluetoothAddress &address, bool isConnectEvent);
87
88private:
89 QBluetoothLocalDevice *q_ptr;
90 QJniObject *obj = nullptr;
91
92 int pendingPairing(const QBluetoothAddress &address);
93
94public:
95 LocalDeviceBroadcastReceiver *receiver;
96 bool pendingConnectableHostModeTransition = false;
97 QList<QPair<QBluetoothAddress, bool> > pendingPairings;
98
99 QList<QBluetoothAddress> connectedDevices;
100};
101
102#elif QT_CONFIG(bluez)
103class QBluetoothLocalDevicePrivate : public QObject
104{
105 Q_OBJECT
106 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
107public:
108 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
109 QBluetoothAddress localAddress = QBluetoothAddress());
110 ~QBluetoothLocalDevicePrivate();
111
112 QSet<QBluetoothAddress> connectedDevicesSet;
113 QtBluetoothPrivate::OrgBluezAdapter1Interface *adapter = nullptr;
114 QtBluetoothPrivate::OrgFreedesktopDBusPropertiesInterface *adapterProperties = nullptr;
115 QtBluetoothPrivate::OrgFreedesktopDBusObjectManagerInterface *manager = nullptr;
116 QMap<QString, QtBluetoothPrivate::OrgFreedesktopDBusPropertiesInterface *> deviceChangeMonitors;
117
118 QList<QBluetoothAddress> connectedDevices() const;
119 bool isValid() const;
120
121 QBluetoothAddress localAddress;
122 QBluetoothAddress address;
123 QBluetoothLocalDevice::Pairing pairing;
124 QtBluetoothPrivate::OrgBluezDevice1Interface *pairingTarget = nullptr;
125 QTimer *pairingDiscoveryTimer = nullptr;
126 QBluetoothLocalDevice::HostMode currentMode;
127 int pendingHostModeChange;
128 bool pairingRequestCanceled = false;
129
130public slots:
131 void pairingCompleted(QDBusPendingCallWatcher *);
132 void requestPairing(const QBluetoothAddress &address,
133 QBluetoothLocalDevice::Pairing targetPairing);
134
135private Q_SLOTS:
136 void PropertiesChanged(const QString &interface,
137 const QVariantMap &changed_properties,
138 const QStringList &invalidated_properties,
139 const QDBusMessage &signal);
140 void InterfacesAdded(const QDBusObjectPath &object_path,
141 InterfaceList interfaces_and_properties);
142 void InterfacesRemoved(const QDBusObjectPath &object_path,
143 const QStringList &interfaces);
144 void processPairing(const QString &objectPath, QBluetoothLocalDevice::Pairing target);
145 void pairingDiscoveryTimedOut();
146
147private:
148 void connectDeviceChanges();
149
150 QString deviceAdapterPath;
151
152 QBluetoothLocalDevice *q_ptr;
153
154 void initializeAdapter();
155};
156
157#elif defined(QT_WINRT_BLUETOOTH)
158class QBluetoothLocalDevicePrivate : public QObject
159{
160 Q_OBJECT
161 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
162public:
163 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
164 QBluetoothAddress = QBluetoothAddress());
165 ~QBluetoothLocalDevicePrivate();
166
167 bool isValid() const;
168
169 void updateAdapterState(QBluetoothLocalDevice::HostMode mode);
170 Q_SLOT void onAdapterRemoved(winrt::hstring id);
171 Q_SLOT void onAdapterAdded(winrt::hstring id);
172 Q_SLOT void radioModeChanged(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
173 Q_SLOT void onDeviceAdded(const QBluetoothAddress &address);
174 Q_SLOT void onDeviceRemoved(const QBluetoothAddress &address);
175
176 QBluetoothLocalDevice *q_ptr;
177 winrt::com_ptr<PairingWorker> mPairingWorker;
178 winrt::Windows::Devices::Bluetooth::BluetoothAdapter mAdapter;
179 winrt::hstring mDeviceId;
180 QString mAdapterName;
181 QBluetoothLocalDevice::HostMode mMode;
182 winrt::event_token mModeChangeToken;
183
184signals:
185 void updateMode(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
186};
187#elif !defined(QT_OSX_BLUETOOTH) // dummy backend
189{
190public:
191 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice * = nullptr,
192 QBluetoothAddress = QBluetoothAddress())
193 {
194 }
195
196 bool isValid() const
197 {
198 return false;
199 }
200};
201#endif
202
203QT_END_NAMESPACE
204
205#endif // QBLUETOOTHLOCALDEVICE_P_H
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *=nullptr, QBluetoothAddress=QBluetoothAddress())
\inmodule QtBluetooth