Open Source Telephony
 help / color / mirror / Atom feed
From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
To: ofono@ofono.org
Subject: [PATCH 1/2][RfC] voicecall: __ofono_voicecall_send_tone internal api.
Date: Wed, 08 Sep 2010 19:59:54 +0200	[thread overview]
Message-ID: <1283968796-5308-2-git-send-email-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <1283968796-5308-1-git-send-email-andrew.zaborowski@intel.com>

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

This provides a way for other atoms to send DTMF tones during a call.
---
 src/ofono.h     |    6 +++
 src/voicecall.c |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index d95f2f2..ce734c5 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -182,6 +182,7 @@ enum ofono_voicecall_interaction {
 };
 
 typedef void (*ofono_voicecall_dial_cb_t)(struct ofono_call *call, void *data);
+typedef void (*ofono_voicecall_tone_cb_t)(int error, void *data);
 
 ofono_bool_t __ofono_voicecall_is_busy(struct ofono_voicecall *vc,
 					enum ofono_voicecall_interaction type);
@@ -193,6 +194,11 @@ int __ofono_voicecall_dial(struct ofono_voicecall *vc,
 				ofono_voicecall_dial_cb_t cb, void *user_data);
 void __ofono_voicecall_dial_cancel(struct ofono_voicecall *vc);
 
+int __ofono_voicecall_send_tone(struct ofono_voicecall *vc,
+				const char *tone_str,
+				ofono_voicecall_tone_cb_t cb, void *user_data);
+void __ofono_voicecall_tone_cancel(struct ofono_voicecall *vc);
+
 #include <ofono/sms.h>
 
 struct sms;
