Skip to contentSkip to conversation

dbus: Don't automatically emit PropertyChanged after Set

RFC PATCH In review Andrew Zaborowski 2 participants 6 messages Aug 30, 2018 – Aug 31, 2018

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 dbus: Don't automatically emit PropertyChanged after Set

Remove the _dbus_object_tree_property_changed call in the complete handler for property setters so a PropertyChanged/PropertiesChanged signal is not sent for every successful Set(). This means that the setter functions will have to emit the signals when the property's value has changed so it affects ell's clients. This attempts to allow clients to solve an issue where PropertyChanged signals were generated even if Set was called with a value equal to the property's current value so the values was not effectively chaning.

I'm not 100% convinced this small benefit is worth the added work for clients. Another possibilty would be for the setter functions to give the complete callback some hint when they want an property change to be signalled. For example an additional parameter or always when the 'reply' parameter is NULL (as opposed to an successful method return message). It could also be argued that a Set with a new value same as old value should return an error reply but that's probably best left to the client to decide.

---
 ell/dbus-service.c | 48 +++-------------------------------------------
 1 file changed, 3 insertions(+), 45 deletions(-)
ell/dbus-service.c +3 -45
index 3ad6c7e..d97eb62 100644
@@ -1227,28 +1227,13 @@ static void set_property_complete(struct l_dbus *dbus,
 					struct l_dbus_message *message,
 					struct l_dbus_message *reply)
 {
-	const char *property_name;
-	struct l_dbus_message_iter variant;
-
 	if (!reply) {
 		reply = l_dbus_message_new_method_return(message);
 		l_dbus_message_set_arguments(reply, "");
 	}
 
-	l_dbus_send(dbus, l_dbus_message_ref(reply));
-
-	if (!l_dbus_message_is_error(reply)) {
-		l_dbus_message_get_arguments(message, "sv", &property_name,
-						&variant);
-
-		_dbus_object_tree_property_changed(dbus,
-					l_dbus_message_get_path(message),
-					l_dbus_message_get_interface(message),
-					property_name);
-	}
-
 	l_dbus_message_unref(message);
-	l_dbus_message_unref(reply);
+	l_dbus_send(dbus, reply);
 }
 
 static struct l_dbus_message *old_set_property(struct l_dbus *dbus,
@@ -1815,33 +1800,6 @@ static struct l_dbus_message *properties_get(struct l_dbus *dbus,
 	return reply;
 }
 
-static void properties_set_complete(struct l_dbus *dbus,
-					struct l_dbus_message *message,
-					struct l_dbus_message *reply)
-{
-	const char *interface_name, *property_name;
-	struct l_dbus_message_iter variant;
-
-	if (!reply) {
-		reply = l_dbus_message_new_method_return(message);
-		l_dbus_message_set_arguments(reply, "");
-	}
-
-	l_dbus_send(dbus, l_dbus_message_ref(reply));
-
-	if (!l_dbus_message_is_error(reply)) {
-		l_dbus_message_get_arguments(message, "ssv", &interface_name,
-						&property_name, &variant);
-
-		_dbus_object_tree_property_changed(dbus,
-					l_dbus_message_get_path(message),
-					interface_name, property_name);
-	}
-
-	l_dbus_message_unref(message);
-	l_dbus_message_unref(reply);
-}
-
 static struct l_dbus_message *properties_set(struct l_dbus *dbus,
 						struct l_dbus_message *message,
 						void *user_data)
@@ -1900,11 +1858,11 @@ static struct l_dbus_message *properties_set(struct l_dbus *dbus,
 						interface_name);
 
 	reply = property->setter(dbus, l_dbus_message_ref(message), &variant,
-					properties_set_complete,
+					set_property_complete,
 					instance->user_data);
 
 	if (reply)
-		properties_set_complete(dbus, message, reply);
+		set_property_complete(dbus, message, reply);
 
 	return NULL;
 }
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH 2/2 unit: Emit PropertyChanged in setters in test-dbus-service

Send the property change signals in the setter now that it's not done automatically. Note that the signals are now sent before the Set method return message.

---
 unit/test-dbus-properties.c | 6 ++++++
 1 file changed, 6 insertions(+)
unit/test-dbus-properties.c +6 -0
index db89ec5..e0a2bfe 100644
@@ -211,6 +211,9 @@ static struct l_dbus_message *test_string_setter(struct l_dbus *dbus,
 
 	setter_called = true;
 
+	l_dbus_property_changed(dbus, l_dbus_message_get_path(message),
+				"org.test", "String");
+
 done:
 	complete(dbus, message, NULL);
 
@@ -248,6 +251,9 @@ static struct l_dbus_message *test_int_setter(struct l_dbus *dbus,
 
 	setter_called = true;
 
+	l_dbus_property_changed(dbus, l_dbus_message_get_path(message),
+				"org.test", "Integer");
+
 done:
 	return l_dbus_message_new_method_return(message);
 }
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2][RFC] unit: Emit PropertyChanged in setters in test-dbus-service

Hi Andrew,

