summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothdevicediscoveryagent_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/qbluetoothdevicediscoveryagent_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/qbluetoothdevicediscoveryagent_bluez.cpp')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp75
1 files changed, 26 insertions, 49 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index f70c3e64..ed09d598 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -186,75 +186,52 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
{
Q_Q(QBluetoothDeviceDiscoveryAgent);
- QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
- reply.waitForFinished();
- if (reply.isError()) {
- errorString = reply.error().message();
- lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
- emit q->error(lastError);
- return;
- }
-
-
- OrgBluezAdapter1Interface *tempAdapter = 0;
- QMap<QString, QVariantMap> devicesForAdapter; // dbus path for devices for matching adapter
-
- 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 (tempAdapter)
- continue;
-
- if (m_adapterAddress.isNull()) {
- // use the first found adapter as default
- tempAdapter = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
- path.path(),
- QDBusConnection::systemBus());
- } else {
- const QString addressString = ifaceList.value(iface).
- value(QStringLiteral("Address")).toString();
- if (m_adapterAddress == QBluetoothAddress(addressString)) {
- tempAdapter = new OrgBluezAdapter1Interface(
- QStringLiteral("org.bluez"),
- path.path(),
- QDBusConnection::systemBus());
- }
- }
- } else if (iface == QStringLiteral("org.bluez.Device1")) {
- devicesForAdapter.insert(path.path(), ifaceList.value(iface));
- }
- }
- }
- if (!tempAdapter) {
- qCDebug(QT_BT_BLUEZ) << "Cannot find Bluez 5 adapter for device search";
+ bool ok = false;
+ const QString adapterPath = findAdapterForAddress(m_adapterAddress, &ok);
+ if (!ok || adapterPath.isEmpty()) {
+ qCWarning(QT_BT_BLUEZ) << "Cannot find Bluez 5 adapter for device search" << ok;
lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot find valid Bluetooth adapter.");
q->error(lastError);
return;
}
- if (!tempAdapter->powered()) {
+ adapterBluez5 = new OrgBluezAdapter1Interface(QStringLiteral("org.bluez"),
+ adapterPath,
+ QDBusConnection::systemBus());
+
+ if (!adapterBluez5->powered()) {
qCDebug(QT_BT_BLUEZ) << "Aborting device discovery due to offline Bluetooth Adapter";
lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError;
errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off");
- delete tempAdapter;
+ delete adapterBluez5;
+ adapterBluez5 = 0;
emit q->error(lastError);
return;
}
- adapterBluez5 = tempAdapter;
+
QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)),
q, SLOT(_q_discoveryInterrupted(QString)));
// collect initial set of information
- foreach (const QString &path, devicesForAdapter.keys()) {
- if (path.indexOf(adapterBluez5->path()) != 0)
- continue; //devices path doesnt start with same path as adapter
+ QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ 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.Device1")) {
+
+ if (path.path().indexOf(adapterBluez5->path()) != 0)
+ continue; //devices whose path doesn't start with same path we skip
- deviceFoundBluez5(path);
+ deviceFoundBluez5(path.path());
+ }
+ }
+ }
}
// wait 20s and sum up what was found