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;
119 bool isValid()
const;
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;
131 void pairingCompleted(QDBusPendingCallWatcher *);
132 void requestPairing(
const QBluetoothAddress &address,
133 QBluetoothLocalDevice::Pairing targetPairing);
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();
148 void connectDeviceChanges();
150 QString deviceAdapterPath;
152 QBluetoothLocalDevice *q_ptr;
154 void initializeAdapter();
157#elif defined(QT_WINRT_BLUETOOTH)
158class QBluetoothLocalDevicePrivate :
public QObject
161 Q_DECLARE_PUBLIC(QBluetoothLocalDevice)
163 QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q,
164 QBluetoothAddress = QBluetoothAddress());
165 ~QBluetoothLocalDevicePrivate();
167 bool isValid()
const;
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);
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;
185 void updateMode(winrt::hstring id, QBluetoothLocalDevice::HostMode mode);
187#elif !defined(QT_OSX_BLUETOOTH)
192 QBluetoothAddress = QBluetoothAddress())
QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *=nullptr, QBluetoothAddress=QBluetoothAddress())