1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include <sys/types.h>
34 #include "gsimpleasyncresult.h"
35 #include "gasyncresult.h"
36 #include "gcancellable.h"
37 #include "gioscheduler.h"
38 #include <gio/gioerror.h>
43 * SECTION:gsimpleasyncresult
44 * @short_description: Simple asynchronous results implementation
46 * @see_also: #GAsyncResult
48 * Implements #GAsyncResult for simple cases. Most of the time, this
49 * will be all an application needs, and will be used transparently.
50 * Because of this, #GSimpleAsyncResult is used throughout GIO for
51 * handling asynchronous functions.
53 * GSimpleAsyncResult handles #GAsyncReadyCallback<!-- -->s, error
54 * reporting, operation cancellation and the final state of an operation,
55 * completely transparent to the application. Results can be returned
56 * as a pointer e.g. for functions that return data that is collected
57 * asynchronously, a boolean value for checking the success or failure
58 * of an operation, or a #gssize for operations which return the number
59 * of bytes modified by the operation; all of the simple return cases
62 * Most of the time, an application will not need to know of the details
63 * of this API; it is handled transparently, and any necessary operations
64 * are handled by #GAsyncResult's interface. However, if implementing a
65 * new GIO module, for writing language bindings, or for complex
66 * applications that need better control of how asynchronous operations
67 * are completed, it is important to understand this functionality.
69 * GSimpleAsyncResults are tagged with the calling function to ensure
70 * that asynchronous functions and their finishing functions are used
73 * To create a new #GSimpleAsyncResult, call g_simple_async_result_new().
74 * If the result needs to be created for a #GError, use
75 * g_simple_async_result_new_from_error(). If a #GError is not available
76 * (e.g. the asynchronous operation's doesn't take a #GError argument),
77 * but the result still needs to be created for an error condition, use
78 * g_simple_async_result_new_error() (or g_simple_async_result_set_error_va()
79 * if your application or binding requires passing a variable argument list
80 * directly), and the error can then be propagated through the use of
81 * g_simple_async_result_propagate_error().
83 * An asynchronous operation can be made to ignore a cancellation event by
84 * calling g_simple_async_result_set_handle_cancellation() with a
85 * #GSimpleAsyncResult for the operation and %FALSE. This is useful for
86 * operations that are dangerous to cancel, such as close (which would
87 * cause a leak if cancelled before being run).
89 * GSimpleAsyncResult can integrate into GLib's event loop, #GMainLoop,
90 * or it can use #GThread<!-- -->s if available.
91 * g_simple_async_result_complete() will finish an I/O task directly
92 * from the point where it is called. g_simple_async_result_complete_in_idle()
93 * will finish it from an idle handler in the <link
94 * linkend="g-main-context-push-thread-default">thread-default main
95 * context</link>. g_simple_async_result_run_in_thread() will run the
96 * job in a separate thread and then deliver the result to the
97 * thread-default main context.
99 * To set the results of an asynchronous function,
100 * g_simple_async_result_set_op_res_gpointer(),
101 * g_simple_async_result_set_op_res_gboolean(), and
102 * g_simple_async_result_set_op_res_gssize()
103 * are provided, setting the operation's result to a gpointer, gboolean, or
104 * gssize, respectively.
106 * Likewise, to get the result of an asynchronous function,
107 * g_simple_async_result_get_op_res_gpointer(),
108 * g_simple_async_result_get_op_res_gboolean(), and
109 * g_simple_async_result_get_op_res_gssize() are
110 * provided, getting the operation's result as a gpointer, gboolean, and
111 * gssize, respectively.
113 * For the details of the requirements implementations must respect, see
114 * #GAsyncResult. A typical implementation of an asynchronous operation
115 * using GSimpleAsyncResult looks something like this:
119 * baked_cb (Cake *cake,
120 * gpointer user_data)
122 * /* In this example, this callback is not given a reference to the cake, so
123 * * the GSimpleAsyncResult has to take a reference to it.
125 * GSimpleAsyncResult *result = user_data;
128 * g_simple_async_result_set_error (result,
130 * BAKER_ERROR_NO_FLOUR,
131 * "Go to the supermarket");
133 * g_simple_async_result_set_op_res_gpointer (result,
134 * g_object_ref (cake),
138 * /* In this example, we assume that baked_cb is called as a callback from
139 * * the mainloop, so it's safe to complete the operation synchronously here.
140 * * If, however, _baker_prepare_cake () might call its callback without
141 * * first returning to the mainloop — inadvisable, but some APIs do so —
142 * * we would need to use g_simple_async_result_complete_in_idle().
144 * g_simple_async_result_complete (result);
145 * g_object_unref (result);
149 * baker_bake_cake_async (Baker *self,
151 * GAsyncReadyCallback callback,
152 * gpointer user_data)
154 * GSimpleAsyncResult *simple;
159 * g_simple_async_report_error_in_idle (G_OBJECT (self),
163 * BAKER_ERROR_TOO_SMALL,
164 * "%ucm radius cakes are silly",
169 * simple = g_simple_async_result_new (G_OBJECT (self),
172 * baker_bake_cake_async);
173 * cake = _baker_get_cached_cake (self, radius);
177 * g_simple_async_result_set_op_res_gpointer (simple,
178 * g_object_ref (cake),
180 * g_simple_async_result_complete_in_idle (simple);
181 * g_object_unref (simple);
182 * /* Drop the reference returned by _baker_get_cached_cake(); the
183 * * GSimpleAsyncResult has taken its own reference.
185 * g_object_unref (cake);
189 * _baker_prepare_cake (self, radius, baked_cb, user_data);
193 * baker_bake_cake_finish (Baker *self,
194 * GAsyncResult *result,
197 * GSimpleAsyncResult *simple;
200 * g_return_val_if_fail (g_simple_async_result_is_valid (result,
202 * baker_bake_cake_async),
205 * simple = (GSimpleAsyncResult *) result;
207 * if (g_simple_async_result_propagate_error (simple, error))
210 * cake = CAKE (g_simple_async_result_get_op_res_gpointer (simple));
211 * return g_object_ref (cake);
216 static void g_simple_async_result_async_result_iface_init (GAsyncResultIface *iface);
218 struct _GSimpleAsyncResult
220 GObject parent_instance;
222 GObject *source_object;
223 GAsyncReadyCallback callback;
225 GMainContext *context;
228 gboolean handle_cancellation;
238 GDestroyNotify destroy_op_res;
241 struct _GSimpleAsyncResultClass
243 GObjectClass parent_class;
247 G_DEFINE_TYPE_WITH_CODE (GSimpleAsyncResult, g_simple_async_result, G_TYPE_OBJECT,
248 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_RESULT,
249 g_simple_async_result_async_result_iface_init))
252 clear_op_res (GSimpleAsyncResult *simple)
254 if (simple->destroy_op_res)
255 simple->destroy_op_res (simple->op_res.v_pointer);
256 simple->destroy_op_res = NULL;
257 simple->op_res.v_ssize = 0;
261 g_simple_async_result_finalize (GObject *object)
263 GSimpleAsyncResult *simple;
265 simple = G_SIMPLE_ASYNC_RESULT (object);
267 if (simple->source_object)
268 g_object_unref (simple->source_object);
271 g_main_context_unref (simple->context);
273 clear_op_res (simple);
276 g_error_free (simple->error);
278 G_OBJECT_CLASS (g_simple_async_result_parent_class)->finalize (object);
282 g_simple_async_result_class_init (GSimpleAsyncResultClass *klass)
284 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
286 gobject_class->finalize = g_simple_async_result_finalize;
290 g_simple_async_result_init (GSimpleAsyncResult *simple)
292 simple->handle_cancellation = TRUE;
294 simple->context = g_main_context_get_thread_default ();
296 g_main_context_ref (simple->context);
300 * g_simple_async_result_new:
301 * @source_object: a #GObject the asynchronous function was called with,
303 * @callback: a #GAsyncReadyCallback.
304 * @user_data: user data passed to @callback.
305 * @source_tag: the asynchronous function.
307 * Creates a #GSimpleAsyncResult.
309 * Returns: a #GSimpleAsyncResult.
312 g_simple_async_result_new (GObject *source_object,
313 GAsyncReadyCallback callback,
317 GSimpleAsyncResult *simple;
319 g_return_val_if_fail (!source_object || G_IS_OBJECT (source_object), NULL);
321 simple = g_object_new (G_TYPE_SIMPLE_ASYNC_RESULT, NULL);
322 simple->callback = callback;
324 simple->source_object = g_object_ref (source_object);
326 simple->source_object = NULL;
327 simple->user_data = user_data;
328 simple->source_tag = source_tag;
334 * g_simple_async_result_new_from_error:
335 * @source_object: a #GObject, or %NULL.
336 * @callback: a #GAsyncReadyCallback.
337 * @user_data: user data passed to @callback.
338 * @error: a #GError location.
340 * Creates a #GSimpleAsyncResult from an error condition.
342 * Returns: a #GSimpleAsyncResult.
345 g_simple_async_result_new_from_error (GObject *source_object,
346 GAsyncReadyCallback callback,
350 GSimpleAsyncResult *simple;
352 g_return_val_if_fail (!source_object || G_IS_OBJECT (source_object), NULL);
354 simple = g_simple_async_result_new (source_object,
357 g_simple_async_result_set_from_error (simple, error);
363 * g_simple_async_result_new_error:
364 * @source_object: a #GObject, or %NULL.
365 * @callback: a #GAsyncReadyCallback.
366 * @user_data: user data passed to @callback.
367 * @domain: a #GQuark.
368 * @code: an error code.
369 * @format: a string with format characters.
370 * @...: a list of values to insert into @format.
372 * Creates a new #GSimpleAsyncResult with a set error.
374 * Returns: a #GSimpleAsyncResult.
377 g_simple_async_result_new_error (GObject *source_object,
378 GAsyncReadyCallback callback,
385 GSimpleAsyncResult *simple;
388 g_return_val_if_fail (!source_object || G_IS_OBJECT (source_object), NULL);
389 g_return_val_if_fail (domain != 0, NULL);
390 g_return_val_if_fail (format != NULL, NULL);
392 simple = g_simple_async_result_new (source_object,
396 va_start (args, format);
397 g_simple_async_result_set_error_va (simple, domain, code, format, args);
405 g_simple_async_result_get_user_data (GAsyncResult *res)
407 return G_SIMPLE_ASYNC_RESULT (res)->user_data;
411 g_simple_async_result_get_source_object (GAsyncResult *res)
413 if (G_SIMPLE_ASYNC_RESULT (res)->source_object)
414 return g_object_ref (G_SIMPLE_ASYNC_RESULT (res)->source_object);
419 g_simple_async_result_async_result_iface_init (GAsyncResultIface *iface)
421 iface->get_user_data = g_simple_async_result_get_user_data;
422 iface->get_source_object = g_simple_async_result_get_source_object;
426 * g_simple_async_result_set_handle_cancellation:
427 * @simple: a #GSimpleAsyncResult.
428 * @handle_cancellation: a #gboolean.
430 * Sets whether to handle cancellation within the asynchronous operation.
434 g_simple_async_result_set_handle_cancellation (GSimpleAsyncResult *simple,
435 gboolean handle_cancellation)
437 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
438 simple->handle_cancellation = handle_cancellation;
442 * g_simple_async_result_get_source_tag:
443 * @simple: a #GSimpleAsyncResult.
445 * Gets the source tag for the #GSimpleAsyncResult.
447 * Returns: a #gpointer to the source object for the #GSimpleAsyncResult.
450 g_simple_async_result_get_source_tag (GSimpleAsyncResult *simple)
452 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), NULL);
453 return simple->source_tag;
457 * g_simple_async_result_propagate_error:
458 * @simple: a #GSimpleAsyncResult.
459 * @dest: a location to propegate the error to.
461 * Propagates an error from within the simple asynchronous result to
462 * a given destination.
464 * Returns: %TRUE if the error was propagated to @dest. %FALSE otherwise.
467 g_simple_async_result_propagate_error (GSimpleAsyncResult *simple,
470 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), FALSE);
474 g_propagate_error (dest, simple->error);
475 simple->error = NULL;
483 * g_simple_async_result_set_op_res_gpointer:
484 * @simple: a #GSimpleAsyncResult.
485 * @op_res: a pointer result from an asynchronous function.
486 * @destroy_op_res: a #GDestroyNotify function.
488 * Sets the operation result within the asynchronous result to a pointer.
491 g_simple_async_result_set_op_res_gpointer (GSimpleAsyncResult *simple,
493 GDestroyNotify destroy_op_res)
495 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
497 clear_op_res (simple);
498 simple->op_res.v_pointer = op_res;
499 simple->destroy_op_res = destroy_op_res;
503 * g_simple_async_result_get_op_res_gpointer:
504 * @simple: a #GSimpleAsyncResult.
506 * Gets a pointer result as returned by the asynchronous function.
508 * Returns: a pointer from the result.
511 g_simple_async_result_get_op_res_gpointer (GSimpleAsyncResult *simple)
513 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), NULL);
514 return simple->op_res.v_pointer;
518 * g_simple_async_result_set_op_res_gssize:
519 * @simple: a #GSimpleAsyncResult.
520 * @op_res: a #gssize.
522 * Sets the operation result within the asynchronous result to
526 g_simple_async_result_set_op_res_gssize (GSimpleAsyncResult *simple,
529 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
530 clear_op_res (simple);
531 simple->op_res.v_ssize = op_res;
535 * g_simple_async_result_get_op_res_gssize:
536 * @simple: a #GSimpleAsyncResult.
538 * Gets a gssize from the asynchronous result.
540 * Returns: a gssize returned from the asynchronous function.
543 g_simple_async_result_get_op_res_gssize (GSimpleAsyncResult *simple)
545 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), 0);
546 return simple->op_res.v_ssize;
550 * g_simple_async_result_set_op_res_gboolean:
551 * @simple: a #GSimpleAsyncResult.
552 * @op_res: a #gboolean.
554 * Sets the operation result to a boolean within the asynchronous result.
557 g_simple_async_result_set_op_res_gboolean (GSimpleAsyncResult *simple,
560 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
561 clear_op_res (simple);
562 simple->op_res.v_boolean = !!op_res;
566 * g_simple_async_result_get_op_res_gboolean:
567 * @simple: a #GSimpleAsyncResult.
569 * Gets the operation result boolean from within the asynchronous result.
571 * Returns: %TRUE if the operation's result was %TRUE, %FALSE
572 * if the operation's result was %FALSE.
575 g_simple_async_result_get_op_res_gboolean (GSimpleAsyncResult *simple)
577 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), FALSE);
578 return simple->op_res.v_boolean;
582 * g_simple_async_result_set_from_error:
583 * @simple: a #GSimpleAsyncResult.
586 * Sets the result from a #GError.
589 g_simple_async_result_set_from_error (GSimpleAsyncResult *simple,
592 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
593 g_return_if_fail (error != NULL);
596 g_error_free (simple->error);
597 simple->error = g_error_copy (error);
598 simple->failed = TRUE;
602 * g_simple_async_result_set_error_va:
603 * @simple: a #GSimpleAsyncResult.
604 * @domain: a #GQuark (usually #G_IO_ERROR).
605 * @code: an error code.
606 * @format: a formatted error reporting string.
607 * @args: va_list of arguments.
609 * Sets an error within the asynchronous result without a #GError.
610 * Unless writing a binding, see g_simple_async_result_set_error().
613 g_simple_async_result_set_error_va (GSimpleAsyncResult *simple,
619 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
620 g_return_if_fail (domain != 0);
621 g_return_if_fail (format != NULL);
624 g_error_free (simple->error);
625 simple->error = g_error_new_valist (domain, code, format, args);
626 simple->failed = TRUE;
630 * g_simple_async_result_set_error:
631 * @simple: a #GSimpleAsyncResult.
632 * @domain: a #GQuark (usually #G_IO_ERROR).
633 * @code: an error code.
634 * @format: a formatted error reporting string.
635 * @...: a list of variables to fill in @format.
637 * Sets an error within the asynchronous result without a #GError.
640 g_simple_async_result_set_error (GSimpleAsyncResult *simple,
648 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
649 g_return_if_fail (domain != 0);
650 g_return_if_fail (format != NULL);
652 va_start (args, format);
653 g_simple_async_result_set_error_va (simple, domain, code, format, args);
658 * g_simple_async_result_complete:
659 * @simple: a #GSimpleAsyncResult.
661 * Completes an asynchronous I/O job immediately. Must be called in
662 * the thread where the asynchronous result was to be delivered, as it
663 * invokes the callback directly. If you are in a different thread use
664 * g_simple_async_result_complete_in_idle().
666 * Calling this function takes a reference to @simple for as long as
667 * is needed to complete the call.
670 g_simple_async_result_complete (GSimpleAsyncResult *simple)
672 #ifndef G_DISABLE_CHECKS
673 GSource *current_source;
674 GMainContext *current_context;
677 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
679 #ifndef G_DISABLE_CHECKS
680 current_source = g_main_current_source ();
681 if (current_source && !g_source_is_destroyed (current_source))
683 current_context = g_source_get_context (current_source);
684 if (current_context == g_main_context_default ())
685 current_context = NULL;
686 if (simple->context != current_context)
687 g_warning ("g_simple_async_result_complete() called from wrong context!");
691 if (simple->callback)
692 simple->callback (simple->source_object,
693 G_ASYNC_RESULT (simple),
698 complete_in_idle_cb (gpointer data)
700 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (data);
702 g_simple_async_result_complete (simple);
708 * g_simple_async_result_complete_in_idle:
709 * @simple: a #GSimpleAsyncResult.
711 * Completes an asynchronous function in an idle handler in the <link
712 * linkend="g-main-context-push-thread-default">thread-default main
713 * loop</link> of the thread that @simple was initially created in.
715 * Calling this function takes a reference to @simple for as long as
716 * is needed to complete the call.
719 g_simple_async_result_complete_in_idle (GSimpleAsyncResult *simple)
723 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
725 g_object_ref (simple);
727 source = g_idle_source_new ();
728 g_source_set_priority (source, G_PRIORITY_DEFAULT);
729 g_source_set_callback (source, complete_in_idle_cb, simple, g_object_unref);
731 g_source_attach (source, simple->context);
732 g_source_unref (source);
736 GSimpleAsyncResult *simple;
737 GCancellable *cancellable;
738 GSimpleAsyncThreadFunc func;
743 complete_in_idle_cb_for_thread (gpointer _data)
745 RunInThreadData *data = _data;
746 GSimpleAsyncResult *simple;
748 simple = data->simple;
750 if (simple->handle_cancellation &&
751 g_cancellable_is_cancelled (data->cancellable))
752 g_simple_async_result_set_error (simple,
754 G_IO_ERROR_CANCELLED,
755 "%s", _("Operation was cancelled"));
757 g_simple_async_result_complete (simple);
759 if (data->cancellable)
760 g_object_unref (data->cancellable);
761 g_object_unref (data->simple);
768 run_in_thread (GIOSchedulerJob *job,
772 RunInThreadData *data = _data;
773 GSimpleAsyncResult *simple = data->simple;
776 if (simple->handle_cancellation &&
777 g_cancellable_is_cancelled (c))
778 g_simple_async_result_set_error (simple,
780 G_IO_ERROR_CANCELLED,
781 "%s", _("Operation was cancelled"));
784 simple->source_object,
787 source = g_idle_source_new ();
788 g_source_set_priority (source, G_PRIORITY_DEFAULT);
789 g_source_set_callback (source, complete_in_idle_cb_for_thread, data, NULL);
791 g_source_attach (source, simple->context);
792 g_source_unref (source);
798 * g_simple_async_result_run_in_thread:
799 * @simple: a #GSimpleAsyncResult.
800 * @func: a #GSimpleAsyncThreadFunc.
801 * @io_priority: the io priority of the request.
802 * @cancellable: optional #GCancellable object, %NULL to ignore.
804 * Runs the asynchronous job in a separate thread and then calls
805 * g_simple_async_result_complete_in_idle() on @simple to return
806 * the result to the appropriate main loop.
808 * Calling this function takes a reference to @simple for as long as
809 * is needed to run the job and report its completion.
812 g_simple_async_result_run_in_thread (GSimpleAsyncResult *simple,
813 GSimpleAsyncThreadFunc func,
815 GCancellable *cancellable)
817 RunInThreadData *data;
819 g_return_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple));
820 g_return_if_fail (func != NULL);
822 data = g_new (RunInThreadData, 1);
824 data->simple = g_object_ref (simple);
825 data->cancellable = cancellable;
827 g_object_ref (cancellable);
828 g_io_scheduler_push_job (run_in_thread, data, NULL, io_priority, cancellable);
832 * g_simple_async_result_is_valid:
833 * @result: the #GAsyncResult passed to the _finish function.
834 * @source: the #GObject passed to the _finish function.
835 * @source_tag: the asynchronous function.
837 * Ensures that the data passed to the _finish function of an async
838 * operation is consistent. Three checks are performed.
840 * First, @result is checked to ensure that it is really a
841 * #GSimpleAsyncResult. Second, @source is checked to ensure that it
842 * matches the source object of @result. Third, @source_tag is
843 * checked to ensure that it is either %NULL (as it is when the result was
844 * created by g_simple_async_report_error_in_idle() or
845 * g_simple_async_report_gerror_in_idle()) or equal to the
846 * @source_tag argument given to g_simple_async_result_new() (which, by
847 * convention, is a pointer to the _async function corresponding to the
848 * _finish function from which this function is called).
850 * Returns: #TRUE if all checks passed or #FALSE if any failed.
853 g_simple_async_result_is_valid (GAsyncResult *result,
857 GSimpleAsyncResult *simple;
860 if (!G_IS_SIMPLE_ASYNC_RESULT (result))
862 simple = (GSimpleAsyncResult *)result;
864 cmp_source = g_async_result_get_source_object (result);
865 if (cmp_source != source)
867 if (cmp_source != NULL)
868 g_object_unref (cmp_source);
871 if (cmp_source != NULL)
872 g_object_unref (cmp_source);
874 return source_tag == NULL ||
875 source_tag == g_simple_async_result_get_source_tag (simple);
879 * g_simple_async_report_error_in_idle:
880 * @object: a #GObject.
881 * @callback: a #GAsyncReadyCallback.
882 * @user_data: user data passed to @callback.
883 * @domain: a #GQuark containing the error domain (usually #G_IO_ERROR).
884 * @code: a specific error code.
885 * @format: a formatted error reporting string.
886 * @...: a list of variables to fill in @format.
888 * Reports an error in an asynchronous function in an idle function by
889 * directly setting the contents of the #GAsyncResult with the given error
893 g_simple_async_report_error_in_idle (GObject *object,
894 GAsyncReadyCallback callback,
901 GSimpleAsyncResult *simple;
904 g_return_if_fail (G_IS_OBJECT (object));
905 g_return_if_fail (domain != 0);
906 g_return_if_fail (format != NULL);
908 simple = g_simple_async_result_new (object,
912 va_start (args, format);
913 g_simple_async_result_set_error_va (simple, domain, code, format, args);
915 g_simple_async_result_complete_in_idle (simple);
916 g_object_unref (simple);
920 * g_simple_async_report_gerror_in_idle:
921 * @object: a #GObject.
922 * @callback: a #GAsyncReadyCallback.
923 * @user_data: user data passed to @callback.
924 * @error: the #GError to report
926 * Reports an error in an idle function. Similar to
927 * g_simple_async_report_error_in_idle(), but takes a #GError rather
928 * than building a new one.
931 g_simple_async_report_gerror_in_idle (GObject *object,
932 GAsyncReadyCallback callback,
936 GSimpleAsyncResult *simple;
938 g_return_if_fail (G_IS_OBJECT (object));
939 g_return_if_fail (error != NULL);
941 simple = g_simple_async_result_new_from_error (object,
945 g_simple_async_result_complete_in_idle (simple);
946 g_object_unref (simple);