From 7b9cc94e662b471c7bbc2c0396e25b8b8344b33e Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 1 Feb 2015 03:08:16 -0600 Subject: [PATCH] supplicant: make NMSupplicantInterface independent of NMSupplicantManager The Interface held a reference to the manager to listen for the 'available' signal. Instead of that, let's make the child unaware of the master to keep the inheritance cleaner. (cherry picked from commit 7ed2d7a8097271fbfe45dd16a537343b2ecbe792) --- .../nm-supplicant-interface.c | 39 ++--------- .../nm-supplicant-interface.h | 6 +- .../nm-supplicant-manager.c | 70 +++++++------------ .../nm-supplicant-manager.h | 9 --- src/supplicant-manager/nm-supplicant-types.h | 4 ++ 5 files changed, 39 insertions(+), 89 deletions(-) diff --git a/src/supplicant-manager/nm-supplicant-interface.c b/src/supplicant-manager/nm-supplicant-interface.c index 9d8b0f1f3c..2f328561b4 100644 --- a/src/supplicant-manager/nm-supplicant-interface.c +++ b/src/supplicant-manager/nm-supplicant-interface.c @@ -27,7 +27,6 @@ #include "NetworkManagerUtils.h" #include "nm-supplicant-interface.h" -#include "nm-supplicant-manager.h" #include "nm-logging.h" #include "nm-supplicant-config.h" #include "nm-dbus-manager.h" @@ -81,8 +80,6 @@ enum { typedef struct { - NMSupplicantManager * smgr; - gulong smgr_avail_id; NMDBusManager * dbus_mgr; char * dev; gboolean is_wireless; @@ -304,12 +301,6 @@ set_state (NMSupplicantInterface *self, guint32 new_state) nm_call_store_clear (priv->other_pcalls); nm_call_store_clear (priv->assoc_pcalls); - /* Disconnect supplicant manager state listeners since we're done */ - if (priv->smgr_avail_id) { - g_signal_handler_disconnect (priv->smgr, priv->smgr_avail_id); - priv->smgr_avail_id = 0; - } - if (priv->iface_proxy) { dbus_g_proxy_disconnect_signal (priv->iface_proxy, "PropertiesChanged", @@ -910,15 +901,13 @@ interface_add (NMSupplicantInterface *self, gboolean is_wireless) g_value_unset (&ifname); } -static void -smgr_avail_cb (NMSupplicantManager *smgr, - GParamSpec *pspec, - gpointer user_data) +void +nm_supplicant_interface_set_supplicant_available (NMSupplicantInterface *self, + gboolean available) { - NMSupplicantInterface *self = NM_SUPPLICANT_INTERFACE (user_data); - NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (user_data); + NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - if (nm_supplicant_manager_available (smgr)) { + if (available) { /* This can happen if the supplicant couldn't be activated but * for some reason was started after the activation failure. */ @@ -1321,8 +1310,7 @@ nm_supplicant_interface_get_max_scan_ssids (NMSupplicantInterface *self) /*******************************************************************/ NMSupplicantInterface * -nm_supplicant_interface_new (NMSupplicantManager *smgr, - const char *ifname, +nm_supplicant_interface_new (const char *ifname, gboolean is_wireless, gboolean fast_supported, ApSupport ap_support, @@ -1330,21 +1318,12 @@ nm_supplicant_interface_new (NMSupplicantManager *smgr, { NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; - guint id; - g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (smgr), NULL); g_return_val_if_fail (ifname != NULL, NULL); self = g_object_new (NM_TYPE_SUPPLICANT_INTERFACE, NULL); priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); - priv->smgr = g_object_ref (smgr); - id = g_signal_connect (priv->smgr, - "notify::" NM_SUPPLICANT_MANAGER_AVAILABLE, - G_CALLBACK (smgr_avail_cb), - self); - priv->smgr_avail_id = id; - priv->dev = g_strdup (ifname); priv->is_wireless = is_wireless; priv->fast_supported = fast_supported; @@ -1436,12 +1415,6 @@ dispose (GObject *object) priv->bss_proxies = NULL; } - if (priv->smgr) { - if (priv->smgr_avail_id) - g_signal_handler_disconnect (priv->smgr, priv->smgr_avail_id); - g_clear_object (&priv->smgr); - } - g_free (priv->dev); priv->dev = NULL; diff --git a/src/supplicant-manager/nm-supplicant-interface.h b/src/supplicant-manager/nm-supplicant-interface.h index 0112e40eae..1b1139d404 100644 --- a/src/supplicant-manager/nm-supplicant-interface.h +++ b/src/supplicant-manager/nm-supplicant-interface.h @@ -119,13 +119,15 @@ typedef struct { GType nm_supplicant_interface_get_type (void); -NMSupplicantInterface * nm_supplicant_interface_new (NMSupplicantManager * smgr, - const char *ifname, +NMSupplicantInterface * nm_supplicant_interface_new (const char *ifname, gboolean is_wireless, gboolean fast_supported, ApSupport ap_support, gboolean start_now); +void nm_supplicant_interface_set_supplicant_available (NMSupplicantInterface *self, + gboolean available); + gboolean nm_supplicant_interface_set_config (NMSupplicantInterface * iface, NMSupplicantConfig * cfg); diff --git a/src/supplicant-manager/nm-supplicant-manager.c b/src/supplicant-manager/nm-supplicant-manager.c index c4e3e6b03a..6c0147c954 100644 --- a/src/supplicant-manager/nm-supplicant-manager.c +++ b/src/supplicant-manager/nm-supplicant-manager.c @@ -38,13 +38,6 @@ G_DEFINE_TYPE (NMSupplicantManager, nm_supplicant_manager, G_TYPE_OBJECT) -/* Properties */ -enum { - PROP_0 = 0, - PROP_AVAILABLE, - LAST_PROP -}; - typedef struct { GDBusProxy * proxy; GCancellable * cancellable; @@ -89,8 +82,7 @@ nm_supplicant_manager_iface_get (NMSupplicantManager * self, start_now = !die_count_exceeded (priv->die_count); nm_log_dbg (LOGD_SUPPLICANT, "(%s): creating new supplicant interface", ifname); - iface = nm_supplicant_interface_new (self, - ifname, + iface = nm_supplicant_interface_new (ifname, is_wireless, priv->fast_supported, priv->ap_support, @@ -194,8 +186,20 @@ update_capabilities (NMSupplicantManager *self) nm_log_dbg (LOGD_SUPPLICANT, "EAP-FAST is %ssupported", priv->fast_supported ? "" : "not "); } -gboolean -nm_supplicant_manager_available (NMSupplicantManager *self) +static void +availability_changed (NMSupplicantManager *self, gboolean available) +{ + NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); + NMSupplicantInterface *iface; + GHashTableIter iter; + + g_hash_table_iter_init (&iter, priv->ifaces); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &iface)) + nm_supplicant_interface_set_supplicant_available (iface, available); +} + +static gboolean +is_available (NMSupplicantManager *self) { g_return_val_if_fail (NM_IS_SUPPLICANT_MANAGER (self), FALSE); @@ -208,22 +212,26 @@ static void set_running (NMSupplicantManager *self, gboolean now_running) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); - gboolean old_available = nm_supplicant_manager_available (self); + gboolean old_available = is_available (self); + gboolean new_available; priv->running = now_running; - if (old_available != nm_supplicant_manager_available (self)) - g_object_notify (G_OBJECT (self), NM_SUPPLICANT_MANAGER_AVAILABLE); + new_available = is_available (self); + if (old_available != new_available) + availability_changed (self, new_available); } static void set_die_count (NMSupplicantManager *self, guint new_die_count) { NMSupplicantManagerPrivate *priv = NM_SUPPLICANT_MANAGER_GET_PRIVATE (self); - gboolean old_available = nm_supplicant_manager_available (self); + gboolean old_available = is_available (self); + gboolean new_available; priv->die_count = new_die_count; - if (old_available != nm_supplicant_manager_available (self)) - g_object_notify (G_OBJECT (self), NM_SUPPLICANT_MANAGER_AVAILABLE); + new_available = is_available (self); + if (old_available != new_available) + availability_changed (self, new_available); } static gboolean @@ -339,25 +347,6 @@ nm_supplicant_manager_init (NMSupplicantManager *self) self); } -static void -set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); -} - -static void -get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - switch (prop_id) { - case PROP_AVAILABLE: - g_value_set_boolean (value, nm_supplicant_manager_available (NM_SUPPLICANT_MANAGER (object))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - static void dispose (GObject *object) { @@ -386,15 +375,6 @@ nm_supplicant_manager_class_init (NMSupplicantManagerClass *klass) g_type_class_add_private (object_class, sizeof (NMSupplicantManagerPrivate)); - object_class->get_property = get_property; - object_class->set_property = set_property; object_class->dispose = dispose; - - g_object_class_install_property - (object_class, PROP_AVAILABLE, - g_param_spec_boolean (NM_SUPPLICANT_MANAGER_AVAILABLE, "", "", - FALSE, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); } diff --git a/src/supplicant-manager/nm-supplicant-manager.h b/src/supplicant-manager/nm-supplicant-manager.h index 5e7f1eb596..3b8fddf4e6 100644 --- a/src/supplicant-manager/nm-supplicant-manager.h +++ b/src/supplicant-manager/nm-supplicant-manager.h @@ -26,11 +26,6 @@ #include "nm-supplicant-types.h" #include "nm-device.h" -#define WPAS_DBUS_SERVICE "fi.w1.wpa_supplicant1" -#define WPAS_DBUS_PATH "/fi/w1/wpa_supplicant1" -#define WPAS_DBUS_INTERFACE "fi.w1.wpa_supplicant1" - - G_BEGIN_DECLS #define NM_TYPE_SUPPLICANT_MANAGER (nm_supplicant_manager_get_type ()) @@ -40,8 +35,6 @@ G_BEGIN_DECLS #define NM_IS_SUPPLICANT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SUPPLICANT_MANAGER)) #define NM_SUPPLICANT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SUPPLICANT_MANAGER, NMSupplicantManagerClass)) -#define NM_SUPPLICANT_MANAGER_AVAILABLE "available" - struct _NMSupplicantManager { GObject parent; @@ -63,6 +56,4 @@ NMSupplicantInterface *nm_supplicant_manager_iface_get (NMSupplicantManager *mgr void nm_supplicant_manager_iface_release (NMSupplicantManager *mgr, NMSupplicantInterface *iface); -gboolean nm_supplicant_manager_available (NMSupplicantManager *mgr); - #endif /* __NETWORKMANAGER_SUPPLICANT_MANAGER_H__ */ diff --git a/src/supplicant-manager/nm-supplicant-types.h b/src/supplicant-manager/nm-supplicant-types.h index 619f0c3e91..1c16e49433 100644 --- a/src/supplicant-manager/nm-supplicant-types.h +++ b/src/supplicant-manager/nm-supplicant-types.h @@ -21,6 +21,10 @@ #ifndef __NETWORKMANAGER_SUPPLICANT_TYPES_H__ #define __NETWORKMANAGER_SUPPLICANT_TYPES_H__ +#define WPAS_DBUS_SERVICE "fi.w1.wpa_supplicant1" +#define WPAS_DBUS_PATH "/fi/w1/wpa_supplicant1" +#define WPAS_DBUS_INTERFACE "fi.w1.wpa_supplicant1" + typedef struct _NMSupplicantManager NMSupplicantManager; typedef struct _NMSupplicantInterface NMSupplicantInterface; typedef struct _NMSupplicantConfig NMSupplicantConfig;