[Patch] Don't activate networking on wake if it was disabled



Hey,

Here's a hack^W patch to keep the enabled/disabled state after waking up
from sleep. Currently, sleep is used for both sleep and disabling
networking so disable networking -> suspend -> resume results in enabled
networking. As Robert pointed out, it's especially bad when resuming on
an airplane since resume always enables networking.

To work around this problem without changing the public dbus api, I
added an optional boolean argument to sleep and wake methods to make
distinction between the two. For 0.7 branch we should probably do
something cleaner.

Tambet
Index: gnome/applet/applet-dbus-devices.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.c,v
retrieving revision 1.51.2.4
diff -u -r1.51.2.4 applet-dbus-devices.c
--- gnome/applet/applet-dbus-devices.c	17 May 2006 20:03:56 -0000	1.51.2.4
+++ gnome/applet/applet-dbus-devices.c	4 Oct 2006 12:21:39 -0000
@@ -1373,6 +1373,9 @@
 
 	if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, method)))
 	{
+		gboolean true = TRUE; /* Eek... */
+
+		dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &true, DBUS_TYPE_INVALID);
 		dbus_connection_send (applet->connection, message, NULL);
 		dbus_message_unref (message);
 	}
Index: src/NetworkManagerMain.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerMain.h,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 NetworkManagerMain.h
--- src/NetworkManagerMain.h	6 Apr 2006 14:12:23 -0000	1.25.2.1
+++ src/NetworkManagerMain.h	4 Oct 2006 12:21:39 -0000
@@ -85,6 +85,7 @@
 	gboolean				wireless_enabled;
 	gboolean				modem_active;
 	gboolean				asleep;
+	gboolean				disconnected;
 
 	GSList *				dialup_list;
 	GMutex *				dialup_list_mutex;
Index: src/nm-dbus-nm.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/nm-dbus-nm.c,v
retrieving revision 1.39.2.2
diff -u -r1.39.2.2 nm-dbus-nm.c
--- src/nm-dbus-nm.c	21 May 2006 17:28:02 -0000	1.39.2.2
+++ src/nm-dbus-nm.c	4 Oct 2006 12:21:39 -0000
@@ -532,8 +532,28 @@
 	if (app_data->asleep == FALSE)
 	{
 		GSList *elt;
+		DBusMessageIter iter;
 
-		nm_info ("Going to sleep.");
+		dbus_message_iter_init (message, &iter);
+
+		switch (dbus_message_iter_get_arg_type (&iter)) {
+		case DBUS_TYPE_INVALID:
+			/* The boolean argument to differentiate between sleep and disabling networking
+			   is optional and defaults to sleep */
+			app_data->disconnected = FALSE;
+			break;
+		case DBUS_TYPE_BOOLEAN:
+			dbus_message_iter_get_basic (&iter, &app_data->disconnected);
+			break;
+		default:
+			//bitch();	
+			break;
+		}
+
+		if (app_data->disconnected)
+			nm_info ("Disconnected.");
+		else
+			nm_info ("Going to sleep.");
 
 		app_data->asleep = TRUE;
 		/* Not using nm_schedule_state_change_signal_broadcast() here
@@ -564,14 +584,36 @@
 static DBusMessage *nm_dbus_nm_wake (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
 {
 	NMData	*app_data;
+	DBusMessageIter iter;
+	gboolean enable_networking = FALSE;
 
 	g_return_val_if_fail (data && data->data && connection && message, NULL);
 
+	dbus_message_iter_init (message, &iter);
+
+	switch (dbus_message_iter_get_arg_type (&iter)) {
+	case DBUS_TYPE_INVALID:
+		/* The boolean argument to differentiate between wake up from sleep and
+		   enabling networking is optional and defaults to wake up. */
+		break;
+	case DBUS_TYPE_BOOLEAN:
+		dbus_message_iter_get_basic (&iter, &enable_networking);
+		break;
+	default:
+		//bitch();
+		break;
+	}
+
 	app_data = data->data;
-	if (app_data->asleep == TRUE)
-	{
-		nm_info  ("Waking up from sleep.");
-		app_data->asleep = FALSE;
+	/* Restore networking only if we're not disconnected or
+	   enable_networking argument is passed. */
+	if (app_data->asleep && (!app_data->disconnected || enable_networking)) {
+		if (enable_networking)
+			nm_info ("Enabling networking.");
+		else
+			nm_info ("Waking up from sleep.");
+
+		app_data->asleep = app_data->disconnected = FALSE;
 
 		/* Remove all devices from the device list */
 		nm_lock_mutex (app_data->dev_list_mutex, __FUNCTION__);


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