All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ 8/9] tools/btgatt-client: Set service changed handler.
Date: Tue, 23 Sep 2014 13:47:16 -0700	[thread overview]
Message-ID: <1411505237-10932-9-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1411505237-10932-1-git-send-email-armansito@chromium.org>

btgatt-client now sets a service changed handler by calling
bt_gatt_client_set_service_changed.
---
 tools/btgatt-client.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 41b85ad..d900e08 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -93,6 +93,8 @@ static void gatt_debug_cb(const char *str, void *user_data)
 }
 
 static void ready_cb(bool success, uint8_t att_ecode, void *user_data);
+static void service_changed_cb(uint16_t start_handle, uint16_t end_handle,
+							void *user_data);
 
 static struct client *client_create(int fd, uint16_t mtu)
 {
@@ -143,6 +145,8 @@ static struct client *client_create(int fd, uint16_t mtu)
 	}
 
 	bt_gatt_client_set_ready_handler(cli->gatt, ready_cb, cli, NULL);
+	bt_gatt_client_set_service_changed(cli->gatt, service_changed_cb, cli,
+									NULL);
 
 	/* bt_gatt_client already holds a reference */
 	bt_att_unref(att);
@@ -269,6 +273,36 @@ static void ready_cb(bool success, uint8_t att_ecode, void *user_data)
 	print_prompt();
 }
 
+static void service_changed_cb(uint16_t start_handle, uint16_t end_handle,
+								void *user_data)
+{
+	struct client *cli = user_data;
+	struct bt_gatt_service_iter iter;
+	const bt_gatt_service_t *service;
+
+	if (!bt_gatt_service_iter_init(&iter, cli->gatt)) {
+		PRLOG("Failed to initialize service iterator\n");
+		return;
+	}
+
+	printf("\nService Changed handled - start: 0x%04x end: 0x%04x\n",
+						start_handle, end_handle);
+
+	if (!bt_gatt_service_iter_next_by_handle(&iter, start_handle, &service))
+		return;
+
+	print_service(service);
+
+	while (bt_gatt_service_iter_next(&iter, &service)) {
+		if (service->start_handle >= end_handle)
+			break;
+
+		print_service(service);
+	}
+
+	print_prompt();
+}
+
 static void services_usage(void)
 {
 	printf("Usage: services [options]\nOptions:\n"
-- 
2.1.0.rc2.206.gedb03e5


  parent reply	other threads:[~2014-09-23 20:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23 20:47 [PATCH BlueZ 0/9] shared/gatt-client: Handle "Service Changed" Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 1/9] shared/gatt-helpers: Allow service discovery by handle range Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 2/9] shared/gatt-client: Make service discovery more modular Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 3/9] shared/gatt-client: Register "Service Changed" handler as part of init Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 4/9] shared/gatt-client: Remove effected services from cache on Service Changed Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 5/9] shared/gatt-client: Rediscover services within changed range Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 6/9] shared/gatt-client: Add handler for "Service Changed" if GATT service changes Arman Uguray
2014-09-23 20:47 ` [PATCH BlueZ 7/9] shared/gatt-client: Add bt_gatt_client_set_service_changed Arman Uguray
2014-09-23 20:47 ` Arman Uguray [this message]
2014-09-23 20:47 ` [PATCH BlueZ 9/9] TODO: shared/gatt-client now handles Service Changed Arman Uguray
2014-09-24  8:08 ` [PATCH BlueZ 0/9] shared/gatt-client: Handle "Service Changed" Johan Hedberg

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=1411505237-10932-9-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.