From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 5/6] plugins/policy: Disable other connect policies while reconnect is active
Date: Thu, 28 Jul 2016 17:27:49 +0300 [thread overview]
Message-ID: <1469716070-16506-6-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1469716070-16506-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Other policies shall not interfere while reconnect is active.
---
plugins/policy.c | 43 ++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/plugins/policy.c b/plugins/policy.c
index 3058824..0330456 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -95,10 +95,29 @@ struct policy_data {
uint8_t tg_retries;
};
+static struct reconnect_data *reconnect_find(struct btd_device *dev)
+{
+ GSList *l;
+
+ for (l = reconnects; l; l = g_slist_next(l)) {
+ struct reconnect_data *reconnect = l->data;
+
+ if (reconnect->dev == dev)
+ return reconnect;
+ }
+
+ return NULL;
+}
+
static void policy_connect(struct policy_data *data,
struct btd_service *service)
{
struct btd_profile *profile = btd_service_get_profile(service);
+ struct reconnect_data *reconnect;
+
+ reconnect = reconnect_find(btd_service_get_device(service));
+ if (reconnect && reconnect->active)
+ return;
DBG("%s profile %s", device_get_path(data->dev), profile->name);
@@ -496,6 +515,7 @@ static void target_cb(struct btd_service *service,
static void reconnect_reset(struct reconnect_data *reconnect)
{
reconnect->attempt = 0;
+ reconnect->active = false;
if (reconnect->timer > 0) {
g_source_remove(reconnect->timer);
@@ -518,20 +538,6 @@ static bool reconnect_match(const char *uuid)
return false;
}
-static struct reconnect_data *reconnect_find(struct btd_device *dev)
-{
- GSList *l;
-
- for (l = reconnects; l; l = g_slist_next(l)) {
- struct reconnect_data *reconnect = l->data;
-
- if (reconnect->dev == dev)
- return reconnect;
- }
-
- return NULL;
-}
-
static struct reconnect_data *reconnect_add(struct btd_service *service)
{
struct btd_device *dev = btd_service_get_device(service);
@@ -643,7 +649,6 @@ static void service_cb(struct btd_service *service,
*/
reconnect = reconnect_add(service);
- reconnect->active = false;
reconnect_reset(reconnect);
/*
@@ -675,7 +680,6 @@ static gboolean reconnect_timeout(gpointer data)
return FALSE;
}
- reconnect->active = true;
reconnect->attempt++;
return FALSE;
@@ -685,10 +689,13 @@ static void reconnect_set_timer(struct reconnect_data *reconnect)
{
static int timeout = 0;
+ reconnect->active = true;
+
if (reconnect->attempt < reconnect_intervals_len)
timeout = reconnect_intervals[reconnect->attempt];
- DBG("%d seconds", timeout);
+ DBG("attempt %u/%zu %d seconds", reconnect->attempt + 1,
+ reconnect_attempts, timeout);
reconnect->timer = g_timeout_add_seconds(timeout, reconnect_timeout,
reconnect);
@@ -726,8 +733,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);
--
2.7.4
next prev parent reply other threads:[~2016-07-28 14:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-28 14:27 [PATCH BlueZ 0/6] plugins/policy: Fixes Luiz Augusto von Dentz
2016-07-28 14:27 ` [PATCH BlueZ 1/6] lib/uuid: Fix using unitialized values Luiz Augusto von Dentz
2016-07-28 14:27 ` [PATCH BlueZ 2/6] plugins/policy: Revert patch 96db78604252eeb17614b9982ced95fd66c6c6fc Luiz Augusto von Dentz
2016-07-28 14:27 ` [PATCH BlueZ 3/6] plugins/policy: Set list separator Luiz Augusto von Dentz
2016-07-28 14:27 ` [PATCH BlueZ 4/6] main.conf: Remove spaces in reconnect list parameters Luiz Augusto von Dentz
2016-07-28 14:27 ` Luiz Augusto von Dentz [this message]
2016-07-28 14:27 ` [PATCH BlueZ 6/6] audio/a2dp: Fix always setting -EAGAIN for all errors Luiz Augusto von Dentz
2016-08-01 11:57 ` [PATCH BlueZ 0/6] plugins/policy: Fixes Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1469716070-16506-6-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).