[PATCH 5/6] android/gatt: Simplify descriptor discovery structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There's no need to pass/keep e.g. both gatt_device and conn_id since
we can retrieve one from another, so let's just use strutcures which
hold more data we can reuse later.
---
 android/gatt.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 15107b9..fbe16c2 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1947,35 +1947,37 @@ static void cache_all_descr(const uint8_t *pdu, guint16 len,
 }
 
 struct discover_desc_data {
-	int32_t conn_id;
-	const struct element_id *srvc_id;
-	const struct characteristic *ch;
-	uint8_t primary;
+	struct gatt_device *dev;
+	struct service *srvc;
+	struct characteristic *ch;
 };
 
 static void gatt_discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
 							gpointer user_data)
 {
 	struct discover_desc_data *data = user_data;
+	struct gatt_device *dev = data->dev;
+	struct service *srvc = data->srvc;
+	struct characteristic *ch = data->ch;
 	struct descriptor *descr;
 
 	if (status)
 		error("gatt: Discover all char descriptors failed: %s",
 							att_ecode2str(status));
-	else if (queue_isempty(data->ch->descriptors))
-		cache_all_descr(pdu, len, data->ch->descriptors);
+	else if (queue_isempty(ch->descriptors))
+		cache_all_descr(pdu, len, ch->descriptors);
 
-	descr = queue_peek_head(data->ch->descriptors);
+	descr = queue_peek_head(ch->descriptors);
 
-	send_client_descr_notify(status, data->conn_id, data->primary,
-						data->srvc_id, &data->ch->id,
+	send_client_descr_notify(status, dev->conn_id, srvc->primary, &srvc->id,
+						&ch->id,
 						descr ? &descr->id : NULL);
 
 	free(data);
 }
 
-static bool build_descr_cache(int32_t conn_id, struct gatt_device *dev,
-					struct service *srvc, uint8_t primary,
+static bool build_descr_cache(struct gatt_device *dev,
+					struct service *srvc,
 					struct characteristic *ch)
 {
 	struct discover_desc_data *cb_data;
@@ -1993,10 +1995,9 @@ static bool build_descr_cache(int32_t conn_id, struct gatt_device *dev,
 	if (!cb_data)
 		return false;
 
-	cb_data->conn_id = conn_id;
-	cb_data->srvc_id = &srvc->id;
+	cb_data->dev = dev;
+	cb_data->srvc = srvc;
 	cb_data->ch = ch;
-	cb_data->primary = primary;
 
 	if (!gatt_discover_char_desc(dev->attrib, start, end,
 					gatt_discover_desc_cb, cb_data)) {
@@ -2053,7 +2054,7 @@ static void handle_client_get_descriptor(const void *buf, uint16_t len)
 	}
 
 	if (queue_isempty(ch->descriptors)) {
-		if (build_descr_cache(conn_id, dev, srvc, primary, ch)) {
+		if (build_descr_cache(dev, srvc, ch)) {
 			ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
 					HAL_OP_GATT_CLIENT_GET_DESCRIPTOR,
 					HAL_STATUS_SUCCESS);
-- 
1.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux