summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-03 09:23:25 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-03 09:23:25 +0200
commitf78b5f54d8c7536257629ad39bc300e233584949 (patch)
treee919f3f79a97e14fe927e840b2ad845d5ee92ee3 /src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
parentd2c043d9bb1172f37b3d9051b0483c4a0f3a5d05 (diff)
parentcb6bdcb3fb94a38613304b60724e0cd02962cd14 (diff)
Merge branch 'dev' into btle
Conflicts: src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp Change-Id: Ib960b9e8d8800af84d2094bdf26c2652d4c81dba
Diffstat (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp')
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index 7d2f1b1c..8e5c3aaa 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -155,38 +155,17 @@ void QBluetoothServiceDiscoveryAgentPrivate::startBluez5(const QBluetoothAddress
if (foundHostAdapterPath.isEmpty()) {
// check that we match adapter addresses or use first if it wasn't specified
- QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
- reply.waitForFinished();
- if (reply.isError()) {
+ bool ok = false;
+ foundHostAdapterPath = findAdapterForAddress(m_deviceAdapterAddress, &ok);
+ if (!ok) {
discoveredDevices.clear();
error = QBluetoothServiceDiscoveryAgent::InputOutputError;
- errorString = reply.error().message();
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot access adapter during service discovery");
emit q->error(error);
_q_serviceDiscoveryFinished();
return;
}
- const QString desiredAdapter = m_deviceAdapterAddress.toString();
- foreach (const QDBusObjectPath &path, reply.value().keys()) {
- const InterfaceList ifaceList = reply.value().value(path);
- foreach (const QString &iface, ifaceList.keys()) {
- if (iface == QStringLiteral("org.bluez.Adapter1")) {
- if (m_deviceAdapterAddress.isNull()
- || desiredAdapter == ifaceList.value(iface).
- value(QStringLiteral("Address")).toString()) {
- // use first adapter or we just matched one
- foundHostAdapterPath = path.path();
- }
-
- if (!foundHostAdapterPath.isEmpty())
- break;
- }
- }
-
- if (!foundHostAdapterPath.isEmpty())
- break;
- }
-
if (foundHostAdapterPath.isEmpty()) {
// Cannot find a local adapter
// Abort any outstanding discoveries
@@ -551,7 +530,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
foreach (const QString &record, reply.value()) {
bool isBtleService = false;
- const QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService);
+ QBluetoothServiceInfo serviceInfo = parseServiceXml(record, &isBtleService);
if (isBtleService) {
qCDebug(QT_BT_BLUEZ) << "Discovered BLE services" << discoveredDevices.at(0).address().toString()
@@ -566,6 +545,20 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
// search pattern during DiscoverServices() call
Q_Q(QBluetoothServiceDiscoveryAgent);
+ // Some service uuids are unknown to Bluez. In such cases we fall back
+ // to our own naming resolution.
+ if (serviceInfo.serviceName().isEmpty()
+ && !serviceInfo.serviceClassUuids().isEmpty()) {
+ foreach (const QBluetoothUuid &classUuid, serviceInfo.serviceClassUuids()) {
+ bool ok = false;
+ QBluetoothUuid::ServiceClassUuid clsId
+ = static_cast<QBluetoothUuid::ServiceClassUuid>(classUuid.toUInt16(&ok));
+ if (ok) {
+ serviceInfo.setServiceName(QBluetoothUuid::serviceClassToString(clsId));
+ break;
+ }
+ }
+ }
if (!isDuplicatedService(serviceInfo)) {
discoveredServices.append(serviceInfo);
@@ -878,7 +871,7 @@ QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamRe
}
xml.skipCurrentElement();
return QVariant::fromValue(uuid);
- } else if (xml.name() == QLatin1String("text")) {
+ } else if (xml.name() == QLatin1String("text") || xml.name() == QLatin1String("url")) {
QString value = xml.attributes().value(QStringLiteral("value")).toString();
if (xml.attributes().value(QStringLiteral("encoding")) == QLatin1String("hex"))
value = QString::fromUtf8(QByteArray::fromHex(value.toLatin1()));