diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-08-21 12:15:20 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-09-03 08:38:55 +0200 |
commit | 5a694018992051a3c99339d5860eda4bbb703275 (patch) | |
tree | 6e9cf5f194873509fac7abc3c730184b929cb0ef /src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | |
parent | da7ccfcd08c587283f4656b30ca15011ebdbeb5c (diff) |
Remove QLowEnergyServiceInfo
There is no need for this class anymore as QBluetoothServiceInfo
covers the same information.
Change-Id: I411a8abb68b34a3a4893a67ee9fac096f44bbd62
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index f3b14d4d..fb956c9e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -33,7 +33,6 @@ #include "qbluetoothservicediscoveryagent.h" #include "qbluetoothservicediscoveryagent_p.h" -#include "qlowenergyserviceinfo_p.h" #include "bluez/manager_p.h" #include "bluez/adapter_p.h" @@ -300,8 +299,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD emit q->error(error); } else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) { foreach (const QString &record, xmlRecords) { - bool isBtleService = false; - const QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService); + const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); //apply uuidFilter if (!uuidFilter.isEmpty()) { @@ -436,19 +434,31 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa b = b.remove(QLatin1Char('{')).remove(QLatin1Char('}')); const QBluetoothUuid uuid(b); - qCDebug(QT_BT_BLUEZ) << "Discovered BLE service" << uuid << uuidFilter.size(); - QLowEnergyServiceInfo lowEnergyService(uuid); - lowEnergyService.setDevice(discoveredDevices.at(0)); + qCDebug(QT_BT_BLUEZ) << "Discovered service" << uuid << uuidFilter.size(); + QBluetoothServiceInfo service; + service.setDevice(discoveredDevices.at(0)); + bool ok = false; + quint16 serviceClass = uuid.toUInt16(&ok); + if (ok) + service.setServiceName(QBluetoothUuid::serviceClassToString( + static_cast<QBluetoothUuid::ServiceClassUuid>(serviceClass))); + + QBluetoothServiceInfo::Sequence classId; + classId << QVariant::fromValue(uuid); + service.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); + + QBluetoothServiceInfo::Sequence protocolDescriptorList; + protocolDescriptorList << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); + if (uuidFilter.isEmpty()) - emit q->serviceDiscovered(lowEnergyService); + emit q->serviceDiscovered(service); else { for (int j = 0; j < uuidFilter.size(); j++) { if (uuidFilter.at(j) == uuid) - emit q->serviceDiscovered(lowEnergyService); - + emit q->serviceDiscovered(service); } } - } if (singleDevice && deviceReply.isError()) { @@ -503,14 +513,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC foreach (const QString &record, reply.value()) { - bool isBtleService = false; - QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService); - - if (isBtleService) { - qCDebug(QT_BT_BLUEZ) << "Discovered BLE services" << discoveredDevices.at(0).address().toString() - << serviceInfo.serviceName() << serviceInfo.serviceUuid() << serviceInfo.serviceClassUuids(); - continue; - } + QBluetoothServiceInfo serviceInfo = parseServiceXml(record); if (!serviceInfo.isValid()) continue; @@ -554,7 +557,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC } QBluetoothServiceInfo QBluetoothServiceDiscoveryAgentPrivate::parseServiceXml( - const QString& xmlRecord, bool *isBtleService) + const QString& xmlRecord) { QXmlStreamReader xml(xmlRecord); @@ -570,25 +573,7 @@ QBluetoothServiceInfo QBluetoothServiceDiscoveryAgentPrivate::parseServiceXml( xml.attributes().value(QLatin1String("id")).toString().toUShort(0, 0); if (xml.readNextStartElement()) { - QVariant value = readAttributeValue(xml); - if (isBtleService) { - if (attributeId == 1) {// Attribute with id 1 contains UUID of the service - const QBluetoothServiceInfo::Sequence seq = - value.value<QBluetoothServiceInfo::Sequence>(); - for (int i = 0; i < seq.count(); i++) { - const QBluetoothUuid uuid = seq.at(i).value<QBluetoothUuid>(); - if ((uuid.data1 & 0x1800) == 0x1800) {// We are taking into consideration that LE services starts at 0x1800 - //TODO don't emit in the middle of nowhere - Q_Q(QBluetoothServiceDiscoveryAgent); - QLowEnergyServiceInfo leService(uuid); - leService.setDevice(discoveredDevices.at(0)); - *isBtleService = true; - emit q->serviceDiscovered(leService); - break; - } - } - } - } + const QVariant value = readAttributeValue(xml); serviceInfo.setAttribute(attributeId, value); } } @@ -655,7 +640,6 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons if (!uuidFilter.isEmpty() && !uuidFilter.contains(uuid)) continue; - // TODO deal with BTLE services under Bluez 5 -> right now they are normal services QBluetoothServiceInfo serviceInfo; serviceInfo.setDevice(discoveredDevices.at(0)); @@ -672,6 +656,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons serviceInfo.setServiceName(QBluetoothUuid::serviceClassToString(clsId)); } + QBluetoothServiceInfo::Sequence protocolDescriptorList; + protocolDescriptorList << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); + //don't include the service if we already discovered it before if (!isDuplicatedService(serviceInfo)) { discoveredServices << serviceInfo; |