Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 3/3] stk: Handle provide local info proactive command
Date: Wed, 01 Dec 2010 10:02:58 +0800	[thread overview]
Message-ID: <1291168978-10587-1-git-send-email-yang.gu@intel.com> (raw)

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

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

diff --git a/src/stk.c b/src/stk.c
index a4abb7d..53eca78 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -26,6 +26,7 @@
 #define _GNU_SOURCE
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <stdint.h>
 
 #include <glib.h>
@@ -1995,6 +1996,85 @@ static gboolean handle_command_refresh(const struct stk_command *cmd,
 	return TRUE;
 }
 
+static void get_time(struct stk_response *rsp, struct ofono_stk *stk)
+{
+	time_t now;
+	struct tm *t;
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+	time(&now);
+	t = localtime(&now);
+
+	if (t == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		goto out;
+	}
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+
+	if (t->tm_year > 100)
+		rsp->provide_local_info.datetime.year = t->tm_year - 100;
+	else
+		rsp->provide_local_info.datetime.year = t->tm_year;
+
+	rsp->provide_local_info.datetime.month = t->tm_mon + 1;
+	rsp->provide_local_info.datetime.day = t->tm_mday;
+	rsp->provide_local_info.datetime.hour = t->tm_hour;
+	rsp->provide_local_info.datetime.minute = t->tm_min;
+	rsp->provide_local_info.datetime.second = t->tm_sec;
+	rsp->provide_local_info.datetime.timezone = t->tm_gmtoff / 900;
+	rsp->provide_local_info.datetime.has_timezone = TRUE;
+
+out:
+	if (stk_respond(stk, rsp, stk_command_cb))
+		stk_command_cb(&failure, stk);
+}
+
+static void get_lang(struct stk_response *rsp, struct ofono_stk *stk)
+{
+	char *l;
+	char lang[3];
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+	l = getenv("LANG");
+	if (l == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		goto out;
+	}
+
+	memcpy(lang, l, 2);
+	lang[2] = '\0';
+
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+	rsp->provide_local_info.language = lang;
+
+out:
+	if (stk_respond(stk, rsp, stk_command_cb))
+		stk_command_cb(&failure, stk);
+}
+
+static gboolean handle_command_provide_local_info(const struct stk_command *cmd,
+				struct stk_response *rsp, struct ofono_stk *stk)
+{
+	switch (cmd->qualifier) {
+	case 3:
+		DBG("Date, time and time zone");
+		get_time(rsp, stk);
+		return FALSE;
+
+	case 4:
+		DBG("Language setting");
+		get_lang(rsp, stk);
+		return FALSE;
+
+	default:
+		ofono_info("Unsupported Provide Local Info qualifier: %d",
+				cmd->qualifier);
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		return TRUE;
+	}
+}
+
 static void send_dtmf_cancel(struct ofono_stk *stk)
 {
 	struct ofono_voicecall *vc = NULL;
@@ -2427,6 +2507,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_PROVIDE_LOCAL_INFO:
+		respond = handle_command_provide_local_info(stk->pending_cmd,
+								&rsp, stk);
+		break;
+
 	case STK_COMMAND_TYPE_SEND_DTMF:
 		respond = handle_command_send_dtmf(stk->pending_cmd,
 							&rsp, stk);
-- 
1.7.2.3


                 reply	other threads:[~2010-12-01  2:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291168978-10587-1-git-send-email-yang.gu@intel.com \
    --to=yang.gu@intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox