OSDN Git Service

device: Use new storage for device alias
authorFrédéric Danis <frederic.danis@linux.intel.com>
Wed, 14 Nov 2012 11:28:50 +0000 (12:28 +0100)
committerJohan Hedberg <johan.hedberg@intel.com>
Wed, 14 Nov 2012 11:50:21 +0000 (13:50 +0200)
As set_alias() changes value in device structure and write to
storage is deferred, property set could not return failure.

src/device.c

index 3ca265e..d71e548 100644 (file)
@@ -222,6 +222,10 @@ static gboolean store_device_info_cb(gpointer user_data)
 
        g_key_file_set_string(key_file, "General", "Name", device->name);
 
+       if (device->alias != NULL)
+               g_key_file_set_string(key_file, "General", "Alias",
+                                       device->alias);
+
        ba2str(adapter_get_address(device->adapter), adapter_addr);
        ba2str(&device->bdaddr, device_addr);
        snprintf(filename, PATH_MAX, INFO_PATH, adapter_addr, device_addr);
@@ -432,28 +436,17 @@ static void set_alias(GDBusPendingPropertySet id, const char *alias,
                                                                void *data)
 {
        struct btd_device *device = data;
-       struct btd_adapter *adapter = device->adapter;
-       char srcaddr[18], dstaddr[18];
-       int err;
 
        /* No change */
        if ((device->alias == NULL && g_str_equal(alias, "")) ||
                                        g_strcmp0(device->alias, alias) == 0)
                return g_dbus_pending_property_success(id);
 
-       ba2str(adapter_get_address(adapter), srcaddr);
-       ba2str(&device->bdaddr, dstaddr);
-
-       /* Remove alias if empty string */
-       err = write_device_alias(srcaddr, dstaddr, device->bdaddr_type,
-                                       g_str_equal(alias, "") ? NULL : alias);
-       if (err < 0)
-               return g_dbus_pending_property_error(id,
-                               ERROR_INTERFACE ".Failed", strerror(-err));
-
        g_free(device->alias);
        device->alias = g_str_equal(alias, "") ? NULL : g_strdup(alias);
 
+       store_device_info(device);
+
        g_dbus_emit_property_changed(btd_get_dbus_connection(),
                                device->path, DEVICE_INTERFACE, "Alias");
 
@@ -1756,6 +1749,10 @@ static void load_info(struct btd_device *device, const gchar *local,
                g_free(str);
        }
 
+       /* Load alias */
+       device->alias = g_key_file_get_string(key_file, "General", "Alias",
+                                               NULL);
+
        if (store_needed)
                store_device_info(device);
 
@@ -1769,7 +1766,7 @@ struct btd_device *device_create(struct btd_adapter *adapter,
        struct btd_device *device;
        const gchar *adapter_path = adapter_get_path(adapter);
        const bdaddr_t *src;
-       char srcaddr[18], alias[MAX_NAME_LENGTH + 1];
+       char srcaddr[18];
        uint16_t vendor, product, version;
 
        device = g_try_malloc0(sizeof(struct btd_device));
@@ -1800,9 +1797,6 @@ struct btd_device *device_create(struct btd_adapter *adapter,
 
        load_info(device, srcaddr, address);
 
-       if (read_device_alias(srcaddr, address, bdaddr_type, alias,
-                                                       sizeof(alias)) == 0)
-               device->alias = g_strdup(alias);
        device->trusted = read_trust(src, address, device->bdaddr_type);
 
        if (read_blocked(src, &device->bdaddr, device->bdaddr_type))