summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/windows
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-10-13 17:18:15 +0300
committerTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2015-10-14 08:26:40 +0000
commitc18927e87e65eefccd8cda9e6671d234e95d387c (patch)
treeb10d59ca000e674257927a548a5e378c08f2f1de /src/bluetooth/windows
parent797624ac0c5f0a7ee3dd0a938454d55cb8786373 (diff)
Windows: Refactor code related to discovering of a remote devices
* There is no need to do parallel scan for LE and Classic devices. It is enough to do it one after another by using one QFutureWatcher instead of two QFutureWatchers. * Now the qwinclassicbluetooth(h).cpp files are deleted from the 'windows' directory, and its related code is moved into QBluetoothDeviceDiscoveryAgentPrivate. Change-Id: I2acf102c3a8d313d078b351e9a2ce54ebca79dee Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/windows')
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth.cpp94
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth_p.h75
-rw-r--r--src/bluetooth/windows/qwinlowenergybluetooth.cpp150
-rw-r--r--src/bluetooth/windows/qwinlowenergybluetooth_p.h18
-rw-r--r--src/bluetooth/windows/windows.pri2
5 files changed, 5 insertions, 334 deletions
diff --git a/src/bluetooth/windows/qwinclassicbluetooth.cpp b/src/bluetooth/windows/qwinclassicbluetooth.cpp
deleted file mode 100644
index 88313ed7..00000000
--- a/src/bluetooth/windows/qwinclassicbluetooth.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qwinclassicbluetooth_p.h"
-
-QT_BEGIN_NAMESPACE
-
-namespace WinClassicBluetooth {
-
-LocalRadiosDiscoveryResult::LocalRadiosDiscoveryResult()
- : error(NO_ERROR)
-{
-}
-
-RemoteDeviceDiscoveryResult::RemoteDeviceDiscoveryResult()
- : hSearch(0)
- , error(NO_ERROR)
-{
- ::ZeroMemory(&device, sizeof(device));
- device.dwSize = sizeof(device);
-}
-
-RemoteDeviceDiscoveryResult startDiscoveryOfFirstRemoteDevice()
-{
- BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams;
- ::ZeroMemory(&searchParams, sizeof(searchParams));
- searchParams.dwSize = sizeof(searchParams);
- searchParams.cTimeoutMultiplier = 10; // 12.8 sec
- searchParams.fIssueInquiry = TRUE;
- searchParams.fReturnAuthenticated = TRUE;
- searchParams.fReturnConnected = TRUE;
- searchParams.fReturnRemembered = TRUE;
- searchParams.fReturnUnknown = TRUE;
- searchParams.hRadio = NULL;
-
- RemoteDeviceDiscoveryResult result;
- result.hSearch = ::BluetoothFindFirstDevice(
- &searchParams, &result.device);
-
- if (!result.hSearch)
- result.error = ::GetLastError();
- return result;
-}
-
-RemoteDeviceDiscoveryResult startDiscoveryOfNextRemoteDevice(
- HBLUETOOTH_DEVICE_FIND hSearch)
-{
- RemoteDeviceDiscoveryResult result;
- result.hSearch = hSearch;
- if (!::BluetoothFindNextDevice(hSearch, &result.device))
- result.error = ::GetLastError();
- return result;
-}
-
-void cancelRemoteDevicesDiscovery(HBLUETOOTH_DEVICE_FIND hSearch)
-{
- if (hSearch)
- ::BluetoothFindDeviceClose(hSearch);
-}
-
-} // namespace WinClassicBluetooth
-
-QT_END_NAMESPACE
diff --git a/src/bluetooth/windows/qwinclassicbluetooth_p.h b/src/bluetooth/windows/qwinclassicbluetooth_p.h
deleted file mode 100644
index 2ba255ce..00000000
--- a/src/bluetooth/windows/qwinclassicbluetooth_p.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL21$
-** 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 http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://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 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QWINCLASSICBLUETOOTH_P_H
-#define QWINCLASSICBLUETOOTH_P_H
-
-#include <QtCore/qlist.h>
-#include <QtCore/qmetatype.h>
-
-#include <qt_windows.h>
-#include <setupapi.h>
-#include <bluetoothapis.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace WinClassicBluetooth {
-
-struct LocalRadiosDiscoveryResult
-{
- LocalRadiosDiscoveryResult();
- QList<BLUETOOTH_RADIO_INFO> radios;
- DWORD error;
-};
-
-struct RemoteDeviceDiscoveryResult
-{
- RemoteDeviceDiscoveryResult();
- BLUETOOTH_DEVICE_INFO device;
- HBLUETOOTH_DEVICE_FIND hSearch;
- DWORD error;
-};
-
-RemoteDeviceDiscoveryResult startDiscoveryOfFirstRemoteDevice();
-RemoteDeviceDiscoveryResult startDiscoveryOfNextRemoteDevice(HBLUETOOTH_DEVICE_FIND hSearch);
-void cancelRemoteDevicesDiscovery(HBLUETOOTH_DEVICE_FIND hSearch);
-
-} // namespace WinClassicBluetooth
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(WinClassicBluetooth::LocalRadiosDiscoveryResult)
-Q_DECLARE_METATYPE(WinClassicBluetooth::RemoteDeviceDiscoveryResult)
-
-#endif // QWINCLASSICBLUETOOTH_P_H
diff --git a/src/bluetooth/windows/qwinlowenergybluetooth.cpp b/src/bluetooth/windows/qwinlowenergybluetooth.cpp
index eeb8ae33..0b917bd3 100644
--- a/src/bluetooth/windows/qwinlowenergybluetooth.cpp
+++ b/src/bluetooth/windows/qwinlowenergybluetooth.cpp
@@ -102,6 +102,11 @@ static inline bool resolveFunctions(QLibrary *library)
Q_GLOBAL_STATIC(QLibrary, bluetoothapis)
+ServicesDiscoveryResult::ServicesDiscoveryResult()
+ : error(NO_ERROR)
+{
+}
+
static QString deviceRegistryProperty(
HDEVINFO deviceInfoHandle,
const PSP_DEVINFO_DATA deviceInfoData,
@@ -135,13 +140,6 @@ static QString deviceRegistryProperty(
reinterpret_cast<const wchar_t *>(propertyBuffer.constData()));
}
-static QString deviceFriendlyName(
- HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData)
-{
- return deviceRegistryProperty(
- deviceInfoSet, deviceInfoData, SPDRP_FRIENDLYNAME);
-}
-
static QString deviceService(
HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData)
{
@@ -149,138 +147,6 @@ static QString deviceService(
deviceInfoSet, deviceInfoData, SPDRP_SERVICE);
}
-static QString deviceSystemPath(
- const PSP_INTERFACE_DEVICE_DETAIL_DATA detailData)
-{
- return QString::fromWCharArray(detailData->DevicePath);
-}
-
-static QBluetoothAddress parseRemoteAddress(const QString &devicePath)
-{
- const int firstbound = devicePath.indexOf(QStringLiteral("dev_"));
- const int lastbound = devicePath.indexOf(QLatin1Char('#'), firstbound);
-
- const QString hex =
- devicePath.mid(firstbound + 4, lastbound - firstbound - 4);
-
- bool ok = false;
- return QBluetoothAddress(hex.toULongLong(&ok, 16));
-}
-
-DeviceInfo::DeviceInfo(
- const QBluetoothAddress &address,
- const QString &name,
- const QString &systemPath)
- : address(address)
- , name(name)
- , systemPath(systemPath)
-{
-}
-
-DeviceDiscoveryResult::DeviceDiscoveryResult()
- : error(NO_ERROR)
-{
-}
-
-ServicesDiscoveryResult::ServicesDiscoveryResult()
- : error(NO_ERROR)
-{
-}
-
-static DeviceDiscoveryResult availableSystemInterfaces(
- const GUID &deviceInterface)
-{
- const DWORD flags = DIGCF_PRESENT | DIGCF_DEVICEINTERFACE;
- const HDEVINFO deviceInfoHandle = ::SetupDiGetClassDevs(
- &deviceInterface, 0, 0, flags);
-
- DeviceDiscoveryResult result;
-
- if (deviceInfoHandle == INVALID_HANDLE_VALUE) {
- result.error = ::GetLastError();
- return result;
- }
-
- DWORD index = 0;
-
- forever {
-
- SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
- ::ZeroMemory(&deviceInterfaceData, sizeof(deviceInterfaceData));
- deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);
-
- if (!::SetupDiEnumDeviceInterfaces(
- deviceInfoHandle,
- NULL,
- &deviceInterface,
- index++,
- &deviceInterfaceData)) {
-
- result.error = ::GetLastError();
- break;
- }
-
- DWORD deviceInterfaceDetailDataSize = 0;
- if (!::SetupDiGetDeviceInterfaceDetail(
- deviceInfoHandle,
- &deviceInterfaceData,
- NULL,
- deviceInterfaceDetailDataSize,
- &deviceInterfaceDetailDataSize,
- NULL)) {
-
- const DWORD error = ::GetLastError();
- if (error != ERROR_INSUFFICIENT_BUFFER) {
- result.error = ::GetLastError();
-
- break;
- }
- }
-
- SP_DEVINFO_DATA deviceInfoData;
- ::ZeroMemory(&deviceInfoData, sizeof(deviceInfoData));
- deviceInfoData.cbSize = sizeof(deviceInfoData);
-
- QByteArray deviceInterfaceDetailDataBuffer(
- deviceInterfaceDetailDataSize, 0);
-
- PSP_INTERFACE_DEVICE_DETAIL_DATA deviceInterfaceDetailData =
- reinterpret_cast<PSP_INTERFACE_DEVICE_DETAIL_DATA>
- (deviceInterfaceDetailDataBuffer.data());
-
- deviceInterfaceDetailData->cbSize =
- sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
-
- if (!::SetupDiGetDeviceInterfaceDetail(
- deviceInfoHandle,
- &deviceInterfaceData,
- deviceInterfaceDetailData,
- deviceInterfaceDetailDataBuffer.size(),
- &deviceInterfaceDetailDataSize,
- &deviceInfoData)) {
- result.error = ::GetLastError();
- break;
- }
-
- const QString systemPath =
- deviceSystemPath(deviceInterfaceDetailData);
-
- const QBluetoothAddress address = parseRemoteAddress(systemPath);
- if (address.isNull())
- continue;
-
- const QString friendlyName =
- deviceFriendlyName(deviceInfoHandle, &deviceInfoData);
-
- const DeviceInfo info(address, friendlyName, systemPath);
- result.devices.append(info);
-
- }
-
- ::SetupDiDestroyDeviceInfoList(deviceInfoHandle);
- return result;
-}
-
static QStringList availableSystemServices(const GUID &deviceInterface)
{
const DWORD flags = DIGCF_PRESENT;
@@ -311,12 +177,6 @@ static QStringList availableSystemServices(const GUID &deviceInterface)
return result;
}
-DeviceDiscoveryResult startDiscoveryOfRemoteDevices()
-{
- return availableSystemInterfaces(
- QUuid("781aee18-7733-4ce4-add0-91f41c67b592"));
-}
-
ServicesDiscoveryResult startDiscoveryOfPrimaryServices(
HANDLE hDevice)
{
diff --git a/src/bluetooth/windows/qwinlowenergybluetooth_p.h b/src/bluetooth/windows/qwinlowenergybluetooth_p.h
index 08a99b38..adc8650e 100644
--- a/src/bluetooth/windows/qwinlowenergybluetooth_p.h
+++ b/src/bluetooth/windows/qwinlowenergybluetooth_p.h
@@ -157,23 +157,6 @@ typedef VOID (CALLBACK *PFNBLUETOOTH_GATT_EVENT_CALLBACK)(
typedef ULONG64 BTH_LE_GATT_RELIABLE_WRITE_CONTEXT, *PBTH_LE_GATT_RELIABLE_WRITE_CONTEXT;
-struct DeviceInfo
-{
- DeviceInfo(const QBluetoothAddress &address,
- const QString &name,
- const QString &systemPath);
- QBluetoothAddress address;
- QString name;
- QString systemPath;
-};
-
-struct DeviceDiscoveryResult
-{
- DeviceDiscoveryResult();
- QList<DeviceInfo> devices;
- DWORD error;
-};
-
struct ServicesDiscoveryResult
{
ServicesDiscoveryResult();
@@ -184,7 +167,6 @@ struct ServicesDiscoveryResult
bool isSupported();
bool hasLocalRadio();
-DeviceDiscoveryResult startDiscoveryOfRemoteDevices();
ServicesDiscoveryResult startDiscoveryOfPrimaryServices(HANDLE hDevice);
} // namespace WinLowEnergyBluetooth
diff --git a/src/bluetooth/windows/windows.pri b/src/bluetooth/windows/windows.pri
index 84e7200a..019d67e4 100644
--- a/src/bluetooth/windows/windows.pri
+++ b/src/bluetooth/windows/windows.pri
@@ -1,7 +1,5 @@
PRIVATE_HEADERS += \
- windows/qwinclassicbluetooth_p.h \
windows/qwinlowenergybluetooth_p.h
SOURCES += \
- windows/qwinclassicbluetooth.cpp \
windows/qwinlowenergybluetooth.cpp