Re: [PATCH v2 2/6] android/gatt: Unsubscribe from autoconnect on unregister

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Lukasz,

On Wed, Sep 3, 2014 at 9:58 AM, Lukasz Rymanowski
<lukasz.rymanowski@xxxxxxxxx> wrote:
> When application does unregister, lets make sure that BfA does not keep
> any auto connect devices for this app.
> ---
>  android/gatt.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index a3486ca..dea253e 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -370,6 +370,13 @@ static bool match_device_by_state(const void *data, const void *user_data)
>         return true;
>  }
>
> +static bool match_device_by_ac_id(const void *data, const void *user_data)
> +{
> +       const struct gatt_device *dev = data;
> +
> +       return queue_find(dev->autoconnect_apps, match_by_value, user_data);
> +}
> +
>  static bool match_pending_device(const void *data, const void *user_data)
>  {
>         const struct gatt_device *dev = data;
> @@ -442,6 +449,11 @@ static struct gatt_device *find_device_by_state(uint32_t state)
>                                                         UINT_TO_PTR(state));
>  }
>
> +static struct gatt_device *find_device_by_autoconnect_app_id(uint32_t id)
> +{
> +       return queue_find(gatt_devices, match_device_by_ac_id,
> +                                                       UINT_TO_PTR(id));
> +}
>  static bool match_srvc_by_element_id(const void *data, const void *user_data)
>  {
>         const struct element_id *exp_id = user_data;
> @@ -1865,10 +1877,41 @@ static bool trigger_connection(struct app_connection *connection)
>         return ret;
>  }
>
> +static void clear_autoconnect_devices(int app_id)
> +{
> +       struct gatt_device *dev;
> +
> +       /*
> +        * Check if application was registered for any devices to
> +        * reconnect
> +        */
> +       dev = find_device_by_autoconnect_app_id(app_id);
> +       while (dev) {
> +               queue_remove(dev->autoconnect_apps, INT_TO_PTR(app_id));
> +
> +               if (queue_isempty(dev->autoconnect_apps)) {
> +                       bt_auto_connect_remove(&dev->bdaddr);
> +
> +                       if (dev->state == DEVICE_CONNECT_INIT)
> +                               device_set_state(dev, DEVICE_DISCONNECTED);
> +
> +                       device_unref(dev);
> +               }
> +
> +               dev = find_device_by_autoconnect_app_id(app_id);
> +       };

Looks like there is a ';; after the while statement, please fix that.
Also this looks very inefficient since it does
find_device_by_autoconnect_app_id does a double lookup and we doing it
in a while loop, I would suggest using queue_foreach(gatt_devices...
then do queue_remove_if(dev->autoconnect_apps,  the result should be
the same but with a single lookup in each queue.

> +}
> +
>  static uint8_t unregister_app(int client_if)
>  {
>         struct gatt_app *cl;
>
> +       /*
> +        * Make sure that there is no devices in auto connect list for this
> +        * application
> +        */
> +       clear_autoconnect_devices(client_if);
> +
>         cl = queue_remove_if(gatt_apps, match_app_by_id, INT_TO_PTR(client_if));
>         if (!cl) {
>                 error("gatt: client_if=%d not found", client_if);
> --
> 1.8.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Luiz Augusto von Dentz
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux