NetworkManager r4174 - in trunk: . include introspection src src/vpn-manager



Author: dcbw
Date: Sat Oct 11 19:57:45 2008
New Revision: 4174
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4174&view=rev

Log:
2008-10-11  Dan Williams  <dcbw redhat com>

	* include/NetworkManager.h
	  introspection/nm-device.xml
	  include/NetworkManagerVPN.h
		- Add a few more state reasons for the device deactivated state

	* src/nm-device-interface.c
	  src/nm-device-interface.h
		- (nm_device_interface_deactivate): add a 'reason' argument

	* src/nm-device.c
	  src/nm-device.h
		- (nm_device_deactivate, nm_device_take_down): add a 'reason' argument
		- (nm_device_state_changed): pass the state change reason to
			nm_device_take_down()
		- (nm_device_set_managed): take a 'reason' argument, and pass it along
			to the state change function

	* src/nm-manager.c
	  src/nm-manager.h
		- (remove_one_device, handle_unmanaged_devices, sync_devices,
		   impl_manager_sleep): pass a reason code to nm_device_set_managed()
		- (nm_manager_deactivate_connection): add a 'reason' argument and pass
			something reasonable along to VPN deactivation

	* src/vpn-manager/nm-vpn-manager.c
	  src/vpn-manager/nm-vpn-manager.h
		- (nm_vpn_manager_deactivate_connection): add a 'reason' argument and
			pass that along to nm_vpn_connection_disconnect()



Modified:
   trunk/ChangeLog
   trunk/include/NetworkManager.h
   trunk/include/NetworkManagerVPN.h
   trunk/introspection/nm-device.xml
   trunk/src/NetworkManagerPolicy.c
   trunk/src/nm-device-interface.c
   trunk/src/nm-device-interface.h
   trunk/src/nm-device.c
   trunk/src/nm-device.h
   trunk/src/nm-manager.c
   trunk/src/nm-manager.h
   trunk/src/vpn-manager/nm-vpn-manager.c
   trunk/src/vpn-manager/nm-vpn-manager.h

Modified: trunk/include/NetworkManager.h
==============================================================================
--- trunk/include/NetworkManager.h	(original)
+++ trunk/include/NetworkManager.h	Sat Oct 11 19:57:45 2008
@@ -325,6 +325,18 @@
 	/* Necessary firmware for the device may be missing */
 	NM_DEVICE_STATE_REASON_FIRMWARE_MISSING,
 
+	/* The device was removed */
+	NM_DEVICE_STATE_REASON_REMOVED,
+
+	/* NetworkManager went to sleep */
+	NM_DEVICE_STATE_REASON_SLEEPING,
+
+	/* The device's active connection disappeared */
+	NM_DEVICE_STATE_REASON_CONNECTION_REMOVED,
+
+	/* Device disconnected by user or client */
+	NM_DEVICE_STATE_REASON_USER_REQUESTED,
+
 	/* Unused */
 	NM_DEVICE_STATE_REASON_LAST = 0xFFFF
 } NMDeviceStateReason;

Modified: trunk/include/NetworkManagerVPN.h
==============================================================================
--- trunk/include/NetworkManagerVPN.h	(original)
+++ trunk/include/NetworkManagerVPN.h	Sat Oct 11 19:57:45 2008
@@ -103,7 +103,8 @@
 	NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT,
 	NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED,
 	NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS,
