public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Alok <develnewbie@gmail.com>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] [PATCH] more headset.c fixes
Date: Tue, 08 Jan 2008 19:33:53 +0530	[thread overview]
Message-ID: <1199801033.20835.4.camel@greatbear> (raw)
In-Reply-To: <000801c851e8$81d6a710$8583f530$@savary@kerlink.fr>

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

Hi Johan/Fredric,

Here is a patch which fixes the following :

1. Consistency with headset_send args. 
2. error checks for headset_send. 
3. Populating answer_call and terminate_call methods.
4. Adding "TerminateCall" signal.

let me know if anything needs to be changed.

-Alok.

[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 5610 bytes --]

Index: audio/headset.c
===================================================================
RCS file: /cvsroot/bluez/utils/audio/headset.c,v
retrieving revision 1.152
diff -u -5 -p -r1.152 headset.c
--- audio/headset.c	8 Jan 2008 08:58:14 -0000	1.152
+++ audio/headset.c	8 Jan 2008 14:02:41 -0000
@@ -173,11 +173,11 @@ static int supported_features(struct dev
 	hs->hfp_features = strtoul(&buf[8], NULL, 10);
 	err = headset_send(hs, "\r\n+BRSF=%u\r\n", ag_features);
 	if (err < 0)
 		return err;
 
-	return headset_send(device->headset, "\r\nOK\r\n");
+	return headset_send(hs, "\r\nOK\r\n");
 }
 
 static int report_indicators(struct device *device, const char *buf)
 {
 	struct headset *hs = device->headset;
@@ -190,16 +190,17 @@ static int report_indicators(struct devi
 		err = headset_send(hs, "\r\n+CIND:1, 0, 0\r\n");
 
 	if (err < 0)
 		return err;
 
-	return headset_send(device->headset, "\r\nOK\r\n");
+	return headset_send(hs, "\r\nOK\r\n");
 }
 
 static int event_reporting(struct device *device, const char *buf)
 {
-	return headset_send(device->headset, "\r\nOK\r\n");
+	struct headset *hs = device->headset;
+	return headset_send(hs, "\r\nOK\r\n");
 }
 
 static int call_hold(struct device *device, const char *buf)
 {
 	struct headset *hs = device->headset;
@@ -207,29 +208,68 @@ static int call_hold(struct device *devi
 
 	err = headset_send(hs, "\r\n+CHLD:(0,1,1x,2,2x,3,4)\r\n");
 	if (err < 0)
 		return err;
 
-	return headset_send(device->headset, "\r\nOK\r\n");
+	return headset_send(hs, "\r\nOK\r\n");
 }
 
 static int answer_call(struct device *device, const char *buf)
 {
+	struct headset *hs = device->headset;
+	int err;
+
 	dbus_connection_emit_signal(device->conn, device->path,
 			AUDIO_HEADSET_INTERFACE, "AnswerRequested",
 			DBUS_TYPE_INVALID);
 
-	return headset_send(device->headset, "\r\nOK\r\n");
+	if (hs->ring_timer) {
+		g_source_remove(hs->ring_timer);
+		hs->ring_timer = 0;
+	}
+
+	if (!hs->hfp_active)
+		return headset_send(hs, "\r\nOK\r\n");
+
+	err = headset_send(hs, "\r\nOK\r\n");
+	if (err < 0)
+		return err;
+
+	/*+CIEV: (call = 1)*/
+	err = headset_send(hs, "\r\n+CIEV:2, 1\r\n");
+	if (err < 0)
+		return err;
+
+	/*+CIEV: (callsetup = 0)*/
+	return headset_send(hs, "\r\n+CIEV:3, 0\r\n");
 }
 
 static int terminate_call(struct device *device, const char *buf)
 {
-	return headset_send(device->headset, "\r\nOK\r\n");
+	struct headset *hs = device->headset;
+	int err;
+
+	dbus_connection_emit_signal(device->conn, device->path,
+			AUDIO_HEADSET_INTERFACE, "TerminateCall",
+			DBUS_TYPE_INVALID);
+
+	if (hs->ring_timer) {
+		g_source_remove(hs->ring_timer);
+		hs->ring_timer = 0;
+	}
+
+	err = headset_send(hs, "\r\nOK\r\n");
+	if (err < 0)
+		return err;
+
+	/*+CIEV: (call = 0)*/
+	return headset_send(hs, "\r\n+CIEV:2, 0\r\n");
 }
 
 static int signal_gain_setting(struct device *device, const char *buf)
 {
+	struct headset *hs = device->headset;
 	const char *name;
 	dbus_uint16_t gain;
 
 	if (strlen(buf) < 8) {
 		error("Too short string for Gain setting");
@@ -243,20 +283,20 @@ static int signal_gain_setting(struct de
 		return -1;
 	}
 
 	switch (buf[5]) {
 	case HEADSET_GAIN_SPEAKER:
-		if (device->headset->sp_gain == gain)
+		if (hs->sp_gain == gain)
 			goto ok;
 		name = "SpeakerGainChanged";
-		device->headset->sp_gain = gain;
+		hs->sp_gain = gain;
 		break;
 	case HEADSET_GAIN_MICROPHONE:
-		if (device->headset->mic_gain == gain)
+		if (hs->mic_gain == gain)
 			goto ok;
 		name = "MicrophoneGainChanged";
-		device->headset->mic_gain = gain;
+		hs->mic_gain = gain;
 		break;
 	default:
 		error("Unknown gain setting");
 		return G_IO_ERROR_INVAL;
 	}
@@ -265,11 +305,11 @@ static int signal_gain_setting(struct de
 				    AUDIO_HEADSET_INTERFACE, name,
 				    DBUS_TYPE_UINT16, &gain,
 				    DBUS_TYPE_INVALID);
 
 ok:
-	return headset_send(device->headset, "\r\nOK\r\n");
+	return headset_send(hs, "\r\nOK\r\n");
 }
 
 static struct event event_callbacks[] = {
 	{"ATA", answer_call},
 	{"AT+VG", signal_gain_setting},
@@ -1123,15 +1163,16 @@ error:
 }
 
 static gboolean ring_timer_cb(gpointer data)
 {
 	struct device *device = data;
+	struct headset *hs = device->headset;
 	int err;
 
-	err = headset_send(device->headset, "\r\nRING\r\n");
+	err = headset_send(hs, "\r\nRING\r\n");
 
-	if (err)
+	if (err < 0)
 		error("Sending RING failed");
 
 	return TRUE;
 }
 
@@ -1153,12 +1194,12 @@ static DBusHandlerResult hs_ring(DBusCon
 	if (hs->ring_timer) {
 		debug("IndicateCall received when already indicating");
 		goto done;
 	}
 
-	err = headset_send(device->headset, "\r\nRING\r\n");
-	if (err) {
+	err = headset_send(hs, "\r\nRING\r\n");
+	if (err < 0) {
 		dbus_message_unref(reply);
 		return error_failed(conn, msg, "Failed");
 	}
 
 	hs->ring_timer = g_timeout_add(RING_INTERVAL, ring_timer_cb, device);
@@ -1311,12 +1352,12 @@ static DBusHandlerResult hs_set_gain(DBu
 	if (!reply)
 		return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
 	if (hs->state != HEADSET_STATE_PLAYING)
 		goto done;
-	err = headset_send(device->headset, "\r\n+VG%c=%u\r\n", type, gain);
-	if (err) {
+	err = headset_send(hs, "\r\n+VG%c=%u\r\n", type, gain);
+	if (err < 0) {
 		dbus_message_unref(reply);
 		return error_failed(conn, msg, "Unable to send to headset");
 	}
 
 done:
@@ -1377,10 +1418,11 @@ static DBusSignalVTable headset_signals[
 	{ "AnswerRequested",		""	},
 	{ "Stopped",			""	},
 	{ "Playing",			""	},
 	{ "SpeakerGainChanged",		"q"	},
 	{ "MicrophoneGainChanged",	"q"	},
+	{ "TerminateCall",		""	},
 	{ NULL, NULL }
 };
 
 static void headset_set_channel(struct headset *headset, sdp_record_t *record)
 {

[-- Attachment #3: Type: text/plain, Size: 278 bytes --]

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

      parent reply	other threads:[~2008-01-08 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-08 11:20 [Bluez-devel] BlueZ as an Haedset Pierre Savary
2008-01-08 11:31 ` Simon Vogl
2008-01-08 14:03 ` Alok [this message]

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=1199801033.20835.4.camel@greatbear \
    --to=develnewbie@gmail.com \
    --cc=bluez-devel@lists.sourceforge.net \
    /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