Skip to contentSkip to conversation

gdbus: add method for immediate property update

PATCH Superseded Jakub Pawlowski 2 participants 3 messages Sep 18, 2015 Bluetooth drivers

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 gdbus: add method for immediate property update

g_dbus_emit_property_changed doesn't send dbus signal immediately. Instead it stores changed properties, and schedule signal to be send at g_iddle_add. Additionally, if this method is called few times for some property, only last value will be sent in property changed signal.

If remote device sends lots of notifications, they're all scheduled to be notified using this method. This might result in some notifications being lost.

This patch adds new method, that can immediately send property changed signal, instead of sheduling it for nearest iddle moment.

---
 gdbus/gdbus.h  |  3 +++
 gdbus/object.c | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
gdbus/gdbus.h +3 -0
index d99c254..28e6d8b 100644
@@ -300,6 +300,9 @@ void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
 void g_dbus_emit_property_changed(DBusConnection *connection,
 				const char *path, const char *interface,
 				const char *name);
+void g_dbus_emit_property_changed_full(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, gboolean flush);
 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
 				const char *interface, DBusMessageIter *iter);
 
gdbus/object.c +13 -3
index 96db516..7a1e749 100644
@@ -1720,9 +1720,9 @@ static void process_property_changes(struct generic_data *data)
 	}
 }
 
-void g_dbus_emit_property_changed(DBusConnection *connection,
+void g_dbus_emit_property_changed_full(DBusConnection *connection,
 				const char *path, const char *interface,
-				const char *name)
+				const char *name, gboolean flush)
 {
 	const GDBusPropertyTable *property;
 	struct generic_data *data;
@@ -1760,7 +1760,17 @@ void g_dbus_emit_property_changed(DBusConnection *connection,
 	iface->pending_prop = g_slist_prepend(iface->pending_prop,
 						(void *) property);
 
-	add_pending(data);
+	if (flush)
+		process_property_changes(data);
+	else
+		add_pending(data);
+}
+
+void g_dbus_emit_property_changed(DBusConnection *connection, const char *path,
+				const char *interface, const char *name)
+{
+	g_dbus_emit_property_changed_full(connection, path, interface, name,
+									FALSE);
 }
 
 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
Signature · 1 line
2.5.0
#1 lore raw

PATCH v3 2/2 core/gatt-client: fix losing notifications

When notifications are quickly send to BlueZ, it tries to signal that through dbus using g_dbus_emit_property_changed, which would merge all changes and schedule sending property changed in g_iddle_add.

If the stream of notifications from device is fast enough, there might be no iddle moment to send properties changed before next notification arives, which would result in notifications being lost.

This patch fixes that by using method that sends properties changed immediately, without waiting for iddle moment.

---
 src/gatt-client.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/gatt-client.c +3 -2
index 399133a..62ac03d 100644
@@ -778,8 +778,9 @@ static void write_characteristic_cb(struct gatt_db_attribute *attr, int err,
 	if (err)
 		return;
 
-	g_dbus_emit_property_changed(btd_get_dbus_connection(), chrc->path,
-					GATT_CHARACTERISTIC_IFACE, "Value");
+	g_dbus_emit_property_changed_full(btd_get_dbus_connection(),
+			chrc->path, GATT_CHARACTERISTIC_IFACE, "Value", true);
+
 }
 
 static void chrc_read_cb(bool success, uint8_t att_ecode, const uint8_t *value,
Signature · 1 line
2.5.0
#2 lore raw
In reply to Jakub Pawlowski

Hi Jakub,

gdbus/gdbus.h void g_dbus_pending_property_error(GDBusPendingReply id, const char *name, · line 305

Quoted 3 lines · Jakub Pawlowski
gdbus/gdbus.h +3 -0
+void g_dbus_emit_property_changed_full(DBusConnection *connection,
+				const char *path, const char *interface,
+				const char *name, gboolean flush);

I can't say I'm a fan of boolean parameters like this where it's essentially impossible to say when looking at the calling code what the parameter does (in this case the completely generic "full" in the function name doesn't even give any hints about what exactly the parameter might be). Instead, using a flags parameter + enum would be one way to keep the calling code understandable.

Johan