-	NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED
+	NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED,
+	NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED
 } NMVPNConnectionStateReason;
 
 typedef enum {

Modified: trunk/introspection/nm-device.xml
==============================================================================
--- trunk/introspection/nm-device.xml	(original)
+++ trunk/introspection/nm-device.xml	Sat Oct 11 19:57:45 2008
@@ -320,6 +320,26 @@
           Necessary firmware for the device may be missing.
         </tp:docstring>
       </tp:enumvalue>
+      <tp:enumvalue suffix="REMOVED" value="36">
+        <tp:docstring>
+          The device was removed.
+        </tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="SLEEPING" value="37">
+        <tp:docstring>
+          NetworkManager went to sleep.
+        </tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="CONNECTION_REMOVED" value="38">
+        <tp:docstring>
+          The device's active connection was removed or disappeared.
+        </tp:docstring>
+      </tp:enumvalue>
+      <tp:enumvalue suffix="USER_REQUESTED" value="39">
+        <tp:docstring>
+          A user or client requested the disconnection.
+        </tp:docstring>
+      </tp:enumvalue>
 	</tp:enum>
 
   </interface>

Modified: trunk/src/NetworkManagerPolicy.c
==============================================================================
--- trunk/src/NetworkManagerPolicy.c	(original)
+++ trunk/src/NetworkManagerPolicy.c	Sat Oct 11 19:57:45 2008
@@ -921,7 +921,7 @@
 		char *path = g_ptr_array_index (list, i);
 		GError *error = NULL;
 
-		if (!nm_manager_deactivate_connection (manager, path, &error)) {
+		if (!nm_manager_deactivate_connection (manager, path, NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, &error)) {
 			nm_warning ("Connection '%s' disappeared, but error deactivating it: (%d) %s",
 			            s_con->id, error->code, error->message);
 			g_error_free (error);

Modified: trunk/src/nm-device-interface.c
==============================================================================
--- trunk/src/nm-device-interface.c	(original)
+++ trunk/src/nm-device-interface.c	Sat Oct 11 19:57:45 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
 #include "nm-marshal.h"
 #include "nm-setting-connection.h"
@@ -234,11 +234,11 @@
 }
 
 void
-nm_device_interface_deactivate (NMDeviceInterface *device)
+nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
 {
 	g_return_if_fail (NM_IS_DEVICE_INTERFACE (device));
 
-	NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device);
+	NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device, reason);
 }
 
 NMDeviceState

Modified: trunk/src/nm-device-interface.h
==============================================================================
--- trunk/src/nm-device-interface.h	(original)
+++ trunk/src/nm-device-interface.h	Sat Oct 11 19:57:45 2008
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
 #ifndef NM_DEVICE_INTERFACE_H
 #define NM_DEVICE_INTERFACE_H
@@ -62,7 +63,7 @@
 	                      NMActRequest *req,
 	                      GError **error);
 
-	void (*deactivate) (NMDeviceInterface *device);
+	void (*deactivate) (NMDeviceInterface *device, NMDeviceStateReason reason);
 
 	/* Signals */
 	void (*state_changed) (NMDeviceInterface *device,
@@ -84,7 +85,7 @@
 				       NMActRequest *req,
 				       GError **error);
 
-void nm_device_interface_deactivate (NMDeviceInterface *device);
+void nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason);
 
 NMDeviceState nm_device_interface_get_state (NMDeviceInterface *device);
 

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Sat Oct 11 19:57:45 2008
@@ -114,7 +114,9 @@
                                     GError **error);
 
 static void	nm_device_activate_schedule_stage5_ip_config_commit (NMDevice *self);
-static void nm_device_deactivate (NMDeviceInterface *device);
+static void nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason);
+
+static void nm_device_take_down (NMDevice *dev, gboolean wait, NMDeviceStateReason reason);
 
 static gboolean nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware);
 static gboolean nm_device_is_up (NMDevice *self);
@@ -1527,19 +1529,21 @@
  *
  */
 static void
-nm_device_deactivate (NMDeviceInterface *device)
+nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
 {
 	NMDevice *self = NM_DEVICE (device);
-	NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
+	NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
 
 	g_return_if_fail (self != NULL);
 
-	nm_info ("(%s): deactivating device.", nm_device_get_iface (self));
+	nm_info ("(%s): deactivating device (reason: %d).",
+	         nm_device_get_iface (self),
+	         reason);
 
 	nm_device_deactivate_quickly (self);
 
 	/* Clean up nameservers and addresses */
-	nm_device_set_ip4_config (self, NULL, &reason);
+	nm_device_set_ip4_config (self, NULL, &ignored);
 
 	/* Take out any entries in the routing table and any IP address the device had. */
 	nm_system_device_flush_ip4_routes (self);
@@ -2061,13 +2065,13 @@
 	return success;
 }
 
