Open Source Telephony
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 2/5] hfp_hf_bluez5: Add audio card .connect() for HFP 1.6
Date: Fri, 05 Apr 2013 12:22:26 -0500	[thread overview]
Message-ID: <515F0852.4050407@gmail.com> (raw)
In-Reply-To: <1365031481-10467-2-git-send-email-vinicius.gomes@openbossa.org>

[-- Attachment #1: Type: text/plain, Size: 2856 bytes --]

Hi Vinicius,

On 04/03/2013 06:24 PM, Vinicius Costa Gomes wrote:
> ---
>   plugins/hfp_hf_bluez5.c | 41 ++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 40 insertions(+), 1 deletion(-)
>
> diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
> index a6cc156..4c8f412 100644
> --- a/plugins/hfp_hf_bluez5.c
> +++ b/plugins/hfp_hf_bluez5.c
> @@ -67,6 +67,8 @@ struct hfp {
>   	struct hfp_slc_info info;
>   	DBusMessage *msg;
>   	struct ofono_handsfree_card *card;
> +	ofono_handsfree_card_connect_cb_t cb;
> +	void *user_data;

Please use the cb_data_new mechanism instead of storing this here.

>   };
>
>   static GDBusClient *bluez = NULL;
> @@ -324,11 +326,48 @@ static void hfp16_card_remove(struct ofono_handsfree_card *card)
>
>   }
>
> +static void bcc_cb(gboolean ok, GAtResult *result, gpointer user_data)
> +{
> +	struct hfp *hfp = user_data;
> +	struct hfp_slc_info *info =&hfp->info;
> +
> +	if (ok)
> +		CALLBACK_WITH_SUCCESS(hfp->cb, hfp->user_data);
> +	else
> +		CALLBACK_WITH_FAILURE(hfp->cb, hfp->user_data);

Please use decode_at_error instead.

e.g. decode_at_error(&error, g_at_result_final_response(result));
callback(&error, ...);

> +
> +	g_at_chat_unref(info->chat);

No need to reference count the g_at_chat.  This is just needless overhead.

> +}
> +
>   static void hfp16_card_connect(struct ofono_handsfree_card *card,
>   					ofono_handsfree_card_connect_cb_t cb,
>   					void *data)
>   {
> -	CALLBACK_WITH_FAILURE(cb, data);
> +	struct hfp *hfp = ofono_handsfree_card_get_data(card);
> +	struct hfp_slc_info *info =&hfp->info;
> +
> +	if (info->chat == NULL) {
> +		CALLBACK_WITH_FAILURE(cb, data);
> +		return;
> +	}

Can this case even happen?

> +
> +	if (!(info->hf_features&  HFP_HF_FEATURE_CODEC_NEGOTIATION&&
> +			info->ag_features&  HFP_AG_FEATURE_CODEC_NEGOTIATION)) {
> +		/*
> +		 * If both sides don't support codec negotiation,
> +		 * fallback to direct SCO connection. Calling
> +		 * connect_sco() hands the connection responsability
> +		 * to the core, so no need to call the callback
> +		 */
> +		ofono_handsfree_card_connect_sco(card);
> +		return;
> +	}

Can we reverse this logic to make it more readable?

e.g. if (HF has CodecNegotiation and AG has CodecNegotiation) {
	send BCC;
	return;
}

> +
> +	info->chat = g_at_chat_ref(info->chat);

No need to take a reference.  Remove this part

> +	hfp->cb = cb;
> +	hfp->user_data = data;
> +

Use the cb_data_new mechanism here

> +	g_at_chat_send(info->chat, "AT+BCC", NULL, bcc_cb, hfp, NULL);

And make sure to set the destroy callback.  There are examples of this 
throughout the drivers/atmodem/* and drivers/hfpmodem/*.

>   }
>
>   static struct ofono_handsfree_card_driver hfp16_hf_driver = {

Regards,
-Denis

  reply	other threads:[~2013-04-05 17:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-03 23:24 [PATCH 1/5] hfp_hf_bluez5: Add extracting version Vinicius Costa Gomes
2013-04-03 23:24 ` [PATCH 2/5] hfp_hf_bluez5: Add audio card .connect() for HFP 1.6 Vinicius Costa Gomes
2013-04-05 17:22   ` Denis Kenzior [this message]
2013-04-05 18:45     ` Vinicius Costa Gomes
2013-04-03 23:24 ` [PATCH 3/5] hfp_hf_bluez5: Select the audio card driver based on version Vinicius Costa Gomes
2013-04-05 17:33   ` Denis Kenzior
2013-04-03 23:24 ` [PATCH 4/5] handsfree-audio: Add function to get the codecs Vinicius Costa Gomes
2013-04-05 17:32   ` Denis Kenzior
2013-04-05 20:56     ` Vinicius Costa Gomes
2013-04-05 21:40       ` Denis Kenzior
2013-04-05 22:00         ` Vinicius Costa Gomes
2013-04-03 23:24 ` [PATCH 5/5] hfpmodem: Send AT+BAC with the supported codecs Vinicius Costa Gomes
2013-04-05 17:22 ` [PATCH 1/5] hfp_hf_bluez5: Add extracting version Denis Kenzior

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=515F0852.4050407@gmail.com \
    --to=denkenz@gmail.com \
    --cc=ofono@ofono.org \
    /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