Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests.
@ 2010-10-11  7:51 Andrzej Zaborowski
  2010-10-11  7:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
  2010-10-13 20:34 ` [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: Andrzej Zaborowski @ 2010-10-11  7:51 UTC (permalink / raw)
  To: ofono

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

---
 src/stkagent.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkagent.h |   13 ++++++++
 2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/src/stkagent.c b/src/stkagent.c
index 354b87d..e123bd2 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -861,3 +861,97 @@ int stk_agent_confirm_call(struct stk_agent *agent, const char *text,
 
 	return 0;
 }
+
+static void play_tone_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_tone_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_TERMINATE, &result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (dbus_message_get_args(reply, NULL, DBUS_TYPE_INVALID) == FALSE) {
+		ofono_error("Can't parse the reply to PlayTone()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, agent->user_data);
+	goto done;
+
+	CALLBACK_END();
+}
+
+int stk_agent_play_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"PlayTone");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &tone,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon->id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, play_tone_cb,
+					agent, NULL);
+
+	return 0;
+}
+
+int stk_agent_loop_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"LoopTone");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &tone,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon->id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, play_tone_cb,
+					agent, NULL);
+
+	return 0;
+}
diff --git a/src/stkagent.h b/src/stkagent.h
index 97c4eca..c8e1886 100644
--- a/src/stkagent.h
+++ b/src/stkagent.h
@@ -56,6 +56,9 @@ typedef void (*stk_agent_confirmation_cb)(enum stk_agent_result result,
 typedef void (*stk_agent_string_cb)(enum stk_agent_result result,
 					char *string, void *user_data);
 
+typedef void (*stk_agent_tone_cb)(enum stk_agent_result result,
+						void *user_data);
+
 struct stk_agent *stk_agent_new(const char *path, const char *sender,
 					ofono_bool_t remove_on_terminate);
 
@@ -121,5 +124,15 @@ int stk_agent_confirm_call(struct stk_agent *agent, const char *text,
 				stk_agent_confirmation_cb cb, void *user_data,
 				ofono_destroy_func destroy, int timeout);
 
+int stk_agent_play_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout);
+
+int stk_agent_loop_tone(struct stk_agent *agent, const char *text,
+			const struct stk_icon_id *icon, ofono_bool_t vibrate,
+			const char *tone, stk_agent_tone_cb cb, void *user_data,
+			ofono_destroy_func destroy, int timeout);
+
 void append_menu_items_variant(DBusMessageIter *iter,
 				const struct stk_menu_item *items);
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] stk: Handle the Play Tone proactive command.
  2010-10-11  7:51 [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Andrzej Zaborowski
@ 2010-10-11  7:51 ` Andrzej Zaborowski
  2010-10-13 20:34 ` [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Andrzej Zaborowski @ 2010-10-11  7:51 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index 22b5270..4879e2c 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -89,6 +89,11 @@ struct extern_req {
 	gboolean cancelled;
 };
 
+struct tone_info {
+	const char *name;
+	gboolean continuous;
+};
+
 #define ENVELOPE_RETRIES_DEFAULT 5
 
 static void envelope_queue_run(struct ofono_stk *stk);
@@ -2095,6 +2100,136 @@ static gboolean handle_command_send_dtmf(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static void play_tone_cb(enum stk_agent_result result, void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+
+	stk->respond_on_exit = FALSE;
+
+	switch (result) {
+	case STK_AGENT_RESULT_OK:
+	case STK_AGENT_RESULT_TIMEOUT:
+		send_simple_response(stk, STK_RESULT_TYPE_SUCCESS);
+		break;
+
+	default:
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+		break;
+	}
+}
+
+static gboolean handle_command_play_tone(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	static int manufacturer_timeout = 10000; /* 10 seconds */
+	/* Continuous true/false according to 02.40 */
+	static const struct tone_info tone_infos[] = {
+		/* Default */
+		[0x00] = { "dial-tone", TRUE },
+
+		/* Standard */
+		[0x01] = { "dial-tone", TRUE },
+		[0x02] = { "busy", TRUE },
+		[0x03] = { "congestion", TRUE },
+		[0x04] = { "radio-path-acknowledge", FALSE },
+		[0x05] = { "radio-path-not-available", FALSE },
+		[0x06] = { "error", TRUE },
+		[0x07] = { "call-waiting", FALSE },
+		[0x08] = { "ringing-tone", TRUE },
+
+		/* Proprietary */
+		[0x10] = { "general-beep", FALSE },
+		[0x11] = { "positive-acknowledgement", FALSE },
+		[0x12] = { "negative-acknowledgement", FALSE },
+		[0x13] = { "user-ringing-tone", TRUE },
+		[0x14] = { "user-sms-alert", FALSE },
+		[0x15] = { "critical", FALSE },
+		[0x20] = { "vibrate", TRUE },
+
+		/* Themed */
+		[0x30] = { "happy", FALSE },
+		[0x31] = { "sad", FALSE },
+		[0x32] = { "urgent-action", FALSE },
+		[0x33] = { "question", FALSE },
+		[0x34] = { "message-received", FALSE },
+
+		/* Melody */
+		[0x40] = { "melody-1", FALSE },
+		[0x41] = { "melody-2", FALSE },
+		[0x42] = { "melody-3", FALSE },
+		[0x43] = { "melody-4", FALSE },
+		[0x44] = { "melody-5", FALSE },
+		[0x45] = { "melody-6", FALSE },
+		[0x46] = { "melody-7", FALSE },
+		[0x47] = { "melody-8", FALSE },
+	};
+
+	const struct stk_command_play_tone *pt = &cmd->play_tone;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	gboolean vibrate = (qualifier & (1 << 0)) != 0;
+	char *text;
+	int timeout;
+	int err;
+
+	text = dbus_apply_text_attributes(pt->alpha_id ? pt->alpha_id : "",
+						&pt->text_attr);
+
+	if (!text) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+
+		return TRUE;
+	}
+
+	if (!tone_infos[pt->tone].name) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+
+		return TRUE;
+	}
+
+	if (pt->duration.interval) {
+		timeout = pt->duration.interval;
+		switch (pt->duration.unit) {
+		case STK_DURATION_TYPE_MINUTES:
+			timeout *= 60;
+		case STK_DURATION_TYPE_SECONDS:
+			timeout *= 10;
+		case STK_DURATION_TYPE_SECOND_TENTHS:
+			timeout *= 100;
+		}
+	} else
+		timeout = manufacturer_timeout;
+
+	if (!tone_infos[pt->tone].continuous)
+		/* Duration ignored */
+		err = stk_agent_play_tone(stk->current_agent, text,
+						&pt->icon_id, vibrate,
+						tone_infos[pt->tone].name,
+						play_tone_cb, stk, NULL,
+						stk->timeout * 1000);
+	else
+		err = stk_agent_loop_tone(stk->current_agent, text,
+						&pt->icon_id, vibrate,
+						tone_infos[pt->tone].name,
+						play_tone_cb, stk, NULL,
+						timeout);
+	g_free(text);
+
+	if (err < 0) {
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+		return TRUE;
+	}
+
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+
+	return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (stk->immediate_response)
@@ -2272,6 +2407,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_PLAY_TONE:
+		respond = handle_command_play_tone(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
 	default:
 		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 		break;
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests.
  2010-10-11  7:51 [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Andrzej Zaborowski
  2010-10-11  7:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
@ 2010-10-13 20:34 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2010-10-13 20:34 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 10/11/2010 02:51 AM, Andrzej Zaborowski wrote:
> ---
>  src/stkagent.c |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/stkagent.h |   13 ++++++++
>  2 files changed, 107 insertions(+), 0 deletions(-)

Both patches look good to me, but no longer apply.  Can you please
rebase and resubmit?

Thanks,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-10-13 20:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-11  7:51 [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Andrzej Zaborowski
2010-10-11  7:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
2010-10-13 20:34 ` [PATCH 1/2] stkagent: Add PlayTone and LoopTone requests Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox