All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: ell@lists.01.org
Subject: [PATCH] dbus: Handle optional properties in PropertiesChanged
Date: Wed, 21 Sep 2016 18:41:45 +0200	[thread overview]
Message-ID: <1474476105-10906-1-git-send-email-andrew.zaborowski@intel.com> (raw)

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

Handle property getter returning an error when building the
PropertiesChanged signal instead of returning NULL.  This is important
because the signal may include multiple properties and if one getter
fails other properties should still be included.  One options is to only
error out if all getters fail, another is to add them to the invalidated
properties list of the signal.  The latter seems to be the right thing
to do for optional properties that may appear and disappear.
---
 ell/dbus-service.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/ell/dbus-service.c b/ell/dbus-service.c
index deffc07..57cafbe 100644
--- a/ell/dbus-service.c
+++ b/ell/dbus-service.c
@@ -962,6 +962,7 @@ static struct l_dbus_message *build_properties_changed_signal(
 	const struct l_queue_entry *entry;
 	const struct _dbus_property *property;
 	const char *signature;
+	struct l_queue *invalidated;
 
 	signal = l_dbus_message_new_signal(dbus, rec->path,
 						L_DBUS_INTERFACE_PROPERTIES,
@@ -969,6 +970,8 @@ static struct l_dbus_message *build_properties_changed_signal(
 
 	builder = l_dbus_message_builder_new(signal);
 
+	invalidated = l_queue_new();
+
 	l_dbus_message_builder_append_basic(builder, 's',
 						rec->instance->interface->name);
 	l_dbus_message_builder_enter_array(builder, "{sv}");
@@ -978,6 +981,8 @@ static struct l_dbus_message *build_properties_changed_signal(
 		property = entry->data;
 		signature = property->metainfo + strlen(property->metainfo) + 1;
 
+		_dbus_message_builder_mark(builder);
+
 		l_dbus_message_builder_enter_dict(builder, "sv");
 		l_dbus_message_builder_append_basic(builder, 's',
 							property->metainfo);
@@ -985,10 +990,16 @@ static struct l_dbus_message *build_properties_changed_signal(
 
 		if (!property->getter(dbus, signal, builder,
 					rec->instance->user_data)) {
-			l_dbus_message_builder_destroy(builder);
-			l_dbus_message_unref(signal);
+			if (!_dbus_message_builder_rewind(builder)) {
+				l_dbus_message_unref(signal);
+				signal = NULL;
 
-			return NULL;
+				goto done;
+			}
+
+			l_queue_push_tail(invalidated, (void *) property);
+
+			continue;
 		}
 
 		l_dbus_message_builder_leave_variant(builder);
@@ -997,10 +1008,19 @@ static struct l_dbus_message *build_properties_changed_signal(
 
 	l_dbus_message_builder_leave_array(builder);
 	l_dbus_message_builder_enter_array(builder, "s");
+
+	while ((property = l_queue_pop_head(invalidated)))
+		l_dbus_message_builder_append_basic(builder, 's',
+							property->metainfo);
+
 	l_dbus_message_builder_leave_array(builder);
 	l_dbus_message_builder_finalize(builder);
+
+done:
 	l_dbus_message_builder_destroy(builder);
 
+	l_queue_destroy(invalidated, NULL);
+
 	return signal;
 }
 
-- 
2.7.4


             reply	other threads:[~2016-09-21 16:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-21 16:41 Andrew Zaborowski [this message]
2016-09-21 21:53 ` [PATCH] dbus: Handle optional properties in PropertiesChanged Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474476105-10906-1-git-send-email-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.