Return-Path: From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= To: linux-bluetooth@vger.kernel.org Cc: Claudio Takahasi Subject: [PATCH BlueZ v5 01/14] core: Control connections based on adapter state Date: Tue, 4 Sep 2012 16:04:29 -0300 Message-Id: <1346785482-13359-2-git-send-email-jprvita@openbossa.org> In-Reply-To: <1346785482-13359-1-git-send-email-jprvita@openbossa.org> References: <1346785482-13359-1-git-send-email-jprvita@openbossa.org> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Claudio Takahasi This patch disable automatic ATTIO connections when the adapter is powered down and enable automatic connection when the adapter is powered on. --- src/adapter.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index f507aa5..d4ba4fc 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -2116,6 +2116,14 @@ static int get_pairable_timeout(const char *src) return main_opts.pairto; } +static void set_auto_connect(gpointer data, gpointer user_data) +{ + struct btd_device *device = data; + gboolean enable = GPOINTER_TO_INT(user_data); + + device_set_auto_connect(device, enable); +} + static void call_adapter_powered_callbacks(struct btd_adapter *adapter, gboolean powered) { @@ -2125,7 +2133,10 @@ static void call_adapter_powered_callbacks(struct btd_adapter *adapter, btd_adapter_powered_cb cb = l->data; cb(adapter, powered); - } + } + + g_slist_foreach(adapter->devices, set_auto_connect, + GINT_TO_POINTER(powered)); } static void emit_device_disappeared(gpointer data, gpointer user_data) @@ -3348,15 +3359,10 @@ static gboolean disable_auto(gpointer user_data) return FALSE; } -static void set_auto_connect(gpointer data, gpointer user_data) -{ - struct btd_device *device = data; - - device_set_auto_connect(device, TRUE); -} - void btd_adapter_enable_auto_connect(struct btd_adapter *adapter) { + gboolean enable = TRUE; + if (!adapter->up) return; @@ -3365,7 +3371,8 @@ void btd_adapter_enable_auto_connect(struct btd_adapter *adapter) if (adapter->auto_timeout_id) return; - g_slist_foreach(adapter->devices, set_auto_connect, NULL); + g_slist_foreach(adapter->devices, set_auto_connect, + GINT_TO_POINTER(enable)); adapter->auto_timeout_id = g_timeout_add_seconds(main_opts.autoto, disable_auto, adapter); -- 1.7.11.4