summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_p.h')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h148
1 files changed, 34 insertions, 114 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 263ab9ca..3e5f2a0c 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QBLUETOOTHDEVICEDISCOVERYAGENT_P_H
#define QBLUETOOTHDEVICEDISCOVERYAGENT_P_H
@@ -54,7 +18,7 @@
#include "qbluetoothdevicediscoveryagent.h"
#ifdef QT_ANDROID_BLUETOOTH
-#include <QtAndroidExtras/QAndroidJniObject>
+#include <QtCore/QJniObject>
#include "android/devicediscoverybroadcastreceiver_p.h"
#include <QtCore/QTimer>
#endif
@@ -84,25 +48,14 @@ class QDBusVariant;
QT_END_NAMESPACE
#endif
-#ifdef QT_WIN_BLUETOOTH
-QT_BEGIN_NAMESPACE
-class QThread;
-
-class ThreadWorkerDeviceDiscovery : public QObject
-{
- Q_OBJECT
-signals:
- void discoveryCompleted(const QVariant res);
-};
-
-QT_END_NAMESPACE
-
-#elif defined(QT_WINRT_BLUETOOTH)
+#ifdef QT_WINRT_BLUETOOTH
#include <QtCore/QPointer>
#include <QtCore/QTimer>
using ManufacturerData = QHash<quint16, QByteArray>;
-Q_DECLARE_METATYPE(ManufacturerData)
+using ServiceData = QHash<QBluetoothUuid, QByteArray>;
+QT_DECL_METATYPE_EXTERN(ManufacturerData, Q_BLUETOOTH_EXPORT)
+QT_DECL_METATYPE_EXTERN(ServiceData, Q_BLUETOOTH_EXPORT)
#endif
QT_BEGIN_NAMESPACE
@@ -112,7 +65,7 @@ class QWinRTBluetoothDeviceDiscoveryWorker;
#endif
class QBluetoothDeviceDiscoveryAgentPrivate
-#if defined(QT_ANDROID_BLUETOOTH) || defined(QT_WINRT_BLUETOOTH) || defined(QT_WIN_BLUETOOTH) \
+#if defined(QT_ANDROID_BLUETOOTH) || defined(QT_WINRT_BLUETOOTH) \
|| defined(Q_OS_DARWIN)
: public QObject
#if defined(Q_OS_MACOS)
@@ -135,24 +88,22 @@ public:
bool isActive() const;
#if QT_CONFIG(bluez)
- void _q_deviceFound(const QString &address, const QVariantMap &dict);
- void _q_propertyChanged(const QString &name, const QDBusVariant &value);
void _q_InterfacesAdded(const QDBusObjectPath &object_path,
InterfaceList interfaces_and_properties);
void _q_discoveryFinished();
void _q_discoveryInterrupted(const QString &path);
void _q_PropertiesChanged(const QString &interface,
+ const QString &path,
const QVariantMap &changed_properties,
const QStringList &invalidated_properties);
- void _q_extendedDeviceDiscoveryTimeout();
#endif
private:
QList<QBluetoothDeviceInfo> discoveredDevices;
- QBluetoothDeviceDiscoveryAgent::InquiryType inquiryType;
- QBluetoothDeviceDiscoveryAgent::Error lastError;
+ QBluetoothDeviceDiscoveryAgent::Error lastError = QBluetoothDeviceDiscoveryAgent::NoError;
QString errorString;
+ QBluetoothAddress adapterAddress;
#ifdef QT_ANDROID_BLUETOOTH
private slots:
@@ -163,72 +114,43 @@ private slots:
private:
void startLowEnergyScan();
+ void classicDiscoveryStartFail();
+ bool setErrorIfPowerOff();
- DeviceDiscoveryBroadcastReceiver *receiver;
- QBluetoothAddress m_adapterAddress;
+ DeviceDiscoveryBroadcastReceiver *receiver = nullptr;
short m_active;
- QAndroidJniObject adapter;
- QAndroidJniObject leScanner;
- QTimer *leScanTimeout;
-
- bool pendingCancel, pendingStart;
+ QJniObject adapter;
+ QJniObject leScanner;
+ QTimer *leScanTimeout = nullptr;
+ QTimer *deviceDiscoveryStartTimeout = nullptr;
+ short deviceDiscoveryStartAttemptsLeft;
+
+ bool pendingCancel = false;
+ bool pendingStart = false;
#elif QT_CONFIG(bluez)
- QBluetoothAddress m_adapterAddress;
- bool pendingCancel;
- bool pendingStart;
- OrgBluezManagerInterface *manager = nullptr;
- OrgBluezAdapterInterface *adapter = nullptr;
- OrgFreedesktopDBusObjectManagerInterface *managerBluez5 = nullptr;
- OrgBluezAdapter1Interface *adapterBluez5 = nullptr;
+ bool pendingCancel = false;
+ bool pendingStart = false;
+ OrgFreedesktopDBusObjectManagerInterface *manager = nullptr;
+ OrgBluezAdapter1Interface *adapter = nullptr;
QTimer *discoveryTimer = nullptr;
QList<OrgFreedesktopDBusPropertiesInterface *> propertyMonitors;
- void deviceFoundBluez5(const QString &devicePath, const QVariantMap &properties);
- void startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods);
+ void deviceFound(const QString &devicePath, const QVariantMap &properties);
- bool useExtendedDiscovery;
- QTimer extendedDiscoveryTimer;
QMap<QString, QVariantMap> devicesProperties;
#endif
-#ifdef QT_WIN_BLUETOOTH
-public:
- static QString discoveredLeDeviceSystemPath(const QBluetoothAddress &deviceAddress);
-
-private:
- void cancelDiscovery();
- void restartDiscovery();
- void finishDiscovery(QBluetoothDeviceDiscoveryAgent::Error errorCode, const QString &errorText);
-
- void startLeDevicesDiscovery();
- void completeLeDevicesDiscovery(const QVariant &res);
- void startClassicDevicesDiscovery(Qt::HANDLE hSearch = nullptr);
- void completeClassicDevicesDiscovery(const QVariant &res);
-
- void processDiscoveredDevice(const QBluetoothDeviceInfo &foundDevice);
-
- QBluetoothAddress adapterAddress;
- bool pendingCancel;
- bool pendingStart;
- bool active;
-
- QThread *threadLE = nullptr;
- QThread *threadClassic = nullptr;
- ThreadWorkerDeviceDiscovery *threadWorkerLE = nullptr;
- ThreadWorkerDeviceDiscovery *threadWorkerClassic = nullptr;
-#endif
-
#ifdef QT_WINRT_BLUETOOTH
private slots:
void registerDevice(const QBluetoothDeviceInfo &info);
void updateDeviceData(const QBluetoothAddress &address, QBluetoothDeviceInfo::Fields fields,
- qint16 rssi, ManufacturerData manufacturerData);
+ qint16 rssi, ManufacturerData manufacturerData, ServiceData serviceData);
+ void onErrorOccured(QBluetoothDeviceDiscoveryAgent::Error e);
void onScanFinished();
private:
void disconnectAndClearWorker();
- QPointer<QWinRTBluetoothDeviceDiscoveryWorker> worker;
- QTimer *leScanTimer;
+ std::shared_ptr<QWinRTBluetoothDeviceDiscoveryWorker> worker = nullptr;
#endif
#ifdef Q_OS_DARWIN
@@ -266,10 +188,8 @@ private:
LEScan
} agentState;
- QBluetoothAddress adapterAddress;
-
- bool startPending;
- bool stopPending;
+ bool startPending = false;
+ bool stopPending = false;
#ifdef Q_OS_MACOS
@@ -282,7 +202,7 @@ private:
#endif // Q_OS_DARWIN
- int lowEnergySearchTimeout;
+ int lowEnergySearchTimeout = 40000;
QBluetoothDeviceDiscoveryAgent::DiscoveryMethods requestedMethods;
QBluetoothDeviceDiscoveryAgent *q_ptr;
};