Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4269428pxf; Tue, 16 Mar 2021 09:22:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtoO3lakqKuVu2l0YqCWHNwzhMgJZit2nnacAAKCmLktV75xKCcYmRGFmj6bqo/Bs74SQB X-Received: by 2002:a17:907:98f5:: with SMTP id ke21mr30639359ejc.552.1615911727244; Tue, 16 Mar 2021 09:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615911727; cv=none; d=google.com; s=arc-20160816; b=CoTViKZ0SP9Xs5jH+nY6VylsE/n9hoIzwHFb82JIqaMd8hEPSzOn0tgenMVh3lDM6D J8nKNbqaHmKlxrAyOfpSnL78l4DcR07X5z7bVrUNXKPHWaU0arrjANo6z2fLkaxLI/9n 3LtOh5q6d50DyVHpjL1XI/TDS5FsvXwF03v8PrTvOm5k+oNMlc3Hczbbk0b0qYd+mvXd LfUoVfjWqbgDv0nfgTSAR87b9WFKuEEHPpo+w+dC2XYlQy9rqj6CgIYxmOrG5OAF4OdN FQ9HU1JFKnSlbgeFzfcSxx3LCwW/jZPP+Cpq+GWFwHWvFbVFSVQMxc7OTKwQ1iSi3hfs LsJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=49x/jznTG0DdWCRKaHmJ73jVRkvcIT9XKBbN0q60a50=; b=u+ao+oSWUC6RPQu46UlIGWgAJA/oUvSDiIlW1XPERz0oljISJJIAD292yXdotTUHW6 JWNJx7aFS6QN0dRJSNUGR8rbPyefj3UWAFXSi6kLWK59tZkFk71NLyQKMNq/XtNwwNkZ wwirLErpNoI4eA81oPRjls6BJEHtcKE1AVMKCOHLBd5ZMaV9bE6CDBSD8+dj2Qu9t7zY cvQbLF2I0Qe2xKiy+VAqBebVOQSNNXYPEcXR0RH04OiNcFDqMHDHqCS0f0MiBko0BLXQ jPrGt4l5iHTmUm6wNspwfs1GjaqfE1rc0Z+gUAQ5wr9zu7fNn5ZpPZZKhXNcBXJ3zSJ3 YBug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo5si15093130ejb.644.2021.03.16.09.21.42; Tue, 16 Mar 2021 09:22:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235283AbhCPO05 (ORCPT + 99 others); Tue, 16 Mar 2021 10:26:57 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:41868 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236274AbhCPO0k (ORCPT ); Tue, 16 Mar 2021 10:26:40 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: fdanis) with ESMTPSA id 154BD1F44BE0 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH Bluez v3 3/4] plugins: Replace calls to g_timeout_add_seconds by timeout_add_seconds Date: Tue, 16 Mar 2021 15:26:26 +0100 Message-Id: <20210316142627.23692-4-frederic.danis@collabora.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210316142627.23692-1-frederic.danis@collabora.com> References: <20210316142627.23692-1-frederic.danis@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- plugins/policy.c | 91 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index ba9e1be02..bf93df096 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -31,6 +31,7 @@ #include "src/service.h" #include "src/profile.h" #include "src/btd.h" +#include "src/shared/timeout.h" #define CONTROL_CONNECT_TIMEOUT 2 #define SOURCE_RETRY_TIMEOUT 2 @@ -46,7 +47,7 @@ struct reconnect_data { struct btd_device *dev; bool reconnect; GSList *services; - guint timer; + unsigned int timer; bool active; unsigned int attempt; bool on_resume; @@ -77,13 +78,13 @@ static bool auto_enable = false; struct policy_data { struct btd_device *dev; - guint source_timer; + unsigned int source_timer; uint8_t source_retries; - guint sink_timer; + unsigned int sink_timer; uint8_t sink_retries; - guint ct_timer; + unsigned int ct_timer; uint8_t ct_retries; - guint tg_timer; + unsigned int tg_timer; uint8_t tg_retries; }; @@ -126,7 +127,7 @@ static void policy_disconnect(struct policy_data *data, btd_service_disconnect(service); } -static gboolean policy_connect_ct(gpointer user_data) +static bool policy_connect_ct(gpointer user_data) { struct policy_data *data = user_data; struct btd_service *service; @@ -144,10 +145,10 @@ static gboolean policy_connect_ct(gpointer user_data) static void policy_set_ct_timer(struct policy_data *data, int timeout) { if (data->ct_timer > 0) - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); - data->ct_timer = g_timeout_add_seconds(timeout, policy_connect_ct, - data); + data->ct_timer = timeout_add_seconds(timeout, policy_connect_ct, + data, NULL); } static struct policy_data *find_data(struct btd_device *dev) @@ -169,16 +170,16 @@ static void policy_remove(void *user_data) struct policy_data *data = user_data; if (data->source_timer > 0) - g_source_remove(data->source_timer); + timeout_remove(data->source_timer); if (data->sink_timer > 0) - g_source_remove(data->sink_timer); + timeout_remove(data->sink_timer); if (data->ct_timer > 0) - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); if (data->tg_timer > 0) - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); g_free(data); } @@ -199,7 +200,7 @@ static struct policy_data *policy_get_data(struct btd_device *dev) return data; } -static gboolean policy_connect_sink(gpointer user_data) +static bool policy_connect_sink(gpointer user_data) { struct policy_data *data = user_data; struct btd_service *service; @@ -217,11 +218,11 @@ static gboolean policy_connect_sink(gpointer user_data) static void policy_set_sink_timer(struct policy_data *data) { if (data->sink_timer > 0) - g_source_remove(data->sink_timer); + timeout_remove(data->sink_timer); - data->sink_timer = g_timeout_add_seconds(SINK_RETRY_TIMEOUT, + data->sink_timer = timeout_add_seconds(SINK_RETRY_TIMEOUT, policy_connect_sink, - data); + data, NULL); } static void sink_cb(struct btd_service *service, btd_service_state_t old_state, @@ -240,7 +241,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state, switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: if (data->sink_timer > 0) { - g_source_remove(data->sink_timer); + timeout_remove(data->sink_timer); data->sink_timer = 0; } break; @@ -255,13 +256,13 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state, data->sink_retries = 0; break; } else if (data->sink_timer > 0) { - g_source_remove(data->sink_timer); + timeout_remove(data->sink_timer); data->sink_timer = 0; } } if (data->ct_timer > 0) { - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); data->ct_timer = 0; } else if (btd_service_get_state(controller) != BTD_SERVICE_STATE_DISCONNECTED) @@ -271,7 +272,7 @@ static void sink_cb(struct btd_service *service, btd_service_state_t old_state, break; case BTD_SERVICE_STATE_CONNECTED: if (data->sink_timer > 0) { - g_source_remove(data->sink_timer); + timeout_remove(data->sink_timer); data->sink_timer = 0; } @@ -325,7 +326,7 @@ static void hs_cb(struct btd_service *service, btd_service_state_t old_state, } } -static gboolean policy_connect_tg(gpointer user_data) +static bool policy_connect_tg(gpointer user_data) { struct policy_data *data = user_data; struct btd_service *service; @@ -343,13 +344,13 @@ static gboolean policy_connect_tg(gpointer user_data) static void policy_set_tg_timer(struct policy_data *data, int timeout) { if (data->tg_timer > 0) - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); - data->tg_timer = g_timeout_add_seconds(timeout, policy_connect_tg, - data); + data->tg_timer = timeout_add_seconds(timeout, policy_connect_tg, + data, NULL); } -static gboolean policy_connect_source(gpointer user_data) +static bool policy_connect_source(gpointer user_data) { struct policy_data *data = user_data; struct btd_service *service; @@ -367,11 +368,11 @@ static gboolean policy_connect_source(gpointer user_data) static void policy_set_source_timer(struct policy_data *data) { if (data->source_timer > 0) - g_source_remove(data->source_timer); + timeout_remove(data->source_timer); - data->source_timer = g_timeout_add_seconds(SOURCE_RETRY_TIMEOUT, + data->source_timer = timeout_add_seconds(SOURCE_RETRY_TIMEOUT, policy_connect_source, - data); + data, NULL); } static void source_cb(struct btd_service *service, @@ -391,7 +392,7 @@ static void source_cb(struct btd_service *service, switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: if (data->source_timer > 0) { - g_source_remove(data->source_timer); + timeout_remove(data->source_timer); data->source_timer = 0; } break; @@ -406,13 +407,13 @@ static void source_cb(struct btd_service *service, data->source_retries = 0; break; } else if (data->source_timer > 0) { - g_source_remove(data->source_timer); + timeout_remove(data->source_timer); data->source_timer = 0; } } if (data->tg_timer > 0) { - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); data->tg_timer = 0; } else if (btd_service_get_state(target) != BTD_SERVICE_STATE_DISCONNECTED) @@ -422,7 +423,7 @@ static void source_cb(struct btd_service *service, break; case BTD_SERVICE_STATE_CONNECTED: if (data->source_timer > 0) { - g_source_remove(data->source_timer); + timeout_remove(data->source_timer); data->source_timer = 0; } @@ -454,7 +455,7 @@ static void controller_cb(struct btd_service *service, switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: if (data->ct_timer > 0) { - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); data->ct_timer = 0; } break; @@ -470,7 +471,7 @@ static void controller_cb(struct btd_service *service, data->ct_retries = 0; break; } else if (data->ct_timer > 0) { - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); data->ct_timer = 0; } } else if (old_state == BTD_SERVICE_STATE_CONNECTED) { @@ -481,7 +482,7 @@ static void controller_cb(struct btd_service *service, break; case BTD_SERVICE_STATE_CONNECTED: if (data->ct_timer > 0) { - g_source_remove(data->ct_timer); + timeout_remove(data->ct_timer); data->ct_timer = 0; } break; @@ -504,7 +505,7 @@ static void target_cb(struct btd_service *service, switch (new_state) { case BTD_SERVICE_STATE_UNAVAILABLE: if (data->tg_timer > 0) { - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); data->tg_timer = 0; } break; @@ -520,7 +521,7 @@ static void target_cb(struct btd_service *service, data->tg_retries = 0; break; } else if (data->tg_timer > 0) { - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); data->tg_timer = 0; } } else if (old_state == BTD_SERVICE_STATE_CONNECTED) { @@ -531,7 +532,7 @@ static void target_cb(struct btd_service *service, break; case BTD_SERVICE_STATE_CONNECTED: if (data->tg_timer > 0) { - g_source_remove(data->tg_timer); + timeout_remove(data->tg_timer); data->tg_timer = 0; } break; @@ -546,7 +547,7 @@ static void reconnect_reset(struct reconnect_data *reconnect) reconnect->active = false; if (reconnect->timer > 0) { - g_source_remove(reconnect->timer); + timeout_remove(reconnect->timer); reconnect->timer = 0; } } @@ -592,7 +593,7 @@ static void reconnect_destroy(gpointer data) struct reconnect_data *reconnect = data; if (reconnect->timer > 0) - g_source_remove(reconnect->timer); + timeout_remove(reconnect->timer); g_slist_free_full(reconnect->services, (GDestroyNotify) btd_service_unref); @@ -622,7 +623,7 @@ static void reconnect_remove(struct btd_service *service) reconnects = g_slist_remove(reconnects, reconnect); if (reconnect->timer > 0) - g_source_remove(reconnect->timer); + timeout_remove(reconnect->timer); g_free(reconnect); } @@ -693,7 +694,7 @@ static void service_cb(struct btd_service *service, DBG("Added %s reconnect %u", profile->name, reconnect->reconnect); } -static gboolean reconnect_timeout(gpointer data) +static bool reconnect_timeout(gpointer data) { struct reconnect_data *reconnect = data; int err; @@ -734,8 +735,8 @@ static void reconnect_set_timer(struct reconnect_data *reconnect, int timeout) DBG("attempt %u/%zu %d seconds", reconnect->attempt + 1, reconnect_attempts, timeout); - reconnect->timer = g_timeout_add_seconds(timeout, reconnect_timeout, - reconnect); + reconnect->timer = timeout_add_seconds(timeout, reconnect_timeout, + reconnect, NULL); } static void disconnect_cb(struct btd_device *dev, uint8_t reason) -- 2.18.0