summaryrefslogtreecommitdiff
path: root/libnm/nm-client.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-09-11 16:27:13 -0400
committerDan Winship <danw@gnome.org>2014-09-19 14:41:58 -0400
commitcdfdb4538d43dddf2a5e6c4f6d66ba0060d92466 (patch)
tree27986f17c2aff6359cbbb4f4f5b3a05c5a6a2290 /libnm/nm-client.c
parent20789b4743fce69012cbe49f4ead3ede46f46f77 (diff)
downloadNetworkManager-danw/libnm-api.tar.gz
libnm: add some missing sync/async method variantsdanw/libnm-api
Add the missing variant in most places in the API where previously there was either only a synchronous version or only an asynchronous version. There is not yet a synchronous nm_client_activate_connection(), nm_client_add_and_activate_connection(), or nm_remote_settings_add_connection(), because the existing async code depends on waiting for other asynchronous events, so making them run synchronously is slightly more complicated. But these APIs can be added later.
Diffstat (limited to 'libnm/nm-client.c')
-rw-r--r--libnm/nm-client.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index 3f24433cd9..c2d32ad936 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -874,6 +874,91 @@ nm_client_deactivate_connection (NMClient *client,
cancellable, error);
}
+static void
+deactivated_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple = user_data;
+ GError *error = NULL;
+
+ if (nmdbus_manager_call_deactivate_connection_finish (NMDBUS_MANAGER (object),
+ result, &error))
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ else
+ g_simple_async_result_take_error (simple, error);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+/**
+ * nm_client_deactivate_connection_async:
+ * @client: a #NMClient
+ * @active: the #NMActiveConnection to deactivate
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: callback to be called when the deactivation has completed
+ * @user_data: caller-specific data passed to @callback
+ *
+ * Asynchronously deactivates an active #NMActiveConnection.
+ **/
+void
+nm_client_deactivate_connection_async (NMClient *client,
+ NMActiveConnection *active,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ NMClientPrivate *priv;
+ const char *path;
+ GSimpleAsyncResult *simple;
+
+ g_return_if_fail (NM_IS_CLIENT (client));
+ g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active));
+
+ simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
+ nm_client_deactivate_connection_async);
+
+ priv = NM_CLIENT_GET_PRIVATE (client);
+ if (!nm_client_get_nm_running (client)) {
+ g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_complete_in_idle (simple);
+ g_object_unref (simple);
+ return;
+ }
+
+ path = nm_object_get_path (NM_OBJECT (active));
+ nmdbus_manager_call_deactivate_connection (priv->manager_proxy,
+ path,
+ cancellable,
+ deactivated_cb, simple);
+}
+
+/**
+ * nm_client_deactivate_connection_finish:
+ * @client: a #NMClient
+ * @result: the result passed to the #GAsyncReadyCallback
+ * @error: location for a #GError, or %NULL
+ *
+ * Gets the result of a call to nm_client_deactivate_connection_async().
+ *
+ * Returns: success or failure
+ **/
+gboolean
+nm_client_deactivate_connection_finish (NMClient *client,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (client), nm_client_deactivate_connection_async), FALSE);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+ else
+ return g_simple_async_result_get_op_res_gboolean (simple);
+}
+
/**
* nm_client_get_active_connections:
* @client: a #NMClient