linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v4 01/11] shared/hfp: Add support for HFP HF
Date: Wed, 22 Oct 2014 13:00:53 +0200	[thread overview]
Message-ID: <2009037.IXf9F6m0Mk@uw000953> (raw)
In-Reply-To: <1412898611-12199-2-git-send-email-lukasz.rymanowski@tieto.com>

Hi Łukasz,

On Friday 10 of October 2014 01:50:01 Lukasz Rymanowski wrote:
> This patch add struct hfp_hf plus fuctions to create an instance ref and
> unref. This code based on existing hfp_gw
> ---
>  src/shared/hfp.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/shared/hfp.h |  6 ++++
>  2 files changed, 98 insertions(+)
> 
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index efc981f..dbd049a 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -62,6 +62,18 @@ struct hfp_gw {
>  	bool destroyed;
>  };
>  
> +struct hfp_hf {
> +	int ref_count;
> +	int fd;
> +	bool close_on_unref;
> +	struct io *io;
> +	struct ringbuf *read_buf;
> +	struct ringbuf *write_buf;
> +
> +	bool in_disconnect;
> +	bool destroyed;
> +};
> +
>  struct cmd_handler {
>  	char *prefix;
>  	void *user_data;
> @@ -807,3 +819,83 @@ bool hfp_gw_disconnect(struct hfp_gw *hfp)
>  
>  	return io_shutdown(hfp->io);
>  }
> +
> +struct hfp_hf *hfp_hf_new(int fd)
> +{
> +	struct hfp_hf *hfp;
> +
> +	if (fd < 0)
> +		return NULL;
> +
> +	hfp = new0(struct hfp_hf, 1);
> +	if (!hfp)
> +		return NULL;
> +
> +	hfp->fd = fd;
> +	hfp->close_on_unref = false;
> +
> +	hfp->read_buf = ringbuf_new(4096);
> +	if (!hfp->read_buf) {
> +		free(hfp);
> +		return NULL;
> +	}
> +
> +	hfp->write_buf = ringbuf_new(4096);
> +	if (!hfp->write_buf) {
> +		ringbuf_free(hfp->read_buf);
> +		free(hfp);
> +		return NULL;
> +	}
> +
> +	hfp->io = io_new(fd);
> +	if (!hfp->io) {
> +		ringbuf_free(hfp->write_buf);
> +		ringbuf_free(hfp->read_buf);
> +		free(hfp);
> +		return NULL;
> +	}
> +
> +	return hfp_hf_ref(hfp);
> +}
> +
> +struct hfp_hf *hfp_hf_ref(struct hfp_hf *hfp)
> +{
> +	if (!hfp)
> +		return NULL;
> +
> +	__sync_fetch_and_add(&hfp->ref_count, 1);
> +
> +	return hfp;
> +}
> +
> +void hfp_hf_unref(struct hfp_hf *hfp)
> +{
> +	if (!hfp)
> +		return;
> +
> +	if (__sync_sub_and_fetch(&hfp->ref_count, 1))
> +		return;
> +
> +	io_set_write_handler(hfp->io, NULL, NULL, NULL);
> +	io_set_read_handler(hfp->io, NULL, NULL, NULL);
> +	io_set_disconnect_handler(hfp->io, NULL, NULL, NULL);
> +
> +	io_destroy(hfp->io);
> +	hfp->io = NULL;
> +
> +	if (hfp->close_on_unref)
> +		close(hfp->fd);
> +
> +	ringbuf_free(hfp->read_buf);
> +	hfp->read_buf = NULL;
> +
> +	ringbuf_free(hfp->write_buf);
> +	hfp->write_buf = NULL;
> +
> +	if (!hfp->in_disconnect) {
> +		free(hfp);
> +		return;
> +	}
> +
> +	hfp->destroyed = true;
> +}
> diff --git a/src/shared/hfp.h b/src/shared/hfp.h
> index 743db65..50d9c4b 100644
> --- a/src/shared/hfp.h
> +++ b/src/shared/hfp.h
> @@ -76,9 +76,11 @@ typedef void (*hfp_destroy_func_t)(void *user_data);
>  typedef void (*hfp_debug_func_t)(const char *str, void *user_data);
>  
>  typedef void (*hfp_command_func_t)(const char *command, void *user_data);
> +

Unrelated.

>  typedef void (*hfp_disconnect_func_t)(void *user_data);
>  
>  struct hfp_gw;
> +struct hfp_hf;

I'd prefer if we have all hfp_hf stuff in same section.

>  
>  struct hfp_gw *hfp_gw_new(int fd);
>  
> @@ -124,3 +126,7 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf,
>  bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf,
>  								uint8_t len);
>  bool hfp_gw_result_has_next(struct hfp_gw_result *result);
> +
> +struct hfp_hf *hfp_hf_new(int fd);
> +struct hfp_hf *hfp_hf_ref(struct hfp_hf *hfp);
> +void hfp_hf_unref(struct hfp_hf *hfp);
> 

-- 
Best regards, 
Szymon Janc

  reply	other threads:[~2014-10-22 11:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-09 23:50 [PATCH v4 00/11] shared/hfp: Add support for HFP HF Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 01/11] " Lukasz Rymanowski
2014-10-22 11:00   ` Szymon Janc [this message]
2014-10-23 15:00     ` Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 02/11] shared/hfp: Add set_debug and close_on_unref API " Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 03/11] shared/hfp: Add set disconnect handler and disconnect API to " Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 04/11] shared/hfp: Add register/unregister event for " Lukasz Rymanowski
2014-10-22 11:00   ` Szymon Janc
2014-10-23 15:00     ` Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 05/11] shared/hfp: Add HFP HF parser Lukasz Rymanowski
2014-10-22 11:00   ` Szymon Janc
2014-10-23 15:00     ` Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 06/11] shared/hfp: Add send AT command API for HFP HF Lukasz Rymanowski
2014-10-22 11:00   ` Szymon Janc
2014-10-23 15:00     ` Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 07/11] unit/test-hfp: Provide test_handler function via struct data Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 08/11] unit/test-hfp: Add init test for HFP HF Lukasz Rymanowski
2014-10-22 11:00   ` Szymon Janc
2014-10-23 15:00     ` Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 09/11] unit/test-hfp: Add send command tests " Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 10/11] unit/test-hfp: Add tests for unsolicited results " Lukasz Rymanowski
2014-10-09 23:50 ` [PATCH v4 11/11] unit/test-hfp: Add some robustness tests " Lukasz Rymanowski
2014-10-21 14:54 ` [PATCH v4 00/11] shared/hfp: Add support " Lukasz Rymanowski

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=2009037.IXf9F6m0Mk@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=lukasz.rymanowski@tieto.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;
as well as URLs for NNTP newsgroup(s).