From 8bb058386d6a74dcb5283f46c2b0aeb3d06a9c5c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Apr 2018 11:31:39 +0200 Subject: [PATCH] connectivity: add connectivity-changed signal to NMDevice NMManager very much cares about changes to the connectivity state of the device and was therefore listening to notify::connectivity signals. However, property changed signals can be suppressed by g_object_freeze_notify(). That is something we even encourage for NMDBusObject instances, because the D-Bus glue makes use of the property changed notifications, and encourages to combine multiple changes by freezing the signal. Using the property changed notifications of NMDBusObject instances is ugly. Don't do that and instead add a special signal. --- src/devices/nm-device.c | 10 ++++++++++ src/devices/nm-device.h | 1 + src/nm-manager.c | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 4607ae3113..55667ffd78 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -180,6 +180,7 @@ enum { REMOVED, RECHECK_AUTO_ACTIVATE, RECHECK_ASSUME, + CONNECTIVITY_CHANGED, LAST_SIGNAL, }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -2457,6 +2458,7 @@ concheck_update_state (NMDevice *self, NMConnectivityState state, gboolean is_pe priv->connectivity_state = state; _notify (self, PROP_CONNECTIVITY); + g_signal_emit (self, signals[CONNECTIVITY_CHANGED], 0); if ( priv->state == NM_DEVICE_STATE_ACTIVATED && !nm_device_sys_iface_state_is_external (self)) { @@ -15744,4 +15746,12 @@ nm_device_class_init (NMDeviceClass *klass) G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); + + signals[CONNECTIVITY_CHANGED] = + g_signal_new (NM_DEVICE_CONNECTIVITY_CHANGED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index fd266d69ab..66720f015c 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -135,6 +135,7 @@ nm_device_state_reason_check (NMDeviceStateReason reason) #define NM_DEVICE_STATE_CHANGED "state-changed" #define NM_DEVICE_LINK_INITIALIZED "link-initialized" #define NM_DEVICE_AUTOCONNECT_ALLOWED "autoconnect-allowed" +#define NM_DEVICE_CONNECTIVITY_CHANGED "connectivity-changed" #define NM_DEVICE_STATISTICS_REFRESH_RATE_MS "refresh-rate-ms" #define NM_DEVICE_STATISTICS_TX_BYTES "tx-bytes" diff --git a/src/nm-manager.c b/src/nm-manager.c index fcebcfd314..cdaeb8a107 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -2512,7 +2512,6 @@ device_realized (NMDevice *device, static void device_connectivity_changed (NMDevice *device, - GParamSpec *pspec, NMManager *self) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); @@ -2646,7 +2645,7 @@ add_device (NMManager *self, NMDevice *device, GError **error) G_CALLBACK (device_realized), self); - g_signal_connect (device, "notify::" NM_DEVICE_CONNECTIVITY, + g_signal_connect (device, NM_DEVICE_CONNECTIVITY_CHANGED, G_CALLBACK (device_connectivity_changed), self);