diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2017-07-27 14:35:20 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2017-08-04 15:31:00 -0700 |
commit | dabd2b715a9104dd2e990fddf06b06f0d4d7bd62 (patch) | |
tree | 6ccbd3663360a192ff70fd2ada266057555dc4d2 /binding-bluetooth | |
parent | 232f305c3f845fcd75918447fc7262a19fdd0399 (diff) |
binding: bluetooth: attempt autoconnect to multiple devices
Round robin through the paired devices every 5 seconds till one
is successful.
Change-Id: I86b6e03e221c48a5f302f292aadcec4293d7e1e7
Bug-AGL: SPEC-722
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding-bluetooth')
-rw-r--r-- | binding-bluetooth/bluetooth-manager.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/binding-bluetooth/bluetooth-manager.c b/binding-bluetooth/bluetooth-manager.c index 3038a6e..b708439 100644 --- a/binding-bluetooth/bluetooth-manager.c +++ b/binding-bluetooth/bluetooth-manager.c @@ -1070,8 +1070,7 @@ gboolean bt_autoconnect(gpointer ptr) { LOGD("\n"); gboolean ret = TRUE; - GSList *list, *tmp; - gchar *bdaddr = NULL; + GSList *list, *tmp, *addr_list = NULL; devices_list_lock(); @@ -1083,14 +1082,15 @@ gboolean bt_autoconnect(gpointer ptr) struct bt_device *BDdevice = tmp->data; tmp = tmp->next; - if (BDdevice->paired && bdaddr == NULL) + if (BDdevice->paired) { - bdaddr = g_strdup(BDdevice->bdaddr); + addr_list = g_slist_append(addr_list, g_strdup(BDdevice->bdaddr)); } if (BDdevice->connected) { g_slist_free_full(list, g_free); + g_slist_free_full(addr_list, g_free); devices_list_unlock(); return FALSE; } @@ -1099,16 +1099,27 @@ gboolean bt_autoconnect(gpointer ptr) g_slist_free_full(list, g_free); devices_list_unlock(); - /* - * NOTE: Attempt to connect to first paired device, and once connected don't - * poll anymore. - */ - if (bdaddr != NULL) + if (addr_list == NULL) { - ret = device_connect(bdaddr, NULL) ? TRUE : FALSE; - g_free(bdaddr); + return FALSE; } + tmp = addr_list; + + while (tmp) + { + LOGD("Autoconnect to %s\n", tmp->data); + ret = device_connect(tmp->data, NULL) ? TRUE : FALSE; + tmp = tmp->next; + + if (ret == FALSE) + { + break; + } + } + + g_slist_free_full(addr_list, g_free); + return ret; } |