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
120 QBluetoothAddress localAddress;
121 QBluetoothAddress address;
122 QBluetoothLocalDevice::Pairing pairing;
123 QtBluetoothPrivate::OrgBluezDevice1Interface *pairingTarget = nullptr;
124 QTimer *pairingDiscoveryTimer = nullptr;
125 QBluetoothLocalDevice::HostMode currentMode;
126 int pendingHostModeChange;
127 bool pairingRequestCanceled = false;
128
129public slots:
130 void pairingCompleted(QDBusPendingCallWatcher *);
131
132 bool isValid() const;
133
134 void requestPairing(const QBluetoothAddress &address,
135 QBluetoothLocalDevice::Pairing targetPairing);
136
137private Q_SLOTS:
138 void PropertiesChanged(const QString &interface,
139 const QVariantMap &changed_properties,
140 const QStringList &invalidated_properties,
141 const QDBusMessage &signal);
142 void InterfacesAdded(const QDBusObjectPath &object_path,
143 InterfaceList interfaces_and_properties);
144 void InterfacesRemoved(const QDBusObjectPath &object_path,
145 const QStringList &interfaces);
146 void processPairing(const QString &objectPath, QBluetoothLocalDevice::Pairing target);
147 void pairingDiscoveryTimedOut();
148
149private:
150 void connectDeviceChanges();
151
152 QString deviceAdapterPath;
153
154 QBluetoothLocalDevice *q_ptr;
155
156 void initializeAdapter();
157};
158
159#elif defined(QT_WINRT_BLUETOOTH)
160class QBluetoothLocalDevicePrivate : public QObject
161{
162 Q_OBJECT
163 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
164public:
165 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
166 QBluetoothAddress = QBluetoothAddress());
167 ~QBluetoothLocalDevicePrivate();
168
169 bool isValid() const;
170
171 void updateAdapterState(QBluetoothLocalDevice::HostMode mode);
172 Q_SLOT void onAdapterRemoved(winrt::hstring id);
173 Q_SLOT void onAdapterAdded(winrt::hstring id);
174 Q_SLOT void radioModeChanged(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
175 Q_SLOT void onDeviceAdded(const QBluetoothAddress &address);
176 Q_SLOT void onDeviceRemoved(const QBluetoothAddress &address);
177
178 QBluetoothLocalDevice *q_ptr;
179 winrt::com_ptr<PairingWorker> mPairingWorker;
180 winrt::Windows::Devices::Bluetooth::BluetoothAdapter mAdapter;
181 winrt::hstring mDeviceId;
182 QString mAdapterName;
183 QBluetoothLocalDevice::HostMode mMode;
184 winrt::event_token mModeChangeToken;
185
186signals:
187 void updateMode(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
188};
189#elif !defined(QT_OSX_BLUETOOTH) // dummy backend
191{
192public:
193 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice * = nullptr,
194 QBluetoothAddress = QBluetoothAddress())
195 {
196 }
197
198 bool isValid() const
199 {
200 return false;
201 }
202};
203#endif
204
205QT_END_NAMESPACE
206
207#endif // QBLUETOOTHLOCALDEVICE_P_H
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *=nullptr, QBluetoothAddress=QBluetoothAddress())
\inmodule QtBluetooth