Commit 1bce0a09 authored by Thomas Haller's avatar Thomas Haller

libnm: implement nm_client_checkpoint_rollback() by using GDBusConnection directly

parent 3a505853
......@@ -2749,25 +2749,6 @@ nm_client_checkpoint_destroy_finish (NMClient *client,
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
checkpoint_rollback_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GHashTable *hash;
GError *error = NULL;
hash = nm_manager_checkpoint_rollback_finish (NM_MANAGER (object), result, &error);
if (hash)
g_simple_async_result_set_op_res_gpointer (simple, hash, (GDestroyNotify) g_hash_table_unref);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_client_checkpoint_rollback:
* @client: the %NMClient
......@@ -2787,24 +2768,22 @@ nm_client_checkpoint_rollback (NMClient *client,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/');
if (!_nm_client_check_nm_running (client, &error)) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
return;
}
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
nm_client_checkpoint_rollback);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nm_manager_checkpoint_rollback (NM_CLIENT_GET_PRIVATE (client)->manager,
checkpoint_path,
cancellable, checkpoint_rollback_cb, simple);
_nm_object_dbus_call (client,
nm_client_checkpoint_rollback,
cancellable,
callback,
user_data,
NM_DBUS_PATH,
NM_DBUS_INTERFACE,
"CheckpointRollback",
g_variant_new ("(o)", checkpoint_path),
G_VARIANT_TYPE ("(a{su})"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb);
}
/**
......@@ -2826,19 +2805,31 @@ nm_client_checkpoint_rollback_finish (NMClient *client,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
gs_unref_variant GVariant *ret = NULL;
gs_unref_variant GVariant *v_result = NULL;
GVariantIter iter;
GHashTable *hash;
const char *path;
guint32 r;
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
g_return_val_if_fail (nm_g_task_is_valid (result, client, nm_client_checkpoint_rollback), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
ret = g_task_propagate_pointer (G_TASK (result), error);
if (!ret)
return NULL;
else {
hash = g_simple_async_result_get_op_res_gpointer (simple);
return g_hash_table_ref (hash);
}
g_variant_get (ret,
"(@a{su})",
&v_result);
hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL);
g_variant_iter_init (&iter, v_result);
while (g_variant_iter_next (&iter, "{&su}", &path, &r))
g_hash_table_insert (hash, g_strdup (path), GUINT_TO_POINTER (r));
return hash;
}
static void
......
......@@ -1076,77 +1076,6 @@ nm_manager_wait_for_checkpoint (NMManager *self,
}
}
static void
checkpoint_rollback_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
GVariant *variant = NULL;
GVariantIter iter;
GHashTable *hash;
const char *path;
guint r;
if (nmdbus_manager_call_checkpoint_rollback_finish (NMDBUS_MANAGER (object),
&variant,
result,
&error)) {
hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, NULL);
g_variant_iter_init (&iter, variant);
while (g_variant_iter_next (&iter, "{&su}", &path, &r))
g_hash_table_insert (hash, g_strdup (path), GUINT_TO_POINTER (r));
g_simple_async_result_set_op_res_gpointer (simple, hash, (GDestroyNotify) g_hash_table_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);
}
void
nm_manager_checkpoint_rollback (NMManager *manager,
const char *checkpoint_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_MANAGER (manager));
g_return_if_fail (checkpoint_path && checkpoint_path[0] == '/');
simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
nm_manager_checkpoint_rollback);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_manager_call_checkpoint_rollback (NM_MANAGER_GET_PRIVATE (manager)->proxy,
checkpoint_path,
cancellable,
checkpoint_rollback_cb, simple);
}
GHashTable *
nm_manager_checkpoint_rollback_finish (NMManager *manager,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager),
nm_manager_checkpoint_rollback),
NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NULL;
else
return g_hash_table_ref (g_simple_async_result_get_op_res_gpointer (simple));
}
static void
checkpoint_adjust_rollback_timeout_cb (GObject *object,
GAsyncResult *result,
......
......@@ -147,14 +147,6 @@ void nm_manager_wait_for_checkpoint (NMManager *self,
const char *checkpoint_path,
GTask *task_take);
void nm_manager_checkpoint_rollback (NMManager *manager,
const char *checkpoint_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GHashTable *nm_manager_checkpoint_rollback_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_adjust_rollback_timeout (NMManager *manager,
const char *checkpoint_path,
guint32 add_timeout,
......
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