Synopsis#include <gio/gio.h> GSimpleAsyncResult; void (*GSimpleAsyncThreadFunc) (GSimpleAsyncResult *res, GObject *object, GCancellable *cancellable); GSimpleAsyncResult* g_simple_async_result_new (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, gpointer source_tag); GSimpleAsyncResult* g_simple_async_result_new_error (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, GQuark domain, gint code, const char *format, ...); GSimpleAsyncResult* g_simple_async_result_new_from_error (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, GError *error); void g_simple_async_result_set_op_res_gpointer (GSimpleAsyncResult *simple, gpointer op_res, GDestroyNotify destroy_op_res); gpointer g_simple_async_result_get_op_res_gpointer (GSimpleAsyncResult *simple); void g_simple_async_result_set_op_res_gssize (GSimpleAsyncResult *simple, gssize op_res); gssize g_simple_async_result_get_op_res_gssize (GSimpleAsyncResult *simple); void g_simple_async_result_set_op_res_gboolean (GSimpleAsyncResult *simple, gboolean op_res); gboolean g_simple_async_result_get_op_res_gboolean (GSimpleAsyncResult *simple); gpointer g_simple_async_result_get_source_tag (GSimpleAsyncResult *simple); void g_simple_async_result_set_handle_cancellation (GSimpleAsyncResult *simple, gboolean handle_cancellation); void g_simple_async_result_complete (GSimpleAsyncResult *simple); void g_simple_async_result_complete_in_idle (GSimpleAsyncResult *simple); void g_simple_async_result_run_in_thread (GSimpleAsyncResult *simple, GSimpleAsyncThreadFunc func, int io_priority, GCancellable *cancellable); void g_simple_async_result_set_from_error (GSimpleAsyncResult *simple, GError *error); gboolean g_simple_async_result_propagate_error (GSimpleAsyncResult *simple, GError **dest); void g_simple_async_result_set_error (GSimpleAsyncResult *simple, GQuark domain, gint code, const char *format, ...); void g_simple_async_result_set_error_va (GSimpleAsyncResult *simple, GQuark domain, gint code, const char *format, va_list args); void g_simple_async_report_error_in_idle (GObject *object, GAsyncReadyCallback callback, gpointer user_data, GQuark domain, gint code, const char *format, ...); void g_simple_async_report_gerror_in_idle (GObject *object, GAsyncReadyCallback callback, gpointer user_data, GError *error); DescriptionImplements GAsyncResult for simple cases. Most of the time, this will be all an application needs, and will be used transparently. Because of this, GSimpleAsyncResult is used throughout GIO for handling asynchronous functions. GSimpleAsyncResult handles GAsyncReadyCallbacks, error reporting, operation cancellation and the final state of an operation, completely transparent to the application. Results can be returned as a pointer e.g. for functions that return data that is collected asynchronously, a boolean value for checking the success or failure of an operation, or a gssize for operations which return the number of bytes modified by the operation; all of the simple return cases are covered. Most of the time, an application will not need to know of the details of this API; it is handled transparently, and any necessary operations are handled by GAsyncResult's interface. However, if implementing a new GIO module, for writing language bindings, or for complex applications that need better control of how asynchronous operations are completed, it is important to understand this functionality. GSimpleAsyncResults are tagged with the calling function to ensure that asynchronous functions and their finishing functions are used together correctly.
To create a new GSimpleAsyncResult, call
An asynchronous operation can be made to ignore a cancellation event by
calling
GSimpleAsyncResult can integrate into GLib's event loop, GMainLoop,
or it can use GThreads if available.
To set the results of an asynchronous function,
Likewise, to get the result of an asynchronous function,
DetailsGSimpleAsyncResulttypedef struct _GSimpleAsyncResult GSimpleAsyncResult; A simple implementation of GAsyncResult.
GSimpleAsyncThreadFunc ()void (*GSimpleAsyncThreadFunc) (GSimpleAsyncResult *res, GObject *object, GCancellable *cancellable); Simple thread function that runs an asynchronous operation and checks for cancellation.
g_simple_async_result_new ()GSimpleAsyncResult* g_simple_async_result_new (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, gpointer source_tag); Creates a GSimpleAsyncResult.
g_simple_async_result_new_error ()GSimpleAsyncResult* g_simple_async_result_new_error (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, GQuark domain, gint code, const char *format, ...); Creates a new GSimpleAsyncResult with a set error.
g_simple_async_result_new_from_error ()GSimpleAsyncResult* g_simple_async_result_new_from_error (GObject *source_object, GAsyncReadyCallback callback, gpointer user_data, GError *error); Creates a GSimpleAsyncResult from an error condition.
g_simple_async_result_set_op_res_gpointer ()void g_simple_async_result_set_op_res_gpointer (GSimpleAsyncResult *simple, gpointer op_res, GDestroyNotify destroy_op_res); Sets the operation result within the asynchronous result to a pointer.
g_simple_async_result_get_op_res_gpointer ()gpointer g_simple_async_result_get_op_res_gpointer (GSimpleAsyncResult *simple); Gets a pointer result as returned by the asynchronous function.
g_simple_async_result_set_op_res_gssize ()void g_simple_async_result_set_op_res_gssize (GSimpleAsyncResult *simple, gssize op_res);
Sets the operation result within the asynchronous result to
the given
g_simple_async_result_get_op_res_gssize ()gssize g_simple_async_result_get_op_res_gssize (GSimpleAsyncResult *simple); Gets a gssize from the asynchronous result.
g_simple_async_result_set_op_res_gboolean ()void g_simple_async_result_set_op_res_gboolean (GSimpleAsyncResult *simple, gboolean op_res); Sets the operation result to a boolean within the asynchronous result.
g_simple_async_result_get_op_res_gboolean ()gboolean g_simple_async_result_get_op_res_gboolean (GSimpleAsyncResult *simple); Gets the operation result boolean from within the asynchronous result.
g_simple_async_result_get_source_tag ()gpointer g_simple_async_result_get_source_tag (GSimpleAsyncResult *simple); Gets the source tag for the GSimpleAsyncResult.
g_simple_async_result_set_handle_cancellation ()void g_simple_async_result_set_handle_cancellation (GSimpleAsyncResult *simple, gboolean handle_cancellation); Sets whether to handle cancellation within the asynchronous operation.
g_simple_async_result_complete ()void g_simple_async_result_complete (GSimpleAsyncResult *simple); Completes an asynchronous I/O job.
g_simple_async_result_complete_in_idle ()void g_simple_async_result_complete_in_idle (GSimpleAsyncResult *simple); Completes an asynchronous function in the main event loop using an idle function.
g_simple_async_result_run_in_thread ()void g_simple_async_result_run_in_thread (GSimpleAsyncResult *simple, GSimpleAsyncThreadFunc func, int io_priority, GCancellable *cancellable); Runs the asynchronous job in a separated thread.
g_simple_async_result_set_from_error ()void g_simple_async_result_set_from_error (GSimpleAsyncResult *simple, GError *error); Sets the result from a GError.
g_simple_async_result_propagate_error ()gboolean g_simple_async_result_propagate_error (GSimpleAsyncResult *simple, GError **dest); Propagates an error from within the simple asynchronous result to a given destination.
g_simple_async_result_set_error ()void g_simple_async_result_set_error (GSimpleAsyncResult *simple, GQuark domain, gint code, const char *format, ...); Sets an error within the asynchronous result without a GError.
g_simple_async_result_set_error_va ()void g_simple_async_result_set_error_va (GSimpleAsyncResult *simple, GQuark domain, gint code, const char *format, va_list args);
Sets an error within the asynchronous result without a GError.
Unless writing a binding, see
g_simple_async_report_error_in_idle ()void g_simple_async_report_error_in_idle (GObject *object, GAsyncReadyCallback callback, gpointer user_data, GQuark domain, gint code, const char *format, ...); Reports an error in an asynchronous function in an idle function by directly setting the contents of the GAsyncResult with the given error information.
g_simple_async_report_gerror_in_idle ()void g_simple_async_report_gerror_in_idle (GObject *object, GAsyncReadyCallback callback, gpointer user_data, GError *error);
Reports an error in an idle function. Similar to
|