summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2012-11-19 17:08:55 +0100
committerJiří Klimeš <jklimes@redhat.com>2013-01-09 16:41:40 +0100
commite837098b0004fc8b2943cd099dc5238f54a9e572 (patch)
treeccd72e99e10a23a3b5f4c9accf57bfc9fcbd1f59 /libnm-glib
parent998f4ccc88710e324c5e4cecc142c8aedf4d565c (diff)
downloadNetworkManager-e837098b0004fc8b2943cd099dc5238f54a9e572.tar.gz
libnm-glib: add nm_device_wifi_request_scan_simple() to tell NM to scan for APs
by calling RequestScan() D-Bus call on the Wi-Fi device (without any options).
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/libnm-glib.ver1
-rw-r--r--libnm-glib/nm-device-wifi.c87
-rw-r--r--libnm-glib/nm-device-wifi.h7
3 files changed, 95 insertions, 0 deletions
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 8e04b3019b..aeea6ab275 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -156,6 +156,7 @@ global:
nm_device_wifi_get_permanent_hw_address;
nm_device_wifi_get_type;
nm_device_wifi_new;
+ nm_device_wifi_request_scan_simple;
nm_device_wimax_error_get_type;
nm_device_wimax_error_quark;
nm_device_wimax_get_active_nsp;
diff --git a/libnm-glib/nm-device-wifi.c b/libnm-glib/nm-device-wifi.c
index aab659f41e..74e9139f9f 100644
--- a/libnm-glib/nm-device-wifi.c
+++ b/libnm-glib/nm-device-wifi.c
@@ -45,6 +45,12 @@ G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
typedef struct {
+ NMDeviceWifi *device;
+ NMDeviceWifiRequestScanFn callback;
+ gpointer user_data;
+} RequestScanInfo;
+
+typedef struct {
DBusGProxy *proxy;
char *hw_address;
@@ -56,6 +62,8 @@ typedef struct {
GPtrArray *aps;
gboolean wireless_enabled;
+ DBusGProxyCall *scan_call;
+ RequestScanInfo *scan_info;
} NMDeviceWifiPrivate;
enum {
@@ -319,6 +327,69 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
}
static void
+request_scan_cb (DBusGProxy *proxy,
+ DBusGProxyCall *call,
+ gpointer user_data)
+{
+ RequestScanInfo *info = user_data;
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
+ GError *error = NULL;
+
+ dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+
+ if (info->callback)
+ info->callback (info->device, error, info->user_data);
+
+ g_clear_error (&error);
+ g_slice_free (RequestScanInfo, info);
+
+ priv->scan_call = NULL;
+ priv->scan_info = NULL;
+}
+
+/**
+ * nm_device_wifi_request_scan_simple:
+ * @device: a #NMDeviceWifi
+ * @callback: (scope async) (allow-none): the function to call when the call is done
+ * @user_data: (closure): user data to pass to the callback function
+ *
+ * Request NM to scan for access points on the #NMDeviceWifi. This function only
+ * instructs NM to perform scanning. Use nm_device_wifi_get_access_points()
+ * to get available access points.
+ *
+ **/
+void
+nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
+ NMDeviceWifiRequestScanFn callback,
+ gpointer user_data)
+{
+ RequestScanInfo *info;
+ GHashTable *options;
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
+
+ g_return_if_fail (NM_IS_DEVICE_WIFI (device));
+
+ /* If a scan is in progress, just return */
+ if (priv->scan_call)
+ return;
+
+ options = g_hash_table_new (g_str_hash, g_str_equal);
+
+ info = g_slice_new0 (RequestScanInfo);
+ info->device = device;
+ info->callback = callback;
+ info->user_data = user_data;
+
+ priv->scan_info = info;
+ priv->scan_call = dbus_g_proxy_begin_call (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy, "RequestScan",
+ request_scan_cb, info, NULL,
+ DBUS_TYPE_G_MAP_OF_VARIANT, options,
+ G_TYPE_INVALID);
+
+ g_hash_table_unref (options);
+}
+
+static void
access_point_added (NMObject *self, NMObject *ap)
{
g_signal_emit (self, signals[ACCESS_POINT_ADDED], 0, ap);
@@ -608,6 +679,22 @@ static void
dispose (GObject *object)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
+ GError *error = NULL;
+
+ if (priv->scan_call) {
+ g_set_error_literal (&error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_UNKNOWN,
+ "Wi-Fi device was destroyed");
+ if (priv->scan_info) {
+ if (priv->scan_info->callback)
+ priv->scan_info->callback (NULL, error, priv->scan_info->user_data);
+ g_slice_free (RequestScanInfo, priv->scan_info);
+ priv->scan_info = NULL;
+ }
+ g_clear_error (&error);
+
+ dbus_g_proxy_cancel_call (priv->proxy, priv->scan_call);
+ priv->scan_call = NULL;
+ }
clean_up_aps (NM_DEVICE_WIFI (object), FALSE);
g_clear_object (&priv->proxy);
diff --git a/libnm-glib/nm-device-wifi.h b/libnm-glib/nm-device-wifi.h
index d909c65c9c..76d76b4dff 100644
--- a/libnm-glib/nm-device-wifi.h
+++ b/libnm-glib/nm-device-wifi.h
@@ -104,6 +104,13 @@ NMAccessPoint * nm_device_wifi_get_access_point_by_path (NMDeviceWifi *
const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *device);
+typedef void (*NMDeviceWifiRequestScanFn) (NMDeviceWifi *device,
+ GError *error,
+ gpointer user_data);
+void nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
+ NMDeviceWifiRequestScanFn callback,
+ gpointer user_data);
+
G_END_DECLS
#endif /* NM_DEVICE_WIFI_H */