All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 4/4] Save CellBroadcast Topics list, handle EF-CBMI, EF-CBMIR.
       [not found] <200912161319.44919.denkenz@gmail.com>
@ 2010-01-11 14:38 ` Andrzej Zaborowski
  2010-01-13  0:09   ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Andrzej Zaborowski @ 2010-01-11 14:38 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

2009/12/16 Denis Kenzior <denkenz@gmail.com>:
> Since you took this approach, can we optimize the flow a little bit?  You can
> count on the sim atom (along with the IMSI) always being there before cbs
> atom, the present code even does this.  So we can check right away whether the
> topic ranges are set in our settings store.  So lets do something like:

You're right, here's a new version which skips reading CBMI / CBMIR
when not necessary, then reads CBMID (which will normally be in cache)
and then sets powered updating the topics list with contents of CBMID
and user topics.

Regards

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Save-CellBroadcast-Topics-list-handle-EF-CBMI-EF-C.patch --]
[-- Type: text/x-patch, Size: 5240 bytes --]

From 0feca823565c9a00cd60a64142bc88b1a7e1bf20 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
Date: Mon, 11 Jan 2010 17:30:35 +0100
Subject: [PATCH] Save CellBroadcast Topics list, handle EF-CBMI, EF-CBMIR.

The two SIM files are only used to bootstrap the topics list value
if there's no previous value.
---
 src/cbs.c |   99 ++++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/src/cbs.c b/src/cbs.c
index 26c31a9..a478e3d 100644
--- a/src/cbs.c
+++ b/src/cbs.c
@@ -348,6 +348,12 @@ static void cbs_set_topics_cb(const struct ofono_error *error, void *data)
 						CBS_MANAGER_INTERFACE,
 						"Topics",
 						DBUS_TYPE_STRING, &topics);
+
+	if (cbs->settings) {
+		g_key_file_set_string(cbs->settings, SETTINGS_GROUP,
+					"Topics", topics);
+		storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
+	}
 	g_free(topics);
 }
 
@@ -669,6 +675,51 @@ struct ofono_cbs *ofono_cbs_create(struct ofono_modem *modem,
 	return cbs;
 }
 
+static void cbs_got_file_contents(struct ofono_cbs *cbs)
+{
+	gboolean powered;
+	GSList *initial_topics = NULL;
+	char *topics_str;
+	GError *error = NULL;
+
+	if (cbs->topics == NULL) {
+		if (cbs->efcbmi_contents != NULL)
+			initial_topics = g_slist_concat(initial_topics,
+					g_slist_copy(cbs->efcbmi_contents));
+
+		if (cbs->efcbmir_contents != NULL)
+			initial_topics = g_slist_concat(initial_topics,
+					g_slist_copy(cbs->efcbmir_contents));
+
+		cbs->topics = cbs_optimize_ranges(initial_topics);
+		g_slist_free(initial_topics);
+
+		topics_str = cbs_topic_ranges_to_string(cbs->topics);
+		g_key_file_set_string(cbs->settings, SETTINGS_GROUP,
+					"Topics", topics_str);
+		g_free(topics_str);
+		storage_sync(cbs->imsi, SETTINGS_STORE, cbs->settings);
+	}
+
+	if (cbs->efcbmi_length) {
+		cbs->efcbmi_length = 0;
+		g_slist_foreach(cbs->efcbmi_contents, (GFunc) g_free, NULL);
+		g_slist_free(cbs->efcbmi_contents);
+		cbs->efcbmi_contents = NULL;
+	}
+
+	if (cbs->efcbmir_length) {
+		cbs->efcbmir_length = 0;
+		g_slist_foreach(cbs->efcbmir_contents, (GFunc) g_free, NULL);
+		g_slist_free(cbs->efcbmir_contents);
+		cbs->efcbmir_contents = NULL;
+	}
+
+	powered = g_key_file_get_boolean(cbs->settings, SETTINGS_GROUP,
+						"Powered", &error);
+	cbs_set_powered(cbs, powered, NULL);
+}
+
 static void sim_cbmi_read_cb(int ok, int length, int record,
 				const unsigned char *data,
 				int record_length, void *userdata)
@@ -708,16 +759,9 @@ static void sim_cbmi_read_cb(int ok, int length, int record,
 	if (cbs->efcbmi_contents == NULL)
 		return;
 
-	cbs->efcbmi_contents = g_slist_reverse(cbs->efcbmi_contents);
-
 	str = cbs_topic_ranges_to_string(cbs->efcbmi_contents);
 	ofono_debug("Got cbmi: %s", str);
 	g_free(str);
-
-	cbs->efcbmi_length = 0;
-	g_slist_foreach(cbs->efcbmi_contents, (GFunc)g_free, NULL);
-	g_slist_free(cbs->efcbmi_contents);
-	cbs->efcbmi_contents = NULL;
 }
 
 static void sim_cbmir_read_cb(int ok, int length, int record,
@@ -762,16 +806,9 @@ static void sim_cbmir_read_cb(int ok, int length, int record,
 	if (cbs->efcbmir_contents == NULL)
 		return;
 
-	cbs->efcbmir_contents = g_slist_reverse(cbs->efcbmir_contents);
-
 	str = cbs_topic_ranges_to_string(cbs->efcbmir_contents);
 	ofono_debug("Got cbmir: %s", str);
 	g_free(str);
-
-	cbs->efcbmir_length = 0;
-	g_slist_foreach(cbs->efcbmir_contents, (GFunc)g_free, NULL);
-	g_slist_free(cbs->efcbmir_contents);
-	cbs->efcbmir_contents = NULL;
 }
 
 static void sim_cbmid_read_cb(int ok, int length, int record,
@@ -815,12 +852,14 @@ static void sim_cbmid_read_cb(int ok, int length, int record,
 	str = cbs_topic_ranges_to_string(cbs->efcbmid_contents);
 	ofono_debug("Got cbmid: %s", str);
 	g_free(str);
+
+	cbs_got_file_contents(cbs);
 }
 
 static void cbs_got_imsi(struct ofono_cbs *cbs)
 {
 	const char *imsi = ofono_sim_get_imsi(cbs->sim);
-	gboolean powered;
+	char *topics_str;
 
 	ofono_debug("Got IMSI: %s", imsi);
 
@@ -830,16 +869,28 @@ static void cbs_got_imsi(struct ofono_cbs *cbs)
 
 	cbs->imsi = g_strdup(imsi);
 
-	powered = g_key_file_get_boolean(cbs->settings, SETTINGS_GROUP,
-						"Powered", NULL);
-	cbs_set_powered(cbs, powered, NULL);
+	cbs->topics = NULL;
+
+	topics_str = g_key_file_get_string(cbs->settings, SETTINGS_GROUP,
+						"Topics", NULL);
+	if (topics_str)
+		cbs->topics = cbs_extract_topic_ranges(topics_str);
+
+	/* If stored value is invalid or no stored value, bootstrap
+	 * topics list from SIM contents */
+	if (topics_str == NULL ||
+			(cbs->topics == NULL && topics_str[0] != '\0')) {
+		ofono_sim_read(cbs->sim, SIM_EFCBMI_FILEID,
+				OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+				sim_cbmi_read_cb, cbs);
+		ofono_sim_read(cbs->sim, SIM_EFCBMIR_FILEID,
+				OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
+				sim_cbmir_read_cb, cbs);
+	}
+
+	if (topics_str)
+		g_free(topics_str);
 
-	ofono_sim_read(cbs->sim, SIM_EFCBMI_FILEID,
-			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
-			sim_cbmi_read_cb, cbs);
-	ofono_sim_read(cbs->sim, SIM_EFCBMIR_FILEID,
-			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
-			sim_cbmir_read_cb, cbs);
 	ofono_sim_read(cbs->sim, SIM_EFCBMID_FILEID,
 			OFONO_SIM_FILE_STRUCTURE_TRANSPARENT,
 			sim_cbmid_read_cb, cbs);
-- 
1.6.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 4/4] Save CellBroadcast Topics list, handle EF-CBMI, EF-CBMIR.
  2010-01-11 14:38 ` [PATCH 4/4] Save CellBroadcast Topics list, handle EF-CBMI, EF-CBMIR Andrzej Zaborowski
@ 2010-01-13  0:09   ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2010-01-13  0:09 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

> You're right, here's a new version which skips reading CBMI / CBMIR
> when not necessary, then reads CBMID (which will normally be in cache)
> and then sets powered updating the topics list with contents of CBMID
> and user topics.

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-13  0:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200912161319.44919.denkenz@gmail.com>
2010-01-11 14:38 ` [PATCH 4/4] Save CellBroadcast Topics list, handle EF-CBMI, EF-CBMIR Andrzej Zaborowski
2010-01-13  0:09   ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.