summaryrefslogtreecommitdiff
path: root/tools/btgatt-client.c
diff options
context:
space:
mode:
authorArman Uguray <armansito@chromium.org>2015-01-30 16:29:05 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-02-02 12:55:06 +0200
commit1122bddd602c4d3f03854d2bf02942ee59ad0085 (patch)
tree08f7ea9a4a9cbe05ab74c7bcdb73e4e0892e76c0 /tools/btgatt-client.c
parentff189f01da8dd4d6f824002eddf0f4fd4d5ed1b1 (diff)
downloadbluez-1122bddd602c4d3f03854d2bf02942ee59ad0085.tar.gz
shared/gatt: Make register_notify cancellable
This patch makes CCC writes via bt_gatt_client_register_notify cancellable. The following changes have been introduced: 1. bt_gatt_client_register_notify now returns the id immediately instead of returning it in a callback. The callback is still used to communicate ATT protocol errors. 2. A notify callback is immediately registered, so that if the remote end sends any ATT notifications/indications, the caller will start receiving them right away.
Diffstat (limited to 'tools/btgatt-client.c')
-rw-r--r--tools/btgatt-client.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 62c4d3e7a..8bda89b8b 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -856,16 +856,15 @@ static void notify_cb(uint16_t value_handle, const uint8_t *value,
PRLOG("\n");
}
-static void register_notify_cb(unsigned int id, uint16_t att_ecode,
- void *user_data)
+static void register_notify_cb(uint16_t att_ecode, void *user_data)
{
- if (!id) {
+ if (att_ecode) {
PRLOG("Failed to register notify handler "
"- error code: 0x%02x\n", att_ecode);
return;
}
- PRLOG("Registered notify handler with id: %u\n", id);
+ PRLOG("Registered notify handler!");
}
static void cmd_register_notify(struct client *cli, char *cmd_str)
@@ -873,6 +872,7 @@ static void cmd_register_notify(struct client *cli, char *cmd_str)
char *argv[2];
int argc = 0;
uint16_t value_handle;
+ unsigned int id;
char *endptr = NULL;
if (!bt_gatt_client_is_ready(cli->gatt)) {
@@ -891,12 +891,15 @@ static void cmd_register_notify(struct client *cli, char *cmd_str)
return;
}
- if (!bt_gatt_client_register_notify(cli->gatt, value_handle,
+ id = bt_gatt_client_register_notify(cli->gatt, value_handle,
register_notify_cb,
- notify_cb, NULL, NULL))
+ notify_cb, NULL, NULL);
+ if (!id) {
printf("Failed to register notify handler\n");
+ return;
+ }
- printf("\n");
+ PRLOG("Registering notify handler with id: %u\n", id);
}
static void unregister_notify_usage(void)