On Wed, 2009-07-01 at 12:18 -0400, Dan Williams wrote:
> If other APs appear later, it may well trigger the
> schedule_activate_check() which might cause NM to try to connect to that
> new network.  To combat that, I'd suggest that the mesh device block the
> wifi device from activating if it already failed by putting it into the
> UNAVAILABLE state or something, but that could be error prone.  What I
> think we really want here is the 'device idle' concept that asac and I
> have been talking over for a while.

The same consideration has to apply for when the mesh device disconnects
the eth device, because the user requested a mesh connection. Right now,
NM immediately reactivates eth0 (usually reconnecting to the same
network as before) and "wins."

What is the "device idle" concept? What do you think of an approach
along these lines? This way the mesh device can attach to the
autoconnect-allowed signal on the main device, and influence when it can
and cannot be used for automatic connections.

Daniel

>From bf78fa416ecf96bf9e607d1dd7c8fec29652a821 Mon Sep 17 00:00:00 2001
From: Daniel Drake <d...@laptop.org>
Date: Mon, 6 Jul 2009 16:42:55 +0100
Subject: [PATCH] Allow devices to inhibit autoconnect through a signal

This allows a device (or a companion) to signal that it is not a good
time for a specific device to autoconnect to a network.
---
 src/NetworkManagerPolicy.c |    2 +-
 src/nm-device.c            |   45 ++++++++++++++++++++++++++++++++++++++++++++
 src/nm-device.h            |    1 +
 3 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c
index 6bba92f..e2d4c95 100644
--- a/src/NetworkManagerPolicy.c
+++ b/src/NetworkManagerPolicy.c
@@ -726,7 +726,7 @@ schedule_activate_check (NMPolicy *policy, NMDevice *device)
 	if (state < NM_DEVICE_STATE_DISCONNECTED)
 		return;
 
-	if (!nm_device_can_activate (device))
+	if (!nm_device_can_activate (device) || !nm_device_autoconnect_allowed (device))
 		return;
 
 	for (iter = policy->pending_activation_checks; iter; iter = g_slist_next (iter)) {
diff --git a/src/nm-device.c b/src/nm-device.c
index 5826a2a..488b2cf 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -50,11 +50,19 @@
 #include "nm-setting-connection.h"
 #include "nm-dnsmasq-manager.h"
 #include "nm-dhcp4-config.h"
+#include "nm-marshal.h"
 
 #define NM_ACT_REQUEST_IP4_CONFIG "nm-act-request-ip4-config"
 
 static void device_interface_init (NMDeviceInterface *device_interface_class);
 
+enum {
+	AUTOCONNECT_ALLOWED,
+	LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 G_DEFINE_TYPE_EXTENDED (NMDevice, nm_device, G_TYPE_OBJECT,
 						G_TYPE_FLAG_ABSTRACT,
 						G_IMPLEMENT_INTERFACE (NM_TYPE_DEVICE_INTERFACE,
@@ -360,6 +368,34 @@ nm_device_can_activate (NMDevice *self)
 	return TRUE;
 }
 
+static gboolean
+autoconnect_allowed_accumulator (GSignalInvocationHint *ihint,
+                                 GValue *return_accu,
+                                 const GValue *handler_return, gpointer data)
+{
+	if (!g_value_get_boolean (handler_return))
+		g_value_set_boolean (return_accu, FALSE);
+	return TRUE;
+}
+
+gboolean
+nm_device_autoconnect_allowed (NMDevice *self)
+{
+	GValue instance = { 0, };
+	GValue retval = { 0, };
+
+	g_value_init (&instance, G_TYPE_OBJECT);
+	g_value_take_object (&instance, self);
+
+	g_value_init (&retval, G_TYPE_BOOLEAN);
+	g_value_set_boolean (&retval, TRUE);
+
+	/* Use g_signal_emitv() rather than g_signal_emit() to avoid the return
+	 * value being changed if no handlers are connected */
+	g_signal_emitv (&instance, signals[AUTOCONNECT_ALLOWED], 0, &retval);
+	return g_value_get_boolean (&retval);
+}
+
 NMConnection *
 nm_device_get_best_auto_connection (NMDevice *dev,
                                     GSList *connections,
@@ -2380,6 +2416,15 @@ nm_device_class_init (NMDeviceClass *klass)
 	g_object_class_override_property (object_class,
 									  NM_DEVICE_INTERFACE_PROP_MANAGED,
 									  NM_DEVICE_INTERFACE_MANAGED);
+
+	signals[AUTOCONNECT_ALLOWED] =
+		g_signal_new ("autoconnect-allowed",
+		              G_OBJECT_CLASS_TYPE (object_class),
+		              G_SIGNAL_RUN_LAST,
+		              0,
+		              autoconnect_allowed_accumulator, NULL,
+		              _nm_marshal_BOOLEAN__VOID,
+		              G_TYPE_BOOLEAN, 0);
 }
 
 static gboolean
diff --git a/src/nm-device.h b/src/nm-device.h
index 9084816..b230da8 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -159,6 +159,7 @@ void			nm_device_activate_schedule_stage4_ip_config_timeout	(NMDevice *device);
 gboolean		nm_device_deactivate_quickly	(NMDevice *dev);
 gboolean		nm_device_is_activating		(NMDevice *dev);
 gboolean		nm_device_can_interrupt_activation		(NMDevice *self);
+gboolean		nm_device_autoconnect_allowed	(NMDevice *self);
 
 NMDeviceState nm_device_get_state (NMDevice *device);
 
-- 
1.6.2.5

_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to