Re: [PATCH 2/2] stk: Handle set up call in handled_notify

2011-07-19 Thread Denis Kenzior
Hi Jeevaka,

On 07/19/2011 02:13 AM, Jeevaka Badrappan wrote:
> ---
>  src/stk.c |  113 
> +++--
>  1 files changed, 110 insertions(+), 3 deletions(-)
> 
> diff --git a/src/stk.c b/src/stk.c
> index e8ffb42..a204e45 100644
> --- a/src/stk.c
> +++ b/src/stk.c
> @@ -1790,6 +1790,45 @@ static void confirm_call_cb(enum stk_agent_result 
> result, gboolean confirm,
>   stk_command_cb(&error, stk);
>  }
>  
> +static void confirm_handled_call_cb(enum stk_agent_result result,
> + gboolean confirm, void *user_data)
> +{
> + struct ofono_stk *stk = user_data;
> + const struct stk_command_setup_call *sc =
> + &stk->pending_cmd->setup_call;
> + struct ofono_voicecall *vc = NULL;
> + struct ofono_atom *vc_atom;
> +
> + if (stk->driver->user_confirmation == NULL)
> + goto out;
> +
> + if (result != STK_AGENT_RESULT_OK) {
> + stk->driver->user_confirmation(stk, FALSE);
> + goto out;
> + }
> +
> + stk->driver->user_confirmation(stk, confirm);
> +
> + 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 == NULL)
> + goto out;
> +
> + __ofono_voicecall_set_alpha_and_icon_id(vc, sc->addr.number,
> + sc->addr.ton_npi,
> + sc->alpha_id_call_setup,
> + sc->icon_id_call_setup.id);
> +
> + return;
> +
> +out:
> + stk_command_free(stk->pending_cmd);
> + stk->pending_cmd = NULL;
> +}
> +
>  static gboolean handle_command_set_up_call(const struct stk_command *cmd,
>   struct stk_response *rsp,
>   struct ofono_stk *stk)
> @@ -2606,6 +2645,74 @@ static gboolean handle_command_launch_browser(const 
> struct stk_command *cmd,
>   return FALSE;
>  }
>  
> +static void proactive_command_handled_end(struct ofono_stk *stk)
> +{
> + if (stk->pending_cmd == NULL)
> + return;
> +
> + switch(stk->pending_cmd->type) {
> + case STK_COMMAND_TYPE_SETUP_CALL:
> + {
> + 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 != NULL)
> + __ofono_voicecall_clear_alpha_and_icon_id(vc);
> +
> + break;
> + }
> + case STK_COMMAND_TYPE_SEND_SMS:
> + case STK_COMMAND_TYPE_SEND_USSD:
> + case STK_COMMAND_TYPE_SEND_SS:
> + case STK_COMMAND_TYPE_SEND_DTMF:
> + stk_alpha_id_unset(stk);
> + break;
> +
> + default:
> + break;
> + }
> +}
> +
> +static void handle_setup_call_confirmation_req(struct stk_command *cmd,
> + struct ofono_stk *stk)
> +{
> + const struct stk_command_setup_call *sc = &cmd->setup_call;
> + int err;
> + char *alpha_id = dbus_apply_text_attributes(
> + sc->alpha_id_usr_cfm ?
> + sc->alpha_id_usr_cfm : "",
> + &sc->text_attr_usr_cfm);
> + if (alpha_id == NULL)
> + goto out;
> +
> + err = stk_agent_confirm_call(stk->current_agent, alpha_id,
> + &sc->icon_id_usr_cfm,
> + confirm_handled_call_cb,
> + stk, NULL,
> + stk->timeout * 1000);
> + g_free(alpha_id);
> +
> + if (err < 0)
> + goto out;
> +
> + stk->pending_cmd = cmd;
> + stk->cancel_cmd = proactive_command_handled_end;
> +
> + return;
> +
> +out:
> + if (stk->driver->user_confirmation)
> + stk->driver->user_confirmation(stk, FALSE);
> +
> + stk_command_free(cmd);
> +}
> +
>  static void stk_proactive_command_cancel(struct ofono_stk *stk)
>  {
>   if (stk->immediate_response)
> @@ -2826,7 +2933,7 @@ void ofono_stk_proactive_command_handled_notify(struct 
> ofono_stk *stk,
>* responses here
>*/
>   if (length > 0 && pdu[0] == 0x81) {
> - stk_alpha_id_unset(stk);
> + proactive_command_handled_end(stk);

You have to be careful here, you're not setting stk->pending_cmd for
anything except SETUP_CALL.

>   return;
>   }
>  
> @@ -2863,8 +2970,8 @@ void ofon

[PATCH 2/2] stk: Handle set up call in handled_notify

2011-07-19 Thread Jeevaka Badrappan
---
 src/stk.c |  113 +++--
 1 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index e8ffb42..a204e45 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -1790,6 +1790,45 @@ static void confirm_call_cb(enum stk_agent_result 
result, gboolean confirm,
stk_command_cb(&error, stk);
 }
 
+static void confirm_handled_call_cb(enum stk_agent_result result,
+   gboolean confirm, void *user_data)
+{
+   struct ofono_stk *stk = user_data;
+   const struct stk_command_setup_call *sc =
+   &stk->pending_cmd->setup_call;
+   struct ofono_voicecall *vc = NULL;
+   struct ofono_atom *vc_atom;
+
+   if (stk->driver->user_confirmation == NULL)
+   goto out;
+
+   if (result != STK_AGENT_RESULT_OK) {
+   stk->driver->user_confirmation(stk, FALSE);
+   goto out;
+   }
+
+   stk->driver->user_confirmation(stk, confirm);
+
+   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 == NULL)
+   goto out;
+
+   __ofono_voicecall_set_alpha_and_icon_id(vc, sc->addr.number,
+   sc->addr.ton_npi,
+   sc->alpha_id_call_setup,
+   sc->icon_id_call_setup.id);
+
+   return;
+
+out:
+   stk_command_free(stk->pending_cmd);
+   stk->pending_cmd = NULL;
+}
+
 static gboolean handle_command_set_up_call(const struct stk_command *cmd,
struct stk_response *rsp,
struct ofono_stk *stk)
@@ -2606,6 +2645,74 @@ static gboolean handle_command_launch_browser(const 
struct stk_command *cmd,
return FALSE;
 }
 
+static void proactive_command_handled_end(struct ofono_stk *stk)
+{
+   if (stk->pending_cmd == NULL)
+   return;
+
+   switch(stk->pending_cmd->type) {
+   case STK_COMMAND_TYPE_SETUP_CALL:
+   {
+   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 != NULL)
+   __ofono_voicecall_clear_alpha_and_icon_id(vc);
+
+   break;
+   }
+   case STK_COMMAND_TYPE_SEND_SMS:
+   case STK_COMMAND_TYPE_SEND_USSD:
+   case STK_COMMAND_TYPE_SEND_SS:
+   case STK_COMMAND_TYPE_SEND_DTMF:
+   stk_alpha_id_unset(stk);
+   break;
+
+   default:
+   break;
+   }
+}
+
+static void handle_setup_call_confirmation_req(struct stk_command *cmd,
+   struct ofono_stk *stk)
+{
+   const struct stk_command_setup_call *sc = &cmd->setup_call;
+   int err;
+   char *alpha_id = dbus_apply_text_attributes(
+   sc->alpha_id_usr_cfm ?
+   sc->alpha_id_usr_cfm : "",
+   &sc->text_attr_usr_cfm);
+   if (alpha_id == NULL)
+   goto out;
+
+   err = stk_agent_confirm_call(stk->current_agent, alpha_id,
+   &sc->icon_id_usr_cfm,
+   confirm_handled_call_cb,
+   stk, NULL,
+   stk->timeout * 1000);
+   g_free(alpha_id);
+
+   if (err < 0)
+   goto out;
+
+   stk->pending_cmd = cmd;
+   stk->cancel_cmd = proactive_command_handled_end;
+
+   return;
+
+out:
+   if (stk->driver->user_confirmation)
+   stk->driver->user_confirmation(stk, FALSE);
+
+   stk_command_free(cmd);
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
if (stk->immediate_response)
@@ -2826,7 +2933,7 @@ void ofono_stk_proactive_command_handled_notify(struct 
ofono_stk *stk,
 * responses here
 */
if (length > 0 && pdu[0] == 0x81) {
-   stk_alpha_id_unset(stk);
+   proactive_command_handled_end(stk);
return;
}
 
@@ -2863,8 +2970,8 @@ void ofono_stk_proactive_command_handled_notify(struct 
ofono_stk *stk,
break;
 
case STK_COMMAND_TYPE_SETUP_CALL:
-   /* TODO */
-   break;
+   handle_setup_call_confirmation_req(cmd, stk);
+   return;