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: [PATCHv2 13/27] android/hog: Replace GSList of hog instances with queue of instances
Date: Fri,  3 Apr 2015 15:43:42 +0200	[thread overview]
Message-ID: <1428068636-13073-14-git-send-email-mariusz.skamra@tieto.com> (raw)
In-Reply-To: <1428068636-13073-1-git-send-email-mariusz.skamra@tieto.com>

Thanks to this patch hog instances can be now stored in queue.
This will help to clean the code from glib dependencies.
---
 android/hog.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/android/hog.c b/android/hog.c
index 9b76357..6bec2aa 100644
--- a/android/hog.c
+++ b/android/hog.c
@@ -101,7 +101,7 @@ struct bt_hog {
 	struct bt_scpp		*scpp;
 	struct bt_dis		*dis;
 	struct queue		*bas;
-	GSList			*instances;
+	struct queue		*instances;
 	struct bt_gatt_client	*client;
 	struct gatt_db		*db;
 };
@@ -875,7 +875,7 @@ static void hog_free(void *data)
 	bt_hog_detach(hog);
 
 	queue_destroy(hog->bas, (void *) bt_bas_unref);
-	g_slist_free_full(hog->instances, hog_free);
+	queue_destroy(hog->instances, hog_free);
 
 	bt_scpp_unref(hog->scpp);
 	bt_dis_unref(hog->dis);
@@ -904,6 +904,7 @@ struct bt_hog *bt_hog_new(int fd, const char *name, uint16_t vendor,
 
 	hog->bas = queue_new();
 	hog->reports = queue_new();
+	hog->instances = queue_new();
 
 	if (fd < 0)
 		hog->uhid = bt_uhid_new_default();
@@ -912,7 +913,7 @@ struct bt_hog *bt_hog_new(int fd, const char *name, uint16_t vendor,
 
 	hog->uhid_fd = fd;
 
-	if (!hog->bas || !hog->uhid || !hog->reports) {
+	if (!hog->bas || !hog->uhid || !hog->reports || !hog->instances) {
 		hog_free(hog);
 		return NULL;
 	}
@@ -1026,7 +1027,7 @@ static void hog_attach_hog(struct bt_hog *hog, uint16_t service_handle)
 		return;
 
 	bt_hog_attach(instance, hog->attrib, hog->client);
-	hog->instances = g_slist_append(hog->instances, instance);
+	queue_push_tail(hog->instances, instance);
 }
 
 static void primary_cb(uint8_t status, GSList *services, void *user_data)
@@ -1095,7 +1096,7 @@ static void service_cb(struct gatt_db_attribute *attrib, void *user_data)
 
 bool bt_hog_attach(struct bt_hog *hog, void *gatt, void *client)
 {
-	GSList *l;
+	const struct queue_entry *hog_entry;
 
 	if (hog->attrib || hog->client)
 		return false;
@@ -1118,8 +1119,9 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt, void *client)
 
 	queue_foreach(hog->bas, (void *) bt_bas_attach, gatt);
 
-	for (l = hog->instances; l; l = l->next) {
-		struct bt_hog *instance = l->data;
+	hog_entry = queue_get_entries(hog->instances);
+	while (hog_entry) {
+		struct bt_hog *instance = hog_entry->data;
 
 		bt_hog_attach(instance, gatt, client);
 	}
@@ -1140,19 +1142,11 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt, void *client)
 
 void bt_hog_detach(struct bt_hog *hog)
 {
-	GSList *l;
-
 	if (!hog->attrib || !hog->client)
 		return;
 
 	queue_foreach(hog->bas, (void *) bt_bas_detach, NULL);
-
-	for (l = hog->instances; l; l = l->next) {
-		struct bt_hog *instance = l->data;
-
-		bt_hog_detach(instance);
-	}
-
+	queue_foreach(hog->instances, (void *) bt_hog_detach, NULL);
 	queue_foreach(hog->reports, report_disable_notif, NULL);
 
 	if (hog->scpp)
@@ -1187,7 +1181,7 @@ int bt_hog_set_control_point(struct bt_hog *hog, bool suspend)
 int bt_hog_send_report(struct bt_hog *hog, void *data, size_t size, int type)
 {
 	struct report *report;
-	GSList *l;
+	const struct queue_entry *hog_entry;
 
 	if (!hog)
 		return -EINVAL;
@@ -1212,10 +1206,12 @@ int bt_hog_send_report(struct bt_hog *hog, void *data, size_t size, int type)
 						report->decl->value_handle,
 						false, data, size);
 
-	for (l = hog->instances; l; l = l->next) {
-		struct bt_hog *instance = l->data;
+	hog_entry = queue_get_entries(hog->instances);
+	while (hog_entry) {
+		struct bt_hog *instance = hog_entry->data;
 
 		bt_hog_send_report(instance, data, size, type);
+		hog_entry = hog_entry->next;
 	}
 
 	return 0;
-- 
1.9.1


  parent reply	other threads:[~2015-04-03 13:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03 13:43 [PATCHv2 00/27] HoG: Replace gattrib with gatt_client Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 01/27] android/hidhost: Create bt_gatt_client Mariusz Skamra
2015-04-03 16:33   ` Michael Janssen
2015-04-03 13:43 ` [PATCHv2 02/27] android/hog: Introduce bt_gatt_client Mariusz Skamra
2015-04-07  7:44   ` Luiz Augusto von Dentz
2015-04-03 13:43 ` [PATCHv2 03/27] shared/gatt-client: Expose gatt_db Mariusz Skamra
2015-04-07  8:01   ` Luiz Augusto von Dentz
2015-04-03 13:43 ` [PATCHv2 04/27] android/hog: Remove tracking gatt operations Mariusz Skamra
2015-04-07  7:50   ` Luiz Augusto von Dentz
2015-04-08  8:47     ` Skamra Mariusz
2015-04-08 10:11       ` Luiz Augusto von Dentz
2015-04-03 13:43 ` [PATCHv2 05/27] android/hog: Use bt_gatt_client to read characteristic value Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 06/27] android/hog: Use bt_gatt_client to register for notifications Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 07/27] android/hog: Use bt_gatt_client to write without response Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 08/27] android/hog: Replace gatt_write_char with bt_gatt_client_write_value Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 09/27] android/hog: Use gatt_db to search for services and characteristics in db Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 10/27] android/hog: Add helper to create uhid device Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 11/27] lib/uuid: Add define for HoG UUID Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 12/27] android/hog: Replace list of reports with a queue of reports Mariusz Skamra
2015-04-03 13:43 ` Mariusz Skamra [this message]
2015-04-03 13:43 ` [PATCHv2 14/27] android/dis: Remove tracking pending gatt operations Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 15/27] android/dis: Introduce bt_gatt_client Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 16/27] android/scpp: Remove tracking pending gatt operations Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 17/27] android/scpp: Introduce bt_gatt_client Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 18/27] android/scpp: Merge refresh_discovered_cb with iwin_discovered_cb Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 19/27] android/bas: Remove tracking pending gatt operations Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 20/27] android/bas: Start using bt_gatt_client Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 21/27] android/hog: Strip btio dependencies Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 22/27] android/hog: Enable Input Report notifications only if uhid is created Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 23/27] android/bas: Enable Battery Level notifications after reconnection Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 24/27] android/hog: Clean the code from attrib dependencies Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 25/27] android/hog: Remove glib dependencies Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 26/27] android/hog: Remove redundant code Mariusz Skamra
2015-04-03 13:43 ` [PATCHv2 27/27] android/hog: Replace definitions of characteristic uuids with bt_uuids 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=1428068636-13073-14-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.