summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2020-02-04 08:12:40 +0100
committerOliver Wolff <oliver.wolff@qt.io>2020-02-06 09:42:50 +0100
commitf4c68cb2fc894f1ff5a9271637d006095c2274d1 (patch)
treec9f14735894d811d656381d2c4a83a5f07f986ec /src
parentdb6cd4110594abe09079ed4106d8fd30a848efa4 (diff)
winrt: set proper state on service detail discovery fail
If the service detail discovery fails, we do not only have to set a proper error but the service state also has to be set accordingly. Task-number: QTBUG-80770 Change-Id: I6abc28875c998b60efcfc513542765a52e19df90 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Miguel Costa <miguel.costa@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_new.cpp53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt_new.cpp b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
index a22064fd..f951d1a6 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_new.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt_new.cpp
@@ -833,6 +833,13 @@ void QLowEnergyControllerPrivateWinRTNew::discoverServiceDetails(const QBluetoot
return;
}
+ auto reactOnDiscoveryError = [](QSharedPointer<QLowEnergyServicePrivate> service,
+ const QString &msg)
+ {
+ qCDebug(QT_BT_WINRT) << msg;
+ service->setError(QLowEnergyService::UnknownError);
+ service->setState(QLowEnergyService::DiscoveryRequired);
+ };
//update service data
QSharedPointer<QLowEnergyServicePrivate> pointer = serviceList.value(service);
qCDebug(QT_BT_WINRT_SERVICE_THREAD) << __FUNCTION__ << "Changing service pointer from thread"
@@ -840,31 +847,43 @@ void QLowEnergyControllerPrivateWinRTNew::discoverServiceDetails(const QBluetoot
pointer->setState(QLowEnergyService::DiscoveringServices);
ComPtr<IGattDeviceService3> deviceService3;
HRESULT hr = deviceService.As(&deviceService3);
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not cast service",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer, QStringLiteral("Could not cast service: %1").arg(hr));
+ return;
+ }
ComPtr<IAsyncOperation<GattDeviceServicesResult *>> op;
hr = deviceService3->GetIncludedServicesAsync(&op);
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not obtain included service list",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer, QStringLiteral("Could not obtain included service list: %1").arg(hr));
+ return;
+ }
ComPtr<IGattDeviceServicesResult> result;
hr = QWinRTFunctions::await(op, result.GetAddressOf());
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not await service operation",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer, QStringLiteral("Could not await service operation: %1").arg(hr));
+ return;
+ }
GattCommunicationStatus status;
hr = result->get_Status(&status);
if (FAILED(hr) || status != GattCommunicationStatus_Success) {
- qCDebug(QT_BT_WINRT) << "Obtaining list of included services failed";
- pointer->setError(QLowEnergyService::UnknownError);
+ reactOnDiscoveryError(pointer,
+ QStringLiteral("Obtaining list of included services failed: %1").arg(hr));
return;
}
ComPtr<IVectorView<GattDeviceService *>> deviceServices;
hr = result->get_Services(&deviceServices);
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not obtain service list from result",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer,
+ QStringLiteral("Could not obtain service list from result: %1").arg(hr));
+ return;
+ }
uint serviceCount;
hr = deviceServices->get_Size(&serviceCount);
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not obtain included service list's size",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer,
+ QStringLiteral("Could not obtain included service list's size: %1").arg(hr));
+ return;
+ }
for (uint i = 0; i < serviceCount; ++i) {
ComPtr<IGattDeviceService> includedService;
hr = deviceServices->GetAt(i, &includedService);
@@ -897,7 +916,7 @@ void QLowEnergyControllerPrivateWinRTNew::discoverServiceDetails(const QBluetoot
connect(worker, &QWinRTLowEnergyServiceHandlerNew::errorOccured,
this, &QLowEnergyControllerPrivateWinRTNew::handleServiceHandlerError);
connect(worker, &QWinRTLowEnergyServiceHandlerNew::charListObtained,
- [this, thread](const QBluetoothUuid &service, QHash<QLowEnergyHandle,
+ [this, reactOnDiscoveryError, thread](const QBluetoothUuid &service, QHash<QLowEnergyHandle,
QLowEnergyServicePrivate::CharData> charList, QVector<QBluetoothUuid> indicateChars,
QLowEnergyHandle startHandle, QLowEnergyHandle endHandle) {
if (!serviceList.contains(service)) {
@@ -917,8 +936,12 @@ void QLowEnergyControllerPrivateWinRTNew::discoverServiceDetails(const QBluetoot
registerForValueChanges(service, indicateChar);
return S_OK;
});
- CHECK_HR_AND_SET_SERVICE_ERROR(hr, "Could not register for value changes in Xaml thread",
- pointer, QLowEnergyService::UnknownError, return)
+ if (FAILED(hr)) {
+ reactOnDiscoveryError(pointer,
+ QStringLiteral("Could not register for value changes in Xaml thread: %1").arg(hr));
+ thread->exit(0);
+ return;
+ }
pointer->setState(QLowEnergyService::ServiceDiscovered);
thread->exit(0);