-void
-nm_device_take_down (NMDevice *self, gboolean block)
+static void
+nm_device_take_down (NMDevice *self, gboolean block, NMDeviceStateReason reason)
 {
 	g_return_if_fail (NM_IS_DEVICE (self));
 
 	if (nm_device_get_act_request (self))
-		nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self));
+		nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self), reason);
 
 	if (nm_device_is_up (self)) {
 		nm_info ("(%s): cleaning up...", nm_device_get_iface (self));
@@ -2107,10 +2111,10 @@
 	 */
 
 	if (self->priv->managed) {
-		NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
+		NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
 
-		nm_device_take_down (self, FALSE);
-		nm_device_set_ip4_config (self, NULL, &reason);
+		nm_device_take_down (self, FALSE, NM_DEVICE_STATE_REASON_REMOVED);
+		nm_device_set_ip4_config (self, NULL, &ignored);
 	}
 
 	clear_act_request (self);
@@ -2348,7 +2352,7 @@
 	switch (state) {
 	case NM_DEVICE_STATE_UNMANAGED:
 		if (old_state > NM_DEVICE_STATE_UNMANAGED)
-			nm_device_take_down (device, TRUE);
+			nm_device_take_down (device, TRUE, reason);
 		break;
 	case NM_DEVICE_STATE_UNAVAILABLE:
 		if (old_state == NM_DEVICE_STATE_UNMANAGED) {
@@ -2359,7 +2363,7 @@
 		 * eg carrier changes we actually deactivate it */
 	case NM_DEVICE_STATE_DISCONNECTED:
 		if (old_state != NM_DEVICE_STATE_UNAVAILABLE)
-			nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
+			nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device), reason);
 		break;
 	default:
 		break;
@@ -2408,7 +2412,9 @@
 }
 
 void
-nm_device_set_managed (NMDevice *device, gboolean managed)
+nm_device_set_managed (NMDevice *device,
+                       gboolean managed,
+                       NMDeviceStateReason reason)
 {
 	NMDevicePrivate *priv;
 
@@ -2430,8 +2436,8 @@
 
 	/* If now managed, jump to unavailable */
 	if (managed)
-		nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
+		nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, reason);
 	else
-		nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
+		nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, reason);
 }
 

Modified: trunk/src/nm-device.h
==============================================================================
--- trunk/src/nm-device.h	(original)
+++ trunk/src/nm-device.h	Sat Oct 11 19:57:45 2008
@@ -143,8 +143,6 @@
                                              NMIP4Config *config,
                                              NMDeviceStateReason *reason);
 
-void		nm_device_take_down (NMDevice *dev, gboolean wait);
-
 void *		nm_device_get_system_config_data	(NMDevice *dev);
 
 NMActRequest *	nm_device_get_act_request	(NMDevice *dev);
@@ -166,7 +164,9 @@
 NMDeviceState nm_device_get_state (NMDevice *device);
 
 gboolean nm_device_get_managed (NMDevice *device);
-void nm_device_set_managed (NMDevice *device, gboolean managed);
+void nm_device_set_managed (NMDevice *device,
+                            gboolean managed,
+                            NMDeviceStateReason reason);
 
 G_END_DECLS
 

Modified: trunk/src/nm-manager.c
==============================================================================
--- trunk/src/nm-manager.c	(original)
+++ trunk/src/nm-manager.c	Sat Oct 11 19:57:45 2008
@@ -420,7 +420,7 @@
 remove_one_device (NMManager *manager, NMDevice *device)
 {
 	if (nm_device_get_managed (device))
-		nm_device_set_managed (device, FALSE);
+		nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_REMOVED);
 
 	g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
 
@@ -1153,7 +1153,7 @@
 		device = nm_manager_get_device_by_udi (manager, udi);
 		if (device) {
 			unmanaged = g_slist_prepend (unmanaged, device);
-			nm_device_set_managed (device, FALSE);
+			nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
 		}
 	}
 
@@ -1162,7 +1162,7 @@
 		NMDevice *device = NM_DEVICE (iter->data);
 
 		if (!g_slist_find (unmanaged, device))
-			nm_device_set_managed (device, TRUE);
+			nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
 	}
 
 	g_slist_free (unmanaged);
