5#ifndef QBLUETOOTHLOCALDEVICE_P_H
6#define QBLUETOOTHLOCALDEVICE_P_H
19#include <QtBluetooth/qtbluetoothglobal.h>
25#include <QDBusObjectPath>
26#include <QDBusMessage>
28#include "bluez/bluez5_helper_p.h"
30namespace QtBluetoothPrivate {
32class OrgBluezAdapter1Interface;
33class OrgFreedesktopDBusPropertiesInterface;
34class OrgFreedesktopDBusObjectManagerInterface;
35class OrgBluezDevice1Interface;
40class QDBusPendingCallWatcher;
44#ifdef QT_WINRT_BLUETOOTH
45#include "qbluetoothutils_winrt_p.h"
46#include <winrt/Windows.Devices.Bluetooth.h>
52#ifdef QT_ANDROID_BLUETOOTH
54#include <QtCore/QJniEnvironment>
55#include <QtCore/QJniObject>
56#include <QtCore/QPair>
61extern void registerQBluetoothLocalDeviceMetaType();
63class QBluetoothAddress;
65#ifdef QT_ANDROID_BLUETOOTH
66class LocalDeviceBroadcastReceiver;
67class QBluetoothLocalDevicePrivate :
public QObject
71 QBluetoothLocalDevicePrivate(
72 QBluetoothLocalDevice *q,
const QBluetoothAddress &address = QBluetoothAddress());
73 ~QBluetoothLocalDevicePrivate();
75 QJniObject *adapter();
76 void initialize(
const QBluetoothAddress &address);
77 static bool startDiscovery();
78 static bool cancelDiscovery();
79 static bool isDiscovering();
83 void processHostModeChange(QBluetoothLocalDevice::HostMode newMode);
84 void processPairingStateChanged(
const QBluetoothAddress &address,
85 QBluetoothLocalDevice::Pairing pairing);
86 void processConnectDeviceChanges(
const QBluetoothAddress &address,
bool isConnectEvent);
89 QBluetoothLocalDevice *q_ptr;
90 QJniObject *obj =
nullptr;
92 int pendingPairing(
const QBluetoothAddress &address);
95 LocalDeviceBroadcastReceiver *receiver;
96 bool pendingConnectableHostModeTransition =
false;
97 QList<QPair<QBluetoothAddress,
bool> > pendingPairings;
99 QList<QBluetoothAddress> connectedDevices;
102#elif QT_CONFIG(bluez)
103class QBluetoothLocalDevicePrivate :
public QObject
106 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
108 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
109 QBluetoothAddress localAddress = QBluetoothAddress());
110 ~QBluetoothLocalDevicePrivate();
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;
118 QList<QBluetoothAddress> connectedDevices()
const;
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;
130 void pairingCompleted(QDBusPendingCallWatcher *);
132 bool isValid()
const;
134 void requestPairing(
const QBluetoothAddress &address,
135 QBluetoothLocalDevice::Pairing targetPairing);
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();
150 void connectDeviceChanges();
152 QString deviceAdapterPath;
154 QBluetoothLocalDevice *q_ptr;
156 void initializeAdapter();
159#elif defined(QT_WINRT_BLUETOOTH)
160class QBluetoothLocalDevicePrivate :
public QObject
163 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
165 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
166 QBluetoothAddress = QBluetoothAddress());
167 ~QBluetoothLocalDevicePrivate();
169 bool isValid()
const;
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);
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;
187 void updateMode(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
189#elif !defined(QT_OSX_BLUETOOTH)
194 QBluetoothAddress = QBluetoothAddress())
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *=nullptr, QBluetoothAddress=QBluetoothAddress())