summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2015-07-14 09:46:55 +0200
committerJiří Klimeš <jklimes@redhat.com>2015-08-14 11:27:15 +0200
commit7691fe575377b5383d4cd6dd62e01ed4f6cafa93 (patch)
tree16cd21bb2b1c7c2bc8dc8821cbf3782fb44b34e5
parent87b2d783b6c732ab9cf3ad8ef0cdaec8d971c74a (diff)
libnm: add new functions allowing passing options to RequestScan() D-Bus call
nm_device_wifi_request_scan_options() nm_device_wifi_request_scan_options_async()
-rw-r--r--libnm/libnm.ver2
-rw-r--r--libnm/nm-device-wifi.c154
-rw-r--r--libnm/nm-device-wifi.h12
3 files changed, 143 insertions, 25 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 8d8f537e8..725b3e5e8 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -851,6 +851,8 @@ global:
nm_access_point_get_last_seen;
nm_device_get_metered;
nm_device_get_nm_plugin_missing;
+ nm_device_wifi_request_scan_options;
+ nm_device_wifi_request_scan_options_async;
nm_metered_get_type;
nm_setting_802_1x_check_cert_scheme;
nm_setting_bridge_get_multicast_snooping;
diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c
index 644a89004..383f43c60 100644
--- a/libnm/nm-device-wifi.c
+++ b/libnm/nm-device-wifi.c
@@ -269,6 +269,52 @@ nm_device_wifi_get_access_point_by_path (NMDeviceWifi *device,
return ap;
}
+static GVariant *
+prepare_scan_options (GVariant *options)
+{
+
+ GVariant *variant;
+ GVariantIter iter;
+ GVariantBuilder builder;
+ char *key;
+ GVariant *value;
+
+ if (!options)
+ variant = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
+ else {
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+ g_variant_iter_init (&iter, options);
+ while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
+ {
+ // FIXME: verify options here?
+ g_variant_builder_add (&builder, "{sv}", key, value);
+ }
+ variant = g_variant_builder_end (&builder);
+ }
+ return variant;
+}
+
+static gboolean
+_device_wifi_request_scan (NMDeviceWifi *device,
+ GVariant *options,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret;
+ GVariant *variant;
+
+ g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
+
+ variant = prepare_scan_options (options);
+
+ ret = nmdbus_device_wifi_call_request_scan_sync (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
+ variant,
+ cancellable, error);
+ if (error && *error)
+ g_dbus_error_strip_remote_error (*error);
+ return ret;
+}
+
/**
* nm_device_wifi_request_scan:
* @device: a #NMDeviceWifi
@@ -287,17 +333,36 @@ nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error)
{
- gboolean ret;
-
- g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
+ return _device_wifi_request_scan (device, NULL, cancellable, error);
+}
- ret = nmdbus_device_wifi_call_request_scan_sync (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
- g_variant_new_array (G_VARIANT_TYPE ("{sv}"),
- NULL, 0),
- cancellable, error);
- if (error && *error)
- g_dbus_error_strip_remote_error (*error);
- return ret;
+/**
+ * nm_device_wifi_request_scan_options:
+ * @device: a #NMDeviceWifi
+ * @options: dictionary with options for RequestScan(), or %NULL
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: location for a #GError, or %NULL
+ *
+ * Request NM to scan for access points on @device. Note that the function
+ * returns immediately after requesting the scan, and it may take some time
+ * after that for the scan to complete.
+ * This is the same as @nm_device_wifi_request_scan except it accepts @options
+ * for the scanning. The argument is the dictionary passed to RequestScan()
+ * D-Bus call. Valid otions inside the dictionary are:
+ * 'ssids' => array of SSIDs (saay)
+ *
+ * Returns: %TRUE on success, %FALSE on error, in which case @error will be
+ * set.
+ *
+ * Since: 1.2
+ **/
+gboolean
+nm_device_wifi_request_scan_options (NMDeviceWifi *device,
+ GVariant *options,
+ GCancellable *cancellable,
+ GError **error)
+{
+ return _device_wifi_request_scan (device, options, cancellable, error);
}
static void
@@ -324,19 +389,9 @@ request_scan_cb (GObject *source,
g_slice_free (RequestScanInfo, info);
}
-/**
- * nm_device_wifi_request_scan_async:
- * @device: a #NMDeviceWifi
- * @cancellable: a #GCancellable, or %NULL
- * @callback: callback to be called when the scan has been requested
- * @user_data: caller-specific data passed to @callback
- *
- * Request NM to scan for access points on @device. Note that @callback will be
- * called immediately after requesting the scan, and it may take some time after
- * that for the scan to complete.
- **/
-void
-nm_device_wifi_request_scan_async (NMDeviceWifi *device,
+static void
+_device_wifi_request_scan_async (NMDeviceWifi *device,
+ GVariant *options,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -344,6 +399,7 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device,
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
RequestScanInfo *info;
GSimpleAsyncResult *simple;
+ GVariant *variant;
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
@@ -362,13 +418,63 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device,
info->device = device;
info->simple = simple;
+ variant = prepare_scan_options (options);
+
priv->scan_info = info;
nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
- g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0),
+ variant,
cancellable, request_scan_cb, info);
}
/**
+ * nm_device_wifi_request_scan_async:
+ * @device: a #NMDeviceWifi
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: callback to be called when the scan has been requested
+ * @user_data: caller-specific data passed to @callback
+ *
+ * Request NM to scan for access points on @device. Note that @callback will be
+ * called immediately after requesting the scan, and it may take some time after
+ * that for the scan to complete.
+ **/
+void
+nm_device_wifi_request_scan_async (NMDeviceWifi *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ _device_wifi_request_scan_async (device, NULL, cancellable, callback, user_data);
+}
+
+/**
+ * nm_device_wifi_request_scan_options_async:
+ * @device: a #NMDeviceWifi
+ * @options: dictionary with options for RequestScan(), or %NULL
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: callback to be called when the scan has been requested
+ * @user_data: caller-specific data passed to @callback
+ *
+ * Request NM to scan for access points on @device. Note that @callback will be
+ * called immediately after requesting the scan, and it may take some time after
+ * that for the scan to complete.
+ * This is the same as @nm_device_wifi_request_scan_async except it accepts @options
+ * for the scanning. The argument is the dictionary passed to RequestScan()
+ * D-Bus call. Valid otions inside the dictionary are:
+ * 'ssids' => array of SSIDs (saay)
+ *
+ * Since: 1.2
+ **/
+void
+nm_device_wifi_request_scan_options_async (NMDeviceWifi *device,
+ GVariant *options,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ _device_wifi_request_scan_async (device, options, cancellable, callback, user_data);
+}
+
+/**
* nm_device_wifi_request_scan_finish:
* @device: a #NMDeviceWifi
* @result: the result passed to the #GAsyncReadyCallback
diff --git a/libnm/nm-device-wifi.h b/libnm/nm-device-wifi.h
index 24339fd3d..b5974ba2c 100644
--- a/libnm/nm-device-wifi.h
+++ b/libnm/nm-device-wifi.h
@@ -77,11 +77,21 @@ const GPtrArray * nm_device_wifi_get_access_points (NMDeviceWifi *
gboolean nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error);
-
+NM_AVAILABLE_IN_1_2
+gboolean nm_device_wifi_request_scan_options (NMDeviceWifi *device,
+ GVariant *options,
+ GCancellable *cancellable,
+ GError **error);
void nm_device_wifi_request_scan_async (NMDeviceWifi *device,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
+NM_AVAILABLE_IN_1_2
+void nm_device_wifi_request_scan_options_async (NMDeviceWifi *device,
+ GVariant *options,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
gboolean nm_device_wifi_request_scan_finish (NMDeviceWifi *device,
GAsyncResult *result,
GError **error);