From: Johan Hedberg <johan.hedberg@gmail.com>
To: Rafal Michalski <michalski.raf@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v4] Fix disconnect devices after enabling offline mode
Date: Wed, 1 Jun 2011 15:06:36 +0300 [thread overview]
Message-ID: <20110601120636.GD26952@dell.ger.corp.intel.com> (raw)
In-Reply-To: <1306918189-2333-1-git-send-email-michalski.raf@gmail.com>
Hi Rafal,
On Wed, Jun 01, 2011, Rafal Michalski wrote:
> Previously paired and connected devices were disconnected automatically
> after turning bluetooth off directly via bluetooth UI. This patch makes
> that also other ways of turning bluetooth off (which should lead to
> disconnecting paired and connected devices), such as enabling offline
> mode (which turns bluetooth off as well), can be handled properly.
> ---
> plugins/maemo6.c | 4 ++--
> src/adapter.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
> src/adapter.h | 2 +-
> 3 files changed, 49 insertions(+), 4 deletions(-)
A couple more things:
> --- a/plugins/maemo6.c
> +++ b/plugins/maemo6.c
> @@ -77,7 +77,7 @@ static gboolean mce_signal_callback(DBusConnection *connection,
> if (mce_bt_set)
> btd_adapter_switch_online(adapter);
> else
> - btd_adapter_switch_offline(adapter);
> + btd_adapter_switch_offline(adapter, TRUE);
> }
>
> return TRUE;
> @@ -124,7 +124,7 @@ static void read_radio_states_cb(DBusPendingCall *call, void *user_data)
> if (mce_bt_set)
> btd_adapter_switch_online(adapter);
> else
> - btd_adapter_switch_offline(adapter);
> + btd_adapter_switch_offline(adapter, TRUE);
Since plugins/maemo6.c seems to be the only user of this API and always
passes TRUE to it, could we just make this the only possible behavior
until a use case shows up where an "unclean" switch_offline is needed?
I.e. remove the boolean completely.
In general this kind of boolean APIs aren't really the most readable
ones since when looking at the function call you have no idea what the
boolean actually does. In this kind of cases it might be worth creating
an enum (even though you've just got two possible values). Then
something like the following is more clear when looking at the function
call:
btd_adapter_switch_offline(adapter, SWITCH_OFFLINE_CLEAN);
However just remove the boolean for now and we don't need to even
consider this.
> +static void off_timer_free(struct btd_adapter *adapter)
> +{
> + g_source_remove(adapter->off_timer);
> + adapter->off_timer = 0;
> +}
I think off_timer_remove would be a more appropriate name here.
> +static void disconnect_device(struct btd_device *device, gpointer user_data)
> +{
> + device_request_disconnect(device, NULL);
> +}
<snip>
> + g_slist_foreach(adapter->connections,
> + (GFunc) disconnect_device, NULL);
In general try to avoid function typecasts by defining the target
function to the exact needed type. However in this case you don't even
need an intermediate function if you do the typecast. Just pass
device_request_disconnect directly to g_slist_foreach.
Johan
prev parent reply other threads:[~2011-06-01 12:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-01 8:49 [PATCH v4] Fix disconnect devices after enabling offline mode Rafal Michalski
2011-06-01 12:06 ` Johan Hedberg [this message]
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=20110601120636.GD26952@dell.ger.corp.intel.com \
--to=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michalski.raf@gmail.com \
/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).