From 8aee650cd146f49170c353e729c49f5d74193d23 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 21 Jan 2013 18:15:24 -0600 Subject: [PATCH] core: allow Wired device subclasses to override carrier handling Bond devices, for example, don't want carrier state to affect connection state. Allow subclasses to override the Wired class' handling if they want. --- src/nm-device-wired.c | 45 ++++++++++++++++++++++++++----------------- src/nm-device-wired.h | 3 +++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/nm-device-wired.c b/src/nm-device-wired.c index e441c43bb4..96029bd1c1 100644 --- a/src/nm-device-wired.c +++ b/src/nm-device-wired.c @@ -131,31 +131,37 @@ carrier_action_defer_clear (NMDeviceWired *self) } } +static void +carrier_action (NMDeviceWired *self, NMDeviceState state, gboolean carrier) +{ + NMDevice *device = NM_DEVICE (self); + + if (state == NM_DEVICE_STATE_UNAVAILABLE) { + if (carrier) + nm_device_queue_state (device, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_CARRIER); + else { + /* clear any queued state changes if they wouldn't be valid when the + * carrier is off. + */ + if (nm_device_queued_state_peek (device) >= NM_DEVICE_STATE_DISCONNECTED) + nm_device_queued_state_clear (device); + } + } else if (state >= NM_DEVICE_STATE_DISCONNECTED) { + if (!carrier && !nm_device_get_enslaved (device)) + nm_device_queue_state (device, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_CARRIER); + } +} + static gboolean carrier_action_defer_cb (gpointer user_data) { NMDeviceWired *self = NM_DEVICE_WIRED (user_data); NMDeviceWiredPrivate *priv = NM_DEVICE_WIRED_GET_PRIVATE (self); - NMDeviceState state; priv->carrier_action_defer_id = 0; - - state = nm_device_get_state (NM_DEVICE (self)); - if (state == NM_DEVICE_STATE_UNAVAILABLE) { - if (priv->carrier) - nm_device_queue_state (NM_DEVICE (self), NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_CARRIER); - else { - /* clear any queued state changes if they wouldn't be valid when the - * carrier is off. - */ - if (nm_device_queued_state_peek (NM_DEVICE (self)) >= NM_DEVICE_STATE_DISCONNECTED) - nm_device_queued_state_clear (NM_DEVICE (self)); - } - } else if (state >= NM_DEVICE_STATE_DISCONNECTED) { - if (!priv->carrier && !nm_device_get_enslaved (NM_DEVICE (self))) - nm_device_queue_state (NM_DEVICE (self), NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_CARRIER); - } - + NM_DEVICE_WIRED_GET_CLASS (self)->carrier_action (self, + nm_device_get_state (NM_DEVICE (self)), + priv->carrier); return FALSE; } @@ -430,6 +436,7 @@ nm_device_wired_class_init (NMDeviceWiredClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass); + NMDeviceWiredClass *wired_class = NM_DEVICE_WIRED_CLASS (klass); g_type_class_add_private (object_class, sizeof (NMDeviceWiredPrivate)); @@ -441,6 +448,8 @@ nm_device_wired_class_init (NMDeviceWiredClass *klass) parent_class->can_interrupt_activation = can_interrupt_activation; parent_class->is_available = is_available; parent_class->connection_match_config = connection_match_config; + + wired_class->carrier_action = carrier_action; } /** diff --git a/src/nm-device-wired.h b/src/nm-device-wired.h index c88f2b8f3e..a808435217 100644 --- a/src/nm-device-wired.h +++ b/src/nm-device-wired.h @@ -42,6 +42,9 @@ typedef struct { typedef struct { NMDeviceClass parent; + void (*carrier_action) (NMDeviceWired *self, + NMDeviceState state, + gboolean carrier); } NMDeviceWiredClass; GType nm_device_wired_get_type (void);