2012-11-15 17:31:34

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 1/8] device: Remove storage path #defines

INFO_PATH and CACHE_PATH will be static for the
entire 5.x series
---
src/device.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/device.c b/src/device.c
index 4ca375b..e3570cb 100644
--- a/src/device.c
+++ b/src/device.c
@@ -76,9 +76,6 @@
#define DISCONNECT_TIMER 2
#define DISCOVERY_TIMER 2

-#define INFO_PATH STORAGEDIR "/%s/%s/info"
-#define CACHE_PATH STORAGEDIR "/%s/cache/%s"
-
struct btd_disconnect_data {
guint id;
disconnect_watch watch;
@@ -231,7 +228,8 @@ static gboolean store_device_info_cb(gpointer user_data)

ba2str(adapter_get_address(device->adapter), adapter_addr);
ba2str(&device->bdaddr, device_addr);
- snprintf(filename, PATH_MAX, INFO_PATH, adapter_addr, device_addr);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+ device_addr);
filename[PATH_MAX] = '\0';

create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -1693,7 +1691,7 @@ static char *load_cached_name(struct btd_device *device, const char *local,
char *str = NULL;
int len;

- snprintf(filename, PATH_MAX, CACHE_PATH, local, peer);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
filename[PATH_MAX] = '\0';

key_file = g_key_file_new();
@@ -1722,7 +1720,7 @@ static void load_info(struct btd_device *device, const gchar *local,
char *str;
gboolean store_needed = FALSE;

- snprintf(filename, PATH_MAX, INFO_PATH, local, peer);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", local, peer);
filename[PATH_MAX] = '\0';

key_file = g_key_file_new();
--
1.7.9.5



2012-11-16 08:24:49

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 8/8] neard: Set device class in device object

Hi Fr?d?ric,

On Thu, Nov 15, 2012, Fr?d?ric Danis wrote:
> This will create a new device object and generate DeviceCreated signal
> ---
> plugins/neard.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)

Your commit message doesn't explain why the old object needs to be
removed (imo it shouldn't need to be removed).

The other patches in this set have been applied.

> + device = adapter_get_device(adapter, remote_address);
> +
> /* store OOB data */

Missing check for failed adapter_get_device() return (NULL).

Johan

2012-11-15 17:31:39

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 6/8] event: Set device class in device object

---
src/event.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/event.c b/src/event.c
index 5f1fc9f..7fc8f02 100644
--- a/src/event.c
+++ b/src/event.c
@@ -419,7 +419,7 @@ void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_typ
update_lastused(local, peer, bdaddr_type);

if (class != 0)
- write_remote_class(local, peer, class);
+ device_set_class(device, class);

device_set_addr_type(device, bdaddr_type);

--
1.7.9.5


2012-11-15 17:31:40

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 7/8] dbusoob: Set device class in device object

---
plugins/dbusoob.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/plugins/dbusoob.c b/plugins/dbusoob.c
index b59ffa8..e58b353 100644
--- a/plugins/dbusoob.c
+++ b/plugins/dbusoob.c
@@ -191,7 +191,9 @@ static gboolean parse_data(DBusMessageIter *data, struct oob_data *remote_data)
return TRUE;
}

-static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
+static gboolean store_data(struct btd_adapter *adapter,
+ struct btd_device *device,
+ struct oob_data *data)
{
bdaddr_t bdaddr;

@@ -204,8 +206,7 @@ static gboolean store_data(struct btd_adapter *adapter, struct oob_data *data)
}

if (data->class)
- write_remote_class(adapter_get_address(adapter), &bdaddr,
- data->class);
+ device_set_class(device, data->class);

