[PATCH] Allow devices to inhibit scanning through a signal



The OLPC mesh device will use this mechanism to prevent scans taking place
on the companion WLAN device while mesh discovery/connectivity is underway.

Based on earlier work by Sjoerd Simons
---
 marshallers/nm-marshal.list |    1 +
 src/nm-device-wifi.c        |   50 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletions(-)

For master branch

diff --git a/marshallers/nm-marshal.list b/marshallers/nm-marshal.list
index 970fe24..6b855f9 100644
--- a/marshallers/nm-marshal.list
+++ b/marshallers/nm-marshal.list
@@ -21,4 +21,5 @@ VOID:POINTER,STRING
 POINTER:POINTER
 VOID:STRING,BOXED
 BOOLEAN:POINTER,STRING,BOOLEAN,UINT,STRING,STRING
+BOOLEAN:VOID
 
diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c
index 3538825..cc8b307 100644
--- a/src/nm-device-wifi.c
+++ b/src/nm-device-wifi.c
@@ -37,6 +37,7 @@
 #include "nm-device-interface.h"
 #include "nm-device-private.h"
 #include "nm-utils.h"
+#include "nm-marshal.h"
 #include "NetworkManagerUtils.h"
 #include "NetworkManagerPolicy.h"
 #include "nm-activation-request.h"
@@ -92,6 +93,7 @@ enum {
 	ACCESS_POINT_REMOVED,
 	HIDDEN_AP_FOUND,
 	PROPERTIES_CHANGED,
+	SCANNING_ALLOWED,
 
 	LAST_SIGNAL
 };
@@ -227,6 +229,11 @@ static guint32 nm_device_wifi_get_bitrate (NMDeviceWifi *self);
 
 static void cull_scan_list (NMDeviceWifi *self);
 
+static gboolean scan_allowed_accumulator (GSignalInvocationHint *ihint,
+                                          GValue *return_accu,
+                                          const GValue *handler_return,
+                                          gpointer data);
+
 static GQuark
 nm_wifi_error_quark (void)
 {
@@ -1670,13 +1677,45 @@ can_scan (NMDeviceWifi *self)
 }
 
 static gboolean
+scan_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;
+}
+
+static gboolean
+scan_allowed (NMDeviceWifi *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[SCANNING_ALLOWED], 0, &retval);
+	if (!g_value_get_boolean (&retval))
+			return FALSE;
+
+	return TRUE;
+}
+
+static gboolean
 request_wireless_scan (gpointer user_data)
 {
 	NMDeviceWifi *self = NM_DEVICE_WIFI (user_data);
 	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
 	gboolean backoff = FALSE;
 
-	if (can_scan (self)) {
+	if (can_scan (self) && scan_allowed (self)) {
 		if (nm_supplicant_interface_request_scan (priv->supplicant.iface)) {
 			/* success */
 			backoff = TRUE;
@@ -3615,6 +3654,15 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
 		nm_properties_changed_signal_new (object_class,
 		                                  G_STRUCT_OFFSET (NMDeviceWifiClass, properties_changed));
 
+	signals[SCANNING_ALLOWED] =
+		g_signal_new ("scanning-allowed",
+		              G_OBJECT_CLASS_TYPE (object_class),
+		              G_SIGNAL_RUN_LAST,
+		              0,
+		              scan_allowed_accumulator, NULL,
+		              _nm_marshal_BOOLEAN__VOID,
+		              G_TYPE_BOOLEAN, 0);
+
 	dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass), &dbus_glib_nm_device_wifi_object_info);
 
 	dbus_g_error_domain_register (NM_WIFI_ERROR, NULL, NM_TYPE_WIFI_ERROR);
-- 
1.6.2.5



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