summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/windows
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-11-19 20:01:15 +0300
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-12-01 15:17:22 +0100
commit11095f3504515f0ec2a754f64f97719340247505 (patch)
tree74c64183fbb5cd6457bd956da574585c35b8ab9e /src/bluetooth/windows
parenta3c295297a4ee1365619cc49f504a9f35b4f7785 (diff)
Refactor of code for "classic" part on Windows
The previous code is based on the assumption where we can use each of local radio separatelly to discovery of remote devices. Windows API allows to use a handle of separately local bluetooth adapter to operate with its power, to start/stop detection of remote devices through it and so on. But in this API there is no opportunity to enumerate services and attributes of the given remote device via the concrete local adapter. Therefore now to discovery of remote devices are used all local bluetooth adapters in system. Also, the power and the host modes management now are belongs to all local adapters at once. Tested on Windows 8 with the USB CSR8510 A10 adapter Change-Id: I949b112158a575f5b563a78163c1e3990c952ada Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/windows')
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth.cpp136
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth_p.h77
-rw-r--r--src/bluetooth/windows/windows.pri5
3 files changed, 218 insertions, 0 deletions
diff --git a/src/bluetooth/windows/qwinclassicbluetooth.cpp b/src/bluetooth/windows/qwinclassicbluetooth.cpp
new file mode 100644
index 00000000..31212d8e
--- /dev/null
+++ b/src/bluetooth/windows/qwinclassicbluetooth.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt 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);
+}
+
+LocalRadiosDiscoveryResult enumerateLocalRadios()
+{
+ BLUETOOTH_FIND_RADIO_PARAMS params;
+ ::ZeroMemory(&params, sizeof(params));
+ params.dwSize = sizeof(params);
+
+ HANDLE hRadio = 0;
+ const HBLUETOOTH_RADIO_FIND hSearch =
+ ::BluetoothFindFirstRadio(&params, &hRadio);
+
+ LocalRadiosDiscoveryResult result;
+
+ if (!hSearch) {
+ result.error = ::GetLastError();
+ return result;
+ }
+
+ forever {
+ BLUETOOTH_RADIO_INFO radio;
+ ::ZeroMemory(&radio, sizeof(radio));
+ radio.dwSize = sizeof(radio);
+
+ const DWORD retval = ::BluetoothGetRadioInfo(hRadio, &radio);
+ ::CloseHandle(hRadio);
+
+ if (retval != ERROR_SUCCESS) {
+ result.error = ::GetLastError();
+ break;
+ }
+
+ result.radios.append(radio);
+
+ if (!::BluetoothFindNextRadio(hSearch, &hRadio)) {
+ result.error = ::GetLastError();
+ break;
+ }
+ }
+
+ ::BluetoothFindRadioClose(hSearch);
+ return result;
+}
+
+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
new file mode 100644
index 00000000..9c0955bf
--- /dev/null
+++ b/src/bluetooth/windows/qwinclassicbluetooth_p.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt 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;
+};
+
+LocalRadiosDiscoveryResult enumerateLocalRadios();
+
+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/windows.pri b/src/bluetooth/windows/windows.pri
new file mode 100644
index 00000000..f08e0497
--- /dev/null
+++ b/src/bluetooth/windows/windows.pri
@@ -0,0 +1,5 @@
+PRIVATE_HEADERS += \
+ windows/qwinclassicbluetooth_p.h
+
+SOURCES += \
+ windows/qwinclassicbluetooth.cpp