Commit 91c0555a authored by Jiří Klimeš's avatar Jiří Klimeš

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()

(cherry picked from commit 7691fe57)
parent 7706b992
......@@ -855,6 +855,8 @@ libnm_1_0_6 {
global:
nm_access_point_get_last_seen;
nm_device_get_metered;
nm_device_wifi_request_scan_options;
nm_device_wifi_request_scan_options_async;
nm_metered_get_type;
nm_setting_connection_get_metered;
} libnm_1_0_4;
......
......@@ -271,6 +271,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
......@@ -289,17 +335,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.0.6
**/
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
......@@ -326,19 +391,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)
......@@ -346,6 +401,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));
......@@ -364,12 +420,62 @@ 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.0.6
**/
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
......
......@@ -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_0_6
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_0_6
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment