📄 gsimpleasyncresult.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>GSimpleAsyncResult</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GIO Reference Manual"><link rel="up" href="async.html" title="Asynchronous I/O"><link rel="prev" href="gio-GIOScheduler.html" title="GIOScheduler"><link rel="next" href="streaming.html" title="Streaming I/O"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="part" href="pt01.html" title="Part I. GIO Overview"><link rel="chapter" href="ch01.html" title="Introduction"><link rel="chapter" href="ch02.html" title="Compiling GIO applications"><link rel="chapter" href="ch03.html" title="Running GIO applications"><link rel="chapter" href="gio-extension-points.html" title="Extending GIO"><link rel="part" href="pt02.html" title="Part II. API Reference"><link rel="chapter" href="file_ops.html" title="File Operations"><link rel="chapter" href="file_mon.html" title="File System Monitoring"><link rel="chapter" href="async.html" title="Asynchronous I/O"><link rel="chapter" href="streaming.html" title="Streaming I/O"><link rel="chapter" href="types.html" title="File types and applications"><link rel="chapter" href="volume_mon.html" title="Volumes and Drives"><link rel="chapter" href="icons.html" title="Icons"><link rel="chapter" href="utils.html" title="Utilities"><link rel="chapter" href="extending.html" title="Extending GIO"><link rel="part" href="migrating.html" title="Part III. Migrating to GIO"><link rel="chapter" href="ch14.html" title="Migrating from POSIX to GIO"><link rel="chapter" href="ch15.html" title="Migrating from GnomeVFS to GIO"><link rel="chapter" href="gio-hierarchy.html" title="Object Hierarchy"><link rel="index" href="ix01.html" title="Index"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="gio-GIOScheduler.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="async.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GIO Reference Manual</th><td><a accesskey="n" href="streaming.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3106482" class="shortcut">Top</a>  |  <a href="#id3180991" class="shortcut">Description</a>  |  <a href="#id3180944" class="shortcut">Object Hierarchy</a>  |  <a href="#id3180969" class="shortcut">Implemented Interfaces</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="GSimpleAsyncResult"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3106482"></a><span class="refentrytitle">GSimpleAsyncResult</span></h2><p>GSimpleAsyncResult — Simple asynchronous results implementation</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <gio/gio.h> <a class="link" href="GSimpleAsyncResult.html#GSimpleAsyncResult-struct">GSimpleAsyncResult</a>;void (<a class="link" href="GSimpleAsyncResult.html#GSimpleAsyncThreadFunc">*GSimpleAsyncThreadFunc</a>) (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *res, <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *object, <a class="link" href="GCancellable.html" title="GCancellable">GCancellable</a> *cancellable);<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a>* <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new">g_simple_async_result_new</a> (<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *source_object, <a class="link" href="GAsyncResult.html#GAsyncReadyCallback">GAsyncReadyCallback</a> callback, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> source_tag);<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a>* <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new-error">g_simple_async_result_new_error</a> (<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *source_object, <a class="link" href="GAsyncResult.html#GAsyncReadyCallback">GAsyncReadyCallback</a> callback, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data, <ahref="/usr/share/gtk-doc/html/glib/glib-Quarks.html#GQuark">GQuark</a> domain, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> code, const char *format, ...);<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a>* <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new-from-error">g_simple_async_result_new_from_error</a> (<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *source_object, <a class="link" href="GAsyncResult.html#GAsyncReadyCallback">GAsyncReadyCallback</a> callback, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> *error);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer">g_simple_async_result_set_op_res_gpointer</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> op_res, <ahref="/usr/share/gtk-doc/html/glib/glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> destroy_op_res);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-get-op-res-gpointer">g_simple_async_result_get_op_res_gpointer</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gssize">g_simple_async_result_set_op_res_gssize</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gssize">gssize</a> op_res);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gssize">gssize</a> <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-get-op-res-gssize">g_simple_async_result_get_op_res_gssize</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gboolean">g_simple_async_result_set_op_res_gboolean</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> op_res);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-get-op-res-gboolean">g_simple_async_result_get_op_res_gboolean</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-get-source-tag">g_simple_async_result_get_source_tag</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-handle-cancellation">g_simple_async_result_set_handle_cancellation</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> handle_cancellation);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-complete">g_simple_async_result_complete</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-complete-in-idle">g_simple_async_result_complete_in_idle</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-run-in-thread">g_simple_async_result_run_in_thread</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <a class="link" href="GSimpleAsyncResult.html#GSimpleAsyncThreadFunc">GSimpleAsyncThreadFunc</a> func, int io_priority, <a class="link" href="GCancellable.html" title="GCancellable">GCancellable</a> *cancellable);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-from-error">g_simple_async_result_set_from_error</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> *error);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-propagate-error">g_simple_async_result_propagate_error</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> **dest);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-error">g_simple_async_result_set_error</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Quarks.html#GQuark">GQuark</a> domain, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> code, const char *format, ...);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-error-va">g_simple_async_result_set_error_va</a> (<a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a> *simple, <ahref="/usr/share/gtk-doc/html/glib/glib-Quarks.html#GQuark">GQuark</a> domain, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> code, const char *format, va_list args);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-report-error-in-idle">g_simple_async_report_error_in_idle</a> (<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *object, <a class="link" href="GAsyncResult.html#GAsyncReadyCallback">GAsyncReadyCallback</a> callback, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data, <ahref="/usr/share/gtk-doc/html/glib/glib-Quarks.html#GQuark">GQuark</a> domain, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> code, const char *format, ...);void <a class="link" href="GSimpleAsyncResult.html#g-simple-async-report-gerror-in-idle">g_simple_async_report_gerror_in_idle</a> (<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *object, <a class="link" href="GAsyncResult.html#GAsyncReadyCallback">GAsyncReadyCallback</a> callback, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> *error);</pre></div><div class="refsect1" lang="en"><a name="id3180944"></a><h2>Object Hierarchy</h2><pre class="synopsis"> <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> +----GSimpleAsyncResult</pre></div><div class="refsect1" lang="en"><a name="id3180969"></a><h2>Implemented Interfaces</h2><p>GSimpleAsyncResult implements <a class="link" href="GAsyncResult.html" title="GAsyncResult">GAsyncResult</a>.</p></div><div class="refsect1" lang="en"><a name="id3180991"></a><h2>Description</h2><p>Implements <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> for simple cases. Most of the time, this will be all an application needs, and will be used transparently. Because of this, <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a> is used throughout GIO for handling asynchronous functions. </p><p>GSimpleAsyncResult handles <a class="link" href="GAsyncResult.html#GAsyncReadyCallback"><span class="type">GAsyncReadyCallback</span></a>s, 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 <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gssize"><span class="type">gssize</span></a> for operations which return the number of bytes modified by the operation; all of the simple return cases are covered.</p><p>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 <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>'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.</p><p>GSimpleAsyncResults are tagged with the calling function to ensure that asynchronous functions and their finishing functions are used together correctly.</p><p>To create a new <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a>, call <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new"><code class="function">g_simple_async_result_new()</code></a>. If the result needs to be created for a <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, use <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new-from-error"><code class="function">g_simple_async_result_new_from_error()</code></a>. If a <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> is not available (e.g. the asynchronous operation's doesn't take a <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> argument), but the result still needs to be created for an error condition, use<a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-new-error"><code class="function">g_simple_async_result_new_error()</code></a> (or <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-error-va"><code class="function">g_simple_async_result_set_error_va()</code></a>if your application or binding requires passing a variable argument list directly), and the error can then be propegated through the use of <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-propagate-error"><code class="function">g_simple_async_result_propagate_error()</code></a>.</p><p>An asynchronous operation can be made to ignore a cancellation event by calling <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-handle-cancellation"><code class="function">g_simple_async_result_set_handle_cancellation()</code></a> with a <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a> for the operation and <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>. </p><p>GSimpleAsyncResult can integrate into GLib's event loop, <ahref="/usr/share/gtk-doc/html/glib/glib-The-Main-Event-Loop.html#GMainLoop"><span class="type">GMainLoop</span></a>, or it can use <ahref="/usr/share/gtk-doc/html/glib/glib-Threads.html#GThread"><span class="type">GThread</span></a>s if available. <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-complete"><code class="function">g_simple_async_result_complete()</code></a> will finish an I/O task directly within the main event loop. <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-complete-in-idle"><code class="function">g_simple_async_result_complete_in_idle()</code></a> will integrate the I/O task into the main event loop as an idle function and <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-run-in-thread"><code class="function">g_simple_async_result_run_in_thread()</code></a> will run the job in a separate thread.</p><p>To set the results of an asynchronous function, <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer"><code class="function">g_simple_async_result_set_op_res_gpointer()</code></a>, <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gboolean"><code class="function">g_simple_async_result_set_op_res_gboolean()</code></a>, and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -