From a097895a6515521eec67861536d126a78d84a9be Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jan 2016 20:48:39 +0100 Subject: [PATCH 1/4] wifi: use "bool" members instead of gboolean in NMDeviceWifiPrivate struct --- src/devices/wifi/nm-device-wifi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 55460c8ed8..61a1310416 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -104,13 +104,13 @@ struct _NMDeviceWifiPrivate { guint8 scan_interval; /* seconds */ guint pending_scan_id; guint ap_dump_id; - gboolean requested_scan; + bool requested_scan; NMSupplicantManager *sup_mgr; NMSupplicantInterface *sup_iface; guint sup_timeout_id; /* supplicant association timeout */ - gboolean ssid_found; + bool ssid_found; NM80211Mode mode; guint periodic_source_id; From e2e22eb574d0c18ccd79bf8b3cee883418632a96 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jan 2016 22:05:04 +0100 Subject: [PATCH 2/4] wifi-olpc: refactor NMDeviceOlpcMesh to hold pointer to NMManager Objects that register to a signal of a singleton should own a reference to the singleton to ensure the proper lifetime of the singleton upon shutdown. --- src/devices/wifi/nm-device-olpc-mesh.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 9642e0955a..cec3887712 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -71,6 +71,7 @@ enum { struct _NMDeviceOlpcMeshPrivate { NMDevice *companion; + NMManager *manager; gboolean stage1_waiting; }; @@ -391,7 +392,7 @@ find_companion (NMDeviceOlpcMesh *self) nm_device_add_pending_action (NM_DEVICE (self), "waiting for companion", TRUE); /* Try to find the companion if it's already known to the NMManager */ - for (list = nm_manager_get_devices (nm_manager_get ()); list ; list = g_slist_next (list)) { + for (list = nm_manager_get_devices (priv->manager); list ; list = g_slist_next (list)) { if (check_companion (self, NM_DEVICE (list->data))) { nm_device_queue_recheck_available (NM_DEVICE (self), NM_DEVICE_STATE_REASON_NONE, @@ -438,6 +439,7 @@ constructor (GType type, GObject *object; GObjectClass *klass; NMDeviceOlpcMesh *self; + NMDeviceOlpcMeshPrivate *priv; NMDeviceWifiCapabilities caps; klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class); @@ -446,6 +448,7 @@ constructor (GType type, return NULL; self = NM_DEVICE_OLPC_MESH (object); + priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver"); @@ -453,8 +456,10 @@ constructor (GType type, return NULL; } - g_signal_connect (nm_manager_get (), "device-added", G_CALLBACK (device_added_cb), self); - g_signal_connect (nm_manager_get (), "device-removed", G_CALLBACK (device_removed_cb), self); + priv->manager = g_object_ref (nm_manager_get ()); + + g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self); + g_signal_connect (priv->manager, "device-removed", G_CALLBACK (device_removed_cb), self); /* shorter timeout for mesh connectivity */ nm_device_set_dhcp_timeout (NM_DEVICE (self), 20); @@ -496,10 +501,15 @@ static void dispose (GObject *object) { NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object); + NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); companion_cleanup (self); - g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_added_cb), self); - g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_removed_cb), self); + + if (priv->manager) { + g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_added_cb), self); + g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_removed_cb), self); + g_clear_object (&priv->manager); + } G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object); } From 044de4cea2c82d289033e75f1e12c7d346dc5537 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jan 2016 21:54:23 +0100 Subject: [PATCH 3/4] wifi: don't fail construction of NMDeviceWifi in constructor We cannot abort the construction of a GLib object instance like we did for NMDeviceWifi and NMDeviceOlpcMesh when nm_platform_wifi_get_capabilities() failed. Instead, check the capabilities first (in the factory method) and only create the object instance when the device can be handled. https://bugzilla.gnome.org/show_bug.cgi?id=760154 --- src/devices/wifi/nm-device-olpc-mesh.c | 10 +----- src/devices/wifi/nm-device-wifi.c | 44 ++++++++++++++------------ src/devices/wifi/nm-device-wifi.h | 2 +- src/devices/wifi/nm-wifi-factory.c | 17 ++++++++-- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index cec3887712..1ac3fa97ce 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -440,22 +440,14 @@ constructor (GType type, GObjectClass *klass; NMDeviceOlpcMesh *self; NMDeviceOlpcMeshPrivate *priv; - NMDeviceWifiCapabilities caps; klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class); object = klass->constructor (type, n_construct_params, construct_params); - if (!object) - return NULL; + g_return_val_if_fail (object, NULL); self = NM_DEVICE_OLPC_MESH (object); priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); - if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { - _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver"); - g_object_unref (object); - return NULL; - } - priv->manager = g_object_ref (nm_manager_get ()); g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self); diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 61a1310416..0e206bfa57 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -185,20 +185,11 @@ constructor (GType type, klass = G_OBJECT_CLASS (nm_device_wifi_parent_class); object = klass->constructor (type, n_construct_params, construct_params); - if (!object) - return NULL; + g_return_val_if_fail (object, NULL); self = NM_DEVICE_WIFI (object); priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, - nm_device_get_ifindex (NM_DEVICE (self)), - &priv->capabilities)) { - _LOGW (LOGD_HW | LOGD_WIFI, "failed to initialize WiFi driver"); - g_object_unref (object); - return NULL; - } - if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) _LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode"); @@ -2905,15 +2896,16 @@ set_enabled (NMDevice *device, gboolean enabled) /********************************************************************/ NMDevice * -nm_device_wifi_new (const char *iface) +nm_device_wifi_new (const char *iface, NMDeviceWifiCapabilities capabilities) { - return (NMDevice *) g_object_new (NM_TYPE_DEVICE_WIFI, - NM_DEVICE_IFACE, iface, - NM_DEVICE_TYPE_DESC, "802.11 WiFi", - NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI, - NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_WIFI, - NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN, - NULL); + return g_object_new (NM_TYPE_DEVICE_WIFI, + NM_DEVICE_IFACE, iface, + NM_DEVICE_TYPE_DESC, "802.11 WiFi", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI, + NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_WIFI, + NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN, + NM_DEVICE_WIFI_CAPABILITIES, (guint) capabilities, + NULL); } static void @@ -3004,7 +2996,18 @@ static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + NMDeviceWifi *device = NM_DEVICE_WIFI (object); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); + + switch (prop_id) { + case PROP_CAPABILITIES: + /* construct-only */ + priv->capabilities = g_value_get_uint (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } @@ -3088,7 +3091,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) (object_class, PROP_CAPABILITIES, g_param_spec_uint (NM_DEVICE_WIFI_CAPABILITIES, "", "", 0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE, - G_PARAM_READABLE | + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); g_object_class_install_property diff --git a/src/devices/wifi/nm-device-wifi.h b/src/devices/wifi/nm-device-wifi.h index e2954b9c5c..7e0d06f5a1 100644 --- a/src/devices/wifi/nm-device-wifi.h +++ b/src/devices/wifi/nm-device-wifi.h @@ -73,7 +73,7 @@ struct _NMDeviceWifiClass GType nm_device_wifi_get_type (void); -NMDevice * nm_device_wifi_new (const char *iface); +NMDevice * nm_device_wifi_new (const char *iface, NMDeviceWifiCapabilities capabilities); G_END_DECLS diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index 20b0a07508..8fa16e728f 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -65,13 +65,24 @@ create_device (NMDeviceFactory *factory, NMConnection *connection, gboolean *out_ignore) { + NMDeviceWifiCapabilities capabilities; + + g_return_val_if_fail (iface != NULL, NULL); g_return_val_if_fail (plink != NULL, NULL); + g_return_val_if_fail (g_strcmp0 (iface, plink->name) == 0, NULL); + g_return_val_if_fail (NM_IN_SET (plink->type, NM_LINK_TYPE_WIFI, NM_LINK_TYPE_OLPC_MESH), NULL); + + if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, + plink->ifindex, + &capabilities)) { + nm_log_warn (LOGD_HW | LOGD_WIFI, "(%s) failed to initialize Wi-Fi driver for ifindex %d", iface, plink->ifindex); + return NULL; + } if (plink->type == NM_LINK_TYPE_WIFI) - return nm_device_wifi_new (iface); - else if (plink->type == NM_LINK_TYPE_OLPC_MESH) + return nm_device_wifi_new (iface, capabilities); + else return nm_device_olpc_mesh_new (iface); - g_return_val_if_reached (NULL); } NM_DEVICE_FACTORY_DECLARE_TYPES ( From 1a835ad3d03ffe39a3caf4796027baaba73bf9b8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jan 2016 22:10:00 +0100 Subject: [PATCH 4/4] wifi: refactor creation of NMDeviceWifi/NMDeviceOlpcMesh to initialize in constructed() method --- src/devices/wifi/nm-device-olpc-mesh.c | 22 ++++++---------------- src/devices/wifi/nm-device-wifi.c | 23 ++++++----------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index 1ac3fa97ce..23ebd9c822 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -431,22 +431,13 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh * self) { } -static GObject* -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static void +constructed (GObject *object) { - GObject *object; - GObjectClass *klass; - NMDeviceOlpcMesh *self; - NMDeviceOlpcMeshPrivate *priv; + NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object); + NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); - klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class); - object = klass->constructor (type, n_construct_params, construct_params); - g_return_val_if_fail (object, NULL); - - self = NM_DEVICE_OLPC_MESH (object); - priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); + G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->constructed (object); priv->manager = g_object_ref (nm_manager_get ()); @@ -455,7 +446,6 @@ constructor (GType type, /* shorter timeout for mesh connectivity */ nm_device_set_dhcp_timeout (NM_DEVICE (self), 20); - return object; } static void @@ -516,7 +506,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_OLPC_MESH_SETTING_NAME, NM_LINK_TYPE_OLPC_MESH) - object_class->constructor = constructor; + object_class->constructed = constructed; object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 0e206bfa57..247534d17e 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -173,30 +173,19 @@ static void remove_supplicant_interface_error_handler (NMDeviceWifi *self); /*****************************************************************/ -static GObject* -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static void +constructed (GObject *object) { - GObject *object; - GObjectClass *klass; - NMDeviceWifi *self; - NMDeviceWifiPrivate *priv; + NMDeviceWifi *self = NM_DEVICE_WIFI (object); + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - klass = G_OBJECT_CLASS (nm_device_wifi_parent_class); - object = klass->constructor (type, n_construct_params, construct_params); - g_return_val_if_fail (object, NULL); - - self = NM_DEVICE_WIFI (object); - priv = NM_DEVICE_WIFI_GET_PRIVATE (self); + G_OBJECT_CLASS (nm_device_wifi_parent_class)->constructed (object); if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) _LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode"); /* Connect to the supplicant manager */ priv->sup_mgr = g_object_ref (nm_supplicant_manager_get ()); - - return object; } static gboolean @@ -3021,7 +3010,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass) NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_WIRELESS_SETTING_NAME, NM_LINK_TYPE_WIFI) - object_class->constructor = constructor; + object_class->constructed = constructed; object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose;