All of lore.kernel.org
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/2] emulator: add CIND support
Date: Wed, 23 Feb 2011 18:02:14 +0100	[thread overview]
Message-ID: <1298480534-12917-3-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1298480534-12917-1-git-send-email-frederic.danis@linux.intel.com>

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

---
 src/emulator.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 53844a7..e6f503d 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -172,6 +172,85 @@ 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;
+	struct indicator *ind;
+	gsize size;
+	int len;
+	char *buf;
+	char *tmp;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		/*
+		 * "+CIND: " + terminating null + number of indicators *
+		 * (max of 3 digits in the value + separator)
+		 */
+		size = 7 + 1 + (g_slist_length(em->indicators) * 4);
+		buf = g_try_malloc0(size);
+		if (buf == NULL)
+			goto fail;
+
+		len = sprintf(buf, "+CIND: ");
+		tmp = buf + len;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			len = sprintf(tmp, "%s%d",
+					l == em->indicators ? "" : ",",
+					ind->value);
+			tmp = tmp + len;
+		}
+
+		g_at_server_send_info(em->server, buf, TRUE);
+		g_free(buf);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		/*
+		 * '+CIND: ' + terminating null + number of indicators *
+		 * ( indicator name + '("",(000,000))' + separator)
+		 */
+		size = 8;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			size += strlen(ind->name) + 15;
+		}
+
+		buf = g_try_malloc0(size);
+		if (buf == NULL)
+			goto fail;
+
+		len = sprintf(buf, "+CIND: ");
+		tmp = buf + len;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			len = sprintf(tmp, "%s(\"%s\",(%d%c%d))",
+					l == em->indicators ? "" : ",",
+					ind->name, ind->min,
+					(ind->max - ind->min) == 1 ? ',' : '-',
+					ind->max);
+			tmp = tmp + len;
+		}
+
+		g_at_server_send_info(server, buf, TRUE);
+		g_free(buf);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+fail:
+		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)
 {
@@ -243,6 +322,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);
-- 
1.7.1


  parent reply	other threads:[~2011-02-23 17:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-23 17:02 [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 17:02 ` [PATCH 1/2] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 17:02 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2011-02-23 17:18 ` [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG 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=1298480534-12917-3-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@linux.intel.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.