diff options
Diffstat (limited to 'libnm/nm-remote-connection.c')
| -rw-r--r-- | libnm/nm-remote-connection.c | 170 |
1 files changed, 139 insertions, 31 deletions
diff --git a/libnm/nm-remote-connection.c b/libnm/nm-remote-connection.c index 5cd42555..25fe3529 100644 --- a/libnm/nm-remote-connection.c +++ b/libnm/nm-remote-connection.c @@ -67,6 +67,111 @@ typedef struct { /*****************************************************************************/ +static void +update2_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) +{ + GSimpleAsyncResult *simple = user_data; + GError *error = NULL; + GVariant *v; + + if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy), + &v, + result, + &error)) + g_simple_async_result_set_op_res_gpointer (simple, + v, + (GDestroyNotify) g_variant_unref); + else { + g_dbus_error_strip_remote_error (error); + g_simple_async_result_take_error (simple, error); + } + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +/** + * nm_remote_connection_update2: + * @connection: the #NMRemoteConnection + * @settings: (allow-none): optional connection to update the settings. + * @flags: update-flags + * @args: (allow-none): optional arguments. + * @cancellable: a #GCancellable, or %NULL + * @callback: callback to be called when the commit operation completes + * @user_data: caller-specific data passed to @callback + * + * Asynchronously calls the Update2() D-Bus method. + * + * Since: 1.10.2 + **/ +void +nm_remote_connection_update2 (NMRemoteConnection *connection, + GVariant *settings, + NMSettingsUpdate2Flags flags, + GVariant *args, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + NMRemoteConnectionPrivate *priv; + GSimpleAsyncResult *simple; + GVariantBuilder builder; + + g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); + g_return_if_fail (!settings || g_variant_is_of_type (settings, NM_VARIANT_TYPE_CONNECTION)); + g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}"))); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); + + simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, + nm_remote_connection_update2); + + if (!settings) { + g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION); + settings = g_variant_builder_end (&builder); + } + if (!args) { + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); + args = g_variant_builder_end (&builder); + } + nmdbus_settings_connection_call_update2 (priv->proxy, + settings, + flags, + args, + cancellable, + update2_cb, + simple); +} + +/** + * nm_remote_connection_update2_finish: + * @connection: the #NMRemoteConnection + * @result: the result passed to the #GAsyncReadyCallback + * @error: location for a #GError, or %NULL + * + * Gets the result of a call to nm_remote_connection_commit_changes_async(). + * + * Returns: on success, a #GVariant of type "a{sv}" with the result. On failure, + * %NULL. + **/ +GVariant * +nm_remote_connection_update2_finish (NMRemoteConnection *connection, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_update2), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + else + return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple)); +} + +/*****************************************************************************/ + /** * nm_remote_connection_commit_changes: * @connection: the #NMRemoteConnection @@ -87,23 +192,25 @@ nm_remote_connection_commit_changes (NMRemoteConnection *connection, GError **error) { NMRemoteConnectionPrivate *priv; - GVariant *settings; + gs_unref_variant GVariant *result = NULL; gboolean ret; + GVariantBuilder args; g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE); priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection); - settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL); - if (save_to_disk) { - ret = nmdbus_settings_connection_call_update_sync (priv->proxy, - settings, - cancellable, error); - } else { - ret = nmdbus_settings_connection_call_update_unsaved_sync (priv->proxy, - settings, - cancellable, error); - } + g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}")); + ret = nmdbus_settings_connection_call_update2_sync (priv->proxy, + nm_connection_to_dbus (NM_CONNECTION (connection), + NM_CONNECTION_SERIALIZE_ALL), + save_to_disk + ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK + : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, + g_variant_builder_end (&args), + &result, + cancellable, + error); if (error && *error) g_dbus_error_strip_remote_error (*error); return ret; @@ -113,11 +220,13 @@ static void update_cb (GObject *proxy, GAsyncResult *result, gpointer user_data) { GSimpleAsyncResult *simple = user_data; - gboolean (*finish_func) (NMDBusSettingsConnection *, GAsyncResult *, GError **); GError *error = NULL; + gs_unref_variant GVariant *v = NULL; - finish_func = g_object_get_data (G_OBJECT (simple), "finish_func"); - if (finish_func (NMDBUS_SETTINGS_CONNECTION (proxy), result, &error)) + if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy), + &v, + result, + &error)) g_simple_async_result_set_op_res_gboolean (simple, TRUE); else { g_dbus_error_strip_remote_error (error); @@ -149,7 +258,7 @@ nm_remote_connection_commit_changes_async (NMRemoteConnection *connection, { NMRemoteConnectionPrivate *priv; GSimpleAsyncResult *simple; - GVariant *settings; + GVariantBuilder args; g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection)); @@ -158,22 +267,17 @@ nm_remote_connection_commit_changes_async (NMRemoteConnection *connection, simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data, nm_remote_connection_commit_changes_async); - settings = nm_connection_to_dbus (NM_CONNECTION (connection), NM_CONNECTION_SERIALIZE_ALL); - if (save_to_disk) { - g_object_set_data (G_OBJECT (simple), "finish_func", - nmdbus_settings_connection_call_update_finish); - nmdbus_settings_connection_call_update (priv->proxy, - settings, - cancellable, - update_cb, simple); - } else { - g_object_set_data (G_OBJECT (simple), "finish_func", - nmdbus_settings_connection_call_update_unsaved_finish); - nmdbus_settings_connection_call_update_unsaved (priv->proxy, - settings, - cancellable, - update_cb, simple); - } + g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}")); + nmdbus_settings_connection_call_update2 (priv->proxy, + nm_connection_to_dbus (NM_CONNECTION (connection), + NM_CONNECTION_SERIALIZE_ALL), + save_to_disk + ? NM_SETTINGS_UPDATE2_FLAG_TO_DISK + : NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY, + g_variant_builder_end (&args), + cancellable, + update_cb, + simple); } /** @@ -202,6 +306,8 @@ nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection, return g_simple_async_result_get_op_res_gboolean (simple); } +/*****************************************************************************/ + /** * nm_remote_connection_save: * @connection: the #NMRemoteConnection @@ -302,6 +408,8 @@ nm_remote_connection_save_finish (NMRemoteConnection *connection, return g_simple_async_result_get_op_res_gboolean (simple); } +/*****************************************************************************/ + /** * nm_remote_connection_delete: * @connection: the #NMRemoteConnection |