diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-02-17 11:54:35 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-20 22:29:30 +0100 |
commit | 7326f1789db31fb69c98d7e37a25f08549c73454 (patch) | |
tree | 4b3f8849344bd342e8e28c825c885571f3d0070e /src | |
parent | dc75ca260e79b01cb5dcbf6682660c948a2935a3 (diff) |
Fix some BTLE service discovery issues
1.) In Bluez avoid incomplete and/or premature finish of service
discovery process.
2.) Add Testcode for
QBluetoothServiceInfo::serviceDiscovered(QLowEnergyServiceInfo) to
bttestui application
Change-Id: I037a6303862dcf2e29aef4b761731b13c85b29aa
Reviewed-by: Nedim Hadzic <nedimhadzija@gmail.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 9c65f056..c3a7a3e4 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -176,28 +176,26 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa delete adapter; adapter = 0; + QVariantMap deviceProperties; + QString classType; QDBusPendingReply<QVariantMap> deviceReply = device->GetProperties(); deviceReply.waitForFinished(); - if (deviceReply.isError()) { - qCDebug(QT_BT_BLUEZ) << "GetProperties error: " << error << deviceObjectPath.error().name(); - //TODO if we abort here who deletes device? - //TODO what happens to still pending discoveredDevices? - return; + if (!deviceReply.isError()) { + deviceProperties = deviceReply.value(); + classType = deviceProperties.value(QStringLiteral("Class")).toString(); } - QVariantMap deviceProperties = deviceReply.value(); - QString classType = deviceProperties.value(QStringLiteral("Class")).toString(); + /* * Low Energy services in bluez are represented as the list of the paths that can be * accessed with org.bluez.Characteristic */ //QDBusArgument services = v.value(QLatin1String("Services")).value<QDBusArgument>(); const QStringList deviceUuids = deviceProperties.value(QStringLiteral("UUIDs")).toStringList(); - for (int i = 0; i < deviceUuids.size(); i++) { QString b = deviceUuids.at(i); b = b.remove(QLatin1Char('{')).remove(QLatin1Char('}')); - //TODO this should be bit field and not String operations + //TODO this should be bit field and not string operations const QString leServiceCheck = QString(b.at(4)) + QString(b.at(5)); /* * In this part we want to emit only Bluetooth Low Energy service. BLE services @@ -207,27 +205,34 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa //TODO where is the uuidFilter match -> uuidFilter could contain a BLE uuid if ((leServiceCheck == QStringLiteral("18") || b.contains(QStringLiteral("000000000000"))) && uuidFilter.size() == 0) { + qCDebug(QT_BT_BLUEZ) << "Discovered BLE service" << deviceUuids.at(i) << leServiceCheck << uuidFilter.size() << b; QBluetoothUuid uuid(b); QLowEnergyServiceInfo lowEnergyService(uuid); //TODO Fix m_DeviceAdapterAddress may not be the actual address lowEnergyService.d_ptr->adapterAddress = m_deviceAdapterAddress; lowEnergyService.setDevice(discoveredDevices.at(0)); - q_ptr->serviceDiscovered(lowEnergyService); + emit q->serviceDiscovered(lowEnergyService); } - } + /* * Bluez v4.1 does not have extra bit which gives information if device is Bluetooth * Low Energy device and the way to discover it is with Class property of the Bluetooth device. * Low Energy devices do not have property Class. - * In case we have have LE device finish service discovery; otherwise search for regular services. + * In case we have LE device finish service discovery; otherwise search for regular services. */ - if (classType.isEmpty()) //is BLE device - //TODO is is not correct why finish here? We have other devices to discover... - //finished signal should not be emitted by this class - //Furthermore there is the assumption here that a BLE device cannot have std Bt service. Is that true? - q_ptr->finished(); - else { + if (classType.isEmpty()) { //is BLE device or device properties above not retrievable + qCDebug(QT_BT_BLUEZ) << "Discovered BLE-only device. Normal service discovery skipped."; + delete device; + device = 0; + + if (singleDevice && deviceReply.isError()) { + error = QBluetoothServiceDiscoveryAgent::InputOutputError; + errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to access device"); + emit q->error(error); + } + _q_serviceDiscoveryFinished(); + } else { QString pattern; foreach (const QBluetoothUuid &uuid, uuidFilter) pattern += uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}')) + QLatin1Char(' '); |