From 75741ef5c86b46e1cbb6c9a5e75da7eb4ee85642 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 8 Feb 2019 13:33:07 +0100 Subject: [PATCH] wifi-p2p: drop constructor property NM_DEVICE_WIFI_P2P_MGMT_IFACE We already have a setter function nm_device_wifi_p2p_set_mgmt_iface() as we may need to change the mgmt-iface later on. Use that to set the supplicant interface instead of a constructor property. That makes the object creation simpler, because nothing noteworthy happens, until the very last statement in constructed() to add the pending action. --- src/devices/wifi/nm-device-wifi-p2p.c | 40 ++++----------------------- src/devices/wifi/nm-device-wifi-p2p.h | 5 +--- src/devices/wifi/nm-device-wifi.c | 22 +++++++++------ 3 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c index 46d23ada23..79b4f262a9 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.c +++ b/src/devices/wifi/nm-device-wifi-p2p.c @@ -52,8 +52,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceWifiP2P, PROP_WFDIES, /* TODO: Make this a property of the setting and Find feature * making the device stateless. */ - - PROP_MGMT_IFACE, ); typedef struct { @@ -1192,9 +1190,6 @@ get_property (GObject *object, guint prop_id, const char **list; switch (prop_id) { - case PROP_MGMT_IFACE: - g_value_set_object (value, priv->mgmt_iface); - break; case PROP_GROUP_OWNER: g_value_set_boolean (value, priv->group_owner); break; @@ -1211,30 +1206,16 @@ get_property (GObject *object, guint prop_id, } } -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P (object); - - switch (prop_id) { - case PROP_MGMT_IFACE: - /* construct-only */ - nm_device_wifi_p2p_set_mgmt_iface (self, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - /*****************************************************************************/ static void nm_device_wifi_p2p_init (NMDeviceWifiP2P * self) { NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self); + c_list_init (&priv->peers_lst_head); + + priv->sup_mgr = g_object_ref (nm_supplicant_manager_get ()); } static void @@ -1245,13 +1226,11 @@ constructed (GObject *object) G_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->constructed (object); - priv->sup_mgr = g_object_ref (nm_supplicant_manager_get ()); - nm_device_add_pending_action (NM_DEVICE (self), NM_PENDING_ACTION_WAITING_FOR_SUPPLICANT, FALSE); } -NMDevice* -nm_device_wifi_p2p_new (NMSupplicantInterface *mgmt_iface, const char *iface) +NMDeviceWifiP2P * +nm_device_wifi_p2p_new (const char *iface) { return g_object_new (NM_TYPE_DEVICE_WIFI_P2P, NM_DEVICE_IFACE, iface, @@ -1259,7 +1238,6 @@ nm_device_wifi_p2p_new (NMSupplicantInterface *mgmt_iface, const char *iface) NM_DEVICE_DEVICE_TYPE, NM_TYPE_DEVICE_WIFI_P2P, NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_WIFI, NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN, - NM_DEVICE_WIFI_P2P_MGMT_IFACE, mgmt_iface, NULL); } @@ -1298,7 +1276,6 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass) object_class->constructed = constructed; object_class->get_property = get_property; - object_class->set_property = set_property; object_class->dispose = dispose; object_class->finalize = finalize; @@ -1346,12 +1323,5 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_MGMT_IFACE] = - g_param_spec_object (NM_DEVICE_WIFI_P2P_MGMT_IFACE, "", "", - NM_TYPE_SUPPLICANT_INTERFACE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); - g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); } diff --git a/src/devices/wifi/nm-device-wifi-p2p.h b/src/devices/wifi/nm-device-wifi-p2p.h index 12c0a8ef4d..64dcdd67c7 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.h +++ b/src/devices/wifi/nm-device-wifi-p2p.h @@ -36,15 +36,12 @@ #define NM_DEVICE_WIFI_P2P_GROUPS "groups" #define NM_DEVICE_WIFI_P2P_WFDIES "WFDIEs" -#define NM_DEVICE_WIFI_P2P_MGMT_IFACE "mgmt-iface" - typedef struct _NMDeviceWifiP2P NMDeviceWifiP2P; typedef struct _NMDeviceWifiP2PClass NMDeviceWifiP2PClass; GType nm_device_wifi_p2p_get_type (void); -NMDevice* nm_device_wifi_p2p_new (NMSupplicantInterface *mgmt_iface, - const char* iface); +NMDeviceWifiP2P *nm_device_wifi_p2p_new (const char *iface); NMSupplicantInterface * nm_device_wifi_p2p_get_mgmt_iface (NMDeviceWifiP2P *self); void nm_device_wifi_p2p_set_mgmt_iface (NMDeviceWifiP2P *self, diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index aaa101a67a..6f23bf15cd 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -2237,7 +2237,6 @@ static void recheck_p2p_availability (NMDeviceWifi *self) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - NMDeviceWifiP2P *p2p_device; gboolean p2p_available; g_object_get (priv->sup_iface, @@ -2251,20 +2250,27 @@ recheck_p2p_availability (NMDeviceWifi *self) * wpa_supplicant internally. */ iface_name = g_strconcat ("p2p-dev-", nm_device_get_iface (NM_DEVICE (self)), NULL); - p2p_device = NM_DEVICE_WIFI_P2P (nm_device_wifi_p2p_new (priv->sup_iface, iface_name)); - priv->p2p_device = p2p_device; - g_signal_emit (self, signals[P2P_DEVICE_CREATED], 0, priv->p2p_device); - g_object_add_weak_pointer (G_OBJECT (p2p_device), (gpointer*) &priv->p2p_device); - g_object_unref (p2p_device); + priv->p2p_device = nm_device_wifi_p2p_new (iface_name); - } else if (p2p_available && priv->p2p_device) { nm_device_wifi_p2p_set_mgmt_iface (priv->p2p_device, priv->sup_iface); - } else if (!p2p_available && priv->p2p_device) { + g_signal_emit (self, signals[P2P_DEVICE_CREATED], 0, priv->p2p_device); + g_object_add_weak_pointer (G_OBJECT (priv->p2p_device), (gpointer*) &priv->p2p_device); + g_object_unref (priv->p2p_device); + return; + } + + if (p2p_available && priv->p2p_device) { + nm_device_wifi_p2p_set_mgmt_iface (priv->p2p_device, priv->sup_iface); + return; + } + + if (!p2p_available && priv->p2p_device) { /* Destroy the P2P device. */ g_object_remove_weak_pointer (G_OBJECT (priv->p2p_device), (gpointer*) &priv->p2p_device); nm_device_wifi_p2p_remove (g_steal_pointer (&priv->p2p_device)); + return; } }