mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-15 08:14:28 +08:00
client: Use g_dbus_dict_append_*()
This commit is contained in:
parent
53f064d5c4
commit
237365998f
@ -237,59 +237,6 @@ static gboolean get_uuids(const GDBusPropertyTable *property,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void append_array_variant(DBusMessageIter *iter, int type, void *val,
|
||||
int n_elements)
|
||||
{
|
||||
DBusMessageIter variant, array;
|
||||
char type_sig[2] = { type, '\0' };
|
||||
char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
|
||||
array_sig, &variant);
|
||||
|
||||
dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
|
||||
type_sig, &array);
|
||||
|
||||
if (dbus_type_is_fixed(type) == TRUE) {
|
||||
dbus_message_iter_append_fixed_array(&array, type, val,
|
||||
n_elements);
|
||||
} else if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
|
||||
const char ***str_array = val;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_elements; i++)
|
||||
dbus_message_iter_append_basic(&array, type,
|
||||
&((*str_array)[i]));
|
||||
}
|
||||
|
||||
dbus_message_iter_close_container(&variant, &array);
|
||||
|
||||
dbus_message_iter_close_container(iter, &variant);
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
|
||||
static void dict_append_array(DBusMessageIter *dict, const char *key, int type,
|
||||
void *val, int n_elements)
|
||||
{
|
||||
dict_append_basic_array(dict, DBUS_TYPE_STRING, &key, type, val,
|
||||
n_elements);
|
||||
}
|
||||
|
||||
static gboolean service_data_exists(const GDBusPropertyTable *property,
|
||||
void *data)
|
||||
{
|
||||
@ -305,7 +252,7 @@ static gboolean get_service_data(const GDBusPropertyTable *property,
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
|
||||
|
||||
dict_append_array(&dict, ad.service.uuid, DBUS_TYPE_BYTE, &val,
|
||||
g_dbus_dict_append_array(&dict, ad.service.uuid, DBUS_TYPE_BYTE, &val,
|
||||
data->len);
|
||||
|
||||
dbus_message_iter_close_container(iter, &dict);
|
||||
@ -328,7 +275,8 @@ static gboolean get_manufacturer_data(const GDBusPropertyTable *property,
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{qv}", &dict);
|
||||
|
||||
dict_append_basic_array(&dict, DBUS_TYPE_UINT16, &ad.manufacturer.id,
|
||||
g_dbus_dict_append_basic_array(&dict, DBUS_TYPE_UINT16,
|
||||
&ad.manufacturer.id,
|
||||
DBUS_TYPE_BYTE, &val, data->len);
|
||||
|
||||
dbus_message_iter_close_container(iter, &dict);
|
||||
|
100
client/main.c
100
client/main.c
@ -1111,93 +1111,6 @@ static void start_discovery_reply(DBusMessage *message, void *user_data)
|
||||
/* Leave the discovery running even on noninteractive mode */
|
||||
}
|
||||
|
||||
static void append_variant(DBusMessageIter *iter, int type, void *val)
|
||||
{
|
||||
DBusMessageIter value;
|
||||
char sig[2] = { type, '\0' };
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
|
||||
|
||||
dbus_message_iter_append_basic(&value, type, val);
|
||||
|
||||
dbus_message_iter_close_container(iter, &value);
|
||||
}
|
||||
|
||||
static void append_array_variant(DBusMessageIter *iter, int type, void *val,
|
||||
int n_elements)
|
||||
{
|
||||
DBusMessageIter variant, array;
|
||||
char type_sig[2] = { type, '\0' };
|
||||
char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
|
||||
|
||||
dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
|
||||
array_sig, &variant);
|
||||
|
||||
dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
|
||||
type_sig, &array);
|
||||
|
||||
if (dbus_type_is_fixed(type) == TRUE) {
|
||||
dbus_message_iter_append_fixed_array(&array, type, val,
|
||||
n_elements);
|
||||
} else if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
|
||||
const char ***str_array = val;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_elements; i++)
|
||||
dbus_message_iter_append_basic(&array, type,
|
||||
&((*str_array)[i]));
|
||||
}
|
||||
|
||||
dbus_message_iter_close_container(&variant, &array);
|
||||
|
||||
dbus_message_iter_close_container(iter, &variant);
|
||||
}
|
||||
|
||||
static void dict_append_entry(DBusMessageIter *dict, const char *key,
|
||||
int type, void *val)
|
||||
{
|
||||
DBusMessageIter entry;
|
||||
|
||||
if (type == DBUS_TYPE_STRING) {
|
||||
const char *str = *((const char **) val);
|
||||
|
||||
if (str == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
|
||||
NULL, &entry);
|
||||
|
||||
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
|
||||
|
||||
append_variant(&entry, type, val);
|
||||
|
||||
dbus_message_iter_close_container(dict, &entry);
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
|
||||
static void dict_append_array(DBusMessageIter *dict, const char *key, int type,
|
||||
void *val, int n_elements)
|
||||
{
|
||||
dict_append_basic_array(dict, DBUS_TYPE_STRING, &key, type, val,
|
||||
n_elements);
|
||||
}
|
||||
|
||||
#define DISTANCE_VAL_INVALID 0x7FFF
|
||||
|
||||
static struct set_discovery_filter_args {
|
||||
@ -1225,22 +1138,25 @@ static void set_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
|
||||
DBUS_TYPE_VARIANT_AS_STRING
|
||||
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
|
||||
|
||||
dict_append_array(&dict, "UUIDs", DBUS_TYPE_STRING, &args->uuids,
|
||||
g_dbus_dict_append_array(&dict, "UUIDs", DBUS_TYPE_STRING,
|
||||
&args->uuids,
|
||||
args->uuids_len);
|
||||
|
||||
if (args->pathloss != DISTANCE_VAL_INVALID)
|
||||
dict_append_entry(&dict, "Pathloss", DBUS_TYPE_UINT16,
|
||||
g_dbus_dict_append_entry(&dict, "Pathloss", DBUS_TYPE_UINT16,
|
||||
&args->pathloss);
|
||||
|
||||
if (args->rssi != DISTANCE_VAL_INVALID)
|
||||
dict_append_entry(&dict, "RSSI", DBUS_TYPE_INT16, &args->rssi);
|
||||
g_dbus_dict_append_entry(&dict, "RSSI", DBUS_TYPE_INT16,
|
||||
&args->rssi);
|
||||
|
||||
if (args->transport != NULL)
|
||||
dict_append_entry(&dict, "Transport", DBUS_TYPE_STRING,
|
||||
g_dbus_dict_append_entry(&dict, "Transport", DBUS_TYPE_STRING,
|
||||
&args->transport);
|
||||
|
||||
if (args->duplicate)
|
||||
dict_append_entry(&dict, "DuplicateData", DBUS_TYPE_BOOLEAN,
|
||||
g_dbus_dict_append_entry(&dict, "DuplicateData",
|
||||
DBUS_TYPE_BOOLEAN,
|
||||
&args->duplicate);
|
||||
|
||||
dbus_message_iter_close_container(iter, &dict);
|
||||
|
Loading…
Reference in New Issue
Block a user