if (data->name)
btd_event_remote_name(adapter_get_address(adapter), &bdaddr,
@@ -255,7 +256,7 @@ static DBusMessage *add_remote_data(DBusConnection *conn, DBusMessage *msg,
if (!parse_data(&data, &remote_data))
return btd_error_invalid_args(msg);

- if (!store_data(adapter, &remote_data))
+ if (!store_data(adapter, device, &remote_data))
return btd_error_failed(msg, "Request failed");

reply = dbus_message_new_method_return(msg);
--
1.7.9.5


2012-11-15 17:31:35

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 2/8] device: Device_remove_stored removes device directory

When a device is removed we should remove the device info
file and storage directory.
---
src/device.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/src/device.c b/src/device.c
index e3570cb..5969f15 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1873,6 +1873,9 @@ static void device_remove_stored(struct btd_device *device)
{
const bdaddr_t *src = adapter_get_address(device->adapter);
uint8_t dst_type = device->bdaddr_type;
+ char adapter_addr[18];
+ char device_addr[18];
+ char filename[PATH_MAX + 1];

delete_entry(src, "profiles", &device->bdaddr, dst_type);
delete_entry(src, "trusts", &device->bdaddr, dst_type);
@@ -1893,6 +1896,19 @@ static void device_remove_stored(struct btd_device *device)

if (device->blocked)
device_unblock(device, TRUE, FALSE);
+
+ ba2str(src, adapter_addr);
+ ba2str(&device->bdaddr, device_addr);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+ device_addr);
+ filename[PATH_MAX] = '\0';
+ remove(filename);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", adapter_addr,
+ device_addr);
+ filename[PATH_MAX] = '\0';
+ remove(filename);
}

void device_remove(struct btd_device *device, gboolean remove_stored)
--
1.7.9.5


2012-11-15 17:31:37

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 4/8] device: Retrieve class from storage

When device class is updated, save it and emit property changed signal.
---
src/device.c | 60 ++++++++++++++++++++++++++++++++++++++--------------------
src/device.h | 1 +
2 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/src/device.c b/src/device.c
index 5969f15..d4d649b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -149,6 +149,7 @@ struct btd_device {
GSList *eir_uuids;
char name[MAX_NAME_LENGTH + 1];
char *alias;
+ uint32_t class;
uint16_t vendor_src;
uint16_t vendor;
uint16_t product;
@@ -211,6 +212,7 @@ static gboolean store_device_info_cb(gpointer user_data)
char adapter_addr[18];
char device_addr[18];
char *str;
+ char class[9];
gsize length = 0;

device->store_id = 0;
@@ -223,6 +225,11 @@ static gboolean store_device_info_cb(gpointer user_data)
g_key_file_set_string(key_file, "General", "Alias",
device->alias);

+ if (device->class) {
+ sprintf(class, "0x%6.6x", device->class);
+ g_key_file_set_string(key_file, "General", "Class", class);
+ }
+
g_key_file_set_boolean(key_file, "General", "Trusted",
device->trusted);

@@ -470,35 +477,23 @@ static void dev_property_set_alias(const GDBusPropertyTable *property,
set_alias(id, alias, data);
}

-static gboolean get_class(const GDBusPropertyTable *property, void *data,
- uint32_t *class)
-{
- struct btd_device *device = data;
-
- if (read_remote_class(adapter_get_address(device->adapter),
- &device->bdaddr, class) == 0)
- return TRUE;
-
- return FALSE;
-}
-
static gboolean dev_property_exists_class(const GDBusPropertyTable *property,
void *data)
{
- uint32_t class;
+ struct btd_device *device = data;

- return get_class(property, data, &class);
+ return device->class != 0;
}

static gboolean dev_property_get_class(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
- uint32_t class;
+ struct btd_device *device = data;

- if (!get_class(property, data, &class))
+ if (device->class == 0)
return FALSE;

- dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &class);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &device->class);

