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

diff --git a/src/stk.c b/src/stk.c
index fd6dcb0..ff47649 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -63,6 +63,7 @@ enum stk_agent_state {
        STK_AGENT_IDLE = 0,
        STK_AGENT_MAIN_MENU,
        STK_AGENT_SELECT_ITEM,
+       STK_AGENT_DISPLAY_TEXT,
 };
 
 struct ofono_stk {
@@ -962,6 +963,110 @@ out:
        return TRUE;
 }
 
+static void request_text_send(struct ofono_stk *stk, DBusMessage *call)
+{
+       struct stk_command_display_text *txt = &stk->pending_cmd->display_text;
+       uint8_t qualifier = stk->pending_cmd->qualifier;
+       dbus_bool_t confirm = (qualifier & (1 << 7)) != 0;
+       dbus_bool_t priority = (qualifier & (1 << 0)) != 0;
+       dbus_bool_t navigation = !txt->immediate_response;
+
+       dbus_message_set_member(call, "DisplayText");
+
+       dbus_message_append_args(call,
+                                       DBUS_TYPE_STRING, &txt->text,
+                                       DBUS_TYPE_BOOLEAN, &confirm,
+                                       DBUS_TYPE_BOOLEAN, &priority,
+                                       DBUS_TYPE_BOOLEAN, &navigation,
+                                       DBUS_TYPE_INVALID);
+}
+
+static void request_text_cb(struct ofono_stk *stk, DBusMessage *reply)
+{
+       struct stk_command_display_text *txt = &stk->pending_cmd->display_text;
+       uint8_t qualifier = stk->pending_cmd->qualifier;
+       gboolean confirm = (qualifier & (1 << 7)) != 0;
+       DBusError err;
+       enum stk_result_type type = STK_RESULT_TYPE_SUCCESS;
+       struct stk_response rsp;
+       struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+       if (!reply) {
+               if (stk->cmd_timeout) {
+                       app_agent_request_cancel(stk);
+
+                       goto out;
+               }
+
+               if (confirm)
+                       type = STK_RESULT_TYPE_NO_RESPONSE;
+
+               goto send;
+       }
+
+       dbus_error_init(&err);
+       if (dbus_set_error_from_message(&err, reply)) {
+               if (g_str_equal(err.name, OFONO_NAVIGATION_TERMINATED))
+                       type = STK_RESULT_TYPE_USER_TERMINATED;
+               else if (g_str_equal(err.name, OFONO_NAVIGATION_GOBACK))
+                       type = STK_RESULT_TYPE_GO_BACK;
+               else {
+                       type = STK_RESULT_TYPE_USER_TERMINATED;
+
+                       ofono_error("Unknown reply %s", err.name);
+               }
+
+               dbus_error_free(&err);
+               goto send;
+       }
+
+       if (dbus_message_get_args(reply, NULL, DBUS_TYPE_INVALID) == FALSE) {
+               type = STK_RESULT_TYPE_USER_TERMINATED;
+
+               ofono_error("Reply not understood");
+       }
+
+send:
+       if (txt->immediate_response)
+               goto out;
+
+       memset(&rsp, 0, sizeof(rsp));
+       rsp.result.type = type;
+
+       if (stk_respond(stk, &rsp, display_command_cb))
+               display_command_cb(&error, stk);
+
+       return;
+out:
+       display_idle(stk);
+}
+
+
+static gboolean handle_command_display_text(const struct stk_command *cmd,
+                                               struct stk_response *rsp,
+                                               struct ofono_stk *stk)
+{
+       int timeout = 0;
+
+       if (cmd->display_text.duration.interval) {
+               timeout = cmd->display_text.duration.interval;
+               switch (cmd->display_text.duration.unit) {
+               case STK_DURATION_TYPE_MINUTES:
+                       timeout *= 60;
+               case STK_DURATION_TYPE_SECONDS:
+                       timeout *= 10;
+               case STK_DURATION_TYPE_SECOND_TENTHS:
+                       timeout *= 100;
+               }
+       }
+
+       stk->custom_timeout = timeout;
+       app_agent_request_start(stk, request_text_send, request_text_cb,
+                               STK_AGENT_DISPLAY_TEXT);
+
+       return cmd->display_text.immediate_response;
+}
+
 void ofono_stk_proactive_command_cancel(struct ofono_stk *stk)
 {
        if (!stk->pending_cmd)
@@ -1032,6 +1137,9 @@ 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_DISPLAY_TEXT:
+                       respond = handle_command_display_text(stk->pending_cmd,
+                                                               &rsp, stk);
                }
 
                if (respond)
-- 
1.7.1.86.g0e460.dirty

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to