diff options
Diffstat (limited to 'common/dbus-helper.c')
-rw-r--r-- | common/dbus-helper.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/common/dbus-helper.c b/common/dbus-helper.c index 7c14952b..d0082451 100644 --- a/common/dbus-helper.c +++ b/common/dbus-helper.c @@ -209,3 +209,38 @@ dbus_bool_t dbus_connection_unregister_interface(DBusConnection *connection, { return TRUE; } + +void dbus_message_iter_append_dict_entry(DBusMessageIter *dict, + const char *key, int type, void *val) +{ + DBusMessageIter entry; + DBusMessageIter value; + char *sig; + + dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + switch (type) { + case DBUS_TYPE_STRING: + sig = DBUS_TYPE_STRING_AS_STRING; + break; + case DBUS_TYPE_UINT32: + sig = DBUS_TYPE_UINT32_AS_STRING; + break; + case DBUS_TYPE_BOOLEAN: + sig = DBUS_TYPE_BOOLEAN_AS_STRING; + break; + default: + sig = DBUS_TYPE_VARIANT_AS_STRING; + break; + } + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, sig, &value); + + dbus_message_iter_append_basic(&value, type, val); + + dbus_message_iter_close_container(&entry, &value); + + dbus_message_iter_close_container(dict, &entry); +} |