All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mariusz Skamra <mariusz.skamra@tieto.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mariusz Skamra <mariusz.skamra@tieto.com>
Subject: [PATCH 15/28] android/dis: Remove tracking pending gatt operations
Date: Wed,  1 Apr 2015 18:40:31 +0200	[thread overview]
Message-ID: <1427906444-11769-16-git-send-email-mariusz.skamra@tieto.com> (raw)
In-Reply-To: <1427906444-11769-1-git-send-email-mariusz.skamra@tieto.com>

Since the use of bt_gatt_client there is no need to queue pending gatt
operations. bt_gatt_client already keeps track on that, so that
on bt_gatt_client_unref the queue of pending requests is destroyed.
---
 android/dis.c | 107 +++-------------------------------------------------------
 1 file changed, 4 insertions(+), 103 deletions(-)

diff --git a/android/dis.c b/android/dis.c
index 75dbe3d..f699046 100644
--- a/android/dis.c
+++ b/android/dis.c
@@ -57,7 +57,6 @@ struct bt_dis {
 	struct gatt_primary	*primary;	/* Primary details */
 	bt_dis_notify		notify;
 	void			*notify_data;
-	struct queue		*gatt_op;
 };
 
 struct characteristic {
@@ -65,25 +64,11 @@ struct characteristic {
 	struct bt_dis		*d;	/* deviceinfo where the char belongs */
 };
 
-struct gatt_request {
-	unsigned int id;
-	struct bt_dis *dis;
-	void *user_data;
-};
-
-static void destroy_gatt_req(struct gatt_request *req)
-{
-	queue_remove(req->dis->gatt_op, req);
-	bt_dis_unref(req->dis);
-	free(req);
-}
-
 static void dis_free(struct bt_dis *dis)
 {
 	bt_dis_detach(dis);
 
 	g_free(dis->primary);
-	queue_destroy(dis->gatt_op, (void *) destroy_gatt_req);
 	g_free(dis);
 }
 
@@ -95,12 +80,6 @@ struct bt_dis *bt_dis_new(void *primary)
 	if (!dis)
 		return NULL;
 
-	dis->gatt_op = queue_new();
-	if (!dis->gatt_op) {
-		dis_free(dis);
-		return NULL;
-	}
-
 	if (primary)
 		dis->primary = g_memdup(primary, sizeof(*dis->primary));
 
@@ -128,39 +107,13 @@ void bt_dis_unref(struct bt_dis *dis)
 	dis_free(dis);
 }
 
-static struct gatt_request *create_request(struct bt_dis *dis,
-							void *user_data)
-{
-	struct gatt_request *req;
-
-	req = new0(struct gatt_request, 1);
-	if (!req)
-		return NULL;
-
-	req->user_data = user_data;
-	req->dis = bt_dis_ref(dis);
-
-	return req;
-}
-
-static bool set_and_store_gatt_req(struct bt_dis *dis,
-						struct gatt_request *req,
-						unsigned int id)
-{
-	req->id = id;
-	return queue_push_head(dis->gatt_op, req);
-}
-
 static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
 							gpointer user_data)
 {
-	struct gatt_request *req = user_data;
-	struct bt_dis *dis = req->user_data;
+	struct bt_dis *dis = user_data;
 	uint8_t value[PNP_ID_SIZE];
 	ssize_t vlen;
 
-	destroy_gatt_req(req);
-
 	if (status != 0) {
 		error("Error reading PNP_ID value: %s", att_ecode2str(status));
 		return;
@@ -190,57 +143,12 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
 						dis->version, dis->notify_data);
 }
 
