summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2019-01-28 18:50:31 +0100
committerThomas Haller <thaller@redhat.com>2019-02-05 08:45:38 +0100
commit70b7679cb41bccd010c050a9e6cac3982f6da802 (patch)
tree2bec979db1bc42a86f58557633e29067aeac39c0
parentd3d8611066a533ce245be6449cba10c6f4b7bb79 (diff)
downloadNetworkManager-70b7679cb41bccd010c050a9e6cac3982f6da802.tar.gz
libnm: Add async start/stop routines for P2P find operations
These were dropped earlier as new sync API must not be the primary way of calling new routines in libnm. In this particular case the DBus calls are simple and unlikely to fail. Most users should use the normal async API and call the finish routine. However, if the API user is not interested in the result, then they can simply set the callback to NULL to ignore it.
-rw-r--r--libnm/libnm.ver4
-rw-r--r--libnm/nm-device-wifi-p2p.c145
-rw-r--r--libnm/nm-device-wifi-p2p.h20
3 files changed, 169 insertions, 0 deletions
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index edef0b6298..ab22017bd2 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1454,6 +1454,10 @@ global:
nm_device_wifi_p2p_get_hw_address;
nm_device_wifi_p2p_get_peers;
nm_device_wifi_p2p_get_type;
+ nm_device_wifi_p2p_start_find;
+ nm_device_wifi_p2p_start_find_finish;
+ nm_device_wifi_p2p_stop_find;
+ nm_device_wifi_p2p_stop_find_finish;
nm_setting_wifi_p2p_get_peer;
nm_setting_wifi_p2p_get_type;
nm_setting_wifi_p2p_get_wps_method;
diff --git a/libnm/nm-device-wifi-p2p.c b/libnm/nm-device-wifi-p2p.c
index 0c90bd89ab..aad87a0fa1 100644
--- a/libnm/nm-device-wifi-p2p.c
+++ b/libnm/nm-device-wifi-p2p.c
@@ -184,6 +184,151 @@ nm_device_wifi_p2p_get_peer_by_path (NMDeviceWifiP2P *device,
}
static void
+start_find_finished_cb (GObject *obj,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj;
+ GTask *task = G_TASK (user_data);
+ GError *error = NULL;
+ gboolean success;
+
+ success = nmdbus_device_wifi_p2p_call_start_find_finish (proxy, res, &error);
+ if (!success)
+ g_task_return_error (task, error);
+ else
+ g_task_return_boolean (task, TRUE);
+
+ g_object_unref (task);
+}
+
+/**
+ * nm_device_wifi_p2p_start_find:
+ * @device: a #NMDeviceWifiP2P
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: a #GAsyncReadyCallback, or %NULL
+ * @user_data: user_data for @callback
+ *
+ * Request NM to search for Wi-Fi P2P peers on @device. Note that the call
+ * returns immediately after requesting the find, and it may take some time
+ * after that for peers to be found.
+ *
+ * The find operation will run for 30s by default. You can stop it earlier
+ * using nm_device_p2p_wifi_stop_find().
+ *
+ * Since: 1.16
+ **/
+void
+nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device);
+ GVariant *options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
+ GTask *task;
+
+ g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device));
+
+ task = g_task_new (device, cancellable, callback, user_data);
+
+ nmdbus_device_wifi_p2p_call_start_find (priv->proxy,
+ options,
+ cancellable,
+ start_find_finished_cb,
+ task);
+}
+
+/**
+ * nm_device_wifi_p2p_start_find_finish:
+ * @device: a #NMDeviceWifiP2P
+ * @result: the #GAsyncResult
+ * @error: #GError return address
+ *
+ * Finish an operation started by nm_device_wifi_p2p_start_find().
+ *
+ * Returns: %TRUE if the call was successful
+ *
+ * Since: 1.16
+ **/
+gboolean
+nm_device_wifi_p2p_start_find_finish (NMDeviceWifiP2P *device,
+ GAsyncResult *result,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static void
+stop_find_finished_cb (GObject *obj,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj;
+ GTask *task = G_TASK (user_data);
+ GError *error = NULL;
+ gboolean success;
+
+ success = nmdbus_device_wifi_p2p_call_stop_find_finish (proxy, res, &error);
+ if (!success)
+ g_task_return_error (task, error);
+ else
+ g_task_return_boolean (task, TRUE);
+
+ g_object_unref (task);
+}
+
+/**
+ * nm_device_wifi_p2p_stop_find:
+ * @device: a #NMDeviceWifiP2P
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: a #GAsyncReadyCallback, or %NULL
+ * @user_data: user_data for @callback
+ *
+ * Request NM to stop any ongoing find operation for Wi-Fi P2P peers on @device.
+ *
+ * Since: 1.16
+ **/
+void
+nm_device_wifi_p2p_stop_find (NMDeviceWifiP2P *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device);
+ GTask *task;
+
+ g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device));
+
+ task = g_task_new (device, cancellable, callback, user_data);
+
+ nmdbus_device_wifi_p2p_call_stop_find (priv->proxy,
+ cancellable,
+ stop_find_finished_cb,
+ task);
+}
+
+/**
+ * nm_device_wifi_p2p_stop_find_finish:
+ * @device: a #NMDeviceWifiP2P
+ * @result: the #GAsyncResult
+ * @error: #GError return address
+ *
+ * Finish an operation started by nm_device_wifi_p2p_stop_find().
+ *
+ * Returns: %TRUE if the call was successful
+ *
+ * Since: 1.16
+ **/
+gboolean
+nm_device_wifi_p2p_stop_find_finish (NMDeviceWifiP2P *device,
+ GAsyncResult *result,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static void
clean_up_peers (NMDeviceWifiP2P *self)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
diff --git a/libnm/nm-device-wifi-p2p.h b/libnm/nm-device-wifi-p2p.h
index 4ff4d03842..357c2216c6 100644
--- a/libnm/nm-device-wifi-p2p.h
+++ b/libnm/nm-device-wifi-p2p.h
@@ -58,6 +58,26 @@ NMWifiP2PPeer * nm_device_wifi_p2p_get_peer_by_path (NMDeviceWifiP2P *d
NM_AVAILABLE_IN_1_16
const GPtrArray * nm_device_wifi_p2p_get_peers (NMDeviceWifiP2P *device);
+NM_AVAILABLE_IN_1_16
+void nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+NM_AVAILABLE_IN_1_16
+gboolean nm_device_wifi_p2p_start_find_finish (NMDeviceWifiP2P *device,
+ GAsyncResult *result,
+ GError **error);
+
+NM_AVAILABLE_IN_1_16
+void nm_device_wifi_p2p_stop_find (NMDeviceWifiP2P *device,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+NM_AVAILABLE_IN_1_16
+gboolean nm_device_wifi_p2p_stop_find_finish (NMDeviceWifiP2P *device,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif /* __NM_DEVICE_WIFI_P2P_H__ */