From: Szymon Janc <szymon.janc@tieto.com>
To: Mariusz Skamra <mariusz.skamra@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 02/28] android/hog: Introduce bt_gatt_client
Date: Thu, 02 Apr 2015 16:17:32 +0200 [thread overview]
Message-ID: <713993885.Yr0x8UAtWy@leonov> (raw)
In-Reply-To: <1427906444-11769-3-git-send-email-mariusz.skamra@tieto.com>
Hi Mariusz,
On Wednesday 01 of April 2015 18:40:18 Mariusz Skamra wrote:
> This patch introduces bt_gatt_client to HoG. Service handle will be used
> to obtain the attribute from cached database.
> ---
> android/hidhost.c | 4 ++--
> android/hog.c | 30 +++++++++++++++++++++---------
> android/hog.h | 6 +++---
> unit/test-hog.c | 4 ++--
> 4 files changed, 28 insertions(+), 16 deletions(-)
>
> diff --git a/android/hidhost.c b/android/hidhost.c
> index 3da1130..47e5840 100644
> --- a/android/hidhost.c
> +++ b/android/hidhost.c
> @@ -818,7 +818,7 @@ static void client_ready_cb(bool success, uint8_t
> att_ecode, void *user_data) goto fail;
> }
>
> - if (!bt_hog_attach(dev->hog, dev->attrib)) {
> + if (!bt_hog_attach(dev->hog, dev->attrib, dev->client)) {
> error("HoG: unable to attach");
> goto fail;
> }
> @@ -864,7 +864,7 @@ static void hog_conn_cb(const bdaddr_t *addr, int err,
> void *attrib) if (!dev->hog) {
> /* TODO: Get device details */
> dev->hog = bt_hog_new_default("bluez-input-device", dev->vendor,
> - dev->product, dev->version, NULL);
> + dev->product, dev->version, NULL, 0);
> if (!dev->hog) {
> error("HoG: unable to create session");
> goto fail;
> diff --git a/android/hog.c b/android/hog.c
> index ff77bb3..5b8c079 100644
> --- a/android/hog.c
> +++ b/android/hog.c
> @@ -45,6 +45,9 @@
> #include "src/shared/util.h"
> #include "src/shared/uhid.h"
> #include "src/shared/queue.h"
> +#include "src/shared/att.h"
> +#include "src/shared/gatt-db.h"
> +#include "src/shared/gatt-client.h"
> #include "src/log.h"
>
> #include "attrib/att.h"
> @@ -79,6 +82,7 @@
>
> struct bt_hog {
> int ref_count;
> + uint16_t service_handle;
> char *name;
> uint16_t vendor;
> uint16_t product;
> @@ -103,6 +107,7 @@ struct bt_hog {
> struct queue *bas;
> GSList *instances;
> struct queue *gatt_op;
> + struct bt_gatt_client *client;
> };
>
> struct report {
> @@ -1173,14 +1178,15 @@ static void hog_free(void *data)
>
> struct bt_hog *bt_hog_new_default(const char *name, uint16_t vendor,
> uint16_t product, uint16_t version,
> - void *primary)
> + void *primary, uint16_t service_handle)
> {
> - return bt_hog_new(-1, name, vendor, product, version, primary);
> + return bt_hog_new(-1, name, vendor, product, version, primary,
> + service_handle);
> }
>
> struct bt_hog *bt_hog_new(int fd, const char *name, uint16_t vendor,
> uint16_t product, uint16_t version,
> - void *primary)
> + void *primary, uint16_t service_handle)
> {
> struct bt_hog *hog;
>
> @@ -1211,6 +1217,9 @@ struct bt_hog *bt_hog_new(int fd, const char *name,
> uint16_t vendor, if (primary)
> hog->primary = g_memdup(primary, sizeof(*hog->primary));
>
> + if (service_handle)
> + hog->service_handle = service_handle;
> +
> return bt_hog_ref(hog);
> }
>
> @@ -1321,14 +1330,14 @@ static void hog_attach_hog(struct bt_hog *hog,
> struct gatt_primary *primary) }
>
> instance = bt_hog_new(hog->uhid_fd, hog->name, hog->vendor,
> - hog->product, hog->version, primary);
> + hog->product, hog->version, primary, 0);
> if (!instance)
> return;
>
> find_included(instance, hog->attrib, primary->range.start,
> primary->range.end, find_included_cb, instance);
>
> - bt_hog_attach(instance, hog->attrib);
> + bt_hog_attach(instance, hog->attrib, hog->client);
> hog->instances = g_slist_append(hog->instances, instance);
> }
>
> @@ -1377,15 +1386,16 @@ static void primary_cb(uint8_t status, GSList
> *services, void *user_data) }
> }
>
> -bool bt_hog_attach(struct bt_hog *hog, void *gatt)
> +bool bt_hog_attach(struct bt_hog *hog, void *gatt, void *client)
> {
> struct gatt_primary *primary = hog->primary;
> GSList *l;
>
> - if (hog->attrib)
> + if (hog->attrib || hog->client)
> return false;
>
> hog->attrib = g_attrib_ref(gatt);
> + hog->client = bt_gatt_client_ref(client);
>
> if (!primary) {
> discover_primary(hog, hog->attrib, NULL, primary_cb, hog);
> @@ -1403,7 +1413,7 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)
> for (l = hog->instances; l; l = l->next) {
> struct bt_hog *instance = l->data;
>
> - bt_hog_attach(instance, gatt);
> + bt_hog_attach(instance, gatt, client);
> }
>
> if (hog->reports == NULL) {
> @@ -1429,7 +1439,7 @@ void bt_hog_detach(struct bt_hog *hog)
> {
> GSList *l;
>
> - if (!hog->attrib)
> + if (!hog->attrib || !hog->client)
> return;
>
> queue_foreach(hog->bas, (void *) bt_bas_detach, NULL);
> @@ -1456,7 +1466,9 @@ void bt_hog_detach(struct bt_hog *hog)
> bt_dis_detach(hog->dis);
>
> queue_foreach(hog->gatt_op, (void *) cancel_gatt_req, NULL);
> + bt_gatt_client_unref(hog->client);
> g_attrib_unref(hog->attrib);
> + hog->client = NULL;
> hog->attrib = NULL;
Usually we do this like:
unref(foo);
foo = NULL;
unref(bar);
bar = NULL;
> }
>
> diff --git a/android/hog.h b/android/hog.h
> index 2a9b899..61d756c 100644
> --- a/android/hog.h
> +++ b/android/hog.h
> @@ -25,16 +25,16 @@ struct bt_hog;
>
> struct bt_hog *bt_hog_new_default(const char *name, uint16_t vendor,
> uint16_t product, uint16_t version,
> - void *primary);
> + void *primary, uint16_t service_handle);
>
> struct bt_hog *bt_hog_new(int fd, const char *name, uint16_t vendor,
> uint16_t product, uint16_t version,
> - void *primary);
> + void *primary, uint16_t service_handle);
>
> struct bt_hog *bt_hog_ref(struct bt_hog *hog);
> void bt_hog_unref(struct bt_hog *hog);
>
> -bool bt_hog_attach(struct bt_hog *hog, void *gatt);
> +bool bt_hog_attach(struct bt_hog *hog, void *gatt, void *client);
> void bt_hog_detach(struct bt_hog *hog);
>
> int bt_hog_set_control_point(struct bt_hog *hog, bool suspend);
> diff --git a/unit/test-hog.c b/unit/test-hog.c
> index 2a25d09..c7c64e4 100644
> --- a/unit/test-hog.c
> +++ b/unit/test-hog.c
> @@ -196,7 +196,7 @@ static struct context *create_context(gconstpointer
> data) fd = open("/dev/null", O_WRONLY | O_CLOEXEC);
> g_assert(fd > 0);
>
> - context->hog = bt_hog_new(fd, name, vendor, product, version, NULL);
> + context->hog = bt_hog_new(fd, name, vendor, product, version, NULL, 0);
> g_assert(context->hog);
>
> channel = g_io_channel_unix_new(sv[1]);
> @@ -222,7 +222,7 @@ static void test_hog(gconstpointer data)
> {
> struct context *context = create_context(data);
>
> - g_assert(bt_hog_attach(context->hog, context->attrib));
> + g_assert(bt_hog_attach(context->hog, context->attrib, NULL));
> }
>
> int main(int argc, char *argv[])
--
BR
Szymon Janc
next prev parent reply other threads:[~2015-04-02 14:17 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-01 16:40 [PATCH 00/28] android/hog Introduce bt_gatt_client Mariusz Skamra
2015-04-01 16:40 ` [PATCH 01/28] android/hidhost: Create bt_gatt_client Mariusz Skamra
2015-04-02 14:16 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 02/28] android/hog: Introduce bt_gatt_client Mariusz Skamra
2015-04-02 14:17 ` Szymon Janc [this message]
2015-04-01 16:40 ` [PATCH 03/28] shared/gatt-client: Expose gatt_db Mariusz Skamra
2015-04-02 14:20 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 04/28] android/hog: Remove tracking gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 05/28] android/hog: Use bt_gatt_client to read characteristic value Mariusz Skamra
2015-04-01 16:40 ` [PATCH 06/28] android/hog: Use bt_gatt_client to register for notifications Mariusz Skamra
2015-04-01 16:40 ` [PATCH 07/28] android/hog: Use bt_gatt_client to write without response Mariusz Skamra
2015-04-01 16:40 ` [PATCH 08/28] android/hog: Replace gatt_write_char with bt_gatt_client_write_value Mariusz Skamra
2015-04-01 16:40 ` [PATCH 09/28] android/hog: Use gatt_db to search for services and characteristics in db Mariusz Skamra
2015-04-02 15:22 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 10/28] android/hog: Add helper to create uhid device Mariusz Skamra
2015-04-01 16:40 ` [PATCH 11/28] lib/uuid: Add define for HoG UUID Mariusz Skamra
2015-04-01 16:40 ` [PATCH 12/28] android/hog: Replace list of reports with a queue of reports Mariusz Skamra
2015-04-01 16:40 ` [PATCH 13/28] android/hog: Replace definitions of characteristic uuids with bt_uuids Mariusz Skamra
2015-04-02 15:26 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 14/28] android/hog: Replace GSList of hog instances with queue of instances Mariusz Skamra
2015-04-02 15:29 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 15/28] android/dis: Remove tracking pending gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 16/28] android/dis: Introduce bt_gatt_client Mariusz Skamra
2015-04-01 16:40 ` [PATCH 17/28] android/scpp: Remove tracking pending gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 18/28] android/scpp: Introduce bt_gatt_client Mariusz Skamra
2015-04-02 15:34 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 19/28] android/scpp: Merge refresh_discovered_cb with iwin_discovered_cb Mariusz Skamra
2015-04-01 16:40 ` [PATCH 20/28] android/bas: Remove tracking pending gatt operations Mariusz Skamra
2015-04-01 16:40 ` [PATCH 21/28] android/bas: Start using bt_gatt_client Mariusz Skamra
2015-04-02 15:37 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 22/28] android/hog: Strip btio dependencies Mariusz Skamra
2015-04-02 15:39 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 23/28] android/hog: Enable Input Report notifications only if uhid is created Mariusz Skamra
2015-04-01 16:40 ` [PATCH 24/28] android/bas: Enable Battery Level notifications after reconnection Mariusz Skamra
2015-04-01 16:40 ` [PATCH 25/28] android/hog: Add MIN definition Mariusz Skamra
2015-04-02 15:41 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 26/28] android/hog: Remove attrib/ Mariusz Skamra
2015-04-02 15:44 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 27/28] android/hog: Remove glib dependencies Mariusz Skamra
2015-04-02 15:45 ` Szymon Janc
2015-04-01 16:40 ` [PATCH 28/28] android/hog: Remove redundant code 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=713993885.Yr0x8UAtWy@leonov \
--to=szymon.janc@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=mariusz.skamra@tieto.com \
/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.