All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 3/3] emulator: add CIND support
Date: Tue, 22 Feb 2011 12:39:09 -0600	[thread overview]
Message-ID: <4D6402CD.30208@gmail.com> (raw)
In-Reply-To: <1298389236-14953-4-git-send-email-frederic.danis@linux.intel.com>

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

Hi Frédéric,

On 02/22/2011 09:40 AM, Frédéric Danis wrote:
> ---
>  src/emulator.c |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 56 insertions(+), 0 deletions(-)
> 
> diff --git a/src/emulator.c b/src/emulator.c
> index 7a46d2a..ece38ab 100644
> --- a/src/emulator.c
> +++ b/src/emulator.c
> @@ -51,6 +51,7 @@ struct indicator {
>  	int value;
>  	int min;
>  	int max;
> +	char separator;
>  };
>  
>  
> @@ -173,6 +174,58 @@ error:
>         g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
>  }
>  
> +static void cind_cb(GAtServer *server, GAtServerRequestType type,
> +			GAtResult *result, gpointer user_data)
> +{
> +	struct ofono_emulator *em = user_data;
> +	GSList *l = em->indicators;
> +	struct indicator *ind = l->data;
> +	GString *gstr;
> +	char *buf;

I prefer we do a simple pre-calculation of the space required.  If it
helps the implementation, limit the min and max values to something
reasonable, e.g. 0-999.

> +
> +	switch (type) {
> +	case G_AT_SERVER_REQUEST_TYPE_QUERY:
> +		gstr = g_string_new("+CIND: ");
> +		g_string_append_printf(gstr, "%d", ind->value);
> +
> +		l = l->next;

doc/coding-style.txt M1.

> +		while (l) {

These style loops look more compact using a for loop, e.g.:

for (l = em->indicators; l; l = l->next) {
	...
}

> +			ind = l->data;
> +			g_string_append_printf(gstr, ",%d", ind->value);
> +			l = l->next;
> +		}
> +		buf = g_string_free(gstr, FALSE);

doc/coding-style.txt M1

> +
> +		g_at_server_send_info(em->server, buf, FALSE);
> +		g_free(buf);
> +		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
> +		break;
> +
> +	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
> +		gstr = g_string_new("+CIND: ");
> +		g_string_append_printf(gstr, "(\"%s\",(%d%c%d))",
> +			ind->name, ind->min, ind->separator, ind->max);

doc/coding-style.txt M4

> +
> +		l = l->next;
> +		while (l) {
> +			ind = l->data;
> +			g_string_append_printf(gstr, ",(\"%s\",(%d%c%d))",
> +				ind->name, ind->min, ind->separator, ind->max);
> +			l = l->next;
> +		}
> +		buf = g_string_free(gstr, FALSE);
> +
> +		g_at_server_send_info(server, buf, FALSE);
> +		g_free(buf);
> +		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
> +		break;
> +
> +	default:
> +		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
> +		break;
> +	}
> +}
> +
>  static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
>  					int min, int max, int dflt)
>  {
> @@ -188,6 +241,7 @@ static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
>  	ind->min = min;
>  	ind->max = max;
>  	ind->value = dflt;
> +	ind->separator = ((max - min) == 1) ? ',' : '-';

I prefer you do this magic inside cind_cb and avoid storing it inside
the indicator structure.

>  
>  	em->indicators = g_slist_append(em->indicators, ind);
>  }
> @@ -237,6 +291,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
>  		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
>  		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
>  		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
> +
> +		g_at_server_register(em->server, "+CIND", cind_cb, em, NULL);
>  	}
>  
>  	__ofono_atom_register(em->atom, emulator_unregister);

Regards,
-Denis

  reply	other threads:[~2011-02-22 18:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 15:40 ` [PATCH 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 15:40 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 18:28   ` Denis Kenzior
2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 18:39   ` Denis Kenzior [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-23 15:48 [PATCH v3 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 15:48 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 15:06 [PATCH 0/3] bluetooth: add HFP AG plugin =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 15:06 ` [PATCH 3/3] emulator: add +CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis

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=4D6402CD.30208@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.