Skip to contentSkip to conversation

dbus: Default empty signature for method return messages

PATCH In review Andrew Zaborowski 2 participants 4 messages Feb 20, 2017 – Feb 21, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dbus: Default empty signature for method return messages

Allow Dbus method or setter handlers to return the result of a l_dbus_message_new_method_return call directly without calling l_dbus_message_set_arguments on the result. This will result in an empty signature message being built inside l_dbus_send.

Note l_dbus_send now modifies the message being passed to it.

Instead of checking if the signature returned by l_dbus_message_get_signature is NULL we could also just call l_dbus_message_builder_new and write an empty message. l_dbus_message_builder_new would return NULL if message->sealed was true.

---
 ell/dbus.c | 5 +++++
 1 file changed, 5 insertions(+)
ell/dbus.c +5 -0
index 5318794..ddc51aa 100644
@@ -324,6 +324,11 @@ static uint32_t send_message(struct l_dbus *dbus, bool priority,
 		return 0;
 	}
 
+	/* Default empty signature for method return messages */
+	if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN &&
+			!l_dbus_message_get_signature(message))
+		l_dbus_message_set_arguments(message, "");
+
 	callback = l_new(struct message_callback, 1);
 
 	callback->serial = dbus->next_serial++;
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/3 dbus: Allow property setters to return method return message

Synchronous property setters can now either call complete with a NULL error argument and return NULL, or return a method return message with an empty signature on success. Previously only error messages could be directly returned like that.

---
 ell/dbus-service.c | 51 ++++++++++++++++++++++-----------------------------
 1 file changed, 22 insertions(+), 29 deletions(-)
ell/dbus-service.c +22 -29
index 8bc9244..1df8f1b 100644
@@ -1163,30 +1163,27 @@ bool _dbus_object_tree_property_changed(struct l_dbus *dbus,
 
 static void set_property_complete(struct l_dbus *dbus,
 					struct l_dbus_message *message,
-					struct l_dbus_message *error)
+					struct l_dbus_message *reply)
 {
-	struct l_dbus_message *reply;
 	const char *property_name;
 	struct l_dbus_message_iter variant;
 
-	if (error) {
-		l_dbus_message_unref(message);
-
-		l_dbus_send(dbus, error);
-
-		return;
+	if (!reply) {
+		reply = l_dbus_message_new_method_return(message);
+		l_dbus_message_set_arguments(reply, "");
 	}
 
-	reply = l_dbus_message_new_method_return(message);
-	l_dbus_message_set_arguments(reply, "");
 	l_dbus_send(dbus, reply);
 
-	l_dbus_message_get_arguments(message, "sv", &property_name, &variant);
+	if (!l_dbus_message_is_error(reply)) {
+		l_dbus_message_get_arguments(message, "sv", &property_name,
+						&variant);
 
-	_dbus_object_tree_property_changed(dbus,
+		_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);
 }
@@ -1232,9 +1229,9 @@ static struct l_dbus_message *old_set_property(struct l_dbus *dbus,
 					set_property_complete, user_data);
 
 	if (reply)
-		l_dbus_message_unref(message);
+		set_property_complete(dbus, message, reply);
 
-	return reply;
+	return NULL;
 }
 
 static struct l_dbus_message *old_get_properties(struct l_dbus *dbus,
@@ -1714,30 +1711,26 @@ static struct l_dbus_message *properties_get(struct l_dbus *dbus,
 
 static void properties_set_complete(struct l_dbus *dbus,
 					struct l_dbus_message *message,
-					struct l_dbus_message *error)
+					struct l_dbus_message *reply)
 {
-	struct l_dbus_message *reply;
 	const char *interface_name, *property_name;
 	struct l_dbus_message_iter variant;
 
-	if (error) {
-		l_dbus_message_unref(message);
-
-		l_dbus_send(dbus, error);
-
-		return;
+	if (!reply) {
+		reply = l_dbus_message_new_method_return(message);
+		l_dbus_message_set_arguments(reply, "");
 	}
 
-	reply = l_dbus_message_new_method_return(message);
-	l_dbus_message_set_arguments(reply, "");
 	l_dbus_send(dbus, reply);
 
-	l_dbus_message_get_arguments(message, "ssv", &interface_name,
-					&property_name, &variant);
+	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,
+		_dbus_object_tree_property_changed(dbus,
 					l_dbus_message_get_path(message),
 					interface_name, property_name);
+	}
 
 	l_dbus_message_unref(message);
 }
@@ -1804,9 +1797,9 @@ static struct l_dbus_message *properties_set(struct l_dbus *dbus,
 					instance->user_data);
 
 	if (reply)
-		l_dbus_message_unref(message);
+		properties_set_complete(dbus, message, reply);
 
-	return reply;
+	return NULL;
 }
 
 static struct l_dbus_message *properties_get_all(struct l_dbus *dbus,
Signature · 1 line
2.9.3
#2 lore raw

PATCH 3/3 unit: Test dbus property setters returning method return

In reply to Andrew Zaborowski

The "String" property now tests that the complete callback works for setters while the "Integer" property tests that a method return message can be returned from the setter directly.

---
 unit/test-dbus-properties.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
unit/test-dbus-properties.c +1 -3
index 08916b3..a184deb 100644
@@ -274,9 +274,7 @@ static struct l_dbus_message *test_int_setter(struct l_dbus *dbus,
 	setter_called = true;
 
 done:
-	complete(dbus, message, NULL);
-
-	return NULL;
+	return l_dbus_message_new_method_return(message);
 }
 
 static struct l_dbus_message *test_error_setter(struct l_dbus *dbus,
Signature · 1 line
2.9.3
#3 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 7 lines · Andrew Zaborowski

Allow Dbus method or setter handlers to return the result of a l_dbus_message_new_method_return call directly without calling l_dbus_message_set_arguments on the result. This will result in an empty signature message being built inside l_dbus_send.

Note l_dbus_send now modifies the message being passed to it.

Quoted 9 lines

Instead of checking if the signature returned by l_dbus_message_get_signature is NULL we could also just call l_dbus_message_builder_new and write an empty message. l_dbus_message_builder_new would return NULL if message->sealed was true.

---
 ell/dbus.c | 5 +++++
 1 file changed, 5 insertions(+)

All three applied, thanks.

Regards,
-Denis