Quoted 3 lines · Andrew Zaborowski

Send the property change signals in the setter now that it's not done automatically. Note that the signals are now sent before the Set method return message.

Hmm, aren't we able to control the order of signals by issuing the complete callback prior to the property changed call? Obviously we can't do so if l_dbus_message_new_method_return() is used as the return value due to the clashing of property changed coalescing logic and the signal flushing logic inside dbus_send.

The way around this, is for the implementer to use complete() if a synchronous method call is being implemented and the property change is immediate. Not a common case for us, but still ugly... Not sure what else we can do though?

By the way, looking at test_string_setter again, I actually don't get how its supposed to work. Shouldn't it return at least some errors somewhere?

Regards,
-Denis

#3 lore raw

Re: [PATCH 2/2][RFC] unit: Emit PropertyChanged in setters in test-dbus-service

Quoted 7 lines · Denis Kenzior
Quoted 3 lines · Andrew Zaborowski

Send the property change signals in the setter now that it's not done automatically. Note that the signals are now sent before the Set method return message.

Hmm, aren't we able to control the order of signals by issuing the complete callback prior to the property changed call?

Yes, it's just for convenience here. Since the complete callback unrefs "message", we'd need to ref/unref it once or use an extra variable to send the reply after.

Quoted 9 lines

Obviously we
can't do so if l_dbus_message_new_method_return() is used as the return value due to the clashing of property changed coalescing logic and the signal flushing logic inside dbus_send.

The way around this, is for the implementer to use complete() if a synchronous method call is being implemented and the property change is immediate. Not a common case for us, but still ugly... Not sure what else we can do though?

I don't think the orders matters if the change is immediate, clients should be able to handle both cases.

Quoted 4 lines

By the way, looking at test_string_setter again, I actually don't get how its supposed to work. Shouldn't it return at least some errors somewhere?

We only use this property to test the success case and we test the error cases using the "SetError" and "Readonly" properties.

Best regards

#4 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 8 lines · Andrew Zaborowski

Remove the _dbus_object_tree_property_changed call in the complete handler for property setters so a PropertyChanged/PropertiesChanged signal is not sent for every successful Set(). This means that the setter functions will have to emit the signals when the property's value has changed so it affects ell's clients. This attempts to allow clients to solve an issue where PropertyChanged signals were generated even if Set was called with a value equal to the property's current value so the values was not effectively chaning.

So if we do it this way, do we even need the complete callback at all? All it does is just sends a reply now. This can be easily done by the caller by issuing a dbus_pending_reply or l_dbus_send...

Quoted 5 lines

I'm not 100% convinced this small benefit is worth the added work for clients. Another possibilty would be for the setter functions to give the complete callback some hint when they want an property change to be signalled. For example an additional parameter or always when the

I thought about this and I'm afraid this would be unreadable. The callback already includes 3 pointers and one of the pointers can be NULL. There's already way too much magic and parameters in there. The GDBus approach of pending_property_success/error is actually more readable and clear. But it still comes down to a dbus_send in the end.

Quoted 1 line

'reply' parameter is NULL (as opposed to an successful method return

Readability wise I hate this. You should not be left wondering whether something is going to be done and have to look it up. It should be immediately apparent when looking at the code...

Quoted 3 lines

message). It could also be argued that a Set with a new value same as old value should return an error reply but that's probably best left to the client to decide.

Could be argued, yes. But I would argue that a Set succeeding and having no PropertyChanged being emitted is nicer. And our projects already do this all the time.

Regards,
-Denis

#5 lore raw

Hi Denis,
[resending to the list]

Quoted 10 lines · Denis Kenzior
Quoted 8 lines · Andrew Zaborowski

Remove the _dbus_object_tree_property_changed call in the complete handler for property setters so a PropertyChanged/PropertiesChanged signal is not sent for every successful Set(). This means that the setter functions will have to emit the signals when the property's value has changed so it affects ell's clients. This attempts to allow clients to solve an issue where PropertyChanged signals were generated even if Set was called with a value equal to the property's current value so the values was not effectively chaning.

Quoted 3 lines

So if we do it this way, do we even need the complete callback at all? All it does is just sends a reply now. This can be easily done by the caller by issuing a dbus_pending_reply or l_dbus_send...

Yes, although I'm not sure that's better. Perhaps it was never a good idea for the complete callback to be an opaque pointer instead of an api call but at least it builds the reply for you.

Quoted 7 lines
Quoted 6 lines

I'm not 100% convinced this small benefit is worth the added work for clients. Another possibilty would be for the setter functions to give the complete callback some hint when they want an property change to be signalled. For example an additional parameter or always when the

Quoted 5 lines

I thought about this and I'm afraid this would be unreadable. The callback already includes 3 pointers and one of the pointers can be NULL. There's already way too much magic and parameters in there. The GDBus approach of pending_property_success/error is actually more readable and clear. But it still comes down to a dbus_send in the end.

With a direct l_dbus_send call you have to know exactly what the method's signature was, it's not difficult but it's nicer when you don't have to care like in the GDBus case.

Best regards