core: generalize unavailable -> disconnected delayed transition

Instead of doing this in every device subclass, do it in the NMDevice
superclass.  nm_device_can_activate() already did the same logic that
each of the subclass device_state_changed() handlers were doing to
figure out whether they could do the transition from unavailable
to disconnected, so just use that in NMDevice and kill lots of code.
This commit is contained in:
Dan Williams
2009-09-14 13:24:29 -07:00
parent f01c565230
commit 393bdd3737
7 changed files with 64 additions and 162 deletions

View File

@@ -106,7 +106,6 @@ typedef struct {
struct ether_addr hw_addr;
gboolean carrier;
guint32 ifindex;
guint state_to_disconnected_id;
NMNetlinkMonitor * monitor;
gulong link_connected_id;
@@ -242,39 +241,6 @@ carrier_off (NMNetlinkMonitor *monitor,
}
}
static gboolean
unavailable_to_disconnected (gpointer user_data)
{
nm_device_state_changed (NM_DEVICE (user_data), NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE);
return FALSE;
}
static void
device_state_changed (NMDeviceInterface *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
gpointer user_data)
{
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (user_data);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
/* Remove any previous delayed transition to disconnected */
if (priv->state_to_disconnected_id) {
g_source_remove (priv->state_to_disconnected_id);
priv->state_to_disconnected_id = 0;
}
/* If transitioning to UNAVAILBLE and we have a carrier, transition to
* DISCONNECTED because the device is ready to use. Otherwise the carrier-on
* handler will handle the transition to DISCONNECTED when the carrier is detected.
*/
if ((new_state == NM_DEVICE_STATE_UNAVAILABLE) && priv->carrier) {
priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);
return;
}
}
static GObject*
constructor (GType type,
guint n_construct_params,
@@ -319,8 +285,6 @@ constructor (GType type,
priv->carrier = TRUE;
}
g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), self);
return object;
}
@@ -1698,11 +1662,6 @@ dispose (GObject *object)
priv->monitor = NULL;
}
if (priv->state_to_disconnected_id) {
g_source_remove (priv->state_to_disconnected_id);
priv->state_to_disconnected_id = 0;
}
G_OBJECT_CLASS (nm_device_ethernet_parent_class)->dispose (object);
}