All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] dbus: Default empty signature for method return messages
@ 2017-02-20 23:30 Andrew Zaborowski
  2017-02-20 23:30 ` [PATCH 2/3] dbus: Allow property setters to return method return message Andrew Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2017-02-20 23:30 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]

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(+)

diff --git a/ell/dbus.c b/ell/dbus.c
index 5318794..ddc51aa 100644
--- a/ell/dbus.c
+++ b/ell/dbus.c
@@ -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++;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] dbus: Allow property setters to return method return message
  2017-02-20 23:30 [PATCH 1/3] dbus: Default empty signature for method return messages Andrew Zaborowski
@ 2017-02-20 23:30 ` Andrew Zaborowski
  2017-02-20 23:30 ` [PATCH 3/3] unit: Test dbus property setters returning method return Andrew Zaborowski
  2017-02-21 16:55 ` [PATCH 1/3] dbus: Default empty signature for method return messages Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2017-02-20 23:30 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 3594 bytes --]

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(-)

diff --git a/ell/dbus-service.c b/ell/dbus-service.c
index 8bc9244..1df8f1b 100644
--- a/ell/dbus-service.c
+++ b/ell/dbus-service.c
@@ -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,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] unit: Test dbus property setters returning method return
  2017-02-20 23:30 [PATCH 1/3] dbus: Default empty signature for method return messages Andrew Zaborowski
  2017-02-20 23:30 ` [PATCH 2/3] dbus: Allow property setters to return method return message Andrew Zaborowski
@ 2017-02-20 23:30 ` Andrew Zaborowski
  2017-02-21 16:55 ` [PATCH 1/3] dbus: Default empty signature for method return messages Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2017-02-20 23:30 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

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(-)

diff --git a/unit/test-dbus-properties.c b/unit/test-dbus-properties.c
index 08916b3..a184deb 100644
--- a/unit/test-dbus-properties.c
+++ b/unit/test-dbus-properties.c
@@ -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,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] dbus: Default empty signature for method return messages
  2017-02-20 23:30 [PATCH 1/3] dbus: Default empty signature for method return messages Andrew Zaborowski
  2017-02-20 23:30 ` [PATCH 2/3] dbus: Allow property setters to return method return message Andrew Zaborowski
  2017-02-20 23:30 ` [PATCH 3/3] unit: Test dbus property setters returning method return Andrew Zaborowski
@ 2017-02-21 16:55 ` Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2017-02-21 16:55 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]

Hi Andrew,

On 02/20/2017 05:30 PM, Andrew Zaborowski wrote:
> 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(+)
>

All three applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-21 16:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-20 23:30 [PATCH 1/3] dbus: Default empty signature for method return messages Andrew Zaborowski
2017-02-20 23:30 ` [PATCH 2/3] dbus: Allow property setters to return method return message Andrew Zaborowski
2017-02-20 23:30 ` [PATCH 3/3] unit: Test dbus property setters returning method return Andrew Zaborowski
2017-02-21 16:55 ` [PATCH 1/3] dbus: Default empty signature for method return messages Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.