diff options
author | Andre de la Rocha <andre.rocha@qt.io> | 2018-11-23 18:04:40 +0100 |
---|---|---|
committer | Andre de la Rocha <andre.rocha@qt.io> | 2019-08-05 09:16:09 +0200 |
commit | 8b7b52d66f2616040ca4aaae3f2732be96e19ab8 (patch) | |
tree | bfc38942bd95718030a142540821f28911a611ef /src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp | |
parent | 5a2c8a39d76d634161e87b1c55d36cbbcc778289 (diff) |
Enable the use of the Win32 Bluetooth backend
This change enables the optional use of the Win32-based Bluetooth
backend on Windows. By default, the WinRT backend is used, if
supported by the platform. The use of the Win32 backend must be
selected by the -native-win32-bluetooth configuration option.
Task-number: QTBUG-40698
Change-Id: I6904bf077467d826e3ff5ad026ebae5f955f2e37
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp index 3645bd21..159428d4 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp @@ -154,7 +154,7 @@ static QBluetoothDeviceInfo findFirstClassicDevice( *systemErrorCode = NO_ERROR; foundDevice = createClassicDeviceInfo(deviceInfo); } else { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); } return foundDevice; @@ -168,7 +168,7 @@ static QBluetoothDeviceInfo findNextClassicDevice( QBluetoothDeviceInfo foundDevice; if (!::BluetoothFindNextDevice(hSearch, &deviceInfo)) { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); } else { *systemErrorCode = NO_ERROR; foundDevice = createClassicDeviceInfo(deviceInfo); @@ -186,6 +186,7 @@ static void closeClassicSearch(HBLUETOOTH_DEVICE_FIND hSearch) static QVector<QBluetoothDeviceInfo> enumerateLeDevices( DWORD *systemErrorCode) { + // GUID_BLUETOOTHLE_DEVICE_INTERFACE const QUuid deviceInterfaceGuid("781aee18-7733-4ce4-add0-91f41c67b592"); const HDEVINFO hDeviceInfo = ::SetupDiGetClassDevs( reinterpret_cast<const GUID *>(&deviceInterfaceGuid), @@ -194,7 +195,7 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices( DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); if (hDeviceInfo == INVALID_HANDLE_VALUE) { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); return QVector<QBluetoothDeviceInfo>(); } @@ -213,7 +214,7 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices( reinterpret_cast<const GUID *>(&deviceInterfaceGuid), index++, &deviceInterfaceData)) { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); break; } @@ -226,7 +227,7 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices( &deviceInterfaceDetailDataSize, nullptr)) { if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); break; } } @@ -251,7 +252,7 @@ static QVector<QBluetoothDeviceInfo> enumerateLeDevices( deviceInterfaceDetailDataBuffer.size(), &deviceInterfaceDetailDataSize, &deviceInfoData)) { - *systemErrorCode = ::GetLastError(); + *systemErrorCode = int(::GetLastError()); break; } @@ -534,28 +535,20 @@ void QBluetoothDeviceDiscoveryAgentPrivate::processDiscoveredDevice( auto end = discoveredDevices.end(); auto deviceIt = std::find_if(discoveredDevices.begin(), end, equalAddress); if (deviceIt == end) { - qCDebug(QT_BT_WINDOWS) << "Emit: " << foundDevice.address(); + qCDebug(QT_BT_WINDOWS) << "Found device: " << foundDevice.name() << foundDevice.address(); discoveredDevices.append(foundDevice); emit q->deviceDiscovered(foundDevice); - } else if (*deviceIt == foundDevice - || deviceIt->coreConfigurations() == foundDevice.coreConfigurations()) { - qCDebug(QT_BT_WINDOWS) << "Duplicate: " << foundDevice.address(); } else { - // We assume that if the existing device it is low energy, it means that - // the found device should be as classic, because it is impossible to get - // same low energy device. - if (deviceIt->coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) - *deviceIt = foundDevice; - - // We assume that it is impossible to have multiple devices with same core - // configurations, which have one address. This possible only in case a device - // provided both low energy and classic features at the same time. - deviceIt->setCoreConfigurations(QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration); - deviceIt->setCached(foundDevice.isCached()); - - Q_Q(QBluetoothDeviceDiscoveryAgent); - qCDebug(QT_BT_WINDOWS) << "Updated: " << deviceIt->address(); - emit q->deviceDiscovered(*deviceIt); + qCDebug(QT_BT_WINDOWS) << "Updating device:" << deviceIt->name() << deviceIt->address(); + // merge service uuids + QList<QBluetoothUuid> uuids = deviceIt->serviceUuids(); + uuids.append(foundDevice.serviceUuids()); + const QSet<QBluetoothUuid> uuidSet = uuids.toSet(); + if (deviceIt->serviceUuids().count() != uuidSet.count()) + deviceIt->setServiceUuids(uuidSet.toList().toVector()); + if (deviceIt->coreConfigurations() != foundDevice.coreConfigurations()) + deviceIt->setCoreConfigurations( + QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration); } } |