[PATCH 10/15] android/gatt: Add helper function to create_service

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

 



This function will be useful when we start cache also included
services
---
 android/gatt.c | 56 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 20 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index f88c72a..3500cd4 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -521,6 +521,40 @@ done:
 
 }
 
+static struct service *create_service(bool primary, char *uuid, void *data)
+{
+	struct service *s;
+
+	s = new0(struct service, 1);
+	if (!s) {
+		error("gatt: Cannot allocate memory for gatt_primary");
+		return NULL;
+	}
+
+	s->chars = queue_new();
+	if (!s->chars) {
+		error("gatt: Cannot allocate memory for char cache");
+		free(s);
+		return NULL;
+	}
+
+	if (bt_string_to_uuid(&s->id.uuid, uuid) < 0) {
+		error("gatt: Cannot convert string to uuid");
+		queue_destroy(s->chars, NULL);
+		free(s);
+		return NULL;
+	}
+
+	/* Put primary service to our local list */
+	s->primary = primary;
+	if (s->primary)
+		memcpy(&s->prim, data, sizeof(s->prim));
+	else
+		memcpy(&s->incl, data, sizeof(s->incl));
+
+	return s;
+}
+
 static void primary_cb(uint8_t status, GSList *services, void *user_data)
 {
 	struct gatt_device *dev = user_data;
@@ -546,27 +580,9 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data)
 		struct gatt_primary *prim = l->data;
 		struct service *p;
 
-		p = new0(struct service, 1);
-		if (!p) {
-			error("gatt: Cannot allocate memory for gatt_primary");
-			continue;
-		}
-
-		p->chars = queue_new();
-		if (!p->chars) {
-			error("gatt: Cannot allocate memory for char cache");
-			free(p);
-			continue;
-		}
-
-		if (bt_string_to_uuid(&p->id.uuid, prim->uuid) < 0) {
-			error("gatt: Cannot convert string to uuid");
+		p = create_service(true, prim->uuid, prim);
+		if (!p)
 			continue;
-		}
-
-		/* Put primary service to our local list */
-		memcpy(&p->prim, prim, sizeof(p->prim));
-		p->primary = true;
 
 		if (!queue_push_tail(dev->services, p)) {
 			error("gatt: Cannot push primary service to the list");
-- 
1.8.4

--
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