[PATCH] android/gatt: Use queue and stdlib instead of glib

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

 



This patch changes using glib to queues, stdlib operators.
---
 android/gatt.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index a874737..436f765 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -37,6 +37,7 @@
 #include "src/log.h"
 #include "hal-msg.h"
 #include "src/shared/util.h"
+#include "src/shared/queue.h"
 
 struct gatt_client {
 	int32_t id;
@@ -45,22 +46,22 @@ struct gatt_client {
 
 static struct ipc *hal_ipc = NULL;
 static bdaddr_t adapter_addr;
-static GSList *gatt_clients = NULL;
+static struct queue *gatt_clients = NULL;
 
-static int find_client_by_uuid(gconstpointer data, gconstpointer user_data)
+static bool find_client_by_uuid(const void *data, const void *user_data)
 {
 	const uint8_t *exp_uuid = user_data;
 	const struct gatt_client *client = data;
 
-	return memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
+	return !memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
 }
 
-static int find_client_by_id(gconstpointer data, gconstpointer user_data)
+static bool find_client_by_id(const void *data, const void *user_data)
 {
 	int32_t exp_id = PTR_TO_INT(user_data);
 	const struct gatt_client *client = data;
 
-	return client->id != exp_id;
+	return client->id == exp_id;
 }
 
 static void handle_client_register(const void *buf, uint16_t len)
@@ -79,19 +80,19 @@ static void handle_client_register(const void *buf, uint16_t len)
 		goto failed;
 	}
 
-	if (g_slist_find_custom(gatt_clients, &cmd->uuid,
-							find_client_by_uuid)) {
+	if (queue_find(gatt_clients, find_client_by_uuid, &cmd->uuid)) {
 		error("gatt: client uuid is already on list");
 		status = HAL_STATUS_FAILED;
 		goto failed;
 	}
 
-	client = g_new0(struct gatt_client, 1);
+	client = (struct gatt_client *) malloc(sizeof(struct gatt_client));
+
 	memcpy(client->uuid, cmd->uuid, sizeof(client->uuid));
 
 	client->id = client_cnt++;
 
-	gatt_clients = g_slist_prepend(gatt_clients, client);
+	queue_push_head(gatt_clients, client);
 
 	status = HAL_STATUS_SUCCESS;
 
@@ -110,21 +111,17 @@ failed:
 static void handle_client_unregister(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_unregister *cmd = buf;
-	GSList *l;
 	uint8_t status;
 
 	DBG("");
 
-	l = g_slist_find_custom(gatt_clients, INT_TO_PTR(cmd->client_if),
-							find_client_by_id);
-	if (!l) {
+	if (!queue_remove_if(gatt_clients, find_client_by_id,
+						INT_TO_PTR(cmd->client_if))) {
 		error("gatt: client_if=%d not found", cmd->client_if);
 		status = HAL_STATUS_FAILED;
 		goto failed;
 	}
 
-	gatt_clients = g_slist_remove(gatt_clients, l->data);
-
 	status = HAL_STATUS_SUCCESS;
 
 failed:
@@ -513,6 +510,13 @@ static const struct ipc_handler cmd_handlers[] = {
 			sizeof(struct hal_cmd_gatt_server_send_response)},
 };
 
+static void destroy_gatt_clients(void *data)
+{
+	struct gatt_client *elem = data;
+
+	free(elem);
+}
+
 bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
 {
 	DBG("");
@@ -524,6 +528,8 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
 	ipc_register(hal_ipc, HAL_SERVICE_ID_GATT, cmd_handlers,
 						G_N_ELEMENTS(cmd_handlers));
 
+	gatt_clients = queue_new();
+
 	return true;
 }
 
@@ -531,6 +537,8 @@ void bt_gatt_unregister(void)
 {
 	DBG("");
 
+	queue_destroy(gatt_clients, destroy_gatt_clients);
+
 	ipc_unregister(hal_ipc, HAL_SERVICE_ID_GATT);
 	hal_ipc = NULL;
 }
-- 
1.8.5.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