NetworkManager r3542 - in trunk: . src



Author: dcbw
Date: Tue Apr  8 04:58:17 2008
New Revision: 3542
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3542&view=rev

Log:
2008-04-07  Dan Williams  <dcbw redhat com>

	* src/nm-gsm-device.c
	  src/nm-cdma-device.c
		- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
			handler to transition to DISCONNECTED



Modified:
   trunk/ChangeLog
   trunk/src/nm-cdma-device.c
   trunk/src/nm-gsm-device.c

Modified: trunk/src/nm-cdma-device.c
==============================================================================
--- trunk/src/nm-cdma-device.c	(original)
+++ trunk/src/nm-cdma-device.c	Tue Apr  8 04:58:17 2008
@@ -19,6 +19,7 @@
 	NMSerialDevice *monitor_device;
 
 	guint pending_id;
+	guint state_to_disconnected_id;
 } NMCdmaDevicePrivate;
 
 enum {
@@ -333,6 +334,33 @@
 	nm_device_set_device_type (NM_DEVICE (self), DEVICE_TYPE_CDMA);
 }
 
+static gboolean
+unavailable_to_disconnected (gpointer user_data)
+{
+	nm_device_state_changed (NM_DEVICE (user_data), NM_DEVICE_STATE_DISCONNECTED);
+	return FALSE;
+}
+
+static void
+device_state_changed (NMDeviceInterface *device, NMDeviceState state, gpointer user_data)
+{
+	NMCdmaDevice *self = NM_CDMA_DEVICE (user_data);
+	NMCdmaDevicePrivate *priv = NM_CDMA_DEVICE_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 (state == NM_DEVICE_STATE_UNAVAILABLE)
+		priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);
+}
+
 static GObject*
 constructor (GType type,
              guint n_construct_params,
@@ -355,6 +383,9 @@
 	}
 #endif
 
+	g_signal_connect (NM_DEVICE (object), "state-changed",
+	                  G_CALLBACK (device_state_changed), NM_CDMA_DEVICE (object));
+
 	return object;
 }
 
@@ -401,6 +432,11 @@
 
 	g_free (priv->monitor_iface);
 
+	if (priv->state_to_disconnected_id) {
+		g_source_remove (priv->state_to_disconnected_id);
+		priv->state_to_disconnected_id = 0;
+	}
+
 	G_OBJECT_CLASS (nm_cdma_device_parent_class)->finalize (object);
 }
 

Modified: trunk/src/nm-gsm-device.c
==============================================================================
--- trunk/src/nm-gsm-device.c	(original)
+++ trunk/src/nm-gsm-device.c	Tue Apr  8 04:58:17 2008
@@ -26,6 +26,7 @@
 
 	NMGsmSecret need_secret;
 	guint pending_id;
+	guint state_to_disconnected_id;
 } NMGsmDevicePrivate;
 
 enum {
@@ -639,6 +640,33 @@
 	nm_device_set_device_type (NM_DEVICE (self), DEVICE_TYPE_GSM);
 }
 
+static gboolean
+unavailable_to_disconnected (gpointer user_data)
+{
+	nm_device_state_changed (NM_DEVICE (user_data), NM_DEVICE_STATE_DISCONNECTED);
+	return FALSE;
+}
+
+static void
+device_state_changed (NMDeviceInterface *device, NMDeviceState state, gpointer user_data)
+{
+	NMGsmDevice *self = NM_GSM_DEVICE (user_data);
+	NMGsmDevicePrivate *priv = NM_GSM_DEVICE_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 (state == NM_DEVICE_STATE_UNAVAILABLE)
+		priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);
+}
+
 static GObject*
 constructor (GType type,
 		   guint n_construct_params,
@@ -661,6 +689,9 @@
 	}
 #endif
 
+	g_signal_connect (NM_DEVICE (object), "state-changed",
+	                  G_CALLBACK (device_state_changed), NM_GSM_DEVICE (object));
+
 	return object;
 }
 
@@ -707,6 +738,11 @@
 
 	g_free (priv->monitor_iface);
 
+	if (priv->state_to_disconnected_id) {
+		g_source_remove (priv->state_to_disconnected_id);
+		priv->state_to_disconnected_id = 0;
+	}
+
 	G_OBJECT_CLASS (nm_gsm_device_parent_class)->finalize (object);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]