Skip to content

Commit

Permalink
Blues service discovery : Search device in dbus before deciding to cr…
Browse files Browse the repository at this point in the history
…eate it

Previously, in blues, we tried to create the dbus device and if it already
existed then we searched / used it. Now the behaviour is reversed.

It's better to do it this way because sometimes a non privileged user
cannot create the device (org.freedesktop.DBus.Error.AuthFailed) as it is
the case in SailfishOS.
  • Loading branch information
Richard Rondu committed Mar 5, 2015
1 parent 9cc6a9b commit 5f42edc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
Expand Up @@ -361,17 +361,18 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa

qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "created" << address.toString();

QDBusPendingReply<QDBusObjectPath> deviceObjectPath = *watcher;
QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter->FindDevice(address.toString());
deviceObjectPath.waitForFinished();
if (deviceObjectPath.isError()) {
if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.AlreadyExists")) {
if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.DoesNotExist")) {
delete adapter;
adapter = 0;
_q_serviceDiscoveryFinished();
qCDebug(QT_BT_BLUEZ) << "Create device failed Error: " << error << deviceObjectPath.error().name();
qCDebug(QT_BT_BLUEZ) << "Can't find device. Can't recover, unmanaged error: " << error << deviceObjectPath.error().name();
return;
}

deviceObjectPath = adapter->FindDevice(address.toString());
deviceObjectPath = *watcher;
deviceObjectPath.waitForFinished();
if (deviceObjectPath.isError()) {
delete adapter;
Expand All @@ -382,7 +383,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
emit q->error(error);
}
_q_serviceDiscoveryFinished();
qCDebug(QT_BT_BLUEZ) << "Can't find device after creation Error: " << error << deviceObjectPath.error().name();
qCDebug(QT_BT_BLUEZ) << "Can't create device after finding unsuccessful. Error: " << error << deviceObjectPath.error().name();
return;
}
}
Expand Down

0 comments on commit 5f42edc

Please sign in to comment.