Re: [PATCH 01/10] unit/avrcp: Refactor check attributes code

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

 



Hi Andrei,

On Wed, Mar 5, 2014 at 4:32 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@xxxxxxxxx> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@xxxxxxxxx>
>
> Make check_attributes() function which would handle attributes check.
> ---
>  unit/test-avrcp.c | 24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
> index 803dd6b..7ce2801 100644
> --- a/unit/test-avrcp.c
> +++ b/unit/test-avrcp.c
> @@ -288,6 +288,20 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
>                 { },
>  };
>
> +static bool check_attributes(const uint8_t *params)
> +{
> +       int i;
> +
> +       for (i = 1; i <= params[0]; i++) {
> +               DBG("params[%d] = 0x%02x", i, params[i]);
> +               if (params[i] > AVRCP_ATTRIBUTE_LAST ||
> +                   params[i] == AVRCP_ATTRIBUTE_ILEGAL)
> +                       return false;
> +       }
> +
> +       return true;
> +}
> +
>  static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
>                                                 uint8_t transaction,
>                                                 uint16_t params_len,
> @@ -326,16 +340,10 @@ static ssize_t avrcp_handle_get_player_attr_text(struct avrcp *session,
>                                                 uint8_t *params,
>                                                 void *user_data)
>  {
> -       int i;
> -
>         DBG("params[0] %d params_len %d", params[0], params_len);
>
> -       for (i = 1; i <= params[0]; i++) {
> -               DBG("params[%d] = 0x%02x", i, params[i]);
> -               if (params[i] > AVRCP_ATTRIBUTE_LAST ||
> -                       params[i] == AVRCP_ATTRIBUTE_ILEGAL)
> -                       return -EINVAL;
> -       }
> +       if (!check_attributes(params))
> +               return -EINVAL;
>
>         params[0] = 0;
>
> --
> 1.8.3.2

Pushed after some code style fixes, please do not mix spaces and tabs.
Also the tests are starting to get logic outside of just testing the
handler but the actual PDU handling so perhaps we need to think if the
API of avrcp-lib.h is really a proper one or we should do create a
different one as it is done for passthrough where the callback are not
actually pure PDU handlers.


-- 
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