From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 15/15] android/hog: Add support for multiple instaces
Date: Thu, 26 Jun 2014 17:46:48 +0300 [thread overview]
Message-ID: <1403794008-18585-15-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1403794008-18585-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This is necessary to pass PTS tests which does include 2 instances.
---
android/hog.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 40 insertions(+), 8 deletions(-)
diff --git a/android/hog.c b/android/hog.c
index 5fa8b94..01229ff 100644
--- a/android/hog.c
+++ b/android/hog.c
@@ -95,6 +95,7 @@ struct bt_hog {
struct bt_dis *dis;
struct bt_scpp *scpp;
struct bt_bas *bas;
+ GSList *instances;
};
struct report {
@@ -648,8 +649,11 @@ static void report_free(void *data)
g_free(report);
}
-static void hog_free(struct bt_hog *hog)
+static void hog_free(void *data)
{
+ struct bt_hog *hog = data;
+
+ g_slist_free_full(hog->instances, hog_free);
bt_dis_unref(hog->dis);
bt_scpp_unref(hog->scpp);
bt_bas_unref(hog->bas);
@@ -804,6 +808,27 @@ static void hog_attach_bas(struct bt_hog *hog, struct gatt_primary *primary)
bt_bas_attach(hog->bas, hog->attrib);
}
+static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary)
+{
+ struct bt_hog *instance;
+
+ if (!hog->primary) {
+ hog->primary = g_memdup(primary, sizeof(*primary));
+ gatt_discover_char(hog->attrib, primary->range.start,
+ primary->range.end, NULL,
+ char_discovered_cb, hog);
+ return;
+ }
+
+ instance = bt_hog_new(hog->name, hog->vendor, hog->product,
+ hog->version, primary);
+ if (!instance)
+ return;
+
+ bt_hog_attach(instance, hog->attrib);
+ hog->instances = g_slist_append(hog->instances, instance);
+}
+
static void primary_cb(uint8_t status, GSList *services, void *user_data)
{
struct bt_hog *hog = user_data;
@@ -842,16 +867,11 @@ static void primary_cb(uint8_t status, GSList *services, void *user_data)
}
if (strcmp(primary->uuid, HOG_UUID) == 0)
- hog->primary = g_memdup(primary, sizeof(*primary));
+ hog_attach_hog(hog, primary);
}
- if (hog->primary) {
- gatt_discover_char(hog->attrib, hog->primary->range.start,
- hog->primary->range.end, NULL,
- char_discovered_cb, hog);
-
+ if (hog->primary)
return;
- }
for (l = services; l; l = l->next) {
primary = l->data;
@@ -886,6 +906,12 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)
if (hog->bas)
bt_bas_attach(hog->bas, gatt);
+ for (l = hog->instances; l; l = l->next) {
+ struct bt_hog *instance = l->data;
+
+ bt_hog_attach(instance, gatt);
+ }
+
if (hog->reports == NULL) {
gatt_discover_char(hog->attrib, primary->range.start,
primary->range.end, NULL,
@@ -912,6 +938,12 @@ void bt_hog_detach(struct bt_hog *hog)
if (!hog->attrib)
return;
+ for (l = hog->instances; l; l = l->next) {
+ struct bt_hog *instance = l->data;
+
+ bt_hog_detach(instance);
+ }
+
for (l = hog->reports; l; l = l->next) {
struct report *r = l->data;
--
1.9.3
prev parent reply other threads:[~2014-06-26 14:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 14:46 [PATCH BlueZ v2 01/15] android/dis: Add copy to Device Info implementation Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 02/15] android/dis: Strip dependencies from deviceinfo plugin Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 03/15] android/dis: Add bt_dis_set_notification Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 04/15] android/dis: Only cache the handle not all the characteristics Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 05/15] android/hog: Add support for reading device details via DIS Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 06/15] lib/uuid: Add define for Scan Parameter UUID Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 07/15] android/scpp: Add copy to Scan Parameter Profile implementation Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 08/15] android/scpp: Strip dependencies from scan plugin Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 09/15] android/scpp: Add bt_scpp_set_interval and bt_scpp_set_window Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 10/15] android/scpp: Check for cached handles on attach Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 11/15] android/hog: Add support for Scan Parameter Service Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 12/15] android: Add initial implementation of Battery Service client Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 13/15] lib/uuid: Add define for Battery UUID Luiz Augusto von Dentz
2014-06-26 14:46 ` [PATCH BlueZ v2 14/15] android/hog: Add support for Battery Service Luiz Augusto von Dentz
2014-06-26 14:46 ` Luiz Augusto von Dentz [this message]
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=1403794008-18585-15-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).