From 16948ce9278f1c5087ddad581f917bc59197254c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 11 Mar 2011 10:09:19 -0600 Subject: [PATCH] libnm-glib: add nm_wimax_nsp_filter_connections() --- libnm-glib/libnm-glib.ver | 1 + libnm-glib/nm-wimax-nsp.c | 60 +++++++++++++++++++++++++++++++++++++++ libnm-glib/nm-wimax-nsp.h | 3 ++ 3 files changed, 64 insertions(+) diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver index 7d0e1b854..054b9b9fa 100644 --- a/libnm-glib/libnm-glib.ver +++ b/libnm-glib/libnm-glib.ver @@ -171,6 +171,7 @@ global: nm_vpn_connection_get_type; nm_vpn_connection_get_vpn_state; nm_vpn_connection_new; + nm_wimax_nsp_filter_connections; nm_wimax_nsp_get_name; nm_wimax_nsp_get_network_type; nm_wimax_nsp_get_signal_quality; diff --git a/libnm-glib/nm-wimax-nsp.c b/libnm-glib/nm-wimax-nsp.c index ce24dcdaf..c33633e97 100644 --- a/libnm-glib/nm-wimax-nsp.c +++ b/libnm-glib/nm-wimax-nsp.c @@ -20,8 +20,13 @@ * Copyright (C) 2011 Red Hat, Inc. */ +#include #include +#include +#include +#include + #include "nm-wimax-nsp.h" #include "NetworkManager.h" #include "nm-types-private.h" @@ -151,6 +156,61 @@ nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp) return priv->network_type; } +/** + * nm_wimax_nsp_filter_connections: + * @nsp: an #NMWimaxNsp to filter connections for + * @connections: a list of #NMConnection objects to filter + * + * Filters a given list of connections for a given #NMWimaxNsp object and + * return connections which may be activated with the access point. Any + * returned connections will match the @nsp's network name and other attributes. + * + * Returns: (transfer container) (element-type NetworkManager.Connection): a + * list of #NMConnection objects that could be activated with the given @nsp. + * The elements of the list are owned by their creator and should not be freed + * by the caller, but the returned list itself is owned by the caller and should + * be freed with g_slist_free() when it is no longer required. + **/ +GSList * +nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GSList *connections) +{ + GSList *filtered = NULL; + const GSList *iter; + + for (iter = connections; iter; iter = g_slist_next (iter)) { + NMConnection *candidate = NM_CONNECTION (iter->data); + NMSettingConnection *s_con; + NMSettingWimax *s_wimax; + const char *ctype; + const char *nsp_name; + const char *setting_name; + + s_con = (NMSettingConnection *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION); + g_assert (s_con); + ctype = nm_setting_connection_get_connection_type (s_con); + if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0) + continue; + + s_wimax = (NMSettingWimax *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_WIMAX); + if (!s_wimax) + continue; + + setting_name = nm_setting_wimax_get_network_name (s_wimax); + if (!setting_name) + continue; + + nsp_name = nm_wimax_nsp_get_name (nsp); + g_warn_if_fail (nsp_name != NULL); + if (g_strcmp0 (nsp_name, setting_name) != 0) + continue; + + /* Connection applies to this device */ + filtered = g_slist_prepend (filtered, candidate); + } + + return g_slist_reverse (filtered); +} + /************************************************************/ static void diff --git a/libnm-glib/nm-wimax-nsp.h b/libnm-glib/nm-wimax-nsp.h index 5507b7529..07736ae4e 100644 --- a/libnm-glib/nm-wimax-nsp.h +++ b/libnm-glib/nm-wimax-nsp.h @@ -73,6 +73,9 @@ const char * nm_wimax_nsp_get_name (NMWimaxNsp *nsp); guint32 nm_wimax_nsp_get_signal_quality (NMWimaxNsp *nsp); NMWimaxNspNetworkType nm_wimax_nsp_get_network_type (NMWimaxNsp *nsp); +GSList * nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, + const GSList *connections); + G_END_DECLS #endif /* NM_WIMAX_NSP_H */