Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Marcin Kraglak <marcin.kraglak@tieto.com>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH 2/4] shared/gatt: Add function to check if handle was found in database
Date: Fri, 30 May 2014 11:16:14 +0200	[thread overview]
Message-ID: <1536745.sNU7QG5cDJ@uw000953> (raw)
In-Reply-To: <CABBYNZLhNAAP8+9Ngw_njve6WsV01yn+S=_yctobacW6ajsayg@mail.gmail.com>

Hi Luiz,

On Friday 30 of May 2014 11:32:34 Luiz Augusto von Dentz wrote:
> Hi Marcin,
> 
> On Fri, May 30, 2014 at 8:51 AM, Marcin Kraglak
> <marcin.kraglak@tieto.com> wrote:
> > It will return true if attribute with given handle exists in db, otherwise
> > false.
> > ---
> >  src/shared/gatt-db.c | 18 ++++++++++++++++++
> >  src/shared/gatt-db.h |  1 +
> >  2 files changed, 19 insertions(+)
> >
> > diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
> > index 998e93e..de1de57 100644
> > --- a/src/shared/gatt-db.c
> > +++ b/src/shared/gatt-db.c
> > @@ -758,3 +758,21 @@ uint32_t gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle)
> >
> >         return attribute->permissions;
> >  }
> > +
> > +bool gatt_db_has_attribute(struct gatt_db *db, uint16_t handle)
> > +{
> > +       struct gatt_db_attribute *attribute;
> > +       struct gatt_db_service *service;
> > +       uint16_t service_handle;
> > +
> > +       service = queue_find(db->services, find_service_for_handle,
> > +                                                       INT_TO_PTR(handle));
> > +       if (!service)
> > +               return false;
> > +
> > +       service_handle = service->attributes[0]->handle;
> > +
> > +       attribute = service->attributes[handle - service_handle];
> > +
> > +       return attribute ? true : false;
> > +}
> > diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
> > index f2f2f4d..ca36d32 100644
> > --- a/src/shared/gatt-db.h
> > +++ b/src/shared/gatt-db.h
> > @@ -93,3 +93,4 @@ const bt_uuid_t *gatt_db_get_attribute_type(struct gatt_db *db,
> >  uint16_t gatt_db_get_end_handle(struct gatt_db *db, uint16_t handle);
> >
> >  uint32_t gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle);
> > +bool gatt_db_has_attribute(struct gatt_db *db, uint16_t handle);
> > --
> > 1.9.0
> 
> This kind of API design is inefficient since it normally gonna cause
> double lookup and in any case gatt_db_get_attribute_permissions needs
> a fix since right now it cannot really tell if an error happen.
> Perhaps we could change the return to int and have another parameter
> to hold the permissions value or we can create an API for attribute
> themselves e.g. gatt_db_get_attribute + gatt_attribute_get_permission.
> 

For now I think we can fix only gatt_db_get_attribute_permissions() as you
suggested. But I agree that on long run having attribute API would be nice.

-- 
Best regards, 
Szymon Janc

  reply	other threads:[~2014-05-30  9:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-30  5:51 [PATCH 1/4] android/gatt: Fix parallel reading/writing attributes values from applications Marcin Kraglak
2014-05-30  5:51 ` [PATCH 2/4] shared/gatt: Add function to check if handle was found in database Marcin Kraglak
2014-05-30  8:32   ` Luiz Augusto von Dentz
2014-05-30  9:16     ` Szymon Janc [this message]
2014-05-30  5:51 ` [PATCH 3/4] android/gatt: Chack if given handle exists " Marcin Kraglak
2014-05-30  5:51 ` [PATCH 4/4] android/gatt: Check for invalid handle errors Marcin Kraglak

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=1536745.sNU7QG5cDJ@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcin.kraglak@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox