[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-glib] [PATCH v2 4/4] GVirDomainSnapshot: Add async version of _delete



---
 libvirt-gobject/libvirt-gobject-domain-snapshot.c | 58 +++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-domain-snapshot.h | 10 ++++
 libvirt-gobject/libvirt-gobject.sym               |  2 +
 3 files changed, 70 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
index 0dcbecc..9c0d60f 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c
@@ -237,6 +237,64 @@ gboolean gvir_domain_snapshot_delete (GVirDomainSnapshot *snapshot,
 }
 
 
+
+static void _delete_async_thread(GTask *task,
+                                 gpointer source_object,
+                                 gpointer task_data,
+                                 GCancellable *cancellable) {
+    GError *error = NULL;
+    gboolean status;
+
+    status = gvir_domain_snapshot_delete(source_object,
+                                         GPOINTER_TO_UINT(task_data),
+                                         &error);
+
+    if (status)
+        g_task_return_boolean(task, TRUE);
+    else
+        g_task_return_error(task, error);
+}
+
+
+/**
+ * gvir_domain_snapshot_delete_async:
+ * @snapshot: A #GVirDomainSnapshot
+ * @flags: Bitwise-OR of #GVirDomainSnapshotDeleteFlags
+ * @cancellable: (allow-none) (transfer none): cancellation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ */
+void gvir_domain_snapshot_delete_async(GVirDomainSnapshot *snapshot,
+                                       guint flags,
+                                       GCancellable *cancellable,
+                                       GAsyncReadyCallback callback,
+                                       gpointer user_data) {
+    GTask *task;
+
+    g_return_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot));
+
+    task = g_task_new(snapshot, cancellable, callback, user_data);
+    g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
+    g_task_run_in_thread(task, _delete_async_thread);
+    g_object_unref(task);
+}
+
+/**
+ * gvir_domain_snapshot_delete_finish:
+ * @snapshot: A #GVirDomainSnapshot
+ * @res: (transfer none): async method result
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ */
+gboolean gvir_domain_snapshot_delete_finish(GVirDomainSnapshot *snapshot,
+                                            GAsyncResult *res,
+                                            GError **error) {
+    g_return_val_if_fail(GVIR_IS_DOMAIN_SNAPSHOT(snapshot), FALSE);
+    g_return_val_if_fail(g_task_is_valid(res, snapshot), FALSE);
+
+    return g_task_propagate_boolean(G_TASK(res), error);
+}
+
 /**
  * gvir_domain_snapshot_get_is_current:
  * @snapshot: The domain snapshot
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
index 0f4d31f..68bad27 100644
--- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h
+++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h
@@ -98,6 +98,16 @@ gboolean gvir_domain_snapshot_delete (GVirDomainSnapshot *snapshot,
                                       guint flags,
                                       GError **error);
 
+void gvir_domain_snapshot_delete_async(GVirDomainSnapshot *snapshot,
+                                       guint flags,
+                                       GCancellable *cancellable,
+                                       GAsyncReadyCallback callback,
+                                       gpointer user_data);
+
+gboolean gvir_domain_snapshot_delete_finish(GVirDomainSnapshot *snapshot,
+                                            GAsyncResult *res,
+                                            GError **error);
+
 gboolean gvir_domain_snapshot_get_is_current(GVirDomainSnapshot *snapshot,
                                              guint flags,
                                              gboolean *is_current,
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index a610121..f335399 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -244,6 +244,8 @@ LIBVIRT_GOBJECT_0.1.9 {
 	gvir_domain_get_snapshots;
 	gvir_domain_get_has_current_snapshot;
 	gvir_domain_snapshot_delete;
+	gvir_domain_snapshot_delete_async;
+	gvir_domain_snapshot_delete_finish;
 	gvir_domain_snapshot_delete_flags_get_type;
 	gvir_domain_snapshot_get_is_current;
 	gvir_domain_snapshot_list_flags_get_type;
-- 
2.0.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]