mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-24 20:54:19 +08:00
core/dbus-common: Add dict helpers for basic keys
The specification allows any basic type to be key: 'A DICT_ENTRY works exactly like a struct, but rather than parentheses it uses curly braces, and it has more restrictions. The restrictions are: it occurs only as an array element type; it has exactly two single complete types inside the curly braces; the first single complete type (the "key") must be a basic type rather than a container type...'
This commit is contained in:
parent
5e418c30cb
commit
54a3f7b2b1
@ -83,8 +83,8 @@ static void append_array_variant(DBusMessageIter *iter, int type, void *val,
|
||||
dbus_message_iter_close_container(iter, &variant);
|
||||
}
|
||||
|
||||
void dict_append_entry(DBusMessageIter *dict,
|
||||
const char *key, int type, void *val)
|
||||
void dict_append_basic(DBusMessageIter *dict, int key_type, const void *key,
|
||||
int type, void *val)
|
||||
{
|
||||
DBusMessageIter entry;
|
||||
|
||||
@ -97,26 +97,41 @@ void dict_append_entry(DBusMessageIter *dict,
|
||||
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
|
||||
NULL, &entry);
|
||||
|
||||
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
|
||||
dbus_message_iter_append_basic(&entry, key_type, key);
|
||||
|
||||
append_variant(&entry, type, val);
|
||||
|
||||
dbus_message_iter_close_container(dict, &entry);
|
||||
|
||||
}
|
||||
|
||||
void dict_append_entry(DBusMessageIter *dict,
|
||||
const char *key, int type, void *val)
|
||||
{
|
||||
dict_append_basic(dict, DBUS_TYPE_STRING, &key, type, val);
|
||||
}
|
||||
|
||||
void dict_append_basic_array(DBusMessageIter *dict, int key_type,
|
||||
const void *key, int type, void *val,
|
||||
int n_elements)
|
||||
{
|
||||
DBusMessageIter entry;
|
||||
|
||||
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
|
||||
NULL, &entry);
|
||||
|
||||
dbus_message_iter_append_basic(&entry, key_type, key);
|
||||
|
||||
append_array_variant(&entry, type, val, n_elements);
|
||||
|
||||
dbus_message_iter_close_container(dict, &entry);
|
||||
}
|
||||
|
||||
void dict_append_array(DBusMessageIter *dict, const char *key, int type,
|
||||
void *val, int n_elements)
|
||||
{
|
||||
DBusMessageIter entry;
|
||||
|
||||
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
|
||||
NULL, &entry);
|
||||
|
||||
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
|
||||
|
||||
append_array_variant(&entry, type, val, n_elements);
|
||||
|
||||
dbus_message_iter_close_container(dict, &entry);
|
||||
dict_append_basic_array(dict, DBUS_TYPE_STRING, &key, type, val,
|
||||
n_elements);
|
||||
}
|
||||
|
||||
void set_dbus_connection(DBusConnection *conn)
|
||||
|
@ -21,9 +21,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
void dict_append_basic(DBusMessageIter *dict, int key_type, const void *key,
|
||||
int type, void *val);
|
||||
void dict_append_entry(DBusMessageIter *dict,
|
||||
const char *key, int type, void *val);
|
||||
|
||||
void dict_append_basic_array(DBusMessageIter *dict, int key_type,
|
||||
const void *key, int type, void *val,
|
||||
int n_elements);
|
||||
void dict_append_array(DBusMessageIter *dict, const char *key, int type,
|
||||
void *val, int n_elements);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user