[network-manager-applet] libnm-gtk: return SID list defined in the mobile providers as an array of guint32



commit 67d672208f20f4fe188ad96fa22826a7dc7d732c
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Nov 27 14:21:20 2012 +0100

    libnm-gtk: return SID list defined in the mobile providers as an array of guint32

 src/libnm-gtk/nm-mobile-providers.c |   50 ++++++++++++++++++++--------------
 src/libnm-gtk/nm-mobile-providers.h |    2 +-
 2 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index aff269c..c9ea8f1 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -220,7 +220,7 @@ struct _NMAMobileProvider {
 	GSList *methods; /* GSList of NmaMobileAccessMethod */
 
 	GPtrArray *mcc_mnc;  /* GPtrArray of strings */
-	GSList *cdma_sid; /* GSList of guint32 */
+	GArray *cdma_sid; /* GArray of guint32 */
 };
 
 static NMAMobileProvider *
@@ -261,7 +261,8 @@ nma_mobile_provider_unref (NMAMobileProvider *provider)
 		if (provider->mcc_mnc)
 			g_ptr_array_unref (provider->mcc_mnc);
 
-		g_slist_free (provider->cdma_sid);
+		if (provider->cdma_sid)
+			g_array_unref (provider->cdma_sid);
 
 		g_slice_free (NMAMobileProvider, provider);
 	}
@@ -314,15 +315,15 @@ nma_mobile_provider_get_3gpp_mcc_mnc (NMAMobileProvider *provider)
  * nma_mobile_provider_get_cdma_sid:
  * @provider: a #NMAMobileProvider
  *
- * Returns: (element-type guint32) (transfer none): the
+ * Returns: (transfer none) (array zero-terminated=1) (element-type guint32): the
  *	 list of CDMA SIDs this provider exposes
  */
-GSList *
+const guint32 *
 nma_mobile_provider_get_cdma_sid (NMAMobileProvider *provider)
 {
 	g_return_val_if_fail (provider != NULL, NULL);
 
-	return provider->cdma_sid;
+	return provider->cdma_sid ? (const guint32 *)provider->cdma_sid->data : NULL;
 }
 
 /******************************************************************************/
@@ -666,13 +667,15 @@ parser_cdma_start (MobileParser *parser,
 
 		for (i = 0; attribute_names && attribute_names[i]; i++) {
 			if (!strcmp (attribute_names[i], "value")) {
-				unsigned long tmp;
+				guint32 tmp;
 
 				errno = 0;
-				tmp = strtoul (attribute_values[i], NULL, 10);
-				if (errno == 0 && tmp > 0)
-					parser->current_provider->cdma_sid = g_slist_prepend (parser->current_provider->cdma_sid,
-					                                                      GUINT_TO_POINTER ((guint32) tmp));
+				tmp = (guint32) strtoul (attribute_values[i], NULL, 10);
+				if (errno == 0 && tmp > 0) {
+					if (!parser->current_provider->cdma_sid)
+						parser->current_provider->cdma_sid = g_array_sized_new (TRUE, FALSE, sizeof (guint32), 2);
+					g_array_append_val (parser->current_provider->cdma_sid, tmp);
+				}
 				break;
 			}
 		}
@@ -750,8 +753,6 @@ parser_provider_end (MobileParser *parser,
 
 		parser->current_provider->methods = g_slist_reverse (parser->current_provider->methods);
 
-		parser->current_provider->cdma_sid = g_slist_reverse (parser->current_provider->cdma_sid);
-
 		parser->current_providers = g_slist_prepend (parser->current_providers, parser->current_provider);
 		parser->current_provider = NULL;
 		parser->text_buffer = NULL;
@@ -1042,6 +1043,7 @@ dump_country (gpointer key, gpointer value, gpointer user_data)
 	for (citer = country_info->providers; citer; citer = g_slist_next (citer)) {
 		NMAMobileProvider *provider = citer->data;
 		const gchar **mcc_mnc;
+		const guint *sid;
 		guint n;
 
 		g_print ("	  Provider: %s (%s)\n", provider->name, (const char *) key);
@@ -1052,12 +1054,14 @@ dump_country (gpointer key, gpointer value, gpointer user_data)
 				g_print ("		  MCC/MNC: %s\n", mcc_mnc[n]);
 		}
 
+		sid = nma_mobile_provider_get_cdma_sid (provider);
+		if (sid) {
+			for (n = 0; sid[n]; n++)
+				g_print ("		  SID: %u\n", sid[n]);
+		}
+
 		for (miter = provider->methods; miter; miter = g_slist_next (miter)) {
 			NMAMobileAccessMethod *method = miter->data;
-			GSList *liter;
-
-			for (liter = provider->cdma_sid; liter; liter = g_slist_next (liter))
-				g_print ("		  SID: %d\n", GPOINTER_TO_UINT (liter->data));
 
 			switch (method->family) {
 			case NMA_MOBILE_FAMILY_CDMA:
@@ -1189,7 +1193,7 @@ nma_mobile_providers_find_for_cdma_sid (GHashTable *country_infos,
 {
 	GHashTableIter iter;
 	gpointer value;
-	GSList *piter, *siter;
+	GSList *piter;
 
 	if (sid == 0)
 		return NULL;
@@ -1204,12 +1208,16 @@ nma_mobile_providers_find_for_cdma_sid (GHashTable *country_infos,
 		     piter;
 		     piter = g_slist_next (piter)) {
 			NMAMobileProvider *provider = piter->data;
+			const guint32 *sid_list;
+			guint i;
 
 			/* Search through CDMA SID list */
-			for (siter = nma_mobile_provider_get_cdma_sid (provider);
-			     siter;
-			     siter = g_slist_next (siter)) {
-				if (GPOINTER_TO_UINT (siter->data) == sid)
+			sid_list = nma_mobile_provider_get_cdma_sid (provider);
+			if (!sid_list)
+				continue;
+
+			for (i = 0; sid_list[i]; i++) {
+				if (sid == sid_list[i])
 					return provider;
 			}
 		}
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index cbc7b00..b1524f8 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -69,7 +69,7 @@ void                nma_mobile_provider_unref            (NMAMobileProvider *pro
 const gchar        *nma_mobile_provider_get_name         (NMAMobileProvider *provider);
 GSList             *nma_mobile_provider_get_methods      (NMAMobileProvider *provider);
 const gchar       **nma_mobile_provider_get_3gpp_mcc_mnc (NMAMobileProvider *provider);
-GSList             *nma_mobile_provider_get_cdma_sid     (NMAMobileProvider *provider);
+const guint32      *nma_mobile_provider_get_cdma_sid     (NMAMobileProvider *provider);
 
 /******************************************************************************/
 /* Country Info type */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]