<div dir="ltr"><p dir="ltr">On Jul 18, 2013 11:25 AM, "Tanu Kaskinen" <<a href="mailto:tanu.kaskinen@linux.intel.com" target="_blank">tanu.kaskinen@linux.intel.com</a>> wrote:<br>
><br>
> On Fri, 2013-07-12 at 15:06 -0300, <a href="mailto:jprvita@gmail.com" target="_blank">jprvita@gmail.com</a> wrote:<br>
> > From: João Paulo Rechi Vita <<a href="mailto:jprvita@openbossa.org" target="_blank">jprvita@openbossa.org</a>><br>
> ><br>
> > Create a structure pa_bluetooth_device to store information about the<br>
> > bluetooth device and utility functions to manipulate this structure.<br>
> > ---<br>
> > src/modules/bluetooth/bluez5-util.c | 84 +++++++++++++++++++++++++++++++++++++<br>
> > src/modules/bluetooth/bluez5-util.h | 18 ++++++++<br>
> > 2 files changed, 102 insertions(+)<br>
> ><br>
> > diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c<br>
> > index d5f1846..574a22d 100644<br>
> > --- a/src/modules/bluetooth/bluez5-util.c<br>
> > +++ b/src/modules/bluetooth/bluez5-util.c<br>
> > @@ -44,8 +44,86 @@ struct pa_bluetooth_discovery {<br>
> > pa_dbus_connection *connection;<br>
> > bool filter_added;<br>
> > pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];<br>
> > + pa_hashmap *devices;<br>
> > };<br>
> ><br>
> > +static pa_bluetooth_device* pa_bluetooth_discovery_create_device(pa_bluetooth_discovery *y, const char *path) {<br>
><br>
> Static functions shouldn't have the "pa_bluetooth" prefix. Since this<br>
> seems to be a normal object allocation function, I'd use name<br>
> "device_new".<br>
></p>
<p dir="ltr">Ok, I didn't remember of this requirement in PA. I'll fix this and other occurrences of this problem for the next patch series.</p>
<p dir="ltr">> > +pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *address) {<br>
> > + pa_bluetooth_device *d;<br>
> > + void *state = NULL;<br>
> > +<br>
> > + pa_assert(y);<br>
> > + pa_assert(PA_REFCNT_VALUE(y) > 0);<br>
> > + pa_assert(address);<br>
> > +<br>
> > + while ((d = pa_hashmap_iterate(y->devices, &state, NULL)))<br>
> > + if (pa_streq(d->address, address))<br>
> > + return d->device_info_valid == 1 ? d : NULL;<br>
><br>
> If there are two devices with the same address, this will return NULL if<br>
> the first encountered device has invalid info, even if the second device<br>
> would be ok.<br>
></p>
<p dir="ltr">You're right. This code is from the BlueZ 4 modules, so this should be fixed there as well (I'll have a look into it). For BlueZ 5 I use this function only in the oFono HFP support, and I've realized that I actually need to take the local adapter address into account as well, so I'll send an updated version of this function that takes the local and remote addresses in the next series.</p>
<p dir="ltr">--<br>
João Paulo Rechi Vita<br>
<a href="http://about.me/jprvita" target="_blank">http://about.me/jprvita</a><br>
</p>
</div>