-static void read_char(struct bt_dis *dis, GAttrib *attrib, uint16_t handle,
-				GAttribResultFunc func, gpointer user_data)
-{
-	struct gatt_request *req;
-	unsigned int id;
-
-	req = create_request(dis, user_data);
-	if (!req)
-		return;
-
-	id = gatt_read_char(attrib, handle, func, req);
-
-	if (set_and_store_gatt_req(dis, req, id))
-		return;
-
-	error("dis: Could not read characteristic");
-	g_attrib_cancel(attrib, id);
-	free(req);
-}
-
-static void discover_char(struct bt_dis *dis, GAttrib *attrib,
-						uint16_t start, uint16_t end,
-						bt_uuid_t *uuid, gatt_cb_t func,
-						gpointer user_data)
-{
-	struct gatt_request *req;
-	unsigned int id;
-
-	req = create_request(dis, user_data);
-	if (!req)
-		return;
-
-	id = gatt_discover_char(attrib, start, end, uuid, func, req);
-
-	if (set_and_store_gatt_req(dis, req, id))
-		return;
-
-	error("dis: Could not send discover characteristic");
-	g_attrib_cancel(attrib, id);
-	free(req);
-}
-
 static void configure_deviceinfo_cb(uint8_t status, GSList *characteristics,
 								void *user_data)
 {
-	struct gatt_request *req = user_data;
-	struct bt_dis *d = req->user_data;
+	struct bt_dis *d = user_data;
 	GSList *l;
 
-	destroy_gatt_req(req);
-
 	if (status != 0) {
 		error("Discover deviceinfo characteristics: %s",
 							att_ecode2str(status));
@@ -252,7 +160,7 @@ static void configure_deviceinfo_cb(uint8_t status, GSList *characteristics,
 
 		if (strcmp(c->uuid, PNPID_UUID) == 0) {
 			d->handle = c->value_handle;
-			read_char(d, d->attrib, d->handle, read_pnpid_cb, d);
+			gatt_read_char(d->attrib, d->handle, read_pnpid_cb, d);
 			break;
 		}
 	}
@@ -268,25 +176,18 @@ bool bt_dis_attach(struct bt_dis *dis, void *attrib)
 	dis->attrib = g_attrib_ref(attrib);
 
 	if (!dis->handle)
-		discover_char(dis, dis->attrib, primary->range.start,
+		gatt_discover_char(dis->attrib, primary->range.start,
 						primary->range.end, NULL,
 						configure_deviceinfo_cb, dis);
 
 	return true;
 }
 
-static void cancel_gatt_req(struct gatt_request *req)
-{
-	if (g_attrib_cancel(req->dis->attrib, req->id))
-		destroy_gatt_req(req);
-}
-
 void bt_dis_detach(struct bt_dis *dis)
 {
 	if (!dis->attrib)
 		return;
 
-	queue_foreach(dis->gatt_op, (void *) cancel_gatt_req, NULL);
 	g_attrib_unref(dis->attrib);
 	dis->attrib = NULL;
 }
-- 
1.9.1


  parent reply	other threads:[~2015-04-01 16:40 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 16:40 [PATCH 00/28] android/hog Introduce bt_gatt_client Mariusz Skamra
2015-04-01 16:40 ` [PATCH 01/28] android/hidhost: Create bt_gatt_client Mariusz Skamra
2015-04-02 14:16   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 02/28] android/hog: Introduce bt_gatt_client Mariusz Skamra
2015-04-02 14:17   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 03/28] shared/gatt-client: Expose gatt_db Mariusz Skamra
2015-04-02 14:20   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 04/28] android/hog: Remove tracking gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 05/28] android/hog: Use bt_gatt_client to read characteristic value Mariusz Skamra
2015-04-01 16:40 ` [PATCH 06/28] android/hog: Use bt_gatt_client to register for notifications Mariusz Skamra
2015-04-01 16:40 ` [PATCH 07/28] android/hog: Use bt_gatt_client to write without response Mariusz Skamra
2015-04-01 16:40 ` [PATCH 08/28] android/hog: Replace gatt_write_char with bt_gatt_client_write_value Mariusz Skamra
2015-04-01 16:40 ` [PATCH 09/28] android/hog: Use gatt_db to search for services and characteristics in db Mariusz Skamra
2015-04-02 15:22   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 10/28] android/hog: Add helper to create uhid device Mariusz Skamra
2015-04-01 16:40 ` [PATCH 11/28] lib/uuid: Add define for HoG UUID Mariusz Skamra
2015-04-01 16:40 ` [PATCH 12/28] android/hog: Replace list of reports with a queue of reports Mariusz Skamra
2015-04-01 16:40 ` [PATCH 13/28] android/hog: Replace definitions of characteristic uuids with bt_uuids Mariusz Skamra
2015-04-02 15:26   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 14/28] android/hog: Replace GSList of hog instances with queue of instances Mariusz Skamra
2015-04-02 15:29   ` Szymon Janc
2015-04-01 16:40 ` Mariusz Skamra [this message]
2015-04-01 16:40 ` [PATCH 16/28] android/dis: Introduce bt_gatt_client Mariusz Skamra
2015-04-01 16:40 ` [PATCH 17/28] android/scpp: Remove tracking pending gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 18/28] android/scpp: Introduce bt_gatt_client Mariusz Skamra
2015-04-02 15:34   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 19/28] android/scpp: Merge refresh_discovered_cb with iwin_discovered_cb Mariusz Skamra
2015-04-01 16:40 ` [PATCH 20/28] android/bas: Remove tracking pending gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 21/28] android/bas: Start using bt_gatt_client Mariusz Skamra
2015-04-02 15:37   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 22/28] android/hog: Strip btio dependencies Mariusz Skamra
2015-04-02 15:39   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 23/28] android/hog: Enable Input Report notifications only if uhid is created Mariusz Skamra
2015-04-01 16:40 ` [PATCH 24/28] android/bas: Enable Battery Level notifications after reconnection Mariusz Skamra
2015-04-01 16:40 ` [PATCH 25/28] android/hog: Add MIN definition Mariusz Skamra
2015-04-02 15:41   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 26/28] android/hog: Remove attrib/ Mariusz Skamra
2015-04-02 15:44   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 27/28] android/hog: Remove glib dependencies Mariusz Skamra
2015-04-02 15:45   ` Szymon Janc
2015-04-01 16:40 ` [PATCH 28/28] android/hog: Remove redundant code Mariusz Skamra

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=1427906444-11769-16-git-send-email-mariusz.skamra@tieto.com \
    --to=mariusz.skamra@tieto.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 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.