summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiemo van Engelen <tvanengelen@victronenergy.com>2019-11-13 08:45:14 +0100
committerThiemo van Engelen <tvanengelen@victronenergy.com>2019-12-04 10:54:06 +0100
commitb7b979d1735764930cc6f736cfa8e22b71547ea8 (patch)
tree0a14102309c2377c3fd05f1518155e272bab5694
parent355f09eccc5ceba421e8c522e04cb7be72fa0a75 (diff)
bluez: Fix out of sync property cache
Since commit 2c6dcc643, a map containing dbus property values is kept per device to be able to make QBluetoothDeviceInfo instances without having to make dbus calls. However, this map could get out of sync. The reason was that the code started to listen to PropertyChanged signals after it received the initial set of properties. This meant that there was a short amount of time where bluez could send out a signal with changed properties and the DiscoveryAgent would not receive it. In order to keep the map in sync, a PropertyChanged listener is now installed when scanning is started, picking up all changes. Change-Id: Iae5e219b187e94bf280a6dd76ccde49cafd1d9c5 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/bluetooth/bluez/properties_p.h3
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp29
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h1
3 files changed, 15 insertions, 18 deletions
diff --git a/src/bluetooth/bluez/properties_p.h b/src/bluetooth/bluez/properties_p.h
index 16a43e80..d8a7b6cb 100644
--- a/src/bluetooth/bluez/properties_p.h
+++ b/src/bluetooth/bluez/properties_p.h
@@ -58,7 +58,8 @@ public Q_SLOTS: // METHODS
}
Q_SIGNALS: // SIGNALS
- void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties);
+ void PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties,
+ const QDBusMessage &msg);
};
namespace org {
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 7dce9dae..243be3b2 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -292,6 +292,17 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscover
q, [this](const QString &path){
this->_q_discoveryInterrupted(path);
});
+ OrgFreedesktopDBusPropertiesInterface *prop = new OrgFreedesktopDBusPropertiesInterface(
+ QStringLiteral("org.bluez"), QStringLiteral(""), QDBusConnection::systemBus());
+ QObject::connect(prop, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged,
+ q, [this](const QString &interface, const QVariantMap &changedProperties,
+ const QStringList &invalidatedProperties,
+ const QDBusMessage &signal) {
+ this->_q_PropertiesChanged(interface, signal.path(), changedProperties, invalidatedProperties);
+ });
+
+ // remember what we have to cleanup
+ propertyMonitors.append(prop);
// collect initial set of information
QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects();
@@ -476,17 +487,6 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString &dev
<< "RSSI" << deviceInfo.rssi()
<< "Num ManufacturerData" << deviceInfo.manufacturerData().size();
- OrgFreedesktopDBusPropertiesInterface *prop = new OrgFreedesktopDBusPropertiesInterface(
- QStringLiteral("org.bluez"), devicePath, QDBusConnection::systemBus(), q);
- QObject::connect(prop, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged,
- q, [this](const QString &interface, const QVariantMap &changedProperties,
- const QStringList &invalidatedProperties) {
- this->_q_PropertiesChanged(interface, changedProperties, invalidatedProperties);
- });
-
- // remember what we have to cleanup
- propertyMonitors.append(prop);
-
// Cache the properties so we do not have to access dbus every time to get a value
devicesProperties[devicePath] = properties;
@@ -641,6 +641,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_discoveryInterrupted(const QStrin
}
void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(const QString &interface,
+ const QString &path,
const QVariantMap &changed_properties,
const QStringList &invalidated_properties)
{
@@ -648,12 +649,6 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_PropertiesChanged(const QString &
if (interface != QStringLiteral("org.bluez.Device1"))
return;
- OrgFreedesktopDBusPropertiesInterface *props =
- qobject_cast<OrgFreedesktopDBusPropertiesInterface *>(q->sender());
- if (!props)
- return;
-
- const QString path = props->path();
if (!devicesProperties.contains(path))
return;
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 27220a09..c9a35c3d 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -142,6 +142,7 @@ public:
void _q_discoveryFinished();
void _q_discoveryInterrupted(const QString &path);
void _q_PropertiesChanged(const QString &interface,
+ const QString &path,
const QVariantMap &changed_properties,
const QStringList &invalidated_properties);
void _q_extendedDeviceDiscoveryTimeout();