mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 19:02:34 +01:00
dbus: add helper for appending a dictionary
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.
This commit is contained in:
parent
668b61ff3a
commit
09b124f073
26
src/dbus.c
26
src/dbus.c
@ -202,6 +202,32 @@ void dbus_pending_reply(struct l_dbus_message **msg,
|
|||||||
*msg = NULL;
|
*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, char type,
|
||||||
|
const void *data)
|
||||||
|
{
|
||||||
|
char strtype[] = { type, '\0' };
|
||||||
|
|
||||||
|
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, strtype))
|
||||||
|
return false;
|
||||||
|
if (!l_dbus_message_builder_append_basic(builder, type, 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)
|
struct l_dbus *dbus_get_bus(void)
|
||||||
{
|
{
|
||||||
return g_dbus;
|
return g_dbus;
|
||||||
|
@ -51,6 +51,9 @@ struct l_dbus *dbus_get_bus(void);
|
|||||||
|
|
||||||
void dbus_pending_reply(struct l_dbus_message **msg,
|
void dbus_pending_reply(struct l_dbus_message **msg,
|
||||||
struct l_dbus_message *reply);
|
struct l_dbus_message *reply);
|
||||||
|
bool dbus_append_dict_basic(struct l_dbus_message_builder *builder,
|
||||||
|
const char *name, char type,
|
||||||
|
const void *data);
|
||||||
|
|
||||||
const char *dbus_iftype_to_string(unsigned int iftype);
|
const char *dbus_iftype_to_string(unsigned int iftype);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user