1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GAsyncResult</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="async.html" title="Asynchronous I/O">
9 <link rel="prev" href="GCancellable.html" title="GCancellable">
10 <link rel="next" href="gio-GIOScheduler.html" title="GIOScheduler">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17 <td><a accesskey="p" href="GCancellable.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="async.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GIO Reference Manual</th>
21 <td><a accesskey="n" href="gio-GIOScheduler.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#GAsyncResult.synopsis" class="shortcut">Top</a>
26 <a href="#GAsyncResult.description" class="shortcut">Description</a>
28 <a href="#GAsyncResult.object-hierarchy" class="shortcut">Object Hierarchy</a>
30 <a href="#GAsyncResult.prerequisites" class="shortcut">Prerequisites</a>
32 <a href="#GAsyncResult.implementations" class="shortcut">Known Implementations</a>
35 <div class="refentry">
36 <a name="GAsyncResult"></a><div class="titlepage"></div>
37 <div class="refnamediv"><table width="100%"><tr>
39 <h2><span class="refentrytitle"><a name="GAsyncResult.top_of_page"></a>GAsyncResult</span></h2>
40 <p>GAsyncResult — Asynchronous Function Results</p>
42 <td valign="top" align="right"></td>
44 <div class="refsynopsisdiv">
45 <a name="GAsyncResult.synopsis"></a><h2>Synopsis</h2>
46 <pre class="synopsis">
47 #include <gio/gio.h>
49 <a class="link" href="GAsyncResult.html#GAsyncResult-struct" title="GAsyncResult">GAsyncResult</a>;
50 struct <a class="link" href="GAsyncResult.html#GAsyncResultIface" title="struct GAsyncResultIface">GAsyncResultIface</a>;
51 <span class="returnvalue">void</span> (<a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()">*GAsyncReadyCallback</a>) (<em class="parameter"><code><a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> *source_object</code></em>,
52 <em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>,
53 <em class="parameter"><code><a href="./../glib/glib/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);
54 <a href="./../glib/glib/glib-Basic-Types.html#gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="GAsyncResult.html#g-async-result-get-user-data" title="g_async_result_get_user_data ()">g_async_result_get_user_data</a> (<em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>);
55 <a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="returnvalue">GObject</span></a> * <a class="link" href="GAsyncResult.html#g-async-result-get-source-object" title="g_async_result_get_source_object ()">g_async_result_get_source_object</a> (<em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>);
58 <div class="refsect1">
59 <a name="GAsyncResult.object-hierarchy"></a><h2>Object Hierarchy</h2>
60 <pre class="synopsis">
65 <div class="refsect1">
66 <a name="GAsyncResult.prerequisites"></a><h2>Prerequisites</h2>
69 <a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a>.</p>
71 <div class="refsect1">
72 <a name="GAsyncResult.implementations"></a><h2>Known Implementations</h2>
74 GAsyncResult is implemented by
75 <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult">GSimpleAsyncResult</a>.</p>
77 <div class="refsect1">
78 <a name="GAsyncResult.description"></a><h2>Description</h2>
80 Provides a base class for implementing asynchronous function results.
83 Asynchronous operations are broken up into two separate operations
84 which are chained together by a <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a>. To begin
85 an asynchronous operation, provide a <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> to the
86 asynchronous function. This callback will be triggered when the
87 operation has completed, and will be passed a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> instance
88 filled with the details of the operation's success or failure, the
89 object the asynchronous function was started for and any error codes
90 returned. The asynchronous callback function is then expected to call
91 the corresponding "<code class="function">_finish()</code>" function, passing the object the
92 function was called for, the <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> instance, and (optionally)
93 an <em class="parameter"><code>error</code></em> to grab any error conditions that may have occurred.
96 The "<code class="function">_finish()</code>" function for an operation takes the generic result
97 (of type <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>) and returns the specific result that the
98 operation in question yields (e.g. a <a class="link" href="GFileEnumerator.html" title="GFileEnumerator"><span class="type">GFileEnumerator</span></a> for a
99 "enumerate children" operation). If the result or error status of the
100 operation is not needed, there is no need to call the "<code class="function">_finish()</code>"
101 function; GIO will take care of cleaning up the result and error
102 information after the <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> returns. You can pass
103 <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> for the <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> if you don't need to take any
104 action at all after the operation completes. Applications may also
105 take a reference to the <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> and call "<code class="function">_finish()</code>" later;
106 however, the "<code class="function">_finish()</code>" function may be called at most once.
109 Example of a typical asynchronous operation flow:
111 <div class="informalexample">
112 <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
115 <td class="listing_lines" align="right"><pre>1
153 <td class="listing_code"><pre class="programlisting"><span class="type">void</span><span class="normal"> </span><span class="function">_theoretical_frobnitz_async</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Theoretical</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">t</span><span class="symbol">,</span>
154 <span class="normal"> </span><span class="usertype">GCancellable</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">c</span><span class="symbol">,</span>
155 <span class="normal"> </span><span class="usertype">GAsyncReadyCallback</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">cb</span><span class="symbol">,</span>
156 <span class="normal"> </span><span class="usertype">gpointer</span><span class="normal"> u</span><span class="symbol">);</span>
158 <span class="normal"><a href="./../glib/glib/glib-Basic-Types.html#gboolean">gboolean</a> </span><span class="function">_theoretical_frobnitz_finish</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Theoretical</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">t</span><span class="symbol">,</span>
159 <span class="normal"> </span><span class="usertype">GAsyncResult</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">res</span><span class="symbol">,</span>
160 <span class="normal"> </span><span class="usertype">GError</span><span class="normal"> </span><span class="symbol">**</span><span class="normal">e</span><span class="symbol">);</span>
162 <span class="keyword">static</span><span class="normal"> </span><span class="type">void</span>
163 <span class="function">frobnitz_result_func</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">GObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">source_object</span><span class="symbol">,</span>
164 <span class="normal"> </span><span class="usertype">GAsyncResult</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">res</span><span class="symbol">,</span>
165 <span class="normal"> </span><span class="usertype">gpointer</span><span class="normal"> user_data</span><span class="symbol">)</span>
166 <span class="cbracket">{</span>
167 <span class="normal"> </span><span class="usertype">gboolean</span><span class="normal"> success </span><span class="symbol">=</span><span class="normal"> <a href="./../glib/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">;</span>
169 <span class="normal"> success </span><span class="symbol">=</span><span class="normal"> </span><span class="function">_theoretical_frobnitz_finish</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">source_object</span><span class="symbol">,</span><span class="normal"> res</span><span class="symbol">,</span><span class="normal"> <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
171 <span class="normal"> </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">success</span><span class="symbol">)</span>
172 <span class="normal"> </span><span class="function"><a href="./../glib/glib/glib-String-Utility-Functions.html#g-printf">g_printf</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"Hurray!</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">);</span>
173 <span class="normal"> </span><span class="keyword">else</span>
174 <span class="normal"> </span><span class="function"><a href="./../glib/glib/glib-String-Utility-Functions.html#g-printf">g_printf</a></span><span class="normal"> </span><span class="symbol">(</span><span class="string">"Uh oh!</span><span class="specialchar">\n</span><span class="string">"</span><span class="symbol">);</span>
176 <span class="normal"> </span><span class="comment">/* ... */</span>
178 <span class="cbracket">}</span>
180 <span class="type">int</span><span class="normal"> </span><span class="function">main</span><span class="normal"> </span><span class="symbol">(</span><span class="type">int</span><span class="normal"> argc</span><span class="symbol">,</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">argv</span><span class="symbol">[])</span>
181 <span class="cbracket">{</span>
182 <span class="normal"> </span><span class="comment">/* ... */</span>
184 <span class="normal"> </span><span class="function">_theoretical_frobnitz_async</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">theoretical_data</span><span class="symbol">,</span>
185 <span class="normal"> <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span>
186 <span class="normal"> frobnitz_result_func</span><span class="symbol">,</span>
187 <span class="normal"> <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
189 <span class="normal"> </span><span class="comment">/* ... */</span>
190 <span class="cbracket">}</span></pre></td>
199 The callback for an asynchronous operation is called only once, and is
200 always called, even in the case of a cancelled operation. On cancellation
201 the result is a <a class="link" href="gio-GIOError.html#G-IO-ERROR-CANCELLED:CAPS"><code class="literal">G_IO_ERROR_CANCELLED</code></a> error.
204 <div class="refsect1">
205 <a name="GAsyncResult.details"></a><h2>Details</h2>
206 <div class="refsect2">
207 <a name="GAsyncResult-struct"></a><h3>GAsyncResult</h3>
208 <pre class="programlisting">typedef struct _GAsyncResult GAsyncResult;</pre>
210 Holds results information for an asynchronous operation,
211 usually passed directly to a asynchronous <code class="function">_finish()</code> operation.
215 <div class="refsect2">
216 <a name="GAsyncResultIface"></a><h3>struct GAsyncResultIface</h3>
217 <pre class="programlisting">struct GAsyncResultIface {
218 GTypeInterface g_iface;
222 gpointer (* get_user_data) (GAsyncResult *res);
223 GObject * (* get_source_object) (GAsyncResult *res);
227 Interface definition for <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>.
229 <div class="variablelist"><table border="0">
230 <col align="left" valign="top">
233 <td><p><span class="term"><a href="./../gobject/gobject/gobject-Type-Information.html#GTypeInterface"><span class="type">GTypeInterface</span></a> <em class="structfield"><code><a name="GAsyncResultIface.g-iface"></a>g_iface</code></em>;</span></p></td>
234 <td>The parent interface.</td>
237 <td><p><span class="term"><em class="structfield"><code><a name="GAsyncResultIface.get-user-data"></a>get_user_data</code></em> ()</span></p></td>
238 <td>Gets the user data passed to the callback.</td>
241 <td><p><span class="term"><em class="structfield"><code><a name="GAsyncResultIface.get-source-object"></a>get_source_object</code></em> ()</span></p></td>
242 <td>Gets the source object that issued the asynchronous operation.</td>
248 <div class="refsect2">
249 <a name="GAsyncReadyCallback"></a><h3>GAsyncReadyCallback ()</h3>
250 <pre class="programlisting"><span class="returnvalue">void</span> (*GAsyncReadyCallback) (<em class="parameter"><code><a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a> *source_object</code></em>,
251 <em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>,
252 <em class="parameter"><code><a href="./../glib/glib/glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
254 Type definition for a function that will be called back when an asynchronous
255 operation within GIO has been completed.
257 <div class="variablelist"><table border="0">
258 <col align="left" valign="top">
261 <td><p><span class="term"><em class="parameter"><code>source_object</code></em> :</span></p></td>
262 <td>the object the asynchronous operation was started with.</td>
265 <td><p><span class="term"><em class="parameter"><code>res</code></em> :</span></p></td>
266 <td>a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>.</td>
269 <td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
270 <td>user data passed to the callback.</td>
276 <div class="refsect2">
277 <a name="g-async-result-get-user-data"></a><h3>g_async_result_get_user_data ()</h3>
278 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gpointer"><span class="returnvalue">gpointer</span></a> g_async_result_get_user_data (<em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>);</pre>
280 Gets the user data from a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>.
282 <div class="variablelist"><table border="0">
283 <col align="left" valign="top">
286 <td><p><span class="term"><em class="parameter"><code>res</code></em> :</span></p></td>
287 <td>a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>.</td>
290 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
291 <td>the user data for <em class="parameter"><code>res</code></em>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
298 <div class="refsect2">
299 <a name="g-async-result-get-source-object"></a><h3>g_async_result_get_source_object ()</h3>
300 <pre class="programlisting"><a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="returnvalue">GObject</span></a> * g_async_result_get_source_object (<em class="parameter"><code><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a> *res</code></em>);</pre>
302 Gets the source object from a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>.
304 <div class="variablelist"><table border="0">
305 <col align="left" valign="top">
308 <td><p><span class="term"><em class="parameter"><code>res</code></em> :</span></p></td>
309 <td>a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>
313 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
314 <td>a new reference to the source object for the <em class="parameter"><code>res</code></em>,
315 or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if there is none. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
322 <div class="refsect1">
323 <a name="GAsyncResult.see-also"></a><h2>See Also</h2>
324 <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a>
329 Generated by GTK-Doc V1.18</div>