diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2017-07-27 14:35:20 -0700 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2017-07-27 17:21:37 -0700 |
commit | b7e7a45106469bdbaa1b296ed1b2a3f8aaadaf0e (patch) | |
tree | 16e03eb9e54e3e6eeb7cfa8bfbbda7cc526ac4e7 /binding-bluetooth/bluetooth-manager.c | |
parent | a260014337f3686a5735ffaba7a79b595839a3f8 (diff) |
binding: bluetooth: attempt autoconnect to multiple devices
Round robin through the paired devices every 5 seconds till one
is successful.
Bug-AGL: SPEC-722
Change-Id: I79ff4ee96eabc4def596ab2b7569c9710eb35bfd
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding-bluetooth/bluetooth-manager.c')
-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; } |