From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 11/15] core: Fix not been able to cancel Device.Connect with Device.Disconnect
Date: Mon, 10 Jun 2013 13:37:06 +0300 [thread overview]
Message-ID: <1370860630-30359-11-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1370860630-30359-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Device.Disconnect should be able to interrupt the connection attempt
started by Device.Connect.
---
src/device.c | 18 ++++++++++++------
src/service.c | 5 +++++
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/device.c b/src/device.c
index d4c1e23..5cb5460 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1082,7 +1082,7 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
device->connect = NULL;
}
- if (msg)
+ if (device->connected && msg)
device->disconnects = g_slist_append(device->disconnects,
dbus_message_ref(msg));
@@ -1110,18 +1110,20 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
g_free(data);
}
+ if (!device->connected) {
+ g_dbus_send_reply(dbus_conn, msg, DBUS_TYPE_INVALID);
+ return;
+ }
+
device->disconn_timer = g_timeout_add_seconds(DISCONNECT_TIMER,
do_disconnect, device);
}
-static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,
+static DBusMessage *dev_disconnect(DBusConnection *conn, DBusMessage *msg,
void *user_data)
{
struct btd_device *device = user_data;
- if (!device->connected)
- return btd_error_not_connected(msg);
-
/*
* Disable connections through passive scanning until
* Device1.Connect is called
@@ -1723,7 +1725,7 @@ static DBusMessage *cancel_pairing(DBusConnection *conn, DBusMessage *msg,
}
static const GDBusMethodTable device_methods[] = {
- { GDBUS_ASYNC_METHOD("Disconnect", NULL, NULL, disconnect) },
+ { GDBUS_ASYNC_METHOD("Disconnect", NULL, NULL, dev_disconnect) },
{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, dev_connect) },
{ GDBUS_ASYNC_METHOD("ConnectProfile", GDBUS_ARGS({ "UUID", "s" }),
NULL, connect_profile) },
@@ -4508,6 +4510,10 @@ static void service_state_changed(struct btd_service *service,
struct btd_device *device = btd_service_get_device(service);
int err = btd_service_get_error(service);
+ if (new_state == BTD_SERVICE_STATE_CONNECTING ||
+ new_state == BTD_SERVICE_STATE_DISCONNECTING)
+ return;
+
if (old_state == BTD_SERVICE_STATE_CONNECTING)
device_profile_connected(device, profile, err);
else if (old_state == BTD_SERVICE_STATE_DISCONNECTING)
diff --git a/src/service.c b/src/service.c
index aef9502..83e1c1a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -238,6 +238,11 @@ int btd_service_disconnect(struct btd_service *service)
if (err == 0)
return 0;
+ if (err == -ENOTCONN) {
+ btd_service_disconnecting_complete(service, 0);
+ return 0;
+ }
+
ba2str(device_get_address(service->device), addr);
error("%s profile disconnect failed for %s: %s", profile->name, addr,
strerror(-err));
--
1.8.1.4
next prev parent reply other threads:[~2013-06-10 10:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-10 10:36 [PATCH BlueZ 01/15] AVRCP: Fix crash when registering unsupported notification Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 02/15] AVCTP: Fix coding style Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 03/15] AVCTP: Call callback in case the request timeout Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 04/15] AVRCP: Fix crash while listing available settings in TG role Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 05/15] AVRCP: Add additional protocol discriptor list for Browsing channel Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 06/15] AVRCP: Fix crash when current addressed player is removed Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 07/15] AVRCP: Fix crash if player status is NULL Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 08/15] AVRCP: Fix setting reserved bit in GetCapabilities response Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 09/15] AVRCP: Fix crash when connecting role without a record Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 10/15] AVRCP: Fix crash while setting player volume Luiz Augusto von Dentz
2013-06-10 10:37 ` Luiz Augusto von Dentz [this message]
2013-06-10 10:37 ` [PATCH BlueZ 12/15] AVRCP: Fix sending invalid attributes when responding to GetElementAttributes Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 13/15] AVRCP: Fix sending SetPlayerApplicationSettingValue using notify command type Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 14/15] obexd: Fix crash when resetting OPP session without a transfer Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 15/15] obexd: Fix not checking for valid fd on NewConnection Luiz Augusto von Dentz
2013-06-11 21:16 ` [PATCH BlueZ 01/15] AVRCP: Fix crash when registering unsupported notification 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=1370860630-30359-11-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).