summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/windows
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-12-08 19:47:03 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2014-12-10 13:42:47 +0100
commitfd96b0aa5ae37188f63e6bd1503024c1b5b3cf60 (patch)
tree63fdd9a4c000fe44dab13b58f361709a902f13a1 /src/bluetooth/windows
parentee9a7a91abda21d66a3162da1273bbe1e69adf23 (diff)
Add discovering of primary GATT services on Windows
It is still partially implemented where are discovered only the primary services UUID's. Change-Id: I2765a8f83be4716cfe875a2f7a3593ba1af211a4 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/windows')
-rw-r--r--src/bluetooth/windows/qwinlowenergybluetooth.cpp31
-rw-r--r--src/bluetooth/windows/qwinlowenergybluetooth_p.h9
2 files changed, 40 insertions, 0 deletions
diff --git a/src/bluetooth/windows/qwinlowenergybluetooth.cpp b/src/bluetooth/windows/qwinlowenergybluetooth.cpp
index 275c5f64..5fe4e16b 100644
--- a/src/bluetooth/windows/qwinlowenergybluetooth.cpp
+++ b/src/bluetooth/windows/qwinlowenergybluetooth.cpp
@@ -182,6 +182,11 @@ DeviceDiscoveryResult::DeviceDiscoveryResult()
{
}
+ServicesDiscoveryResult::ServicesDiscoveryResult()
+ : error(NO_ERROR)
+{
+}
+
static DeviceDiscoveryResult availableSystemInterfaces(
const GUID &deviceInterface)
{
@@ -312,6 +317,32 @@ DeviceDiscoveryResult startDiscoveryOfRemoteDevices()
QUuid("781aee18-7733-4ce4-add0-91f41c67b592"));
}
+ServicesDiscoveryResult startDiscoveryOfPrimaryServices(
+ HANDLE hDevice)
+{
+ ServicesDiscoveryResult result;
+ USHORT servicesCount = 0;
+ forever {
+ const HRESULT hr = BluetoothGATTGetServices(
+ hDevice,
+ result.services.count(),
+ result.services.isEmpty() ? NULL : &result.services[0],
+ &servicesCount,
+ BLUETOOTH_GATT_FLAG_NONE);
+
+ if (hr == HRESULT_FROM_WIN32(ERROR_MORE_DATA)) {
+ result.services.resize(servicesCount);
+ } else if (hr == S_OK) {
+ break;
+ } else {
+ result.error = ::GetLastError();
+ result.services.clear();
+ break;
+ }
+ }
+ return result;
+}
+
bool isSupported()
{
static bool resolved = resolveFunctions(bluetoothapis());
diff --git a/src/bluetooth/windows/qwinlowenergybluetooth_p.h b/src/bluetooth/windows/qwinlowenergybluetooth_p.h
index d7987966..cf83f331 100644
--- a/src/bluetooth/windows/qwinlowenergybluetooth_p.h
+++ b/src/bluetooth/windows/qwinlowenergybluetooth_p.h
@@ -36,6 +36,7 @@
#define QWINLOWENERGYBLUETOOTH_P_H
#include <QtCore/qstringlist.h>
+#include <QtCore/qvector.h>
#include <QtBluetooth/qbluetoothaddress.h>
@@ -173,10 +174,18 @@ struct DeviceDiscoveryResult
DWORD error;
};
+struct ServicesDiscoveryResult
+{
+ ServicesDiscoveryResult();
+ QVector<BTH_LE_GATT_SERVICE> services;
+ DWORD error;
+};
+
bool isSupported();
bool hasLocalRadio();
DeviceDiscoveryResult startDiscoveryOfRemoteDevices();
+ServicesDiscoveryResult startDiscoveryOfPrimaryServices(HANDLE hDevice);
} // namespace WinLowEnergyBluetooth