Return-Path: MIME-Version: 1.0 In-Reply-To: <1347349100-24228-8-git-send-email-chen.ganir@ti.com> References: <1347349100-24228-1-git-send-email-chen.ganir@ti.com> <1347349100-24228-8-git-send-email-chen.ganir@ti.com> From: Joao Paulo Rechi Vita Date: Tue, 11 Sep 2012 18:40:39 -0300 Message-ID: Subject: Re: [PATCH 07/10] battery: Add Battery to device To: chen.ganir@ti.com Cc: linux-bluetooth@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-bluetooth-owner@vger.kernel.org List-ID: On Tue, Sep 11, 2012 at 4:38 AM, wrote: > From: Chen Ganir > > Add/Remove battery from device > --- > profiles/battery/battery.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c > index d1e0b6e..31f2297 100644 > --- a/profiles/battery/battery.c > +++ b/profiles/battery/battery.c > @@ -49,8 +49,9 @@ struct battery { > static GSList *servers; > > struct characteristic { > - struct gatt_char attr; /* Characteristic */ > - struct battery *batt; /* Parent Battery Service */ > + struct device_battery *devbatt; /* device_battery pointer */ > + struct gatt_char attr; /* Characteristic */ > + struct battery *batt; /* Parent Battery Service */ Just a minor pick here: the comment alignment of attr and batt should have been fixed on the previous commit, to keep it consistent along the series. > GSList *desc; /* Descriptors */ > uint8_t ns; /* Battery Namespace */ > uint16_t description; /* Battery description */ > @@ -79,6 +80,8 @@ static void char_free(gpointer user_data) > > g_slist_free_full(c->desc, g_free); > > + btd_device_remove_battery(c->devbatt); > + > g_free(c); > } > > @@ -160,12 +163,12 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len, > if (status != 0) { > error("Discover all characteristic descriptors failed [%s]: %s", > ch->attr.uuid, att_ecode2str(status)); > - return; > + goto update_char; > } > > list = dec_find_info_resp(pdu, len, &format); > if (list == NULL) > - return; > + goto update_char; > > for (i = 0; i < list->num; i++) { > struct descriptor *desc; > @@ -186,6 +189,9 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len, > } > > att_data_list_free(list); > + > +update_char: > + ch->devbatt = btd_device_add_battery(ch->batt->dev); If I understood correctly, adding a battery to the device is a consequence of finding the "Battery Level" characteristic, and not related to the descriptors discovery. So the call to btd_device_add_battery() should be done inside the configure_battery_cb() instead of the discover_desc_cb(). This way you'll not need all these goto's. > } > > > -- > 1.7.9.5 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- João Paulo Rechi Vita Openbossa Labs - INdT