On Thu, Jun 21, 2012 at 03:12:39PM +0200, Marc-André Lureau wrote:
---
libvirt-gobject/libvirt-gobject-domain.c | 75 ++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 9 ++++
libvirt-gobject/libvirt-gobject.sym | 3 ++
3 files changed, 87 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c
b/libvirt-gobject/libvirt-gobject-domain.c
index 59af63f..088cd33 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -345,6 +345,81 @@ gboolean gvir_domain_start(GVirDomain *dom,
return TRUE;
}
+typedef struct {
+ guint flags;
+} DomainStartData;
+
+static void domain_start_data_free(DomainStartData *data)
+{
+ g_slice_free(DomainStartData, data);
+}
+
+static void
+gvir_domain_start_helper(GSimpleAsyncResult *res,
+ GObject *object,
+ GCancellable *cancellable G_GNUC_UNUSED)
+{
+ GVirDomain *dom = GVIR_DOMAIN(object);
+ DomainStartData *data;
+ GError *err = NULL;
+
+ data = g_simple_async_result_get_op_res_gpointer(res);
+
+ if (!gvir_domain_start(dom, data->flags, &err))
+ g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_domain_start_async:
+ * @dom: the domain
+ * @flags: the flags
+ * @cancellable: (allow-none)(transfer none): cancellation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_start.
+ */
+void gvir_domain_start_async(GVirDomain *dom,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res;
+ DomainStartData *data;
+
+ g_return_if_fail(GVIR_IS_DOMAIN(dom));
+ g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+ data = g_slice_new0(DomainStartData);
+ data->flags = flags;
+
+ res = g_simple_async_result_new(G_OBJECT(dom),
+ callback,
+ user_data,
+ gvir_domain_start_async);
+ g_simple_async_result_set_op_res_gpointer (res, data,
(GDestroyNotify)domain_start_data_free);
This looks like a slight abuse of the GSimpleAsyncResult API as I
understand it (set_op_res_* is meant to give the result of the async
operation to the API user, not to transfer some helper data to the async machinery),
but there are already other parts of the code doing that.
ACK.
Christophe