diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-05-09 11:46:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-22 09:07:49 +0200 |
commit | 291a62a8150164c8b848b8dd5c6f26ef19a51246 (patch) | |
tree | 99873d7f38f1ef44353fd480e913e186f25e37ff /src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp | |
parent | 26e9cf5bc608c7b50fc27a73442966b3880f0825 (diff) |
Bluez5: Ensure device discovery returns meaningfull RSSI data
If the discovery process was started by QBluetoothDeviceDiscoveryAgent
and Bluez wasn't already in discovery mode then the RSSI values
are 0. The retrieval of RSSI data takes a bit more time.
To find a compromise between speedy return of device scan information
and the delayed RSSI information we continue to monitor the device scan
and update RSSI information as the values are propagated by Bluez.
However the deviceDiscovered() signal is not emitted again after an
update. Only re-calling discoveredDevices() will return the most
up-to-date RSSI values.
Task-number: QTBUG-32085
Change-Id: Icb6566d51503a6004fa3f25c499fc7f941bd7fee
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index b167d322..a84a9b82 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -52,6 +52,7 @@ #include "bluez/objectmanager_p.h" #include "bluez/adapter1_bluez5_p.h" #include "bluez/device1_bluez5_p.h" +#include "bluez/properties_p.h" QT_BEGIN_NAMESPACE @@ -350,6 +351,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& dev << "total device" << discoveredDevices.count() << "cached" << "RSSI" << device.rSSI(); + OrgFreedesktopDBusPropertiesInterface *prop = new OrgFreedesktopDBusPropertiesInterface( + QStringLiteral("org.bluez"), devicePath, QDBusConnection::systemBus(), q); + QObject::connect(prop, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), + q, SLOT(_q_PropertiesChanged(QString,QVariantMap,QStringList))); + // remember what we have to cleanup + propertyMonitors.append(prop); + // read information QBluetoothDeviceInfo deviceInfo(btAddress, btName, btClass); deviceInfo.setRssi(device.rSSI()); @@ -422,6 +430,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryFinished() QtBluezDiscoveryManager::instance()->disconnect(q); QtBluezDiscoveryManager::instance()->unregisterDiscoveryInterest(adapterBluez5->path()); + qDeleteAll(propertyMonitors); + propertyMonitors.clear(); + delete adapterBluez5; adapterBluez5 = 0; @@ -463,4 +474,30 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryInterrupted(const QStrin } } +void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(const QString &interface, + const QVariantMap &changed_properties, + const QStringList &) +{ + Q_Q(QBluetoothDeviceDiscoveryAgent); + if (interface == QStringLiteral("org.bluez.Device1") + && changed_properties.contains(QStringLiteral("RSSI"))) { + OrgFreedesktopDBusPropertiesInterface *props = + qobject_cast<OrgFreedesktopDBusPropertiesInterface *>(q->sender()); + if (!props) + return; + + OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), props->path(), + QDBusConnection::systemBus()); + for (int i = 0; i < discoveredDevices.size(); i++) { + if (discoveredDevices[i].address().toString() == device.address()) { + qCDebug(QT_BT_BLUEZ) << "Updating RSSI for" << device.address() + << changed_properties.value(QStringLiteral("RSSI")); + discoveredDevices[i].setRssi( + changed_properties.value(QStringLiteral("RSSI")).toInt()); + return; + } + } + } +} + QT_END_NAMESPACE |