summaryrefslogtreecommitdiff
path: root/src/dbus.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-12-19 00:24:47 -0800
committerMarcel Holtmann <marcel@holtmann.org>2009-12-19 00:24:47 -0800
commit0c87b66b1687f815151bc9303ba6ae4dad09d93a (patch)
tree1c6d426fdc6f4feb8e0f2e51cf6aad3469b03019 /src/dbus.c
parent9b5472dbf0453de3e3e53584c9697a8f5de2010c (diff)
downloadconnman-0c87b66b1687f815151bc9303ba6ae4dad09d93a.tar.gz
connman-0c87b66b1687f815151bc9303ba6ae4dad09d93a.tar.bz2
connman-0c87b66b1687f815151bc9303ba6ae4dad09d93a.zip
Add helpers for appending flexible D-Bus arrays
Diffstat (limited to 'src/dbus.c')
-rw-r--r--src/dbus.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/dbus.c b/src/dbus.c
index 9cb13dd4..c025979a 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -118,7 +118,20 @@ void connman_dbus_property_append_variant(DBusMessageIter *iter,
dbus_message_iter_close_container(iter, &value);
}
-void connman_dbus_dict_append_array(DBusMessageIter *dict,
+void connman_dbus_dict_append_variant(DBusMessageIter *dict,
+ const char *key, int type, void *val)
+{
+ DBusMessageIter entry;
+
+ dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+ NULL, &entry);
+
+ connman_dbus_property_append_variant(&entry, key, type, val);
+
+ dbus_message_iter_close_container(dict, &entry);
+}
+
+void connman_dbus_dict_append_fixed_array(DBusMessageIter *dict,
const char *key, int type, void *val, int len)
{
DBusMessageIter entry, value, array;
@@ -151,15 +164,40 @@ void connman_dbus_dict_append_array(DBusMessageIter *dict,
dbus_message_iter_close_container(dict, &entry);
}
-void connman_dbus_dict_append_variant(DBusMessageIter *dict,
- const char *key, int type, void *val)
+void connman_dbus_dict_append_variable_array(DBusMessageIter *dict,
+ const char *key, int type, connman_dbus_append_cb_t function)
{
- DBusMessageIter entry;
+ DBusMessageIter entry, value, array;
+ const char *variant_sig, *array_sig;
+
+ switch (type) {
+ case DBUS_TYPE_STRING:
+ variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
+ array_sig = DBUS_TYPE_STRING_AS_STRING;
+ break;
+ case DBUS_TYPE_OBJECT_PATH:
+ variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING;
+ array_sig = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+ break;
+ default:
+ return;
+ }
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
NULL, &entry);
- connman_dbus_property_append_variant(&entry, key, type, val);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+ variant_sig, &value);
+
+ dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
+ array_sig, &array);
+ if (function)
+ function(&array);
+ dbus_message_iter_close_container(&value, &array);
+
+ dbus_message_iter_close_container(&entry, &value);
dbus_message_iter_close_container(dict, &entry);
}