summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-04-08 13:32:22 +0300
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2016-03-11 11:37:21 +0200
commitc4db10d2cde32ab4c05417a75e11698816a87c27 (patch)
tree73727134988711124118c2c348b6e0042df10ae5
parent0054d1419f18795df710caac274a8a5dec7b1a0f (diff)
downloadbluez-c4db10d2cde32ab4c05417a75e11698816a87c27.tar.gz
policy: Mark reconnect services
This make use of btd_service_reconnect to set reconnecting flag of services.
-rw-r--r--plugins/policy.c31
1 files 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);