diff --git a/src/voicecall.c b/src/voicecall.c
index a5ee2ed..3bd4dff 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -59,6 +59,7 @@ struct ofono_voicecall {
 	void *driver_data;
 	struct ofono_atom *atom;
 	struct dial_request *dial_req;
+	struct tone_request *tone_req;
 };
 
 struct voicecall {
@@ -82,12 +83,22 @@ struct dial_request {
 	struct ofono_phone_number ph;
 };
 
+struct tone_request {
+	char *tone_str;
+	char *left;
+	int delay;
+	guint source;
+	ofono_voicecall_tone_cb_t cb;
+	void *user_data;
+};
+
 static const char *default_en_list[] = { "911", "112", NULL };
 static const char *default_en_list_no_sim[] = { "119", "118", "999", "110",
 						"08", "000", NULL };
 
 static void generic_callback(const struct ofono_error *error, void *data);
 static void multirelease_callback(const struct ofono_error *err, void *data);
+static gboolean tone_request_run(gpointer user_data);
 
 static gint call_compare_by_id(gconstpointer a, gconstpointer b)
 {
@@ -229,6 +240,22 @@ static void dial_request_finish(struct ofono_voicecall *vc, gboolean callback)
 	vc->dial_req = NULL;
 }
 
+static void tone_request_finish(struct ofono_voicecall *vc, int error)
+{
+	struct tone_request *tone_req = vc->tone_req;
+
+	vc->tone_req = NULL;
+
+	if (tone_req->cb)
+		tone_req->cb(-error, tone_req->user_data);
+
+	if (tone_req->source)
+		g_source_remove(tone_req->source);
+
+	g_free(tone_req->tone_str);
+	g_free(tone_req);
+}
+
 static void append_voicecall_properties(struct voicecall *v,
 					DBusMessageIter *dict)
 {
@@ -574,6 +601,9 @@ static void voicecall_set_call_status(struct voicecall *call, int status)
 	if (status == CALL_STATUS_DISCONNECTED && call->vc->dial_req &&
 			call == call->vc->dial_req->call)
 		dial_request_finish(call->vc, TRUE);
+
+	if (old_status == CALL_STATUS_ACTIVE && call->vc->tone_req)
+		tone_request_finish(call->vc, ENOENT);
 }
 
 static void voicecall_set_call_lineid(struct voicecall *v,
@@ -1956,6 +1986,9 @@ static void voicecall_unregister(struct ofono_atom *atom)
 	if (vc->dial_req)
 		dial_request_finish(vc, TRUE);
 
+	if (vc->tone_req)
+		tone_request_finish(vc, ENOENT);
+
 	for (l = vc->call_list; l; l = l->next)
 		voicecall_dbus_unregister(vc, l->data);
 
@@ -2311,3 +2344,106 @@ void __ofono_voicecall_dial_cancel(struct ofono_voicecall *vc)
 
 	vc->dial_req->cb = NULL;
 }
+
+static void tone_request_cb(const struct ofono_error *error, void *data)
+{
+	struct ofono_voicecall *vc = data;
+
+	if (!vc->tone_req)
+		return;
+
+	if (error && error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		DBG("command failed with error: %s",
+				telephony_error_to_str(error));
+
+		tone_request_finish(vc, EIO);
+		return;
+	}
+
+	vc->tone_req->source = g_timeout_add_seconds(vc->tone_req->delay,
+							tone_request_run, vc);
+}
+
+static gboolean tone_request_run(gpointer user_data)
+{
+	struct ofono_voicecall *vc = user_data;
+	static const char *dtmf = "0123456789ABDEFabdef";
+	char tones[256], *i;
+
+	if (!vc->tone_req)
+		return FALSE;
+
+	vc->tone_req->source = 0;
+
+	if (*vc->tone_req->left == '\0') {
+		tone_request_finish(vc, 0);
+		return FALSE;
+	}
+
+	i = tones;
+	vc->tone_req->delay = 0;
+
+	/* Wait 3 seconds per tone */
+	while (*vc->tone_req->left && strchr(dtmf, *vc->tone_req->left)) {
+		*i++ = *vc->tone_req->left++;
+		vc->tone_req->delay += 3;
+	}
+
+	while (*vc->tone_req->left && *vc->tone_req->left != 'c') {
+		tone_request_finish(vc, EINVAL);
+		return FALSE;
+	}
+
+	while (*vc->tone_req->left == 'c') {
+		vc->tone_req->left++;
+		vc->tone_req->delay += 3;
+	}
+
+	if (i > tones) {
+		*i = '\0';
+
+		vc->driver->send_tones(vc, tones, tone_request_cb, vc);
+	} else
+		tone_request_cb(NULL, vc);
+
+	return FALSE;
+}
+
+int __ofono_voicecall_send_tone(struct ofono_voicecall *vc,
+				const char *tone_str,
+				ofono_voicecall_tone_cb_t cb, void *user_data)
+{
+	struct tone_request *req;
+
+	if (!vc->driver->send_tones)
+		return -ENOSYS;
+
+	/* Send DTMFs only if we have at least one connected call */
+	if (!voicecalls_can_dtmf(vc))
+		return -ENOENT;
+
+	if (vc->tone_req)
+		return -EBUSY;
+
+	req = g_try_new0(struct tone_request, 1);
+	req->tone_str = g_strdup(tone_str);
+	req->left = req->tone_str;
+	req->cb = cb;
+	req->user_data = user_data;
+
+	vc->tone_req = req;
+
+	tone_request_run(vc);
+
+	return 0;
+}
+
+void __ofono_voicecall_tone_cancel(struct ofono_voicecall *vc)
+{
+	if (!vc->tone_req || !vc->tone_req->cb)
+		return;
+
+	vc->tone_req->cb = NULL;
+
+	tone_request_finish(vc, 0);
+}
-- 
1.7.1.86.g0e460.dirty


  reply	other threads:[~2010-09-08 17:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-08 17:59 [PATCH] doc: Play Tone command proposed d-bus API Andrzej Zaborowski
2010-09-08 17:59 ` Andrzej Zaborowski [this message]
2010-09-08 17:59 ` [PATCH 2/2] stk: Handle the Send DTMF proactive command Andrzej Zaborowski
2010-09-08 17:59 ` [PATCH] Fix sending User Cancel response to Set Up Call Andrzej Zaborowski
2010-09-09 14:37   ` Denis Kenzior
2010-09-10  1:03     ` Andrzej Zaborowski
2010-09-10  2:46   ` Denis Kenzior
2010-09-09 16:23 ` [PATCH] doc: Play Tone command proposed d-bus API Marcel Holtmann
2010-09-10  1:12   ` andrzej zaborowski

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=1283968796-5308-2-git-send-email-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@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