* [PATCH v3 1/5] android/bluetooth: Split devices list to devices and bonded_devices
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
@ 2014-01-23 22:18 ` Szymon Janc
2014-01-23 22:18 ` [PATCH v3 2/5] android/bluetooth: Use defines for settings and devices files paths Szymon Janc
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-23 22:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Bonded devices are permament until unbondedn. Non-bonded devices will
be held in (size limited) cache based on timestamp property so split
list to ease separation.
---
android/bluetooth.c | 48 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 4849dab..5d222e1 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -132,6 +132,8 @@ static const uint16_t uuid_list[] = {
static uint16_t option_index = MGMT_INDEX_NONE;
static struct mgmt *mgmt_if = NULL;
+
+static GSList *bonded_devices = NULL;
static GSList *devices = NULL;
/* This list contains addresses which are asked for records */
@@ -283,6 +285,10 @@ static struct device *find_device(const bdaddr_t *bdaddr)
{
GSList *l;
+ l = g_slist_find_custom(bonded_devices, bdaddr, device_match);
+ if (l)
+ return l->data;
+
l = g_slist_find_custom(devices, bdaddr, device_match);
if (l)
return l->data;
@@ -559,12 +565,30 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
if (!dev)
return;
- if (dev->bond_state != state) {
- dev->bond_state = state;
- send_bond_state_change(&dev->bdaddr, status, state);
+ if (dev->bond_state == state)
+ return;
- store_device_info(dev);
+ switch (state) {
+ case HAL_BOND_STATE_NONE:
+ if (dev->bond_state == HAL_BOND_STATE_BONDED) {
+ bonded_devices = g_slist_remove(bonded_devices, dev);
+ devices = g_slist_prepend(devices, dev);
+ }
+ break;
+ case HAL_BOND_STATE_BONDED:
+ devices = g_slist_remove(devices, dev);
+ bonded_devices = g_slist_prepend(bonded_devices, dev);
+ break;
+ case HAL_BOND_STATE_BONDING:
+ default:
+ break;
}
+
+ dev->bond_state = state;
+
+ store_device_info(dev);
+
+ send_bond_state_change(&dev->bdaddr, status, state);
}
static void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
@@ -935,6 +959,7 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
if (adapter.discovering) {
cp.state = HAL_DISCOVERY_STATE_STARTED;
} else {
+ g_slist_foreach(bonded_devices, clear_device_found, NULL);
g_slist_foreach(devices, clear_device_found, NULL);
cp.state = HAL_DISCOVERY_STATE_STOPPED;
}
@@ -2128,18 +2153,15 @@ static uint8_t get_adapter_scan_mode(void)
static uint8_t get_adapter_bonded_devices(void)
{
- uint8_t buf[sizeof(bdaddr_t) * g_slist_length(devices)];
+ uint8_t buf[sizeof(bdaddr_t) * g_slist_length(bonded_devices)];
int i = 0;
GSList *l;
DBG("");
- for (l = devices; l; l = g_slist_next(l)) {
+ for (l = bonded_devices; l; l = g_slist_next(l)) {
struct device *dev = l->data;
- if (dev->bond_state != HAL_BOND_STATE_BONDED)
- continue;
-
bdaddr2android(&dev->bdaddr, buf + (i * sizeof(bdaddr_t)));
i++;
}
@@ -2691,11 +2713,10 @@ static void send_bonded_devices_props(void)
{
GSList *l;
- for (l = devices; l; l = g_slist_next(l)) {
+ for (l = bonded_devices; l; l = g_slist_next(l)) {
struct device *dev = l->data;
- if (dev->bond_state == HAL_BOND_STATE_BONDED)
- get_remote_device_props(dev);
+ get_remote_device_props(dev);
}
}
@@ -3093,6 +3114,9 @@ void bt_bluetooth_unregister(void)
{
DBG("");
+ g_slist_free_full(bonded_devices, (GDestroyNotify) free_device);
+ bonded_devices = NULL;
+
g_slist_free_full(devices, (GDestroyNotify) free_device);
devices = NULL;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 2/5] android/bluetooth: Use defines for settings and devices files paths
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
2014-01-23 22:18 ` [PATCH v3 1/5] android/bluetooth: Split devices list to devices and bonded_devices Szymon Janc
@ 2014-01-23 22:18 ` Szymon Janc
2014-01-23 22:18 ` [PATCH v3 3/5] android/bluetooth: Add support for caching remote device info Szymon Janc
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-23 22:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
android/bluetooth.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 5d222e1..f5ac0e4 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -54,6 +54,9 @@
#define DUT_MODE_FILE "/sys/kernel/debug/bluetooth/hci%u/dut_mode"
+#define SETTINGS_FILE ANDROID_STORAGEDIR"/settings"
+#define DEVICES_FILE ANDROID_STORAGEDIR"/devices"
+
#define DEVICE_ID_SOURCE 0x0002 /* USB */
#define DEVICE_ID_VENDOR 0x1d6b /* Linux Foundation */
#define DEVICE_ID_PRODUCT 0x0247 /* BlueZ for Android */
@@ -148,8 +151,7 @@ static void store_adapter_config(void)
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/settings", 0,
- NULL);
+ g_key_file_load_from_file(key_file, SETTINGS_FILE, 0, NULL);
ba2str(&adapter.bdaddr, addr);
@@ -160,7 +162,7 @@ static void store_adapter_config(void)
data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(ANDROID_STORAGEDIR"/settings", data, length, NULL);
+ g_file_set_contents(SETTINGS_FILE, data, length, NULL);
g_free(data);
g_key_file_free(key_file);
@@ -173,8 +175,7 @@ static void load_adapter_config(void)
char *str;
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/settings", 0,
- NULL);
+ g_key_file_load_from_file(key_file, SETTINGS_FILE, 0, NULL);
str = g_key_file_get_string(key_file, "General", "Address", NULL);
if (!str) {
@@ -216,8 +217,7 @@ static void store_device_info(struct device *dev)
ba2str(&dev->bdaddr, addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices", 0,
- NULL);
+ g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL);
if (dev->bond_state == HAL_BOND_STATE_NONE) {
g_key_file_remove_group(key_file, addr, NULL);
@@ -266,7 +266,7 @@ static void store_device_info(struct device *dev)
done:
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(ANDROID_STORAGEDIR"/devices", str, length, NULL);
+ g_file_set_contents(DEVICES_FILE, str, length, NULL);
g_free(str);
g_key_file_free(key_file);
@@ -521,8 +521,7 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
key_file = g_key_file_new();
- if (!g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices",
- 0, NULL))
+ if (!g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL))
return;
ba2str(dst, addr);
@@ -537,7 +536,7 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key,
g_key_file_set_integer(key_file, addr, "LinkKeyPinLength", pin_length);
data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(ANDROID_STORAGEDIR"/devices", data, length, NULL);
+ g_file_set_contents(DEVICES_FILE, data, length, NULL);
g_free(data);
g_key_file_free(key_file);
@@ -1727,8 +1726,7 @@ static void load_devices_info(bt_bluetooth_ready cb)
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/devices", 0,
- NULL);
+ g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL);
devs = g_key_file_get_groups(key_file, &len);
--
1.8.5.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 3/5] android/bluetooth: Add support for caching remote device info
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
2014-01-23 22:18 ` [PATCH v3 1/5] android/bluetooth: Split devices list to devices and bonded_devices Szymon Janc
2014-01-23 22:18 ` [PATCH v3 2/5] android/bluetooth: Use defines for settings and devices files paths Szymon Janc
@ 2014-01-23 22:18 ` Szymon Janc
2014-01-23 22:18 ` [PATCH v3 4/5] android/bluetooth: Add support for loading caches devices from storage Szymon Janc
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-23 22:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
From: Szymon Janc <szymon.janc@tieto.com>
Cache is limited to DEVICES_CACHE_MAX. Devices are sorted with
timestamp so if cache is full olderst device is removed.
---
android/bluetooth.c | 115 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 82 insertions(+), 33 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index f5ac0e4..cf2dc83 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -56,6 +56,7 @@
#define SETTINGS_FILE ANDROID_STORAGEDIR"/settings"
#define DEVICES_FILE ANDROID_STORAGEDIR"/devices"
+#define CACHE_FILE ANDROID_STORAGEDIR"/cache"
#define DEVICE_ID_SOURCE 0x0002 /* USB */
#define DEVICE_ID_VENDOR 0x1d6b /* Linux Foundation */
@@ -70,6 +71,8 @@
/* Default discoverable timeout 120sec as in Android */
#define DEFAULT_DISCOVERABLE_TIMEOUT 120
+#define DEVICES_CACHE_MAX 300
+
#define BASELEN_PROP_CHANGED (sizeof(struct hal_ev_adapter_props_changed) \
+ (sizeof(struct hal_property)))
@@ -199,7 +202,7 @@ static void load_adapter_config(void)
g_key_file_free(key_file);
}
-static void store_device_info(struct device *dev)
+static void store_device_info(struct device *dev, const char *path)
{
GKeyFile *key_file;
char addr[18];
@@ -207,22 +210,10 @@ static void store_device_info(struct device *dev)
char **uuids = NULL;
char *str;
- /* We only store bonded devices and need to modify the storage
- * if the state is either NONE or BONDED.
- */
- if (dev->bond_state != HAL_BOND_STATE_BONDED &&
- dev->bond_state != HAL_BOND_STATE_NONE)
- return;
-
ba2str(&dev->bdaddr, addr);
key_file = g_key_file_new();
- g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL);
-
- if (dev->bond_state == HAL_BOND_STATE_NONE) {
- g_key_file_remove_group(key_file, addr, NULL);
- goto done;
- }
+ g_key_file_load_from_file(key_file, path, 0, NULL);
g_key_file_set_integer(key_file, addr, "Type", dev->bdaddr_type);
@@ -264,15 +255,35 @@ static void store_device_info(struct device *dev)
g_key_file_remove_key(key_file, addr, "Services", NULL);
}
-done:
str = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(DEVICES_FILE, str, length, NULL);
+ g_file_set_contents(path, str, length, NULL);
g_free(str);
g_key_file_free(key_file);
g_strfreev(uuids);
}
+static void remove_device_info(struct device *dev, const char *path)
+{
+ GKeyFile *key_file;
+ gsize length = 0;
+ char addr[18];
+ char *str;
+
+ ba2str(&dev->bdaddr, addr);
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, path, 0, NULL);
+
+ g_key_file_remove_group(key_file, addr, NULL);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(path, str, length, NULL);
+ g_free(str);
+
+ g_key_file_free(key_file);
+}
+
static int device_match(gconstpointer a, gconstpointer b)
{
const struct device *dev = a;
@@ -296,6 +307,41 @@ static struct device *find_device(const bdaddr_t *bdaddr)
return NULL;
}
+static void free_device(struct device *dev)
+{
+ g_free(dev->name);
+ g_free(dev->friendly_name);
+ g_slist_free_full(dev->uuids, g_free);
+ g_free(dev);
+}
+
+static void cache_device(struct device *new_dev)
+{
+ struct device *dev;
+ GSList *l;
+
+ l = g_slist_find(devices, new_dev);
+ if (l) {
+ devices = g_slist_remove(devices, new_dev);
+ goto cache;
+ }
+
+ if (g_slist_length(devices) < DEVICES_CACHE_MAX)
+ goto cache;
+
+ l = g_slist_last(devices);
+ dev = l->data;
+
+ devices = g_slist_remove(devices, dev);
+ remove_device_info(dev, CACHE_FILE);
+ free_device(dev);
+
+cache:
+ devices = g_slist_prepend(devices, new_dev);
+ new_dev->timestamp = time(NULL);
+ store_device_info(new_dev, CACHE_FILE);
+}
+
static struct device *create_device(const bdaddr_t *bdaddr, uint8_t type)
{
struct device *dev;
@@ -314,19 +360,10 @@ static struct device *create_device(const bdaddr_t *bdaddr, uint8_t type)
/* use address for name, will be change if one is present
* eg. in EIR or set by set_property. */
dev->name = g_strdup(addr);
- devices = g_slist_prepend(devices, dev);
return dev;
}
-static void free_device(struct device *dev)
-{
- g_free(dev->name);
- g_free(dev->friendly_name);
- g_slist_free_full(dev->uuids, g_free);
- g_free(dev);
-}
-
static struct device *get_device(const bdaddr_t *bdaddr, uint8_t type)
{
struct device *dev;
@@ -335,7 +372,11 @@ static struct device *get_device(const bdaddr_t *bdaddr, uint8_t type)
if (dev)
return dev;
- return create_device(bdaddr, type);
+ dev = create_device(bdaddr, type);
+
+ cache_device(dev);
+
+ return dev;
}
static void send_adapter_property(uint8_t type, uint16_t len, const void *val)
@@ -571,12 +612,15 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
case HAL_BOND_STATE_NONE:
if (dev->bond_state == HAL_BOND_STATE_BONDED) {
bonded_devices = g_slist_remove(bonded_devices, dev);
- devices = g_slist_prepend(devices, dev);
+ remove_device_info(dev, DEVICES_FILE);
+ cache_device(dev);
}
break;
case HAL_BOND_STATE_BONDED:
devices = g_slist_remove(devices, dev);
bonded_devices = g_slist_prepend(bonded_devices, dev);
+ remove_device_info(dev, CACHE_FILE);
+ store_device_info(dev, DEVICES_FILE);
break;
case HAL_BOND_STATE_BONDING:
default:
@@ -585,8 +629,6 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
dev->bond_state = state;
- store_device_info(dev);
-
send_bond_state_change(&dev->bdaddr, status, state);
}
@@ -627,7 +669,10 @@ static void set_device_uuids(struct device *dev, GSList *uuids)
g_slist_free_full(dev->uuids, g_free);
dev->uuids = uuids;
- store_device_info(dev);
+ if (dev->bond_state == HAL_BOND_STATE_BONDED)
+ store_device_info(dev, DEVICES_FILE);
+ else
+ store_device_info(dev, CACHE_FILE);
send_device_uuids_notif(dev);
}
@@ -1058,8 +1103,6 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
ev->status = HAL_STATUS_SUCCESS;
bdaddr2android(bdaddr, ev->bdaddr);
-
- dev->timestamp = time(NULL);
}
if (eir.class) {
@@ -1087,6 +1130,9 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
(*num_prop)++;
}
+ if (dev->bond_state != HAL_BOND_STATE_BONDED)
+ cache_device(dev);
+
if (*num_prop)
ipc_send_notif(HAL_SERVICE_ID_BLUETOOTH, opcode, size, buf);
@@ -2860,7 +2906,10 @@ static uint8_t set_device_friendly_name(struct device *dev, const uint8_t *val,
g_free(dev->friendly_name);
dev->friendly_name = g_strndup((const char *) val, len);
- store_device_info(dev);
+ if (dev->bond_state == HAL_BOND_STATE_BONDED)
+ store_device_info(dev, DEVICES_FILE);
+ else
+ store_device_info(dev, CACHE_FILE);
send_device_property(&dev->bdaddr, HAL_PROP_DEVICE_FRIENDLY_NAME,
strlen(dev->friendly_name), dev->friendly_name);
--
1.8.5.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 4/5] android/bluetooth: Add support for loading caches devices from storage
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
` (2 preceding siblings ...)
2014-01-23 22:18 ` [PATCH v3 3/5] android/bluetooth: Add support for caching remote device info Szymon Janc
@ 2014-01-23 22:18 ` Szymon Janc
2014-01-23 22:18 ` [PATCH v3 5/5] android/bluetooth: Rename devices list to cached_devices Szymon Janc
2014-01-24 14:21 ` [PATCH v3 0/5] Remote device cache support Szymon Janc
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-23 22:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
From: Szymon Janc <szymon.janc@tieto.com>
Info is now stored for all devices and bond state depends on file.
Based on that devices loaded from storage are put either to cache
or to bonded_devices list.
---
android/bluetooth.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 54 insertions(+), 5 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index cf2dc83..126b26a 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -1679,7 +1679,8 @@ static void clear_uuids(void)
sizeof(cp), &cp, NULL, NULL, NULL);
}
-static void create_device_from_info(GKeyFile *key_file, const char *peer)
+static struct device *create_device_from_info(GKeyFile *key_file,
+ const char *peer)
{
struct device *dev;
uint8_t type;
@@ -1694,7 +1695,11 @@ static void create_device_from_info(GKeyFile *key_file, const char *peer)
str2ba(peer, &bdaddr);
dev = create_device(&bdaddr, type);
- dev->bond_state = HAL_BOND_STATE_BONDED;
+ str = g_key_file_get_string(key_file, peer, "LinkKey", NULL);
+ if (str) {
+ g_free(str);
+ dev->bond_state = HAL_BOND_STATE_BONDED;
+ }
str = g_key_file_get_string(key_file, peer, "Name", NULL);
if (str) {
@@ -1730,6 +1735,8 @@ static void create_device_from_info(GKeyFile *key_file, const char *peer)
g_strfreev(uuids);
}
+
+ return dev;
}
static struct mgmt_link_key_info *get_key_info(GKeyFile *key_file, const char *peer)
@@ -1762,6 +1769,40 @@ failed:
return info;
}
+static int device_timestamp_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct device *deva = a;
+ const struct device *devb = b;
+
+ return deva->timestamp < devb->timestamp;
+}
+
+static void load_devices_cache(void)
+{
+ GKeyFile *key_file;
+ gchar **devs;
+ gsize len = 0;
+ unsigned int i;
+
+ key_file = g_key_file_new();
+
+ g_key_file_load_from_file(key_file, CACHE_FILE, 0, NULL);
+
+ devs = g_key_file_get_groups(key_file, &len);
+
+ for (i = 0; i < len; i++) {
+ struct device *dev;
+
+ dev = create_device_from_info(key_file, devs[i]);
+ devices = g_slist_prepend(devices, dev);
+ }
+
+ devices = g_slist_sort(devices, device_timestamp_cmp);
+
+ g_strfreev(devs);
+ g_key_file_free(key_file);
+}
+
static void load_devices_info(bt_bluetooth_ready cb)
{
GKeyFile *key_file;
@@ -1778,14 +1819,21 @@ static void load_devices_info(bt_bluetooth_ready cb)
for (i = 0; i < len; i++) {
struct mgmt_link_key_info *key_info;
+ struct device *dev;
- create_device_from_info(key_file, devs[i]);
+ dev = create_device_from_info(key_file, devs[i]);
key_info = get_key_info(key_file, devs[i]);
- if (key_info)
- keys = g_slist_prepend(keys, key_info);
+ if (!key_info) {
+ error("Failed to load linkkey for %s, skipping",
+ devs[i]);
+ continue;
+ }
/* TODO ltk */
+
+ keys = g_slist_prepend(keys, key_info);
+ bonded_devices = g_slist_prepend(bonded_devices, dev);
}
load_link_keys(keys, cb);
@@ -1873,6 +1921,7 @@ static void read_info_complete(uint8_t status, uint16_t length,
clear_uuids();
load_devices_info(cb);
+ load_devices_cache();
set_io_capability();
set_device_id();
--
1.8.5.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 5/5] android/bluetooth: Rename devices list to cached_devices
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
` (3 preceding siblings ...)
2014-01-23 22:18 ` [PATCH v3 4/5] android/bluetooth: Add support for loading caches devices from storage Szymon Janc
@ 2014-01-23 22:18 ` Szymon Janc
2014-01-24 14:21 ` [PATCH v3 0/5] Remote device cache support Szymon Janc
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-23 22:18 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This makes it clear what is the purpose of this list.
---
android/bluetooth.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 126b26a..a9e529f 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -140,7 +140,7 @@ static uint16_t option_index = MGMT_INDEX_NONE;
static struct mgmt *mgmt_if = NULL;
static GSList *bonded_devices = NULL;
-static GSList *devices = NULL;
+static GSList *cached_devices = NULL;
/* This list contains addresses which are asked for records */
static GSList *browse_reqs;
@@ -300,7 +300,7 @@ static struct device *find_device(const bdaddr_t *bdaddr)
if (l)
return l->data;
- l = g_slist_find_custom(devices, bdaddr, device_match);
+ l = g_slist_find_custom(cached_devices, bdaddr, device_match);
if (l)
return l->data;
@@ -320,24 +320,24 @@ static void cache_device(struct device *new_dev)
struct device *dev;
GSList *l;
- l = g_slist_find(devices, new_dev);
+ l = g_slist_find(cached_devices, new_dev);
if (l) {
- devices = g_slist_remove(devices, new_dev);
+ cached_devices = g_slist_remove(cached_devices, new_dev);
goto cache;
}
- if (g_slist_length(devices) < DEVICES_CACHE_MAX)
+ if (g_slist_length(cached_devices) < DEVICES_CACHE_MAX)
goto cache;
- l = g_slist_last(devices);
+ l = g_slist_last(cached_devices);
dev = l->data;
- devices = g_slist_remove(devices, dev);
+ cached_devices = g_slist_remove(cached_devices, dev);
remove_device_info(dev, CACHE_FILE);
free_device(dev);
cache:
- devices = g_slist_prepend(devices, new_dev);
+ cached_devices = g_slist_prepend(cached_devices, new_dev);
new_dev->timestamp = time(NULL);
store_device_info(new_dev, CACHE_FILE);
}
@@ -617,7 +617,7 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
}
break;
case HAL_BOND_STATE_BONDED:
- devices = g_slist_remove(devices, dev);
+ cached_devices = g_slist_remove(cached_devices, dev);
bonded_devices = g_slist_prepend(bonded_devices, dev);
remove_device_info(dev, CACHE_FILE);
store_device_info(dev, DEVICES_FILE);
@@ -1004,7 +1004,7 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
cp.state = HAL_DISCOVERY_STATE_STARTED;
} else {
g_slist_foreach(bonded_devices, clear_device_found, NULL);
- g_slist_foreach(devices, clear_device_found, NULL);
+ g_slist_foreach(cached_devices, clear_device_found, NULL);
cp.state = HAL_DISCOVERY_STATE_STOPPED;
}
@@ -1794,10 +1794,10 @@ static void load_devices_cache(void)
struct device *dev;
dev = create_device_from_info(key_file, devs[i]);
- devices = g_slist_prepend(devices, dev);
+ cached_devices = g_slist_prepend(cached_devices, dev);
}
- devices = g_slist_sort(devices, device_timestamp_cmp);
+ cached_devices = g_slist_sort(cached_devices, device_timestamp_cmp);
g_strfreev(devs);
g_key_file_free(key_file);
@@ -3213,8 +3213,8 @@ void bt_bluetooth_unregister(void)
g_slist_free_full(bonded_devices, (GDestroyNotify) free_device);
bonded_devices = NULL;
- g_slist_free_full(devices, (GDestroyNotify) free_device);
- devices = NULL;
+ g_slist_free_full(cached_devices, (GDestroyNotify) free_device);
+ cached_devices = NULL;
ipc_unregister(HAL_SERVICE_ID_CORE);
}
--
1.8.5.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 0/5] Remote device cache support
2014-01-23 22:18 [PATCH v3 0/5] Remote device cache support Szymon Janc
` (4 preceding siblings ...)
2014-01-23 22:18 ` [PATCH v3 5/5] android/bluetooth: Rename devices list to cached_devices Szymon Janc
@ 2014-01-24 14:21 ` Szymon Janc
5 siblings, 0 replies; 7+ messages in thread
From: Szymon Janc @ 2014-01-24 14:21 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi,
On Thursday 23 of January 2014 23:18:05 Szymon Janc wrote:
> V3:
> - bugfixes in cache handling
>
> V2:
> - keep cache in separate file
> - patch 3/5 and 4/5 from V1 squashed to 3/4
>
> V1:
> - set cache limit to 300
> - update timestamp of cached device
> - rebased to master
> - other minor fixes
>
> Szymon Janc (5):
> android/bluetooth: Split devices list to devices and bonded_devices
> android/bluetooth: Use defines for settings and devices files paths
> android/bluetooth: Add support for caching remote device info
> android/bluetooth: Add support for loading caches devices from storage
> android/bluetooth: Rename devices list to cached_devices
>
> android/bluetooth.c | 246 ++++++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 183 insertions(+), 63 deletions(-)
>
This is now pushed upstream.
--
Best regards,
Szymon Janc
^ permalink raw reply [flat|nested] 7+ messages in thread