supplicant: use a GHashTable instead of a GSList for tracking interfaces

It's just less code. Yay.
This commit is contained in:
Dan Williams 2010-10-05 14:19:56 -05:00
parent 71c4e2338b
commit 262db04e20
3 changed files with 25 additions and 33 deletions

View file

@ -1119,6 +1119,14 @@ nm_supplicant_interface_connection_state_to_string (guint32 state)
return "unknown"; return "unknown";
} }
const char *
nm_supplicant_interface_get_ifname (NMSupplicantInterface *self)
{
g_return_val_if_fail (self != NULL, FALSE);
return NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self)->dev;
}
/*******************************************************************/ /*******************************************************************/
NMSupplicantInterface * NMSupplicantInterface *

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* Copyright (C) 2006 - 2008 Red Hat, Inc. * Copyright (C) 2006 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc. * Copyright (C) 2007 - 2008 Novell, Inc.
*/ */
@ -140,6 +140,8 @@ const char *nm_supplicant_interface_connection_state_to_string (guint32 state);
gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self); gboolean nm_supplicant_interface_get_scanning (NMSupplicantInterface *self);
const char *nm_supplicant_interface_get_ifname (NMSupplicantInterface *self);
G_END_DECLS G_END_DECLS
#endif /* NM_SUPPLICANT_INTERFACE_H */ #endif /* NM_SUPPLICANT_INTERFACE_H */

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* Copyright (C) 2006 - 2008 Red Hat, Inc. * Copyright (C) 2006 - 2010 Red Hat, Inc.
* Copyright (C) 2007 - 2008 Novell, Inc. * Copyright (C) 2007 - 2008 Novell, Inc.
*/ */
@ -35,7 +35,7 @@
typedef struct { typedef struct {
NMDBusManager * dbus_mgr; NMDBusManager * dbus_mgr;
guint32 state; guint32 state;
GSList * ifaces; GHashTable * ifaces;
gboolean dispose_has_run; gboolean dispose_has_run;
guint poke_id; guint poke_id;
} NMSupplicantManagerPrivate; } NMSupplicantManagerPrivate;
@ -125,6 +125,8 @@ nm_supplicant_manager_init (NMSupplicantManager * self)
priv->dbus_mgr = nm_dbus_manager_get (); priv->dbus_mgr = nm_dbus_manager_get ();
priv->poke_id = 0; priv->poke_id = 0;
priv->ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
running = nm_supplicant_manager_startup (self); running = nm_supplicant_manager_startup (self);
g_signal_connect (priv->dbus_mgr, g_signal_connect (priv->dbus_mgr,
@ -265,33 +267,23 @@ nm_supplicant_manager_startup (NMSupplicantManager * self)
NMSupplicantInterface * NMSupplicantInterface *
nm_supplicant_manager_get_iface (NMSupplicantManager * self, nm_supplicant_manager_get_iface (NMSupplicantManager * self,
const char *ifname, const char *ifname,
gboolean is_wireless) gboolean is_wireless)
{ {
NMSupplicantManagerPrivate *priv; NMSupplicantManagerPrivate *priv;
NMSupplicantInterface * iface = NULL; NMSupplicantInterface * iface = NULL;
GSList * elt;
g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), NULL); g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), NULL);
g_return_val_if_fail (ifname != NULL, NULL); g_return_val_if_fail (ifname != NULL, NULL);
priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
/* Ensure we don't already have this interface */ iface = g_hash_table_lookup (priv->ifaces, ifname);
for (elt = priv->ifaces; elt; elt = g_slist_next (elt)) {
NMSupplicantInterface * if_tmp = (NMSupplicantInterface *) elt->data;
if (!strcmp (ifname, nm_supplicant_interface_get_device (if_tmp))) {
iface = if_tmp;
break;
}
}
if (!iface) { if (!iface) {
nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname); nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname);
iface = nm_supplicant_interface_new (self, ifname, is_wireless); iface = nm_supplicant_interface_new (self, ifname, is_wireless);
if (iface) if (iface)
priv->ifaces = g_slist_append (priv->ifaces, iface); g_hash_table_insert (priv->ifaces, g_strdup (ifname), iface);
} else { } else {
nm_log_dbg (LOGD_SUPPLICANT, "(%s): returning existing supplicant interface", ifname); nm_log_dbg (LOGD_SUPPLICANT, "(%s): returning existing supplicant interface", ifname);
} }
@ -300,30 +292,20 @@ nm_supplicant_manager_get_iface (NMSupplicantManager * self,
} }
void void
nm_supplicant_manager_release_iface (NMSupplicantManager * self, nm_supplicant_manager_release_iface (NMSupplicantManager *self,
NMSupplicantInterface * iface) NMSupplicantInterface *iface)
{ {
NMSupplicantManagerPrivate *priv; NMSupplicantManagerPrivate *priv;
GSList * elt; const char *ifname;
g_return_if_fail (NM_IS_SUPPLICANT_MANAGER (self)); g_return_if_fail (NM_IS_SUPPLICANT_MANAGER (self));
g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (iface)); g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (iface));
priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self);
for (elt = priv->ifaces; elt; elt = g_slist_next (elt)) { ifname = nm_supplicant_interface_get_ifname (iface);
NMSupplicantInterface * if_tmp = (NMSupplicantInterface *) elt->data; g_assert (ifname);
g_hash_table_remove (priv->ifaces, ifname);
if (if_tmp == iface) {
/* Remove the iface from the supplicant manager's list and
* dereference to match additional reference in get_iface.
*/
priv->ifaces = g_slist_remove_link (priv->ifaces, elt);
g_slist_free_1 (elt);
g_object_unref (iface);
break;
}
}
} }
const char * const char *