@@ -1394,7 +1394,10 @@
 		const char *udi = nm_device_get_udi (device);
 
 		if (nm_hal_manager_udi_exists (priv->hal_mgr, udi)) {
-			nm_device_set_managed (device, nm_manager_udi_is_managed (self, udi));
+			if (nm_manager_udi_is_managed (self, udi))
+				nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
+			else
+				nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
 		} else {
 			priv->devices = g_slist_delete_link (priv->devices, iter);
 			remove_one_device (self, device);
@@ -2006,12 +2009,14 @@
 gboolean
 nm_manager_deactivate_connection (NMManager *manager,
                                   const char *connection_path,
+                                  NMDeviceStateReason reason,
                                   GError **error)
 {
 	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
 	NMVPNManager *vpn_manager;
 	GSList *iter;
 	gboolean success = FALSE;
+	NMVPNConnectionStateReason vpn_reason = NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED;
 
 	/* Check for device connections first */
 	for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
@@ -2025,7 +2030,7 @@
 		if (!strcmp (connection_path, nm_act_request_get_active_connection_path (req))) {
 			nm_device_state_changed (device,
 			                         NM_DEVICE_STATE_DISCONNECTED,
-			                         NM_DEVICE_STATE_REASON_NONE);
+			                         reason);
 			success = TRUE;
 			goto done;
 		}
@@ -2033,7 +2038,9 @@
 
 	/* Check for VPN connections next */
 	vpn_manager = nm_vpn_manager_get ();
-	if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path)) {
+	if (reason == NM_DEVICE_STATE_REASON_CONNECTION_REMOVED)
+		vpn_reason = NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED;
+	if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path, vpn_reason)) {
 		success = TRUE;
 	} else {
 		g_set_error (error,
@@ -2052,7 +2059,10 @@
                                     const char *connection_path,
                                     GError **error)
 {
-	return nm_manager_deactivate_connection (manager, connection_path, error);
+	return nm_manager_deactivate_connection (manager,
+	                                         connection_path,
+	                                         NM_DEVICE_STATE_REASON_USER_REQUESTED,
+	                                         error);
 }
 
 static gboolean
@@ -2082,7 +2092,7 @@
 		 * we'll remove them in 'wake' for speed's sake.
 		 */
 		for (iter = priv->devices; iter; iter = iter->next)
-			nm_device_set_managed (NM_DEVICE (iter->data), FALSE);
+			nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING);
 	} else {
 		nm_info  ("Waking up...");
 

Modified: trunk/src/nm-manager.h
==============================================================================
--- trunk/src/nm-manager.h	(original)
+++ trunk/src/nm-manager.h	Sat Oct 11 19:57:45 2008
@@ -70,6 +70,7 @@
 
 gboolean nm_manager_deactivate_connection (NMManager *manager,
                                            const char *connection_path,
+                                           NMDeviceStateReason reason,
                                            GError **error);
 
 /* State handling */

Modified: trunk/src/vpn-manager/nm-vpn-manager.c
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-manager.c	(original)
+++ trunk/src/vpn-manager/nm-vpn-manager.c	Sat Oct 11 19:57:45 2008
@@ -206,7 +206,9 @@
 }
 
 gboolean
-nm_vpn_manager_deactivate_connection (NMVPNManager *manager, const char *path)
+nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
+                                      const char *path,
+                                      NMVPNConnectionStateReason reason)
 {
 	NMVPNManagerPrivate *priv;
 	GSList *iter;
@@ -226,7 +228,7 @@
 
 			vpn_path = nm_vpn_connection_get_active_connection_path (vpn);
 			if (!strcmp (path, vpn_path)) {
-				nm_vpn_connection_disconnect (vpn, NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED);
+				nm_vpn_connection_disconnect (vpn, reason);
 				found = TRUE;
 			}
 		}

Modified: trunk/src/vpn-manager/nm-vpn-manager.h
==============================================================================
--- trunk/src/vpn-manager/nm-vpn-manager.h	(original)
+++ trunk/src/vpn-manager/nm-vpn-manager.h	Sat Oct 11 19:57:45 2008
@@ -55,7 +55,8 @@
                                                 GError **error);
 
 gboolean nm_vpn_manager_deactivate_connection (NMVPNManager *manager,
-                                               const char *path);
+                                               const char *path,
+                                               NMVPNConnectionStateReason reason);
 
 void nm_vpn_manager_add_active_connections (NMVPNManager *manager,
                                             NMConnection *filter,



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