summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-02-02 17:16:27 +0100
committerThomas Haller <thaller@redhat.com>2017-02-10 14:40:24 +0100
commit4e84472b471cf82baea3cf3f61562575928f0e0c (patch)
tree7227c4a47d6192aee079b89c73c98d84abc7552f
parent1b7f03d1a554c91ac7df2412b8e0f3449512cb74 (diff)
downloadNetworkManager-4e84472b471cf82baea3cf3f61562575928f0e0c.tar.gz
device/wifi: cache GObject property "scanning"
Cache the value for accessing the GObject property NM_DEVICE_WIFI_SCANNING. Re-evaluating the property every time by checking the supplicant interface is ugly because it might change under the hood. It should only change if (and only if) we emit a notify changed signal. Also, avoid accessing nm_supplicant_interface_get_scanning (priv->sup_iface) without checking whether priv->sup_iface is not NULL.
-rw-r--r--src/devices/wifi/nm-device-wifi.c40
-rw-r--r--src/supplicant/nm-supplicant-interface.c2
2 files changed, 29 insertions, 13 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 116612d549..4c36fdc6ef 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -95,6 +95,7 @@ typedef struct {
bool enabled:1; /* rfkilled or not */
bool requested_scan:1;
bool ssid_found:1;
+ bool is_scanning:1;
gint32 last_scan;
gint32 scheduled_scan_time;
@@ -209,6 +210,23 @@ _ap_dump (NMDeviceWifi *self,
nm_wifi_ap_to_string (ap, buf, sizeof (buf), now_s));
}
+static void
+_notify_scanning (NMDeviceWifi *self)
+{
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
+ gboolean scanning;
+
+ scanning = priv->sup_iface
+ && nm_supplicant_interface_get_scanning (priv->sup_iface);
+
+ if (scanning == priv->is_scanning)
+ return;
+
+ _LOGD (LOGD_WIFI, "wifi-scan: scanning-state: %s", scanning ? "scanning" : "idle");
+ priv->is_scanning = scanning;
+ _notify (self, PROP_SCANNING);
+}
+
static gboolean
unmanaged_on_quit (NMDevice *self)
{
@@ -269,6 +287,8 @@ supplicant_interface_acquire (NMDeviceWifi *self)
G_CALLBACK (supplicant_iface_notify_current_bss),
self);
+ _notify_scanning (self);
+
return TRUE;
}
@@ -319,6 +339,8 @@ supplicant_interface_release (NMDeviceWifi *self)
g_clear_object (&priv->sup_iface);
}
+
+ _notify_scanning (self);
}
static NMWifiAP *
@@ -1530,7 +1552,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface,
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
- _LOGD (LOGD_WIFI, "wifi-scan: done [%s]", success ? "successful" : "failed");
+ _LOGD (LOGD_WIFI, "wifi-scan: scan-done callback: %s", success ? "successful" : "failed");
priv->last_scan = nm_utils_get_monotonic_timestamp_s ();
schedule_scan (self, success);
@@ -2138,7 +2160,7 @@ supplicant_iface_state_cb (NMSupplicantInterface *iface,
/* Signal scanning state changes */
if ( new_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING
|| old_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING)
- _notify (self, PROP_SCANNING);
+ _notify_scanning (self);
}
static void
@@ -2176,17 +2198,11 @@ supplicant_iface_notify_scanning_cb (NMSupplicantInterface *iface,
GParamSpec *pspec,
NMDeviceWifi *self)
{
- NMDeviceState state;
- gboolean scanning;
-
- scanning = nm_supplicant_interface_get_scanning (iface);
- _LOGD (LOGD_WIFI, "wifi-scan: now %s", scanning ? "scanning" : "idle");
-
- _notify (self, PROP_SCANNING);
+ _notify_scanning (self);
/* Run a quick update of current AP when coming out of a scan */
- state = nm_device_get_state (NM_DEVICE (self));
- if (!scanning && state == NM_DEVICE_STATE_ACTIVATED)
+ if ( !NM_DEVICE_WIFI_GET_PRIVATE (self)->is_scanning
+ && nm_device_get_state (NM_DEVICE (self)) == NM_DEVICE_STATE_ACTIVATED)
periodic_update (self);
}
@@ -3114,7 +3130,7 @@ get_property (GObject *object, guint prop_id,
nm_utils_g_value_set_object_path (value, priv->current_ap);
break;
case PROP_SCANNING:
- g_value_set_boolean (value, nm_supplicant_interface_get_scanning (priv->sup_iface));
+ g_value_set_boolean (value, priv->is_scanning);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c
index 70f05e1c9f..1fad8f2c3b 100644
--- a/src/supplicant/nm-supplicant-interface.c
+++ b/src/supplicant/nm-supplicant-interface.c
@@ -352,7 +352,7 @@ nm_supplicant_interface_get_scanning (NMSupplicantInterface *self)
{
NMSupplicantInterfacePrivate *priv;
- g_return_val_if_fail (self != NULL, FALSE);
+ g_return_val_if_fail (self, FALSE);
priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self);
if (priv->scanning)