summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2016-10-04 13:04:27 +0200
committerOliver Wolff <oliver.wolff@qt.io>2016-10-04 11:28:34 +0000
commitbd7dda4614eb776c40a1eb3b6f1bbe531fa8abb5 (patch)
tree9c58e09a79ba088e6cda252f09c806cb68331ab0
parentd6fd07c9260f5a1411f8e6468182f1096344b146 (diff)
winrt: Added missing error handling to device discovery and low energy
Task-number: QTBUG-56191 Task-number: QTBUG-56219 Change-Id: I8ad3dc392d09055418b0dca3794386e53f287307 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp51
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp13
2 files changed, 44 insertions, 20 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
index ab2524a2..3ff53c89 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_winrt.cpp
@@ -72,7 +72,7 @@ QBluetoothDeviceInfo bluetoothInfoFromDeviceId(HSTRING deviceId)
ComPtr<IAsyncOperation<BluetoothDevice *>> deviceFromIdOperation;
hr = deviceStatics->FromIdAsync(deviceId, &deviceFromIdOperation);
WARN_AND_RETURN_IF_FAILED("Could not obtain bluetooth device from id", return QBluetoothDeviceInfo());
- QWinRTFunctions::await(deviceFromIdOperation, device.GetAddressOf());
+ hr = QWinRTFunctions::await(deviceFromIdOperation, device.GetAddressOf());
WARN_AND_RETURN_IF_FAILED("Could not wait for bluetooth device operation to finish", return QBluetoothDeviceInfo());
if (!device)
return QBluetoothDeviceInfo();
@@ -80,24 +80,32 @@ QBluetoothDeviceInfo bluetoothInfoFromDeviceId(HSTRING deviceId)
HString name;
ComPtr<IBluetoothClassOfDevice> classOfDevice;
UINT32 classOfDeviceInt;
- device->get_BluetoothAddress(&address);
- device->get_Name(name.GetAddressOf());
+ hr = device->get_BluetoothAddress(&address);
+ WARN_AND_RETURN_IF_FAILED("Could not obtain device's bluetooth address", return QBluetoothDeviceInfo());
+ hr = device->get_Name(name.GetAddressOf());
+ WARN_AND_RETURN_IF_FAILED("Could not obtain device's name", return QBluetoothDeviceInfo());
const QString btName = QString::fromWCharArray(WindowsGetStringRawBuffer(name.Get(), nullptr));
- device->get_ClassOfDevice(&classOfDevice);
- classOfDevice->get_RawValue(&classOfDeviceInt);
+ hr = device->get_ClassOfDevice(&classOfDevice);
+ WARN_AND_RETURN_IF_FAILED("Could not obtain device's ckass", return QBluetoothDeviceInfo());
+ hr = classOfDevice->get_RawValue(&classOfDeviceInt);
+ WARN_AND_RETURN_IF_FAILED("Could not obtain raw device value", return QBluetoothDeviceInfo());
IVectorView <Rfcomm::RfcommDeviceService *> *deviceServices;
hr = device->get_RfcommServices(&deviceServices);
WARN_AND_RETURN_IF_FAILED("Could not obtain bluetooth device services", return QBluetoothDeviceInfo());
uint serviceCount;
- deviceServices->get_Size(&serviceCount);
+ hr = deviceServices->get_Size(&serviceCount);
+ Q_ASSERT_SUCCEEDED(hr);
QList<QBluetoothUuid> uuids;
for (uint i = 0; i < serviceCount; ++i) {
ComPtr<Rfcomm::IRfcommDeviceService> service;
- deviceServices->GetAt(i, &service);
+ hr = deviceServices->GetAt(i, &service);
+ Q_ASSERT_SUCCEEDED(hr);
ComPtr<Rfcomm::IRfcommServiceId> id;
- service->get_ServiceId(&id);
+ hr = service->get_ServiceId(&id);
+ Q_ASSERT_SUCCEEDED(hr);
GUID uuid;
- id->get_Uuid(&uuid);
+ hr = id->get_Uuid(&uuid);
+ Q_ASSERT_SUCCEEDED(hr);
uuids.append(QBluetoothUuid(uuid));
}
@@ -121,27 +129,32 @@ QBluetoothDeviceInfo bluetoothInfoFromLeDeviceId(HSTRING deviceId)
ComPtr<IAsyncOperation<BluetoothLEDevice *>> deviceFromIdOperation;
hr = deviceStatics->FromIdAsync(deviceId, &deviceFromIdOperation);
WARN_AND_RETURN_IF_FAILED("Could not obtain bluetooth LE device from id", return QBluetoothDeviceInfo());
- QWinRTFunctions::await(deviceFromIdOperation, device.GetAddressOf());
+ hr = QWinRTFunctions::await(deviceFromIdOperation, device.GetAddressOf());
WARN_AND_RETURN_IF_FAILED("Could not wait for bluetooth LE device operation to finish", return QBluetoothDeviceInfo());
if (!device)
return QBluetoothDeviceInfo();
UINT64 address;
HString name;
- device->get_BluetoothAddress(&address);
- device->get_Name(name.GetAddressOf());
+ hr = device->get_BluetoothAddress(&address);
+ WARN_AND_RETURN_IF_FAILED("Could not obtain device's bluetooth address", return QBluetoothDeviceInfo());
+ hr = device->get_Name(name.GetAddressOf());
+ WARN_AND_RETURN_IF_FAILED("Could not obtain device's name", return QBluetoothDeviceInfo());
const QString btName = QString::fromWCharArray(WindowsGetStringRawBuffer(name.Get(), nullptr));
IVectorView <GenericAttributeProfile::GattDeviceService *> *deviceServices;
hr = device->get_GattServices(&deviceServices);
WARN_AND_RETURN_IF_FAILED("Could not obtain bluetooth LE device services", return QBluetoothDeviceInfo());
uint serviceCount;
- deviceServices->get_Size(&serviceCount);
+ hr = deviceServices->get_Size(&serviceCount);
+ Q_ASSERT_SUCCEEDED(hr);
QList<QBluetoothUuid> uuids;
for (uint i = 0; i < serviceCount; ++i) {
ComPtr<GenericAttributeProfile::IGattDeviceService> service;
- deviceServices->GetAt(i, &service);
+ hr = deviceServices->GetAt(i, &service);
+ Q_ASSERT_SUCCEEDED(hr);
ComPtr<Rfcomm::IRfcommServiceId> id;
GUID uuid;
- service->get_Uuid(&uuid);
+ hr = service->get_Uuid(&uuid);
+ Q_ASSERT_SUCCEEDED(hr);
uuids.append(QBluetoothUuid(uuid));
}
@@ -208,7 +221,7 @@ private:
ComPtr<IAsyncOperation<DeviceInformationCollection *>> op;
hr = deviceInformationStatics->FindAllAsyncAqsFilter(deviceSelector.Get(), &op);
WARN_AND_RETURN_IF_FAILED("Could not start bluetooth device discovery operation", return);
- op->put_Completed(
+ hr = op->put_Completed(
Callback<IAsyncOperationCompletedHandler<DeviceInformationCollection *>>([this, mode](IAsyncOperation<DeviceInformationCollection *> *op, AsyncStatus) {
onDeviceDiscoveryFinished(op, mode);
return S_OK;
@@ -236,7 +249,9 @@ private:
void onDeviceAdded(IDeviceInformation *deviceInfo, QBluetoothDeviceDiscoveryAgent::DiscoveryMethod mode)
{
HString deviceId;
- deviceInfo->get_Id(deviceId.GetAddressOf());
+ HRESULT hr;
+ hr = deviceInfo->get_Id(deviceId.GetAddressOf());
+ Q_ASSERT_SUCCEEDED(hr);
const QBluetoothDeviceInfo info = mode == QBluetoothDeviceDiscoveryAgent::LowEnergyMethod
? bluetoothInfoFromLeDeviceId(deviceId.Get())
: bluetoothInfoFromDeviceId(deviceId.Get());
@@ -267,10 +282,12 @@ private:
{
quint32 deviceCount;
HRESULT hr = devices->get_Size(&deviceCount);
+ Q_ASSERT_SUCCEEDED(hr);
deviceList.reserve(deviceList.length() + deviceCount);
for (quint32 i = 0; i < deviceCount; ++i) {
ComPtr<IDeviceInformation> device;
hr = devices->GetAt(i, &device);
+ Q_ASSERT_SUCCEEDED(hr);
onDeviceAdded(device.Get(), mode);
}
}
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index 7de12d2c..25371e74 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -79,7 +79,8 @@ static QVector<QBluetoothUuid> getIncludedServiceIds(const ComPtr<IGattDeviceSer
Q_ASSERT_SUCCEEDED(hr);
uint count;
- includedServices->get_Size(&count);
+ hr = includedServices->get_Size(&count);
+ Q_ASSERT_SUCCEEDED(hr);
for (uint i = 0; i < count; ++i) {
ComPtr<IGattDeviceService> includedService;
hr = includedServices->GetAt(i, &includedService);
@@ -154,6 +155,7 @@ public slots:
uint characteristicsCount;
hr = characteristics->get_Size(&characteristicsCount);
+ Q_ASSERT_SUCCEEDED(hr);
for (uint i = 0; i < characteristicsCount; ++i) {
ComPtr<IGattCharacteristic> characteristic;
hr = characteristics->GetAt(i, &characteristic);
@@ -178,6 +180,7 @@ public slots:
if (charData.properties & QLowEnergyCharacteristic::Read) {
ComPtr<IAsyncOperation<GattReadResult *>> readOp;
hr = characteristic->ReadValueWithCacheModeAsync(BluetoothCacheMode_Uncached, &readOp);
+ Q_ASSERT_SUCCEEDED(hr);
ComPtr<IGattReadResult> readResult;
hr = QWinRTFunctions::await(readOp, readResult.GetAddressOf());
Q_ASSERT_SUCCEEDED(hr);
@@ -314,7 +317,9 @@ void QLowEnergyControllerPrivate::connectToDevice()
HRESULT hr;
hr = mDevice->add_ConnectionStatusChanged(Callback<StatusHandler>([this, q](IBluetoothLEDevice *dev, IInspectable *) {
BluetoothConnectionStatus status;
- dev->get_ConnectionStatus(&status);
+ HRESULT hr;
+ hr = dev->get_ConnectionStatus(&status);
+ Q_ASSERT_SUCCEEDED(hr);
if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Connected) {
setState(QLowEnergyController::ConnectedState);
emit q->connected();
@@ -327,6 +332,7 @@ void QLowEnergyControllerPrivate::connectToDevice()
Q_ASSERT_SUCCEEDED(hr);
return S_OK;
});
+ Q_ASSERT_SUCCEEDED(hr);
if (status == BluetoothConnectionStatus::BluetoothConnectionStatus_Connected) {
setState(QLowEnergyController::ConnectedState);
@@ -438,7 +444,8 @@ void QLowEnergyControllerPrivate::obtainIncludedServices(QSharedPointer<QLowEner
Q_ASSERT_SUCCEEDED(hr);
uint count;
- includedServices->get_Size(&count);
+ hr = includedServices->get_Size(&count);
+ Q_ASSERT_SUCCEEDED(hr);
for (uint i = 0; i < count; ++i) {
ComPtr<IGattDeviceService> includedService;
hr = includedServices->GetAt(i, &includedService);