From 2a5f325733fa43961d785bf9a0d5c209bd8c5c76 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 2 Nov 2017 14:26:21 +0100 Subject: winrt: Reflect unsupported state of peripheral role of lowenergycontroller There currently is no API for supporting the peripheral role on winrt, but there is no way to reflect that inside our API. If a user tries to set up a low energy peripheral device, the application should not crash though. The crash occurred, when the controller was set up in a perihperal role and the application tried to read or write a descriptor or characteristic. In this case the functions should just return early. Task-number: QTBUG-63709 Change-Id: I30b277788d822f869743e1f294ee1402abd36309 Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycontroller_winrt.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp index e4ae76b0..8517a942 100644 --- a/src/bluetooth/qlowenergycontroller_winrt.cpp +++ b/src/bluetooth/qlowenergycontroller_winrt.cpp @@ -651,6 +651,7 @@ void QLowEnergyControllerPrivate::discoverServiceDetails(const QBluetoothUuid &s void QLowEnergyControllerPrivate::startAdvertising(const QLowEnergyAdvertisingParameters &, const QLowEnergyAdvertisingData &, const QLowEnergyAdvertisingData &) { + setError(QLowEnergyController::AdvertisingError); Q_UNIMPLEMENTED(); } @@ -669,6 +670,12 @@ void QLowEnergyControllerPrivate::readCharacteristic(const QSharedPointersetError(QLowEnergyService::CharacteristicReadError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << charHandle << "could not be found in service" << service->uuid; service->setError(QLowEnergyService::CharacteristicReadError); @@ -728,6 +735,12 @@ void QLowEnergyControllerPrivate::readDescriptor(const QSharedPointersetError(QLowEnergyService::DescriptorReadError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Descriptor" << descHandle << "in characteristic" << charHandle << "cannot be found in service" << service->uuid; @@ -854,6 +867,11 @@ void QLowEnergyControllerPrivate::writeCharacteristic(const QSharedPointersetError(QLowEnergyService::CharacteristicWriteError); + Q_UNIMPLEMENTED(); + return; + } if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Characteristic" << charHandle << "cannot be found in service" << service->uuid; service->setError(QLowEnergyService::CharacteristicWriteError); @@ -938,6 +956,12 @@ void QLowEnergyControllerPrivate::writeDescriptor( { qCDebug(QT_BT_WINRT) << __FUNCTION__ << service << charHandle << descHandle << newValue; Q_ASSERT(!service.isNull()); + if (role == QLowEnergyController::PeripheralRole) { + service->setError(QLowEnergyService::DescriptorWriteError); + Q_UNIMPLEMENTED(); + return; + } + if (!service->characteristicList.contains(charHandle)) { qCDebug(QT_BT_WINRT) << "Descriptor" << descHandle << "in characteristic" << charHandle << "could not be found in service" << service->uuid; -- cgit v1.2.3