Re: [PATCH] wifi: add the on-demand WiFi scan support V2



On Tue, 2012-06-05 at 11:19 +0800, Gary Ching-Pang Lin wrote:
> A new D-Bus method was added to invoke the on-demand WiFi scan.

Thanks!  Pushed with a few fixes on top.

Dan

> ---
>  introspection/nm-device-wifi.xml |   13 ++++++++
>  src/nm-device-wifi.c             |   60 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 73 insertions(+), 0 deletions(-)
> 
> diff --git a/introspection/nm-device-wifi.xml b/introspection/nm-device-wifi.xml
> index fb50762..531fc89 100644
> --- a/introspection/nm-device-wifi.xml
> +++ b/introspection/nm-device-wifi.xml
> @@ -14,6 +14,19 @@
>        </tp:docstring>
>      </method>
>  
> +    <method name="RequestScan">
> +      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_device_request_scan"/>
> +      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
> +      <arg name="options" type="a{sv}" direction="in">
> +        <tp:docstring>
> +          Options of scan
> +        </tp:docstring>
> +      </arg>
> +      <tp:docstring>
> +        Request the device to scan
> +      </tp:docstring>
> +    </method>
> +
>      <property name="HwAddress" type="s" access="read">
>        <tp:docstring>
>          The active hardware address of the device.
> diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c
> index ad1cfe3..a2d5667 100644
> --- a/src/nm-device-wifi.c
> +++ b/src/nm-device-wifi.c
> @@ -56,6 +56,7 @@
>  #include "nm-setting-ip4-config.h"
>  #include "nm-setting-ip6-config.h"
>  #include "nm-system.h"
> +#include "nm-manager-auth.h"
>  #include "nm-settings-connection.h"
>  #include "nm-enum-types.h"
>  #include "wifi-utils.h"
> @@ -64,6 +65,10 @@ static gboolean impl_device_get_access_points (NMDeviceWifi *device,
>                                                 GPtrArray **aps,
>                                                 GError **err);
>  
> +static void impl_device_request_scan (NMDeviceWifi *device,
> +                                      GHashTable *options,
> +                                      DBusGMethodInvocation *context);
> +
>  #include "nm-device-wifi-glue.h"
>  
> 
> @@ -150,6 +155,8 @@ struct _NMDeviceWifiPrivate {
>  	guint             periodic_source_id;
>  	guint             link_timeout_id;
>  
> +	glong             request_scan_time;
> +
>  	NMDeviceWifiCapabilities capabilities;
>  };
>  
> @@ -191,6 +198,8 @@ static void supplicant_iface_notify_scanning_cb (NMSupplicantInterface * iface,
>  
>  static void schedule_scanlist_cull (NMDeviceWifi *self);
>  
> +static gboolean request_wireless_scan (gpointer user_data);
> +
>  /*****************************************************************/
>  
>  #define NM_WIFI_ERROR (nm_wifi_error_quark ())
> @@ -330,6 +339,8 @@ constructor (GType type,
>  	}
>  	priv->ipw_rfkill_state = nm_device_wifi_get_ipw_rfkill_state (self);
>  
> +	priv->request_scan_time = 0;
> +
>  	return object;
>  }
>  
> @@ -1441,6 +1452,55 @@ impl_device_get_access_points (NMDeviceWifi *self,
>  	return TRUE;
>  }
>  
> +static void
> +request_scan_cb (NMDevice *device,
> +		 DBusGMethodInvocation *context,
> +		 GError *error,
> +		 gpointer user_data)
> +{
> +	NMDeviceWifi *self = NM_DEVICE_WIFI (device);
> +	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
> +	GTimeVal now;
> +
> +	if (error) {
> +		dbus_g_method_return_error (context, error);
> +		g_clear_error (&error);
> +	} else {
> +		g_get_current_time (&now);
> +		cancel_pending_scan (self);
> +		request_wireless_scan (self);
> +		priv->request_scan_time = now.tv_sec;
> +
> +		dbus_g_method_return (context);
> +	}
> +}
> +
> +static void
> +impl_device_request_scan (NMDeviceWifi *self,
> +                          GHashTable *options,
> +                          DBusGMethodInvocation *context)
> +{
> +	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
> +	GTimeVal now;
> +
> +	g_get_current_time (&now);
> +	if (!priv->enabled || now.tv_sec - priv->request_scan_time < 10) {
> +		dbus_g_method_return (context);
> +		return;
> +	}
> +
> +	/* Ask the manager to authenticate this request for us */
> +	g_signal_emit_by_name (NM_DEVICE (self),
> +	                       NM_DEVICE_AUTH_REQUEST,
> +	                       context,
> +	                       NM_AUTH_PERMISSION_NETWORK_CONTROL,
> +	                       TRUE,
> +	                       request_scan_cb,
> +	                       NULL);
> +
> +	return;
> +}
> +
>  static gboolean
>  scanning_allowed (NMDeviceWifi *self)
>  {




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