stk: Cancel pending DTMF tones if session is ended
authorDenis Kenzior <denkenz@gmail.com>
Wed, 1 Jun 2011 04:31:41 +0000 (23:31 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 1 Jun 2011 04:31:41 +0000 (23:31 -0500)
The Send DTMF command is special in its use of DisplayAction method of
STK agent.  This allows the user to send a 'User Terminated Session'
response to the SIM.  If the user performs this action, then any pending
DTMFs should also be canceled as soon as possible.

src/stk.c

index 8214b65..9575f0e 100644 (file)
--- a/src/stk.c
+++ b/src/stk.c
@@ -474,12 +474,34 @@ static void emit_menu_changed(struct ofono_stk *stk)
        g_dbus_send_message(conn, signal);
 }
 
+static void cancel_pending_dtmf(struct ofono_stk *stk)
+{
+       struct ofono_voicecall *vc = NULL;
+       struct ofono_atom *vc_atom;
+
+       vc_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom),
+                                               OFONO_ATOM_TYPE_VOICECALL);
+       if (vc_atom)
+               vc = __ofono_atom_get_data(vc_atom);
+
+       if (vc) /* Should be always true here */
+               __ofono_voicecall_tone_cancel(vc, stk->dtmf_id);
+}
+
 static void user_termination_cb(enum stk_agent_result result, void *user_data)
 {
        struct ofono_stk *stk = user_data;
 
-       if (result == STK_AGENT_RESULT_TERMINATE)
-               send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+       if (result != STK_AGENT_RESULT_TERMINATE)
+               return;
+
+       switch (stk->pending_cmd->type) {
+       case STK_COMMAND_TYPE_SEND_DTMF:
+               cancel_pending_dtmf(stk);
+               break;
+       }
+
+       send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
 }
 
 static void stk_alpha_id_set(struct ofono_stk *stk,
@@ -2265,17 +2287,7 @@ static gboolean handle_command_provide_local_info(const struct stk_command *cmd,
 
 static void send_dtmf_cancel(struct ofono_stk *stk)
 {
-       struct ofono_voicecall *vc = NULL;
-       struct ofono_atom *vc_atom;
-
-       vc_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom),
-                                               OFONO_ATOM_TYPE_VOICECALL);
-       if (vc_atom)
-               vc = __ofono_atom_get_data(vc_atom);
-
-       if (vc) /* Should be always true here */
-               __ofono_voicecall_tone_cancel(vc, stk->dtmf_id);
-
+       cancel_pending_dtmf(stk);
        stk_alpha_id_unset(stk);
 }