diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2019-03-29 13:53:40 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2019-04-10 09:12:19 +0000 |
commit | a1f63352338ba8bd6b212a393f9f45e0c817008c (patch) | |
tree | 1d42f354e9e022ee724e10be4f29ed3fcf6f941f | |
parent | cddb1c96c6b5d3f2e5e3715bfda6721fb31410c6 (diff) |
winrt: Avoid asserts in getNativeCharacteristic
Change-Id: I4a555222071c75a56b45477b1a894b929ffc1e58
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/bluetooth/qlowenergycontroller_winrt_new.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new.cpp b/src/bluetooth/qlowenergycontroller_winrt_new.cpp index 9c543b6d..a6514188 100644 --- a/src/bluetooth/qlowenergycontroller_winrt_new.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt_new.cpp @@ -644,9 +644,30 @@ ComPtr<IGattCharacteristic> QLowEnergyControllerPrivateWinRTNew::getNativeCharac if (!service) return nullptr; - ComPtr<IVectorView<GattCharacteristic *>> characteristics; - HRESULT hr = service->GetCharacteristics(charUuid, &characteristics); + ComPtr<IGattDeviceService3> service3; + HRESULT hr = service.As(&service3); + RETURN_IF_FAILED("Could not cast service", return nullptr); + + ComPtr<IAsyncOperation<GattCharacteristicsResult *>> op; + ComPtr<IGattCharacteristicsResult> result; + hr = service3->GetCharacteristicsForUuidAsync(charUuid, &op); RETURN_IF_FAILED("Could not obtain native characteristics for service", return nullptr); + hr = QWinRTFunctions::await(op, result.GetAddressOf(), QWinRTFunctions::ProcessMainThreadEvents, 5000); + RETURN_IF_FAILED("Could not await completion of characteristic operation", return nullptr); + GattCommunicationStatus status; + hr = result->get_Status(&status); + if (FAILED(hr) || status != GattCommunicationStatus_Success) { + qErrnoWarning(hr, "Native characteristic operation failed."); + return nullptr; + } + ComPtr<IVectorView<GattCharacteristic *>> characteristics; + hr = result->get_Characteristics(&characteristics); + RETURN_IF_FAILED("Could not obtain characteristic list.", return nullptr); + uint size; + hr = characteristics->get_Size(&size); + RETURN_IF_FAILED("Could not obtain characteristic list's size.", return nullptr); + if (size != 1) + qErrnoWarning("More than 1 characteristic found."); ComPtr<IGattCharacteristic> characteristic; hr = characteristics->GetAt(0, &characteristic); RETURN_IF_FAILED("Could not obtain first characteristic for service", return nullptr); |