Linux bluetooth development
 help / color / mirror / Atom feed
From: Andrei Emeltchenko <andrei.emeltchenko.news@gmail.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ 03/16] android/avrcp-lib: Rework handler callback parameters
Date: Mon, 3 Mar 2014 11:52:39 +0200	[thread overview]
Message-ID: <20140303095237.GB4999@aemeltch-MOBL1> (raw)
In-Reply-To: <1393786109-6554-3-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Sun, Mar 02, 2014 at 08:48:18PM +0200, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This rework handler callback parameters to make it able to return
> proper error such as -EAGAIN to implement asynchronous responses.
> ---
>  android/avrcp-lib.c | 12 +++++++++---
>  android/avrcp-lib.h |  5 +++--
>  unit/test-avrcp.c   | 42 +++++++++++++++++++++---------------------
>  3 files changed, 33 insertions(+), 26 deletions(-)
> 
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> index cdad6ac..339be16 100644
> --- a/android/avrcp-lib.c
> +++ b/android/avrcp-lib.c
> @@ -125,6 +125,7 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
>  	struct avrcp_header *pdu = (void *) operands;
>  	uint32_t company_id = ntoh24(pdu->company_id);
>  	uint16_t params_len = ntohs(pdu->params_len);
> +	ssize_t ret;
>  
>  	if (company_id != IEEEID_BTSIG) {
>  		*code = AVC_CTYPE_NOT_IMPLEMENTED;
> @@ -159,12 +160,17 @@ static ssize_t handle_vendordep_pdu(struct avctp *conn, uint8_t transaction,
>  		goto reject;
>  	}
>  
> -	*code = handler->func(session, transaction, &params_len,
> +	ret = handler->func(session, transaction, code, params_len,
>  					pdu->params, session->control_data);
> +	if (ret < 0) {
> +		if (ret == -EAGAIN)
> +			return ret;
> +		goto reject;
> +	}
>  
> -	pdu->params_len = htons(params_len);
> +	pdu->params_len = htons(ret);
>  
> -	return AVRCP_HEADER_LENGTH + params_len;
> +	return AVRCP_HEADER_LENGTH + ret;
>  
>  reject:
>  	pdu->params_len = htons(1);
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> index a33bdfe..d7a805b 100644
> --- a/android/avrcp-lib.h
> +++ b/android/avrcp-lib.h
> @@ -79,8 +79,9 @@ struct avrcp;
>  struct avrcp_control_handler {
>  	uint8_t id;
>  	uint8_t code;
> -	uint8_t (*func) (struct avrcp *session, uint8_t transaction,
> -			uint16_t *params_len, uint8_t *params, void *user_data);
> +	ssize_t (*func) (struct avrcp *session, uint8_t transaction,
> +			uint8_t *code, uint16_t params_len, uint8_t *params,
> +			void *user_data);
>  };
>  
>  struct avrcp_passthrough_handler {
> diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
> index 302c331..2d5711b 100644
> --- a/unit/test-avrcp.c
> +++ b/unit/test-avrcp.c
> @@ -292,54 +292,54 @@ static const struct avrcp_passthrough_handler passthrough_handlers[] = {
>  		{ },
>  };
>  
> -static uint8_t avrcp_handle_get_capabilities(struct avrcp *session,
> -				uint8_t transaction, uint16_t *params_len,
> -				uint8_t *params, void *user_data)
> +static ssize_t avrcp_handle_get_capabilities(struct avrcp *session,
> +					uint8_t transaction, uint8_t *code,
> +					uint16_t params_len, uint8_t *params,
> +					void *user_data)
>  {
>  	uint32_t id = 0x001958;
>  
> -	DBG("params[0] %d params_len %d", params[0], *params_len);
> -
> -	if (*params_len != 1)
> +	if (params_len != 1)
>  		goto fail;
>  
>  	switch (params[0]) {
>  	case CAP_COMPANY_ID:
> -		*params_len = 5;
>  		params[1] = 1;
>  		hton24(&params[2], id);
> -		return AVC_CTYPE_STABLE;
> +		*code = AVC_CTYPE_STABLE;
> +		return 5;

What is 5? Shall we define constants or use formulas?

Best regards 
Andrei Emeltchenko 


  reply	other threads:[~2014-03-03  9:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-02 18:48 [PATCH BlueZ 01/16] android/avrcp-lib: Add avrcp_send function Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 02/16] android/avctp: Make handler return ssize_t Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 03/16] android/avrcp-lib: Rework handler callback parameters Luiz Augusto von Dentz
2014-03-03  9:52   ` Andrei Emeltchenko [this message]
2014-03-03 12:41     ` Luiz Augusto von Dentz
2014-03-04  8:05       ` Andrei Emeltchenko
2014-03-02 18:48 ` [PATCH BlueZ 04/16] android/avrcp-lib: Embed response code into handler table Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 05/16] android/avrcp-lib: Fix not passing user data of passthrough callback Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 06/16] android/avrcp-lib: Add pressed status to passthrough handler callback Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 07/16] android/avrcp: Add passthrough handler for fast forward Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 08/16] android/avrcp: Add passthrough handler for rewind Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 09/16] android/avrcp-lib: Make hton24 and ntoh24 public Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 10/16] android/avrcp: Add handler for GetCapabilities command Luiz Augusto von Dentz
2014-03-03 10:10   ` Andrei Emeltchenko
2014-03-02 18:48 ` [PATCH BlueZ 11/16] android/avrcp: Add handler for GetPlayStatus command Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 12/16] android/avrcp: Add handler for GetElementAttributes command Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 13/16] android/avrcp: Add handler for RegisterNotification command Luiz Augusto von Dentz
2014-03-02 18:48 ` [PATCH BlueZ 14/16] android/avrcp: Bump version to 1.3 Luiz Augusto von Dentz
2014-03-04 11:47 ` [PATCH BlueZ 01/16] android/avrcp-lib: Add avrcp_send function Luiz Augusto von Dentz

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=20140303095237.GB4999@aemeltch-MOBL1 \
    --to=andrei.emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.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