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: [RFC v3 11/12] emulator: Add AT+VGS support
Date: Mon, 02 Apr 2012 15:27:21 +0200	[thread overview]
Message-ID: <1333373242-11117-12-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1333373242-11117-1-git-send-email-frederic.danis@linux.intel.com>

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

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

diff --git a/src/emulator.c b/src/emulator.c
index a976a13..0ae86e0 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -57,6 +57,8 @@ struct ofono_emulator {
 	guint audio_watch;
 	int mic_gain;
 	int mic_pending;
+	int sp_gain;
+	int sp_pending;
 };
 
 struct indicator {
@@ -992,6 +994,48 @@ fail:
 	};
 }
 
+static void vgs_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GAtResultIter iter;
+	int val;
+
+	if (em->slc == FALSE)
+		goto fail;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		if (em->audio_transport == NULL)
+			goto fail;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val < 0 || val > 15)
+			goto fail;
+
+		/* check this is last parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		if (em->sp_pending != -1)
+			ofono_error("Receiving AT+VGS while processing one");
+
+		em->sp_pending = val;
+		audio_transport_set_property(server, em->audio_transport,
+					"SpeakerGain", DBUS_TYPE_UINT16, &val);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+	};
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt,
 					gboolean mandatory)
@@ -1096,6 +1140,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+BIA", bia_cb, em, NULL);
 		g_at_server_register(em->server, "+NREC", nrec_cb, em, NULL);
 		g_at_server_register(em->server, "+VGM", vgm_cb, em, NULL);
+		g_at_server_register(em->server, "+VGS", vgs_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
@@ -1161,6 +1206,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	em->events_mode = 3;	/* default mode is forwarding events */
 	em->cmee_mode = 0;	/* CME ERROR disabled by default */
 	em->mic_pending = -1;
+	em->sp_pending = -1;
 
 	em->atom = __ofono_modem_add_atom_offline(modem, atom_t,
 							emulator_remove, em);
@@ -1243,6 +1289,41 @@ static gboolean audio_property_changed(DBusConnection *connection,
 		} else if (em->mic_pending == value)
 			em->mic_pending = -1;
 		em->mic_gain = value;
+	} else if (g_str_equal(property, "SpeakerGain") == TRUE) {
+		DBusMessageIter variant;
+		int value;
+
+		if (!(em->r_features & HFP_HF_FEATURE_REMOTE_VOLUME_CONTROL))
+			return TRUE;
+
+		if (!dbus_message_iter_next(&iter))
+			return TRUE;
+
+		if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+			return TRUE;
+
+		dbus_message_iter_recurse(&iter, &variant);
+
+		if (dbus_message_iter_get_arg_type(&variant) !=
+							DBUS_TYPE_UINT16)
+			return TRUE;
+
+		dbus_message_iter_get_basic(&variant, &value);
+
+		/* Send unsolicited +VGS only if :
+		 *   - the value has changed
+		 *   - and this is not a side effect of AT+VGS
+		 * But, if we receive a value change while waiting for another
+		 * pending change, we may have to send +VGS for other changes
+		 * (multiple AT+VGS received) to keep speaker gain in sync
+		 */
+		if (em->sp_pending != value && em->sp_gain != value) {
+			sprintf(buf, "+VGS: %d", value);
+			g_at_server_send_unsolicited(em->server, buf);
+			em->sp_pending = -1;
+		} else if (em->sp_pending == value)
+			em->sp_pending = -1;
+		em->sp_gain = value;
 	}
 
 	return TRUE;
-- 
1.7.1


  parent reply	other threads:[~2012-04-02 13:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-02 13:27 [RFC v3 00/12] org.bluez.Telephony interface integration =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 01/12] bluetooth: Add org.bluez.Telephony helpers =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 02/12] hfp_hf: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 03/12] hfp_ag: " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 04/12] bluetooth: Add org.bluez.MediaTransport interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 05/12] include: Add audio transport set API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 06/12] emulator: Add audio transport set =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 07/12] hfp_ag: Add media transport support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 08/12] emulator: Add AT+NREC support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-04  3:38   ` Denis Kenzior
2012-04-02 13:27 ` [RFC v3 09/12] emulator: Add +BSIR support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` [RFC v3 10/12] emulator: Add AT+VGM support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-04-02 13:27 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2012-04-02 13:27 ` [RFC v3 12/12] hfp_ag: Update supported features =?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=1333373242-11117-12-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.