diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2016-08-08 10:47:21 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2016-08-09 06:57:54 +0000 |
commit | 971c898235d3f48a6b33a17359cd3d644b9f8b5f (patch) | |
tree | 02e9c8acfa149c6d7f44e6b5f92bf89c7eda67c9 | |
parent | efaa9711183b1a7d518baa89fa74cbe5606a073a (diff) |
winrt: Filter devices found by the LE device watcher
It is possible that devices are found by the initial scan
and by the device watcher. In this cases the "device found"
signal should not be emitted.
Change-Id: Ic8aa5a088092adfa8a5b2ea5a3c91350a7897e6a
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_p.h | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp | 16 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h index 44a067c5..94d4f50b 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h @@ -162,6 +162,7 @@ private: #ifdef QT_WINRT_BLUETOOTH private slots: void onListInitializationCompleted(); + void onLeDeviceFound(const QBluetoothDeviceInfo &info); void onScanFinished(); void onScanCanceled(); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp index 674302bf..ec8de3e8 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp @@ -365,7 +365,6 @@ QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent: void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods) { - Q_Q(QBluetoothDeviceDiscoveryAgent); if (worker) return; @@ -378,12 +377,12 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent discoveredDevices.clear(); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::initializationCompleted, this, &QBluetoothDeviceDiscoveryAgentPrivate::onListInitializationCompleted); + connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::leDeviceFound, + this, &QBluetoothDeviceDiscoveryAgentPrivate::onLeDeviceFound); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanFinished, this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished); connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::scanCanceled, this, &QBluetoothDeviceDiscoveryAgentPrivate::onScanCanceled); - connect(worker, &QWinRTBluetoothDeviceDiscoveryWorker::leDeviceFound, - q, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered); worker->start(); if (lowEnergySearchTimeout > 0 && methods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) { // otherwise no timeout and stop() required @@ -417,6 +416,17 @@ void QBluetoothDeviceDiscoveryAgentPrivate::onListInitializationCompleted() emit q->deviceDiscovered(info); } +void QBluetoothDeviceDiscoveryAgentPrivate::onLeDeviceFound(const QBluetoothDeviceInfo &info) +{ + Q_Q(QBluetoothDeviceDiscoveryAgent); + for (auto discoveredInfo : discoveredDevices) + if (discoveredInfo.address() == info.address()) + return; + + discoveredDevices << info; + emit q->deviceDiscovered(info); +} + void QBluetoothDeviceDiscoveryAgentPrivate::onScanFinished() { Q_Q(QBluetoothDeviceDiscoveryAgent); |