Open Source Telephony
 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 3/3] emulator: add CIND support
Date: Wed, 23 Feb 2011 16:48:50 +0100	[thread overview]
Message-ID: <1298476130-8969-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1298476130-8969-1-git-send-email-frederic.danis@linux.intel.com>

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

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

diff --git a/src/emulator.c b/src/emulator.c
index 77113e6..3c2154b 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -172,6 +172,77 @@ 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:
+		size = 7 + (g_slist_length(em->indicators) * 4) + 1;
+		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, FALSE);
+		g_free(buf);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		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, FALSE);
+		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)
 {
@@ -241,6 +312,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 15:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 16:20   ` Denis Kenzior
2011-02-23 15:48 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 15:48 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
  -- strict thread matches above, loose matches on Subject: below --
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 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 18:39   ` Denis Kenzior
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=1298476130-8969-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox