From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 4/8] gap: Implement disconnect callback
Date: Mon, 12 Sep 2016 17:07:35 +0300 [thread overview]
Message-ID: <1473689259-9523-4-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1473689259-9523-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This implements the profile disconnect callback using it to cleanup
existing references of bt_gatt_client and gatt_db.
---
profiles/gap/gas.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 93a9a6d..2077ed9 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -251,6 +251,15 @@ static void foreach_gap_service(struct gatt_db_attribute *attr, void *user_data)
handle_gap_service(gas);
}
+static void gas_reset(struct gas *gas)
+{
+ gas->attr = NULL;
+ gatt_db_unref(gas->db);
+ gas->db = NULL;
+ bt_gatt_client_unref(gas->client);
+ gas->client = NULL;
+}
+
static int gap_driver_accept(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
@@ -268,11 +277,6 @@ static int gap_driver_accept(struct btd_service *service)
return -1;
}
- /* Clean-up any old client/db and acquire the new ones */
- gas->attr = NULL;
- gatt_db_unref(gas->db);
- bt_gatt_client_unref(gas->client);
-
gas->db = gatt_db_ref(db);
gas->client = bt_gatt_client_ref(client);
@@ -282,6 +286,7 @@ static int gap_driver_accept(struct btd_service *service)
if (!gas->attr) {
error("GAP attribute not found");
+ gas_reset(gas);
return -1;
}
@@ -290,12 +295,24 @@ static int gap_driver_accept(struct btd_service *service)
return 0;
}
+static int gap_disconnect(struct btd_service *service)
+{
+ struct gas *gas = btd_service_get_user_data(service);
+
+ gas_reset(gas);
+
+ btd_service_disconnecting_complete(service, 0);
+
+ return 0;
+}
+
static struct btd_profile gap_profile = {
.name = "gap-profile",
.remote_uuid = GAP_UUID,
.device_probe = gap_driver_probe,
.device_remove = gap_driver_remove,
- .accept = gap_driver_accept
+ .accept = gap_driver_accept,
+ .disconnect = gap_disconnect,
};
static int gap_init(void)
--
2.7.4
next prev parent reply other threads:[~2016-09-12 14:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 2/8] gap: Fix not handling accept properly Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 3/8] gap: Make use of service user_data to store service context Luiz Augusto von Dentz
2016-09-12 14:07 ` Luiz Augusto von Dentz [this message]
2016-09-12 14:07 ` [PATCH BlueZ 5/8] gap: Use shorter names for profile callback Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 6/8] deviceinfo: Fix not handling accept properly Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 7/8] deviceinfo: Implement disconnect callback Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 8/8] deviceinfo: Use shorter names for profile callback Luiz Augusto von Dentz
2016-09-13 14:09 ` [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client 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=1473689259-9523-4-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).