All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH v2 1/7] dbus: add helper for appending a dictionary
Date: Mon, 11 Jan 2021 13:34:56 -0800	[thread overview]
Message-ID: <20210111213502.551370-1-prestwoj@gmail.com> (raw)

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

Arrays of dictionaries are quite common, and for basic
types this API makes things much more convenient by
putting all the enter/append/leave calls in one place.
---
 src/dbus.c | 24 ++++++++++++++++++++++++
 src/dbus.h |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/src/dbus.c b/src/dbus.c
index ceede5c8..d6bfc52d 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -202,6 +202,30 @@ void dbus_pending_reply(struct l_dbus_message **msg,
 	*msg = NULL;
 }
 
+/*
+ * Convenience helper for appending a dictionary "{sv}". This only works when
+ * the variant is a basic type.
+ */
+bool dbus_append_dict_basic(struct l_dbus_message_builder *builder,
+				const char *name, const char *type,
+				const void *data)
+{
+	if (!l_dbus_message_builder_enter_dict(builder, "sv"))
+		return false;
+	if (!l_dbus_message_builder_append_basic(builder, 's', name))
+		return false;
+	if (!l_dbus_message_builder_enter_variant(builder, type))
+		return false;
+	if (!l_dbus_message_builder_append_basic(builder, type[0], data))
+		return false;
+	if (!l_dbus_message_builder_leave_variant(builder))
+		return false;
+	if (!l_dbus_message_builder_leave_dict(builder))
+		return false;
+
+	return true;
+}
+
 struct l_dbus *dbus_get_bus(void)
 {
 	return g_dbus;
diff --git a/src/dbus.h b/src/dbus.h
index 3e2018d8..3a055482 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -51,6 +51,9 @@ struct l_dbus *dbus_get_bus(void);
 
 void dbus_pending_reply(struct l_dbus_message **msg,
 				struct l_dbus_message *reply);
+bool dbus_append_dict_basic(struct l_dbus_message_builder *builder,
+				const char *name, const char *type,
+				const void *data);
 
 const char *dbus_iftype_to_string(unsigned int iftype);
 
-- 
2.26.2

             reply	other threads:[~2021-01-11 21:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 21:34 James Prestwood [this message]
2021-01-11 21:34 ` [PATCH v2 2/7] netdev: add netdev_get_station/current_station James Prestwood
2021-01-11 21:34 ` [PATCH v2 3/7] netdev: update RSSI polling to use netdev_get_station James Prestwood
2021-01-11 21:34 ` [PATCH v2 4/7] netdev: parse rates in netdev_get_station James Prestwood
2021-01-11 21:35 ` [PATCH v2 5/7] netdev: parse expected throughput " James Prestwood
2021-01-11 21:35 ` [PATCH v2 6/7] station: create StationDiagnostic interface James Prestwood
2021-01-11 21:35 ` [PATCH v2 7/7] test: add a script for GetDiagnostics James Prestwood

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=20210111213502.551370-1-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@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.