Drop usage of deprecated GSimpleAsyncResult API. --- libvirt-gobject/libvirt-gobject-domain.c | 273 +++++++++++------------ libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++---- libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++---- libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++++++++++-------------- libvirt-gobject/libvirt-gobject-stream.c | 52 +++-- 5 files changed, 333 insertions(+), 425 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 34eb7ca..6d57a73 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -380,18 +380,19 @@ static void domain_start_data_free(DomainStartData *data) } static void -gvir_domain_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); - DomainStartData *data; + GVirDomain *dom = GVIR_DOMAIN(source_object); + DomainStartData *data = (DomainStartData *) task_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); + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -410,7 +411,7 @@ void gvir_domain_start_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; DomainStartData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); @@ -419,16 +420,13 @@ void gvir_domain_start_async(GVirDomain *dom, 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); - g_simple_async_result_run_in_thread(res, - gvir_domain_start_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify)domain_start_data_free); + g_task_run_in_thread(task, gvir_domain_start_helper); + g_object_unref(task); } gboolean gvir_domain_start_finish(GVirDomain *dom, @@ -436,13 +434,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE); + g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -472,15 +467,18 @@ gboolean gvir_domain_resume(GVirDomain *dom, } static void -gvir_domain_resume_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_resume_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); + GVirDomain *dom = GVIR_DOMAIN(source_object); GError *err = NULL; if (!gvir_domain_resume(dom, &err)) - g_simple_async_result_take_error(res, err); + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -497,20 +495,17 @@ void gvir_domain_resume_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(dom), - callback, - user_data, - gvir_domain_resume_async); - g_simple_async_result_run_in_thread(res, - gvir_domain_resume_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_domain_resume_helper); + g_object_unref(task); } gboolean gvir_domain_resume_finish(GVirDomain *dom, @@ -518,13 +513,10 @@ gboolean gvir_domain_resume_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_resume_async), FALSE); + g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -555,16 +547,29 @@ gboolean gvir_domain_wakeup(GVirDomain *dom, return TRUE; } +typedef struct { + guint flags; +} DomainWakeupData; + +static void domain_wakeup_data_free(DomainWakeupData *data) +{ + g_slice_free(DomainWakeupData, data); +} + static void -gvir_domain_wakeup_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_wakeup_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); + GVirDomain *dom = GVIR_DOMAIN(source_object); + DomainWakeupData *data = (DomainWakeupData *) task_data; GError *err = NULL; - if (!gvir_domain_wakeup(dom, (guint)g_simple_async_result_get_op_res_gssize(res), &err)) - g_simple_async_result_take_error(res, err); + if (!gvir_domain_wakeup(dom, data->flags, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -583,21 +588,22 @@ void gvir_domain_wakeup_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; + DomainWakeupData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(dom), - callback, - user_data, - gvir_domain_wakeup_async); - g_simple_async_result_set_op_res_gssize (res, (gssize)flags); - g_simple_async_result_run_in_thread(res, - gvir_domain_wakeup_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + data = g_slice_new0(DomainWakeupData); + data->flags = flags; + + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify)domain_wakeup_data_free); + g_task_run_in_thread(task, gvir_domain_wakeup_helper); + g_object_unref(task); } gboolean gvir_domain_wakeup_finish(GVirDomain *dom, @@ -605,13 +611,10 @@ gboolean gvir_domain_wakeup_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_wakeup_async), FALSE); + g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -785,18 +788,19 @@ static void domain_save_to_file_data_free(DomainSaveToFileData *data) } static void -gvir_domain_save_to_file_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_save_to_file_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); - DomainSaveToFileData *data; + GVirDomain *dom = GVIR_DOMAIN(source_object); + DomainSaveToFileData *data = (DomainSaveToFileData *) task_data; GError *err = NULL; - data = g_simple_async_result_get_op_res_gpointer(res); - if (!gvir_domain_save_to_file(dom, data->filename, data->custom_conf, data->flags, &err)) - g_simple_async_result_take_error(res, err); + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -819,7 +823,7 @@ void gvir_domain_save_to_file_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; DomainSaveToFileData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); @@ -832,19 +836,15 @@ void gvir_domain_save_to_file_async(GVirDomain *dom, data->custom_conf = g_object_ref(custom_conf); data->flags = flags; - res = g_simple_async_result_new(G_OBJECT(dom), - callback, - user_data, - gvir_domain_save_to_file_async); - g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify) - domain_save_to_file_data_free); - - g_simple_async_result_run_in_thread(res, - gvir_domain_save_to_file_helper, - G_PRIORITY_DEFAULT, - cancellable); - - g_object_unref(res); + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_set_task_data(task, + data, + (GDestroyNotify) domain_save_to_file_data_free); + g_task_run_in_thread(task, gvir_domain_save_to_file_helper); + g_object_unref(task); } /** @@ -862,16 +862,10 @@ gboolean gvir_domain_save_to_file_finish(GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid - (result, - G_OBJECT(dom), - gvir_domain_save_to_file_async), FALSE); + g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -1012,22 +1006,22 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, } static void -gvir_domain_get_info_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_get_info_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); + GVirDomain *dom = GVIR_DOMAIN(source_object); GVirDomainInfo *info; GError *err = NULL; info = gvir_domain_get_info(dom, &err); if (err) - g_simple_async_result_take_error(res, err); + g_task_return_error(task, err); else - g_simple_async_result_set_op_res_gpointer - (res, - info, - (GDestroyNotify) gvir_domain_info_free); + g_task_return_pointer(task, + info, + (GDestroyNotify) gvir_domain_info_free); } /** @@ -1044,20 +1038,17 @@ void gvir_domain_get_info_async(GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; g_return_if_fail(GVIR_IS_DOMAIN(dom)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(dom), - callback, - user_data, - gvir_domain_get_info_async); - g_simple_async_result_run_in_thread(res, - gvir_domain_get_info_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_domain_get_info_helper); + g_object_unref(task); } /** @@ -1075,22 +1066,11 @@ GVirDomainInfo *gvir_domain_get_info_finish(GVirDomain *dom, GAsyncResult *result, GError **err) { - GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT(result); - GVirDomainInfo *ret; - g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL); - g_return_val_if_fail - (g_simple_async_result_is_valid(result, - G_OBJECT(dom), - gvir_domain_get_info_async), - NULL); - - if (g_simple_async_result_propagate_error(res, err)) - return NULL; - - ret = g_simple_async_result_get_op_res_gpointer(res); + g_return_val_if_fail(g_task_is_valid(result, dom), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); - return gvir_domain_info_copy (ret); + return g_task_propagate_pointer(G_TASK(result), err); } /** @@ -1375,18 +1355,19 @@ static void domain_save_data_free(DomainSaveData *data) } static void -gvir_domain_save_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_domain_save_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirDomain *dom = GVIR_DOMAIN(object); - DomainSaveData *data; + GVirDomain *dom = GVIR_DOMAIN(source_object); + DomainSaveData *data = (DomainSaveData *) task_data; GError *err = NULL; - data = g_simple_async_result_get_op_res_gpointer (res); - if (!gvir_domain_save(dom, data->flags, &err)) - g_simple_async_result_take_error(res, err); + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -1405,7 +1386,7 @@ void gvir_domain_save_async (GVirDomain *dom, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; DomainSaveData *data; g_return_if_fail(GVIR_IS_DOMAIN(dom)); @@ -1414,16 +1395,13 @@ void gvir_domain_save_async (GVirDomain *dom, data = g_slice_new0(DomainSaveData); data->flags = flags; - res = g_simple_async_result_new(G_OBJECT(dom), - callback, - user_data, - gvir_domain_save_async); - g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) domain_save_data_free); - g_simple_async_result_run_in_thread(res, - gvir_domain_save_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(dom), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify) domain_save_data_free); + g_task_run_in_thread(task, gvir_domain_save_helper); + g_object_unref(task); } /** @@ -1441,15 +1419,10 @@ gboolean gvir_domain_save_finish (GVirDomain *dom, GError **err) { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), - gvir_domain_save_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, dom), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -1682,6 +1655,7 @@ GVirDomainSnapshot *gvir_domain_create_snapshot_finish(GVirDomain *domain, GError **error) { g_return_val_if_fail(g_task_is_valid(result, domain), NULL); + g_return_val_if_fail(error == NULL || *error == NULL, NULL); return g_task_propagate_pointer(G_TASK(result), error); } @@ -1847,6 +1821,7 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain *dom, { g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); g_return_val_if_fail(g_task_is_valid(res, dom), FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); return g_task_propagate_boolean(G_TASK(res), error); } diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c index ff1a70c..cd107e1 100644 --- a/libvirt-gobject/libvirt-gobject-input-stream.c +++ b/libvirt-gobject/libvirt-gobject-input-stream.c @@ -45,8 +45,7 @@ struct _GVirInputStreamPrivate GVirStream *stream; /* pending operation metadata */ - GSimpleAsyncResult *result; - GCancellable *cancellable; + GTask *task; gpointer buffer; gsize count; }; @@ -103,48 +102,44 @@ gvir_input_stream_read_ready(GVirStream *stream, { GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque); GVirInputStreamPrivate *priv = input_stream->priv; - GSimpleAsyncResult *simple = priv->result; + GTask *task = priv->task; + GCancellable *cancellable = g_task_get_cancellable(task); GError *error = NULL; gssize result; + priv->task = NULL; + if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) { g_warn_if_reached(); - g_simple_async_result_set_error(simple, - G_IO_ERROR, - G_IO_ERROR_INVALID_ARGUMENT, - "%s", - "Expected stream to be readable"); + g_task_return_new_error(task, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + "%s", + "Expected stream to be readable"); goto cleanup; } - result = gvir_stream_receive(stream, priv->buffer, priv->count, - priv->cancellable, &error); + result = gvir_stream_receive(stream, priv->buffer, priv->count, + cancellable, &error); + if (error != NULL) { + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { + g_warn_if_reached(); + g_task_return_new_error(task, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + "%s", + "Expected stream to be readable"); + } else { + g_task_return_error(task, error); + } - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { - g_warn_if_reached(); - g_simple_async_result_set_error(simple, - G_IO_ERROR, - G_IO_ERROR_INVALID_ARGUMENT, - "%s", - "Expected stream to be readable"); goto cleanup; } - if (result >= 0) - g_simple_async_result_set_op_res_gssize(simple, result); - - if (error) - g_simple_async_result_take_error(simple, error); - - if (priv->cancellable) { - g_object_unref(priv->cancellable); - priv->cancellable = NULL; - } + g_task_return_int(task, result); cleanup: - priv->result = NULL; - g_simple_async_result_complete(simple); - g_object_unref(simple); + g_object_unref(task); return FALSE; } @@ -159,7 +154,7 @@ static void gvir_input_stream_read_async(GInputStream *stream, GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream); g_return_if_fail(GVIR_IS_INPUT_STREAM(stream)); - g_return_if_fail(input_stream->priv->result == NULL); + g_return_if_fail(input_stream->priv->task == NULL); gvir_stream_add_watch_full(input_stream->priv->stream, G_PRIORITY_DEFAULT, @@ -168,12 +163,8 @@ static void gvir_input_stream_read_async(GInputStream *stream, g_object_ref(stream), (GDestroyNotify)g_object_unref); - input_stream->priv->result = - g_simple_async_result_new(G_OBJECT(stream), callback, user_data, - gvir_input_stream_read_async); - if (cancellable) - g_object_ref(cancellable); - input_stream->priv->cancellable = cancellable; + input_stream->priv->task = + g_task_new(stream, cancellable, callback, user_data); input_stream->priv->buffer = buffer; input_stream->priv->count = count; } @@ -181,22 +172,18 @@ static void gvir_input_stream_read_async(GInputStream *stream, static gssize gvir_input_stream_read_finish(GInputStream *stream, GAsyncResult *result, - GError **error G_GNUC_UNUSED) + GError **error) { GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream); - GSimpleAsyncResult *simple; virStreamPtr handle; gssize count; g_return_val_if_fail(GVIR_IS_INPUT_STREAM(stream), -1); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream), - gvir_input_stream_read_async), - -1); + g_return_val_if_fail(g_task_is_valid(result, stream), -1); + g_return_val_if_fail(error == NULL || *error == NULL, -1); g_object_get(input_stream->priv->stream, "handle", &handle, NULL); - simple = G_SIMPLE_ASYNC_RESULT(result); - - count = g_simple_async_result_get_op_res_gssize(simple); + count = g_task_propagate_int(G_TASK(result), error); virStreamFree(handle); diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c index f39328b..a9c1236 100644 --- a/libvirt-gobject/libvirt-gobject-output-stream.c +++ b/libvirt-gobject/libvirt-gobject-output-stream.c @@ -45,8 +45,7 @@ struct _GVirOutputStreamPrivate GVirStream *stream; /* pending operation metadata */ - GSimpleAsyncResult *result; - GCancellable *cancellable; + GTask *task; const void * buffer; gsize count; }; @@ -103,48 +102,44 @@ gvir_output_stream_write_ready(GVirStream *stream, { GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(opaque); GVirOutputStreamPrivate *priv = output_stream->priv; - GSimpleAsyncResult *simple = priv->result; + GTask *task = priv->task; + GCancellable *cancellable = g_task_get_cancellable(task); GError *error = NULL; gssize result; if (!(cond & GVIR_STREAM_IO_CONDITION_WRITABLE)) { g_warn_if_reached(); - g_simple_async_result_set_error(simple, - G_IO_ERROR, - G_IO_ERROR_INVALID_ARGUMENT, - "%s", - "Expected stream to be writable"); + g_task_return_new_error(task, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + "%s", + "Expected stream to be readable"); goto cleanup; } result = gvir_stream_send(stream, priv->buffer, priv->count, - priv->cancellable, &error); + cancellable, &error); + + if (error != NULL) { + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { + g_warn_if_reached(); + g_task_return_new_error(task, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + "%s", + "Expected stream to be writable"); + } else { + g_task_return_error(task, error); + } - if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { - g_warn_if_reached(); - g_simple_async_result_set_error(simple, - G_IO_ERROR, - G_IO_ERROR_INVALID_ARGUMENT, - "%s", - "Expected stream to be writable"); goto cleanup; } - if (result >= 0) - g_simple_async_result_set_op_res_gssize(simple, result); - - if (error) - g_simple_async_result_take_error(simple, error); - - if (priv->cancellable) { - g_object_unref(priv->cancellable); - priv->cancellable = NULL; - } + g_task_return_int(task, result); cleanup: - priv->result = NULL; - g_simple_async_result_complete(simple); - g_object_unref(simple); + priv->task = NULL; + g_object_unref(task); return FALSE; } @@ -159,7 +154,7 @@ static void gvir_output_stream_write_async(GOutputStream *stream, GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream)); - g_return_if_fail(output_stream->priv->result == NULL); + g_return_if_fail(output_stream->priv->task == NULL); gvir_stream_add_watch_full(output_stream->priv->stream, G_PRIORITY_DEFAULT, @@ -168,12 +163,8 @@ static void gvir_output_stream_write_async(GOutputStream *stream, g_object_ref(stream), (GDestroyNotify)g_object_unref); - output_stream->priv->result = - g_simple_async_result_new(G_OBJECT(stream), callback, user_data, - gvir_output_stream_write_async); - if (cancellable) - g_object_ref(cancellable); - output_stream->priv->cancellable = cancellable; + output_stream->priv->task = + g_task_new(stream, cancellable, callback, user_data); output_stream->priv->buffer = buffer; output_stream->priv->count = count; } @@ -181,22 +172,18 @@ static void gvir_output_stream_write_async(GOutputStream *stream, static gssize gvir_output_stream_write_finish(GOutputStream *stream, GAsyncResult *result, - GError **error G_GNUC_UNUSED) + GError **error) { GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); - GSimpleAsyncResult *simple; virStreamPtr handle; gssize count; g_return_val_if_fail(GVIR_IS_OUTPUT_STREAM(stream), -1); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream), - gvir_output_stream_write_async), - -1); + g_return_val_if_fail(g_task_is_valid(result, stream), -1); + g_return_val_if_fail(error == NULL || *error == NULL, -1); g_object_get(output_stream->priv->stream, "handle", &handle, NULL); - simple = G_SIMPLE_ASYNC_RESULT(result); - - count = g_simple_async_result_get_op_res_gssize(simple); + count = g_task_propagate_int(G_TASK(result), error); virStreamFree(handle); diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index a0dcebc..6290fcb 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -439,17 +439,18 @@ cleanup: } static void -gvir_storage_pool_refresh_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_refresh_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); GError *err = NULL; - if (!gvir_storage_pool_refresh(pool, cancellable, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } + if (!gvir_storage_pool_refresh(pool, cancellable, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -464,20 +465,17 @@ void gvir_storage_pool_refresh_async(GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_refresh_async); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_refresh_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_storage_pool_refresh_helper); + g_object_unref(task); } /** @@ -490,15 +488,10 @@ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_refresh_async), - FALSE); - - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); + g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED) @@ -658,24 +651,25 @@ typedef struct { guint flags; } StoragePoolBuildData; +static void storage_pool_build_data_free(StoragePoolBuildData *data) +{ + g_slice_free(StoragePoolBuildData, data); +} + static void -gvir_storage_pool_build_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_build_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); - StoragePoolBuildData *data; + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); + StoragePoolBuildData *data = (StoragePoolBuildData *) task_data; GError *err = NULL; - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), - "StoragePoolBuildData"); - - if (!gvir_storage_pool_build(pool, data->flags, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } - - g_slice_free (StoragePoolBuildData, data); + if (!gvir_storage_pool_build(pool, data->flags, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -692,7 +686,7 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; StoragePoolBuildData *data; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); @@ -701,16 +695,13 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool, data = g_slice_new0(StoragePoolBuildData); data->flags = flags; - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_build_async); - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_build_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); + g_task_run_in_thread(task, gvir_storage_pool_build_helper); + g_object_unref(task); } /** @@ -726,16 +717,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_build_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -762,17 +747,18 @@ gboolean gvir_storage_pool_undefine (GVirStoragePool *pool, } static void -gvir_storage_pool_undefine_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_undefine_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); GError *err = NULL; - if (!gvir_storage_pool_undefine(pool, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } + if (!gvir_storage_pool_undefine(pool, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -787,20 +773,17 @@ void gvir_storage_pool_undefine_async (GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_undefine_async); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_undefine_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_storage_pool_undefine_helper); + g_object_unref(task); } /** @@ -816,16 +799,10 @@ gboolean gvir_storage_pool_undefine_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_undefine_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -854,23 +831,21 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool, } static void -gvir_storage_pool_start_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_start_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); StoragePoolBuildData *data; GError *err = NULL; - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), - "StoragePoolBuildData"); + data = (StoragePoolBuildData *) task_data; - if (!gvir_storage_pool_start(pool, data->flags, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } - - g_slice_free (StoragePoolBuildData, data); + if (!gvir_storage_pool_start(pool, data->flags, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -887,7 +862,7 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; StoragePoolBuildData *data; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); @@ -896,16 +871,13 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool, data = g_slice_new0(StoragePoolBuildData); data->flags = flags; - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_start_async); - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_start_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); + g_task_run_in_thread(task, gvir_storage_pool_start_helper); + g_object_unref(task); } /** @@ -921,16 +893,10 @@ gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_start_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -957,17 +923,18 @@ gboolean gvir_storage_pool_stop (GVirStoragePool *pool, } static void -gvir_storage_pool_stop_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_stop_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, GCancellable *cancellable G_GNUC_UNUSED) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); GError *err = NULL; - if (!gvir_storage_pool_stop(pool, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } + if (!gvir_storage_pool_stop(pool, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -982,20 +949,17 @@ void gvir_storage_pool_stop_async (GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_stop_async); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_stop_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_storage_pool_stop_helper); + g_object_unref(task); } /** @@ -1011,16 +975,10 @@ gboolean gvir_storage_pool_stop_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_stop_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } /** @@ -1100,23 +1058,21 @@ gboolean gvir_storage_pool_set_autostart(GVirStoragePool *pool, } static void -gvir_storage_pool_delete_helper(GSimpleAsyncResult *res, - GObject *object, +gvir_storage_pool_delete_helper(GTask *task, + gpointer source_object, + gpointer task_data, GCancellable *cancellable G_GNUC_UNUSED) { - GVirStoragePool *pool = GVIR_STORAGE_POOL(object); + GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object); StoragePoolBuildData *data; GError *err = NULL; - data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res), - "StoragePoolBuildData"); + data = (StoragePoolBuildData *) task_data; - if (!gvir_storage_pool_delete(pool, data->flags, &err)) { - g_simple_async_result_set_from_error(res, err); - g_error_free(err); - } - - g_slice_free (StoragePoolBuildData, data); + if (!gvir_storage_pool_delete(pool, data->flags, &err)) + g_task_return_error(task, err); + else + g_task_return_boolean(task, TRUE); } /** @@ -1133,7 +1089,7 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool, GAsyncReadyCallback callback, gpointer user_data) { - GSimpleAsyncResult *res; + GTask *task; StoragePoolBuildData *data; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); @@ -1142,16 +1098,13 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool, data = g_slice_new0(StoragePoolBuildData); data->flags = flags; - res = g_simple_async_result_new(G_OBJECT(pool), - callback, - user_data, - gvir_storage_pool_delete_async); - g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data); - g_simple_async_result_run_in_thread(res, - gvir_storage_pool_delete_helper, - G_PRIORITY_DEFAULT, - cancellable); - g_object_unref(res); + task = g_task_new(G_OBJECT(pool), + cancellable, + callback, + user_data); + g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free); + g_task_run_in_thread(task, gvir_storage_pool_delete_helper); + g_object_unref(task); } /** @@ -1167,16 +1120,10 @@ gboolean gvir_storage_pool_delete_finish(GVirStoragePool *pool, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); - g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), - gvir_storage_pool_delete_async), - FALSE); + g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), - err)) - return FALSE; - - return TRUE; + return g_task_propagate_boolean(G_TASK(result), err); } G_GNUC_INTERNAL void gvir_storage_pool_delete_vol(GVirStoragePool *pool, diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c index 46dbd9a..a40ac99 100644 --- a/libvirt-gobject/libvirt-gobject-stream.c +++ b/libvirt-gobject/libvirt-gobject-stream.c @@ -129,14 +129,13 @@ static gboolean gvir_stream_close(GIOStream *io_stream, return (i_ret && o_ret); } - -static void gvir_stream_close_async(GIOStream *stream, - int io_priority G_GNUC_UNUSED, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +static void +gvir_stream_close_helper(GTask *task, + gpointer source_object, + gpointer task_data G_GNUC_UNUSED, + GCancellable *cancellable) { - GSimpleAsyncResult *res; + GIOStream *stream = G_IO_STREAM(source_object); GIOStreamClass *class; GError *error; @@ -146,27 +145,40 @@ static void gvir_stream_close_async(GIOStream *stream, error = NULL; if (class->close_fn && !class->close_fn(stream, cancellable, &error)) { - g_simple_async_report_take_gerror_in_idle(G_OBJECT (stream), - callback, user_data, - error); + g_task_return_error(task, error); return; } - res = g_simple_async_result_new(G_OBJECT (stream), - callback, - user_data, - gvir_stream_close_async); - g_simple_async_result_complete_in_idle(res); - g_object_unref (res); + g_task_return_boolean(task, TRUE); +} + +static void gvir_stream_close_async(GIOStream *stream, + int io_priority G_GNUC_UNUSED, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + task = g_task_new(G_OBJECT(stream), + cancellable, + callback, + user_data); + g_task_run_in_thread(task, gvir_stream_close_helper); + g_object_unref(task); } static gboolean -gvir_stream_close_finish(GIOStream *stream G_GNUC_UNUSED, - GAsyncResult *result G_GNUC_UNUSED, - GError **error G_GNUC_UNUSED) +gvir_stream_close_finish(GIOStream *stream, + GAsyncResult *result, + GError **error) { - return TRUE; + g_return_val_if_fail(GVIR_IS_STREAM(stream), -1); + g_return_val_if_fail(g_task_is_valid(result, stream), -1); + g_return_val_if_fail(error == NULL || *error == NULL, -1); + + return g_task_propagate_boolean(G_TASK(result), error); } -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list