Hi, On 27 July 2010 02:27, Marcel Holtmann <[email protected]> wrote: >> + switch (result) { >> + case STK_AGENT_RESULT_OK: >> + type = STK_RESULT_TYPE_SUCCESS; >> + break; >> + >> + case STK_AGENT_RESULT_BACK: >> + type = STK_RESULT_TYPE_GO_BACK; >> + goto send; >> + >> + case STK_AGENT_RESULT_TIMEOUT: >> + type = STK_RESULT_TYPE_NO_RESPONSE; >> + goto send; >> + >> + case STK_AGENT_RESULT_TERMINATE: >> + default: >> + type = STK_RESULT_TYPE_USER_TERMINATED; >> + goto send; >> + >> + case STK_AGENT_RESULT_CANCEL: >> + goto out; >> + } > > have you tested this? The STK_AGENT_RESULT_CANCEL will never be reached > since we hit default label first.
This would really be a matter of incompliant compiler if it didn't work because of the order of the labels. I also just checked checked a similar code in gcc and it works. So possibly let's add this rule to the coding-style file. I'm attaching the same patch with just the labels reordered. I left the default label in because this function should just treat any other response as ..USER_TERMINATED, even if a new one is added. Best regards
From a8f5c870723d17b5909697de7d10249e737cac78 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski <[email protected]> Date: Mon, 26 Jul 2010 14:39:28 +0200 Subject: [PATCH 5/6] stk: Handle the Select Item proactive command. --- src/stk.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 105 insertions(+), 1 deletions(-) diff --git a/src/stk.c b/src/stk.c index f212e9a..0aaf83d 100644 --- a/src/stk.c +++ b/src/stk.c @@ -75,7 +75,7 @@ struct ofono_stk { guint remove_agent_source; struct stk_app_agent *session_agent; struct stk_app_agent *default_agent; - struct stk_menu *main_menu; + struct stk_menu *main_menu, *select_item_menu; gboolean in_session; struct sms_submit_req *sms_submit_req; char *idle_mode_text; @@ -1000,6 +1000,106 @@ static gboolean handle_command_set_up_menu(const struct stk_command *cmd, return TRUE; } +static void request_menu_send(DBusMessage *call, void *user_data) +{ + struct ofono_stk *stk = user_data; + struct stk_menu *menu = stk->select_item_menu; + + dbus_message_set_member(call, "RequestSelection"); + + append_menu(call, menu); +} + +static void request_menu_cb(enum stk_agent_result result, DBusMessage *reply, + void *user_data) +{ + struct ofono_stk *stk = user_data; + struct stk_menu *menu = stk->select_item_menu; + struct stk_item *item = NULL; + enum stk_result_type type; + unsigned char selection; + struct stk_response rsp; + static struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE }; + + switch (result) { + case STK_AGENT_RESULT_OK: + type = STK_RESULT_TYPE_SUCCESS; + break; + + case STK_AGENT_RESULT_BACK: + type = STK_RESULT_TYPE_GO_BACK; + goto send; + + case STK_AGENT_RESULT_TIMEOUT: + type = STK_RESULT_TYPE_NO_RESPONSE; + goto send; + + case STK_AGENT_RESULT_CANCEL: + goto out; + + case STK_AGENT_RESULT_TERMINATE: + default: + type = STK_RESULT_TYPE_USER_TERMINATED; + goto send; + } + + if (dbus_message_get_args(reply, NULL, + DBUS_TYPE_BYTE, &selection, + DBUS_TYPE_INVALID) == FALSE) { + type = STK_RESULT_TYPE_USER_TERMINATED; + + ofono_error("Can't parse the reply to SelectItem()"); + goto send; + } + + item = g_slist_nth_data(menu->items, selection); + if (!item) { + type = STK_RESULT_TYPE_USER_TERMINATED; + ofono_error("Invalid item selected"); + } + +send: + memset(&rsp, 0, sizeof(rsp)); + rsp.result.type = type; + + if (item) + rsp.select_item.item_id = item->id; + + if (stk_respond(stk, &rsp, stk_command_cb)) + stk_command_cb(&error, stk); + +out: + stk_menu_free(menu); + stk->select_item_menu = NULL; +} + +static gboolean handle_command_select_item(const struct stk_command *cmd, + struct stk_response *rsp, + struct ofono_stk *stk) +{ + stk->select_item_menu = stk_menu_create_from_select_item(cmd); + + if (!stk->select_item_menu) { + rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD; + + return TRUE; + } + + if (!stk->in_session) { + stk->in_session = TRUE; + + if (stk->main_menu) + emit_menu_changed(stk); + } + + stk->cancel_cmd = stk_agent_request_cancel; + + stk_agent_request_start(stk, + request_menu_send, request_menu_cb, 0); + + return FALSE; +} + static void stk_proactive_command_cancel(struct ofono_stk *stk) { if (!stk->pending_cmd) @@ -1088,6 +1188,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk, respond = handle_command_set_up_menu(stk->pending_cmd, &rsp, stk); break; + case STK_COMMAND_TYPE_SELECT_ITEM: + respond = handle_command_select_item(stk->pending_cmd, + &rsp, stk); + break; } if (respond) -- 1.7.1.86.g0e460.dirty
_______________________________________________ ofono mailing list [email protected] http://lists.ofono.org/listinfo/ofono