return TRUE;
}
@@ -542,12 +537,12 @@ static gboolean dev_property_get_appearance(const GDBusPropertyTable *property,

static const char *get_icon(const GDBusPropertyTable *property, void *data)
{
+ struct btd_device *device = data;
const char *icon = NULL;
- uint32_t class;
uint16_t appearance;

- if (get_class(property, data, &class))
- icon = class_to_icon(class);
+ if (device->class != 0)
+ icon = class_to_icon(device->class);
else if (get_appearance(property, data, &appearance))
icon = gap_appearance_to_icon(appearance);

@@ -1745,6 +1740,16 @@ static void load_info(struct btd_device *device, const gchar *local,
device->alias = g_key_file_get_string(key_file, "General", "Alias",
NULL);

+ /* Load class */
+ str = g_key_file_get_string(key_file, "General", "Class", NULL);
+ if (str) {
+ uint32_t class;
+
+ if (sscanf(str, "%x", &class) == 1)
+ device->class = class;
+ g_free(str);
+ }
+
/* Load trust */
device->trusted = g_key_file_get_boolean(key_file, "General",
"Trusted", NULL);
@@ -1849,6 +1854,21 @@ bool device_name_known(struct btd_device *device)
return device->name[0] != '\0';
}

+void device_set_class(struct btd_device *device, uint32_t class)
+{
+ if (device->class == class)
+ return;
+
+ DBG("%s 0x%06X", device->path, class);
+
+ device->class = class;
+
+ store_device_info(device);
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), device->path,
+ DEVICE_INTERFACE, "Class");
+}
+
uint16_t btd_device_get_vendor(struct btd_device *device)
{
return device->vendor;
diff --git a/src/device.h b/src/device.h
index ea646a8..3715698 100644
--- a/src/device.h
+++ b/src/device.h
@@ -32,6 +32,7 @@ struct btd_device *device_create(struct btd_adapter *adapter,
void device_set_name(struct btd_device *device, const char *name);
void device_get_name(struct btd_device *device, char *name, size_t len);
bool device_name_known(struct btd_device *device);
+void device_set_class(struct btd_device *device, uint32_t class);
uint16_t btd_device_get_vendor(struct btd_device *device);
uint16_t btd_device_get_vendor_src(struct btd_device *device);
uint16_t btd_device_get_product(struct btd_device *device);
--
1.7.9.5


2012-11-15 17:31:41

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 8/8] neard: Set device class in device object

This will create a new device object and generate
DeviceCreated signal
---
plugins/neard.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 8f8381c..069953a 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -287,10 +287,11 @@ static int process_eir(struct btd_adapter *adapter, uint8_t *eir, size_t size,
if (device)
adapter_remove_device(adapter, device, TRUE);

+ device = adapter_get_device(adapter, remote_address);
+
/* store OOB data */
if (eir_data.class != 0)
- write_remote_class(adapter_get_address(adapter),
- &eir_data.addr, eir_data.class);
+ device_set_class(device, eir_data.class);

/* TODO handle incomplete name? */
if (eir_data.name)
--
1.7.9.5


2012-11-15 17:31:38

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 5/8] adapter: Set device class in device object

Move storage of device class after device object creation.
---
src/adapter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5157b46..9ecc0fa 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3070,9 +3070,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
return;
}

- if (eir_data.class != 0)
- write_remote_class(&adapter->bdaddr, bdaddr, eir_data.class);
-
if (eir_data.appearance != 0)
write_remote_appearance(&adapter->bdaddr, bdaddr, bdaddr_type,
eir_data.appearance);
@@ -3102,6 +3099,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter,
if (eir_data.name)
device_set_name(dev, eir_data.name);

+ if (eir_data.class != 0)
+ device_set_class(dev, eir_data.class);
+
device_add_eir_uuids(dev, eir_data.services);

eir_data_free(&eir_data);
--
1.7.9.5


2012-11-15 17:31:36

by Frederic Danis

[permalink] [raw]
Subject: [PATCH 3/8] adapter: Convert storage classes

---
src/adapter.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index ea2d2ad..5157b46 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2545,6 +2545,11 @@ static void convert_trusts_entry(GKeyFile *key_file, void *value)
g_key_file_set_boolean(key_file, "General", "Trusted", TRUE);
}

+static void convert_classes_entry(GKeyFile *key_file, void *value)
+{
+ g_key_file_set_string(key_file, "General", "Class", value);
+}
+
static void convert_entry(char *key, char *value, void *user_data)
{
struct device_converter *converter = user_data;
@@ -2624,6 +2629,9 @@ static void convert_device_storage(struct btd_adapter *adapter)

/* Convert trusts */
convert_file("trusts", address, convert_trusts_entry);
+
+ /* Convert classes */
+ convert_file("classes", address, convert_classes_entry);
}

static void convert_config(struct btd_adapter *adapter, const char *filename,
--
1.7.9.5