From c4db10d2cde32ab4c05417a75e11698816a87c27 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 8 Apr 2015 13:32:22 +0300 Subject: policy: Mark reconnect services This make use of btd_service_reconnect to set reconnecting flag of services. --- plugins/policy.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index 80f1732d8..5a289101d 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -493,6 +493,25 @@ static void target_cb(struct btd_service *service, } } +static void mark_service(void *data, void *user_data) +{ + struct btd_service *service = data; + bool value = GPOINTER_TO_UINT(user_data); + + btd_service_reconnect(service, value); +} + +static void reconnect_set_active(struct reconnect_data *reconnect, bool value) +{ + if (reconnect->active == value) + return; + + reconnect->active = value; + + g_slist_foreach(reconnect->services, mark_service, + GUINT_TO_POINTER(value)); +} + static void reconnect_reset(struct reconnect_data *reconnect) { reconnect->attempt = 0; @@ -501,6 +520,8 @@ static void reconnect_reset(struct reconnect_data *reconnect) g_source_remove(reconnect->timer); reconnect->timer = 0; } + + reconnect_set_active(reconnect, false); } static bool reconnect_match(const char *uuid) @@ -643,7 +664,6 @@ static void service_cb(struct btd_service *service, */ reconnect = reconnect_add(service); - reconnect->active = false; reconnect_reset(reconnect); /* @@ -675,9 +695,6 @@ static gboolean reconnect_timeout(gpointer data) return FALSE; } - reconnect->active = true; - reconnect->attempt++; - return FALSE; } @@ -688,12 +705,14 @@ static void reconnect_set_timer(struct reconnect_data *reconnect) reconnect->attempt++; if (reconnect->attempt < reconnect_intervals_len) - timeout = reconnect_intervals[reconnect->attempt]; + timeout = reconnect_intervals[reconnect->attempt++]; DBG("%d seconds", timeout); reconnect->timer = g_timeout_add_seconds(timeout, reconnect_timeout, reconnect); + + reconnect_set_active(reconnect, true); } static void disconnect_cb(struct btd_device *dev, uint8_t reason) @@ -728,8 +747,6 @@ static void conn_fail_cb(struct btd_device *dev, uint8_t status) if (!reconnect->active) return; - reconnect->active = false; - /* Give up if we were powered off */ if (status == MGMT_STATUS_NOT_POWERED) { reconnect_reset(reconnect); -- cgit v1.2.1