summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/dbus-helper.c35
-rw-r--r--common/dbus-helper.h3
2 files changed, 38 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);
+}
diff --git a/common/dbus-helper.h b/common/dbus-helper.h
index 0c33a04f..312ab9b5 100644
--- a/common/dbus-helper.h
+++ b/common/dbus-helper.h
@@ -55,3 +55,6 @@ dbus_bool_t dbus_connection_register_interface(DBusConnection *connection,
dbus_bool_t dbus_connection_unregister_interface(DBusConnection *connection,
const char *path, const char *interface);
+void dbus_message_iter_append_dict_entry(DBusMessageIter *dict,
+ const char *key, int type, void *val);
+