summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp10
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.h1
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp37
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h8
-rw-r--r--tests/bttestui/btlocaldevice.cpp2
5 files changed, 56 insertions, 2 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index d8c93054..ab0643d6 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -99,6 +99,16 @@ QT_BEGIN_NAMESPACE
\fn void QBluetoothDeviceDiscoveryAgent::deviceDiscovered(const QBluetoothDeviceInfo &info)
This signal is emitted when the Bluetooth device described by \a info is discovered.
+
+ The signal is emitted as soon as the most important device information
+ has been collected. However, as long as the \l finished() signal has not
+ been emitted the information collection continues even for already discovered
+ devices. This is particularly true for signal strength information (RSSI). If
+ signal strength information is required it is advisable to retrieve the device
+ information via \l discoveredDevices() once the discovery has finished. This
+ will yield the most recent RSSI information.
+
+ \sa QBluetoothDeviceInfo::rssi()
*/
/*!
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h
index 54d664c2..45615e74 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h
@@ -109,6 +109,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_InterfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList))
Q_PRIVATE_SLOT(d_func(), void _q_discoveryFinished())
Q_PRIVATE_SLOT(d_func(), void _q_discoveryInterrupted(const QString &path))
+ Q_PRIVATE_SLOT(d_func(), void _q_PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties))
#endif
};
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
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 1e20f92e..168b6c0c 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -59,6 +59,7 @@
class OrgBluezManagerInterface;
class OrgBluezAdapterInterface;
class OrgFreedesktopDBusObjectManagerInterface;
+class OrgFreedesktopDBusPropertiesInterface;
class OrgBluezAdapter1Interface;
class OrgBluezDevice1Interface;
@@ -94,9 +95,13 @@ public:
#ifdef QT_BLUEZ_BLUETOOTH
void _q_deviceFound(const QString &address, const QVariantMap &dict);
void _q_propertyChanged(const QString &name, const QDBusVariant &value);
- void _q_InterfacesAdded(const QDBusObjectPath &object_path, InterfaceList interfaces_and_properties);
+ void _q_InterfacesAdded(const QDBusObjectPath &object_path,
+ InterfaceList interfaces_and_properties);
void _q_discoveryFinished();
void _q_discoveryInterrupted(const QString &path);
+ void _q_PropertiesChanged(const QString &interface,
+ const QVariantMap &changed_properties,
+ const QStringList &invalidated_properties);
#endif
private:
@@ -127,6 +132,7 @@ private:
OrgFreedesktopDBusObjectManagerInterface *managerBluez5;
OrgBluezAdapter1Interface *adapterBluez5;
QTimer *discoveryTimer;
+ QList<OrgFreedesktopDBusPropertiesInterface *> propertyMonitors;
void deviceFoundBluez5(const QString& devicePath);
void startBluez5();
diff --git a/tests/bttestui/btlocaldevice.cpp b/tests/bttestui/btlocaldevice.cpp
index d67b13fb..bafb3e76 100644
--- a/tests/bttestui/btlocaldevice.cpp
+++ b/tests/bttestui/btlocaldevice.cpp
@@ -333,7 +333,7 @@ void BtLocalDevice::dumpServiceDiscovery()
qDebug() << "Discovered Devices:" << list.count();
foreach (const QBluetoothDeviceInfo &info, list)
- qDebug() << info.name() << info.address().toString();
+ qDebug() << info.name() << info.address().toString() << info.rssi();
}
if (serviceAgent) {
qDebug() << "Service Discovery active:" << serviceAgent->isActive();