From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ v1 3/7] shared/gatt-client: Implement bt_gatt_client_unregister_notify.
Date: Tue, 9 Sep 2014 10:04:05 -0700 [thread overview]
Message-ID: <1410282249-22004-4-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1410282249-22004-1-git-send-email-armansito@chromium.org>
This patch implements bt_gatt_client_unregister_notify, which is used to remove
a previous registered notification/indication handler. This function decreases
the per-characteristic count of handlers, and if the count drops to 0, a write
request is sent to the CCC descriptor to disable notifications/indications.
---
src/shared/gatt-client.c | 54 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 974fa1d..d68c8aa 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -604,6 +604,14 @@ static void notify_data_unref(void *data)
free(notify_data);
}
+static bool match_notify_data_id(const void *a, const void *b)
+{
+ const struct notify_data *notify_data = a;
+ unsigned int id = PTR_TO_UINT(b);
+
+ return notify_data->id == id;
+}
+
static void complete_notify_request(void *data)
{
struct notify_data *notify_data = data;
@@ -706,7 +714,23 @@ static void enable_ccc_callback(uint8_t opcode, const void *pdu,
static void disable_ccc_callback(uint8_t opcode, const void *pdu,
uint16_t length, void *user_data)
{
- /* TODO */
+ struct notify_data *notify_data = user_data;
+ struct notify_data *next_data;
+
+ assert(!notify_data->chrc->not_ref_count);
+ assert(notify_data->chrc->ccc_write_id);
+
+ notify_data->chrc->ccc_write_id = 0;
+
+ /* This is a best effort procedure, so ignore errors and process any
+ * queued requests.
+ */
+ while (1) {
+ next_data = queue_pop_head(notify_data->chrc->reg_notify_queue);
+ if (!next_data || notify_data_write_ccc(notify_data, true,
+ enable_ccc_callback))
+ return;
+ }
}
struct bt_gatt_client *bt_gatt_client_new(struct bt_att *att, uint16_t mtu)
@@ -1667,6 +1691,30 @@ bool bt_gatt_client_register_notify(struct bt_gatt_client *client,
bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,
unsigned int id)
{
- /* TODO */
- return false;
+ struct notify_data *notify_data;
+
+ if (!client || !id)
+ return false;
+
+ notify_data = queue_find(client->notify_list, match_notify_data_id,
+ UINT_TO_PTR(id));
+ if (!notify_data)
+ return false;
+
+ assert(notify_data->chrc->not_ref_count > 0);
+ assert(!notify_data->chrc->ccc_write_id);
+
+ /* TODO: Delay destruction/removal if we're in the middle of processing
+ * a notification.
+ */
+ queue_remove(client->notify_list, notify_data);
+
+ if (__sync_sub_and_fetch(¬ify_data->chrc->not_ref_count, 1)) {
+ notify_data_unref(notify_data);
+ return true;
+ }
+
+ notify_data_write_ccc(notify_data, false, disable_ccc_callback);
+
+ return true;
}
--
2.1.0.rc2.206.gedb03e5
next prev parent reply other threads:[~2014-09-09 17:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 17:04 [PATCH BlueZ v1 0/7] shared/gatt-client: Handle notifications Arman Uguray
2014-09-09 17:04 ` [PATCH BlueZ v1 1/7] shared/gatt-client: Introduce struct bt_gatt_characteristic_iter Arman Uguray
2014-09-09 17:04 ` [PATCH BlueZ v1 2/7] shared/gatt-client: Implement bt_gatt_client_register_notify Arman Uguray
2014-09-09 17:04 ` Arman Uguray [this message]
2014-09-09 22:54 ` [PATCH BlueZ v1 3/7] shared/gatt-client: Implement bt_gatt_client_unregister_notify Marcel Holtmann
2014-09-09 17:04 ` [PATCH BlueZ v1 4/7] shared/gatt-client: Handle incoming not/ind PDUs Arman Uguray
2014-09-09 22:58 ` Marcel Holtmann
2014-09-10 0:09 ` Arman Uguray
2014-09-10 0:29 ` Johan Hedberg
2014-09-10 0:48 ` Arman Uguray
2014-09-10 2:04 ` Marcel Holtmann
2014-09-10 2:06 ` Marcel Holtmann
2014-09-10 16:24 ` Arman Uguray
2014-09-09 17:04 ` [PATCH BlueZ v1 5/7] tools/btgatt-client: Add the "register-notify" command Arman Uguray
2014-09-09 17:04 ` [PATCH BlueZ v1 6/7] tools/btgatt-client: Add "unregister-notify" command Arman Uguray
2014-09-09 17:04 ` [PATCH BlueZ v1 7/7] TODO: Reference counted notify functions implemented Arman Uguray
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=1410282249-22004-4-git-send-email-armansito@chromium.org \
--to=armansito@chromium.org \
--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