[network-manager-applet/aleksander/mobile-providers: 9/11] libnm-gtk, mobile-providers: new 'nma_mobile_providers_find_for_sid()' method



commit 60267582a8778f80fd1ec4d5dc33aa8fea332953
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Nov 23 13:38:27 2012 +0100

    libnm-gtk,mobile-providers: new 'nma_mobile_providers_find_for_sid()' method
    
    This new method of the API takes care of looking for a specific
    'NMAMobileProvider' given a SID integer.
    
    Originally developed as 'find_provider_for_sid()' in
    'src/applet-device-cdma.c'.

 src/applet-device-cdma.c            |   46 +++++-----------------------------
 src/libnm-gtk/nm-mobile-providers.c |   42 +++++++++++++++++++++++++++++++
 src/libnm-gtk/nm-mobile-providers.h |    2 +
 3 files changed, 51 insertions(+), 39 deletions(-)
---
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index f081256..cfec847 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -707,43 +707,6 @@ signal_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 
 #define SERVING_SYSTEM_TYPE (dbus_g_type_get_struct ("GValueArray", G_TYPE_UINT, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
 
-static char *
-find_provider_for_sid (GHashTable *table, guint32 sid)
-{
-	GHashTableIter iter;
-	gpointer value;
-	GSList *piter, *siter;
-	char *name = NULL;
-
-	if (sid == 0)
-		return NULL;
-
-	g_hash_table_iter_init (&iter, table);
-	/* Search through each country */
-	while (g_hash_table_iter_next (&iter, NULL, &value) && !name) {
-		NMACountryInfo *country_info = value;
-
-		/* Search through each country's providers */
-		for (piter = nma_country_info_get_providers (country_info);
-		     piter && !name;
-		     piter = g_slist_next (piter)) {
-			NMAMobileProvider *provider = piter->data;
-
-			/* 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) {
-					name = g_strdup (nma_mobile_provider_get_name (provider));
-					break;
-				}
-			}
-		}
-	}
-
-	return name;
-}
-
 static void
 serving_system_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
 {
@@ -768,9 +731,14 @@ serving_system_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_dat
 	if (new_sid && (new_sid != info->sid)) {
 		info->sid = new_sid;
 		if (info->country_infos) {
+			NMAMobileProvider *provider;
+
 			g_free (info->provider_name);
-			info->provider_name = NULL;
-			info->provider_name = find_provider_for_sid (info->country_infos, new_sid);
+
+			provider = nma_mobile_providers_find_for_sid (info->country_infos, new_sid);
+			info->provider_name = (provider ?
+			                       g_strdup (nma_mobile_provider_get_name (provider)) :
+			                       NULL);
 		}
 	} else if (!new_sid) {
 		info->sid = 0;
diff --git a/src/libnm-gtk/nm-mobile-providers.c b/src/libnm-gtk/nm-mobile-providers.c
index aeadb2d..c4b25b8 100644
--- a/src/libnm-gtk/nm-mobile-providers.c
+++ b/src/libnm-gtk/nm-mobile-providers.c
@@ -1156,3 +1156,45 @@ nma_mobile_providers_find_for_mcc_mnc (GHashTable  *country_infos,
 
 	return provider_match_2mnc;
 }
+
+/**
+ * nma_mobile_providers_find_for_sid:
+ * @country_infos: (element-type utf8 NMGtk.CountryInfo) (transfer none): the table of country infos.
+ * @sid: the SID to look for.
+ *
+ * Returns: (transfer none): a #NMAMobileProvider.
+ */
+NMAMobileProvider *
+nma_mobile_providers_find_for_sid (GHashTable  *country_infos,
+                                   guint32 sid)
+{
+	GHashTableIter iter;
+	gpointer value;
+	GSList *piter, *siter;
+
+	if (sid == 0)
+		return NULL;
+
+	g_hash_table_iter_init (&iter, country_infos);
+	/* Search through each country */
+	while (g_hash_table_iter_next (&iter, NULL, &value)) {
+		NMACountryInfo *country_info = value;
+
+		/* Search through each country's providers */
+		for (piter = nma_country_info_get_providers (country_info);
+		     piter;
+		     piter = g_slist_next (piter)) {
+			NMAMobileProvider *provider = piter->data;
+
+			/* 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)
+					return provider;
+			}
+		}
+	}
+
+	return NULL;
+}
diff --git a/src/libnm-gtk/nm-mobile-providers.h b/src/libnm-gtk/nm-mobile-providers.h
index 50a8cf3..98febc2 100644
--- a/src/libnm-gtk/nm-mobile-providers.h
+++ b/src/libnm-gtk/nm-mobile-providers.h
@@ -107,5 +107,7 @@ GHashTable        *nma_mobile_providers_parse            (const gchar *country_c
 void               nma_mobile_providers_dump             (GHashTable *country_infos);
 NMAMobileProvider *nma_mobile_providers_find_for_mcc_mnc (GHashTable  *country_infos,
                                                           const gchar *mccmnc);
+NMAMobileProvider *nma_mobile_providers_find_for_sid     (GHashTable  *country_infos,
+                                                          guint32      sid);
 
 #endif /* NM_MOBILE_PROVIDERS_H */



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