summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-09-28 21:15:28 +0300
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-10-13 13:09:38 +0000
commit797624ac0c5f0a7ee3dd0a938454d55cb8786373 (patch)
treecb834888381805b491d373d63ef4a5c5e0b4a284 /src
parent3e7d0c6b62d2fd6acd2c8a64b8e007729843e088 (diff)
Windows: Simplify code related to enumerating of a local radios
It is the first stage to cleaning of the 'windows' directory. A shared code related to enumerating of a local adapters are moved to the QBluetoothLocalDevicePrivate class. Change-Id: I208b79c29cd1f906b6fed627d25c7b1310718581 Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp16
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_p.h6
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_win.cpp78
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth.cpp42
-rw-r--r--src/bluetooth/windows/qwinclassicbluetooth_p.h2
5 files changed, 50 insertions, 94 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
index 05f7091d..937bc2a4 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_win.cpp
@@ -36,6 +36,7 @@
#include "qbluetoothdevicediscoveryagent_p.h"
#include "qbluetoothaddress.h"
#include "qbluetoothuuid.h"
+#include "qbluetoothlocaldevice_p.h"
QT_BEGIN_NAMESPACE
@@ -171,20 +172,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::initialize(
bool QBluetoothDeviceDiscoveryAgentPrivate::isClassicAdapterValid(
const QBluetoothAddress &deviceAdapter)
{
- const WinClassicBluetooth::LocalRadiosDiscoveryResult result =
- WinClassicBluetooth::enumerateLocalRadios();
-
- if (!isDiscoveredSuccessfully(result.error)) {
- qCWarning(QT_BT_WINDOWS) << "Occurred error during search of classic local radios";
- return false;
- } else if (result.radios.isEmpty()) {
- qCWarning(QT_BT_WINDOWS) << "No any classic local radio found";
- return false;
- }
-
- foreach (const BLUETOOTH_RADIO_INFO &radio, result.radios) {
+ foreach (const QBluetoothHostInfo &adapterInfo, QBluetoothLocalDevicePrivate::localAdapters()) {
if (deviceAdapter == QBluetoothAddress()
- || deviceAdapter == QBluetoothAddress(radio.address.ullLong)) {
+ || deviceAdapter == adapterInfo.address()) {
return true;
}
}
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h
index 844be01b..66f5c1c0 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.h
+++ b/src/bluetooth/qbluetoothlocaldevice_p.h
@@ -79,10 +79,6 @@ QT_END_NAMESPACE
#include <QtCore/QPair>
#endif
-#ifdef Q_OS_WIN32
-#include "windows/qwinclassicbluetooth_p.h"
-#endif
-
QT_BEGIN_NAMESPACE
class QBluetoothAddress;
@@ -218,6 +214,8 @@ public:
bool isValid() const;
void initialize(const QBluetoothAddress &address);
+ static QList<QBluetoothHostInfo> localAdapters();
+
QBluetoothAddress deviceAddress;
QString deviceName;
bool deviceValid;
diff --git a/src/bluetooth/qbluetoothlocaldevice_win.cpp b/src/bluetooth/qbluetoothlocaldevice_win.cpp
index 4b1c252d..2ccf2b70 100644
--- a/src/bluetooth/qbluetoothlocaldevice_win.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_win.cpp
@@ -39,6 +39,9 @@
#include <QtCore/QLoggingCategory>
+#include <qt_windows.h>
+#include <bluetoothapis.h>
+
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINDOWS)
@@ -154,17 +157,7 @@ QList<QBluetoothAddress> QBluetoothLocalDevice::connectedDevices() const
QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
{
- const WinClassicBluetooth::LocalRadiosDiscoveryResult result =
- WinClassicBluetooth::enumerateLocalRadios();
-
- QList<QBluetoothHostInfo> devices;
- foreach (const BLUETOOTH_RADIO_INFO &radio, result.radios) {
- QBluetoothHostInfo device;
- device.setAddress(QBluetoothAddress(radio.address.ullLong));
- device.setName(QString::fromWCharArray(radio.szName));
- devices.append(device);
- }
- return devices;
+ return QBluetoothLocalDevicePrivate::localAdapters();
}
void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing)
@@ -206,29 +199,11 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
{
Q_Q(QBluetoothLocalDevice);
- const WinClassicBluetooth::LocalRadiosDiscoveryResult result =
- WinClassicBluetooth::enumerateLocalRadios();
-
- if (result.error != NO_ERROR
- && result.error != ERROR_NO_MORE_ITEMS) {
- qCWarning(QT_BT_WINDOWS) << qt_error_string(result.error);
- QMetaObject::invokeMethod(q, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::UnknownError));
- return;
- } else if (result.radios.isEmpty()) {
- qCWarning(QT_BT_WINDOWS) << "No any classic local radio found";
- QMetaObject::invokeMethod(q, "error", Qt::QueuedConnection,
- Q_ARG(QBluetoothLocalDevice::Error,
- QBluetoothLocalDevice::UnknownError));
- return;
- }
-
- foreach (const BLUETOOTH_RADIO_INFO &radio, result.radios) {
+ foreach (const QBluetoothHostInfo &adapterInfo, QBluetoothLocalDevicePrivate::localAdapters()) {
if (address == QBluetoothAddress()
- || address == QBluetoothAddress(radio.address.ullLong)) {
- deviceAddress = QBluetoothAddress(radio.address.ullLong);
- deviceName = QString::fromWCharArray(radio.szName);
+ || address == adapterInfo.address()) {
+ deviceAddress = adapterInfo.address();
+ deviceName = adapterInfo.name();
deviceValid = true;
return;
}
@@ -240,4 +215,41 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address)
QBluetoothLocalDevice::UnknownError));
}
+QList<QBluetoothHostInfo> QBluetoothLocalDevicePrivate::localAdapters()
+{
+ BLUETOOTH_FIND_RADIO_PARAMS params;
+ ::ZeroMemory(&params, sizeof(params));
+ params.dwSize = sizeof(params);
+
+ QList<QBluetoothHostInfo> foundAdapters;
+
+ HANDLE hRadio = 0;
+ if (const HBLUETOOTH_RADIO_FIND hSearch = ::BluetoothFindFirstRadio(&params, &hRadio)) {
+ 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)
+ break;
+
+ QBluetoothHostInfo adapterInfo;
+ adapterInfo.setAddress(QBluetoothAddress(radio.address.ullLong));
+ adapterInfo.setName(QString::fromWCharArray(radio.szName));
+
+ foundAdapters << adapterInfo;
+
+ if (!::BluetoothFindNextRadio(hSearch, &hRadio))
+ break;
+ }
+
+ ::BluetoothFindRadioClose(hSearch);
+ }
+
+ return foundAdapters;
+}
+
QT_END_NAMESPACE
diff --git a/src/bluetooth/windows/qwinclassicbluetooth.cpp b/src/bluetooth/windows/qwinclassicbluetooth.cpp
index 44a73c9e..88313ed7 100644
--- a/src/bluetooth/windows/qwinclassicbluetooth.cpp
+++ b/src/bluetooth/windows/qwinclassicbluetooth.cpp
@@ -51,48 +51,6 @@ RemoteDeviceDiscoveryResult::RemoteDeviceDiscoveryResult()
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;
diff --git a/src/bluetooth/windows/qwinclassicbluetooth_p.h b/src/bluetooth/windows/qwinclassicbluetooth_p.h
index 87c4093c..2ba255ce 100644
--- a/src/bluetooth/windows/qwinclassicbluetooth_p.h
+++ b/src/bluetooth/windows/qwinclassicbluetooth_p.h
@@ -61,8 +61,6 @@ struct RemoteDeviceDiscoveryResult
DWORD error;
};
-LocalRadiosDiscoveryResult enumerateLocalRadios();
-
RemoteDeviceDiscoveryResult startDiscoveryOfFirstRemoteDevice();
RemoteDeviceDiscoveryResult startDiscoveryOfNextRemoteDevice(HBLUETOOTH_DEVICE_FIND hSearch);
void cancelRemoteDevicesDiscovery(HBLUETOOTH_DEVICE_FIND hSearch);