diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-03-24 18:04:12 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2008-03-24 18:04:12 +0000 |
commit | 769c4b021665a26c9a6c20457ef9b7ded54c8ad6 (patch) | |
tree | 61971f355a2a9fd823df492f193efc222702ae75 | |
parent | 30b429c3852bb036dc473b3ff11a278df443026d (diff) |
Fix dbus_message_iter_append_variant to use dbus string array format (char **) instead GSList.
-rw-r--r-- | common/dbus-helper.c | 14 | ||||
-rw-r--r-- | hcid/device.c | 50 |
2 files changed, 42 insertions, 22 deletions
diff --git a/common/dbus-helper.c b/common/dbus-helper.c index 6c7946a8..e6211824 100644 --- a/common/dbus-helper.c +++ b/common/dbus-helper.c @@ -415,11 +415,6 @@ dbus_bool_t dbus_connection_unregister_interface(DBusConnection *connection, return TRUE; } -static void append_array_item_string(const char *val, DBusMessageIter *iter) -{ - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &val); -} - void dbus_message_iter_append_variant(DBusMessageIter *iter, int type, void *val) { DBusMessageIter value; @@ -459,10 +454,15 @@ void dbus_message_iter_append_variant(DBusMessageIter *iter, int type, void *val dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value); if (type == DBUS_TYPE_ARRAY) { + int i; + const char ***str_array = val; + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array); - g_slist_foreach((GSList*) val, (GFunc) append_array_item_string, - &array); + + for (i = 0; (*str_array)[i]; i++) + dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, + &((*str_array)[i])); dbus_message_iter_close_container(&value, &array); } else diff --git a/hcid/device.c b/hcid/device.c index f5929861..d5d2606f 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -748,6 +748,30 @@ static DBusHandlerResult disconnect(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } +static gboolean device_is_paired(struct device *device) +{ + struct adapter *adapter = device->adapter; + char filename[PATH_MAX + 1], *str; + gboolean ret; + + create_name(filename, PATH_MAX, STORAGEDIR, + adapter->address, "linkkeys"); + str = textfile_caseget(filename, device->address); + ret = str ? TRUE : FALSE; + g_free(str); + + return ret; +} + +static char *device_get_name(struct device *device) +{ + struct adapter *adapter = device->adapter; + char filename[PATH_MAX + 1]; + + create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "names"); + return textfile_caseget(filename, device->address); +} + static DBusHandlerResult get_properties(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -757,12 +781,14 @@ static DBusHandlerResult get_properties(DBusConnection *conn, DBusMessageIter iter; DBusMessageIter dict; bdaddr_t src, dst; - char filename[PATH_MAX + 1], path[MAX_PATH_LENGTH]; + char path[MAX_PATH_LENGTH]; char buf[64]; const char *ptr; - char *str, *name, *ppath; + char *name, *ppath, **uuids; dbus_bool_t boolean; uint32_t class; + int i; + GSList *l; reply = dbus_message_new_method_return(msg); if (!reply) @@ -780,8 +806,7 @@ static DBusHandlerResult get_properties(DBusConnection *conn, &device->address); /* Name */ - create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "names"); - name = textfile_caseget(filename, device->address); + name = device_get_name(device); if (name) { dbus_message_iter_append_dict_entry(&dict, "Name", DBUS_TYPE_STRING, &name); @@ -808,16 +833,7 @@ static DBusHandlerResult get_properties(DBusConnection *conn, } /* Paired */ - create_name(filename, PATH_MAX, STORAGEDIR, - adapter->address, "linkkeys"); - str = textfile_caseget(filename, device->address); - if (str) { - boolean = TRUE; - free(str); - } else { - boolean = FALSE; - } - + boolean = device_is_paired(device); dbus_message_iter_append_dict_entry(&dict, "Paired", DBUS_TYPE_BOOLEAN, &boolean); @@ -837,8 +853,12 @@ static DBusHandlerResult get_properties(DBusConnection *conn, DBUS_TYPE_BOOLEAN, &boolean); /* UUIDs */ + uuids = g_new0(char *, g_slist_length(device->uuids) + 1); + for (i = 0, l = device->uuids; l; l = l->next, i++) + uuids[i] = l->data; dbus_message_iter_append_dict_entry(&dict, "UUIDs", - DBUS_TYPE_ARRAY, device->uuids); + DBUS_TYPE_ARRAY, &uuids); + g_free(uuids); /* Adapter */ snprintf(path, sizeof(path), "/hci%d", adapter->dev_id); |