mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 08:18:03 +02:00
libnm: add nm_remote_connection_update2()
- only add an async version. I think sync requests are fundamentally flawed
because they mess up the order of D-Bus messages. Hence, also don't
call the function *_async(), like we do for other functions. As there
is only the async form, it doesn't have a suffix.
- Don't accept a NMConnection as @settings argument, but a GVariant.
In general, keep the libnm API closer to the D-Bus API and don't hide
the underlying function with a less powerful form. The user still can
conveniently call the function with
nm_remote_connection_update2 (connection,
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,
NULL,
cancellable,
callback,
user_data);
I believe the parts of libnm that invoke D-Bus methods, should be
close to the D-Bus API. Not like nm_remote_connection_commit_changes()
which has no corresponding D-Bus method.
This commit is contained in:
parent
98ee18d888
commit
d00eb95c55
3 changed files with 124 additions and 0 deletions
|
|
@ -1235,6 +1235,8 @@ global:
|
||||||
nm_client_checkpoint_rollback_async;
|
nm_client_checkpoint_rollback_async;
|
||||||
nm_client_checkpoint_rollback_finish;
|
nm_client_checkpoint_rollback_finish;
|
||||||
nm_client_get_checkpoints;
|
nm_client_get_checkpoints;
|
||||||
|
nm_remote_connection_update2;
|
||||||
|
nm_remote_connection_update2_finish;
|
||||||
nm_setting_team_add_runner_tx_hash;
|
nm_setting_team_add_runner_tx_hash;
|
||||||
nm_setting_team_get_mcast_rejoin_count;
|
nm_setting_team_get_mcast_rejoin_count;
|
||||||
nm_setting_team_get_mcast_rejoin_interval;
|
nm_setting_team_get_mcast_rejoin_interval;
|
||||||
|
|
|
||||||
|
|
@ -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.12
|
||||||
|
**/
|
||||||
|
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:
|
* nm_remote_connection_commit_changes:
|
||||||
* @connection: the #NMRemoteConnection
|
* @connection: the #NMRemoteConnection
|
||||||
|
|
@ -201,6 +306,8 @@ nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection,
|
||||||
return g_simple_async_result_get_op_res_gboolean (simple);
|
return g_simple_async_result_get_op_res_gboolean (simple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_remote_connection_save:
|
* nm_remote_connection_save:
|
||||||
* @connection: the #NMRemoteConnection
|
* @connection: the #NMRemoteConnection
|
||||||
|
|
@ -301,6 +408,8 @@ nm_remote_connection_save_finish (NMRemoteConnection *connection,
|
||||||
return g_simple_async_result_get_op_res_gboolean (simple);
|
return g_simple_async_result_get_op_res_gboolean (simple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_remote_connection_delete:
|
* nm_remote_connection_delete:
|
||||||
* @connection: the #NMRemoteConnection
|
* @connection: the #NMRemoteConnection
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,19 @@ typedef struct {
|
||||||
|
|
||||||
GType nm_remote_connection_get_type (void);
|
GType nm_remote_connection_get_type (void);
|
||||||
|
|
||||||
|
NM_AVAILABLE_IN_1_12
|
||||||
|
void nm_remote_connection_update2 (NMRemoteConnection *connection,
|
||||||
|
GVariant *settings,
|
||||||
|
NMSettingsUpdate2Flags flags,
|
||||||
|
GVariant *args,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
NM_AVAILABLE_IN_1_12
|
||||||
|
GVariant *nm_remote_connection_update2_finish (NMRemoteConnection *connection,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean nm_remote_connection_commit_changes (NMRemoteConnection *connection,
|
gboolean nm_remote_connection_commit_changes (NMRemoteConnection *connection,
|
||||||
gboolean save_to_disk,
|
gboolean save_to_disk,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue