~ubuntu-branches/ubuntu/vivid/glib2.0/vivid-proposed

« back to all changes in this revision

Viewing changes to docs/reference/gio/html/GSimpleAsyncResult.html

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2015-03-03 17:36:38 UTC
  • mfrom: (207.1.11 experimental)
  • Revision ID: package-import@ubuntu.com-20150303173638-plazvisc6kzfsve3
Tags: 2.43.91-1
* New upstream release 2.43.91
  - We have now added 'g_autofree' as a libgsystem-style autocleanup macro
    that calls g_free() on the content of a local variable when it leaves
    scope (working only on GCC and clang).
  - GApplication now has an "is-busy" property, allowing one to query the
    effective busy state.
* debian/libglib2.0-0.symbols: Add new symbols for this release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<html>
3
3
<head>
4
4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
 
<title>GIO Reference Manual: GSimpleAsyncResult</title>
 
5
<title>GSimpleAsyncResult: GIO Reference Manual</title>
6
6
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7
7
<link rel="home" href="index.html" title="GIO Reference Manual">
8
8
<link rel="up" href="async.html" title="Asynchronous I/O">
9
9
<link rel="prev" href="gio-GIOScheduler.html" title="GIOScheduler">
10
10
<link rel="next" href="conversion.html" title="Data conversion">
11
 
<meta name="generator" content="GTK-Doc V1.21 (XML mode)">
 
11
<meta name="generator" content="GTK-Doc V1.21.1 (XML mode)">
12
12
<link rel="stylesheet" href="style.css" type="text/css">
13
13
</head>
14
14
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
439
439
90
440
440
91
441
441
92</pre></td>
442
 
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span>
443
 
<span class="function">baked_cb</span> <span class="gtkdoc opt">(</span>Cake    <span class="gtkdoc opt">*</span>cake<span class="gtkdoc opt">,</span>
444
 
          gpointer user_data<span class="gtkdoc opt">)</span>
445
 
<span class="gtkdoc opt">{</span>
446
 
  <span class="gtkdoc slc">// In this example, this callback is not given a reference to the cake,</span>
447
 
  <span class="gtkdoc slc">// so the GSimpleAsyncResult has to take a reference to it.</span>
448
 
  GSimpleAsyncResult <span class="gtkdoc opt">*</span>result <span class="gtkdoc opt">=</span> user_data<span class="gtkdoc opt">;</span>
 
442
        <td class="listing_code"><pre class="programlisting"><span class="type">static</span> <span class="type">void</span>
 
443
baked_cb (Cake    *cake,
 
444
          <span class="type">gpointer</span> user_data)
 
445
{
 
446
  <span class="comment">// In this example, this callback is not given a reference to the cake,</span>
 
447
  <span class="comment">// so the GSimpleAsyncResult has to take a reference to it.</span>
 
448
  <span class="type">GSimpleAsyncResult</span> *result = user_data;
449
449
 
450
 
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>cake <span class="gtkdoc opt">==</span> NULL<span class="gtkdoc opt">)</span>
451
 
    <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-error">g_simple_async_result_set_error</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">,</span>
452
 
                                     BAKER_ERRORS<span class="gtkdoc opt">,</span>
453
 
                                     BAKER_ERROR_NO_FLOUR<span class="gtkdoc opt">,</span>
454
 
                                     <span class="string">&quot;Go to the supermarket&quot;</span><span class="gtkdoc opt">);</span>
 
450
  <span class="keyword">if</span> (cake == <span class="number">NULL</span>)
 
451
    <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-error">g_simple_async_result_set_error</a></span> (result,
 
452
                                     BAKER_ERRORS,
 
453
                                     BAKER_ERROR_NO_FLOUR,
 
454
                                     <span class="number">&quot;Go to the supermarket&quot;</span>);
455
455
  <span class="keyword">else</span>
456
 
    <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer">g_simple_async_result_set_op_res_gpointer</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">,</span>
457
 
                                               <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> <span class="gtkdoc opt">(</span>cake<span class="gtkdoc opt">),</span>
458
 
                                               g_object_unref<span class="gtkdoc opt">);</span>
459
 
 
460
 
 
461
 
  <span class="gtkdoc slc">// In this example, we assume that baked_cb is called as a callback from</span>
462
 
  <span class="gtkdoc slc">// the mainloop, so it's safe to complete the operation synchronously here.</span>
463
 
  <span class="gtkdoc slc">// If, however, _baker_prepare_cake () might call its callback without</span>
464
 
  <span class="gtkdoc slc">// first returning to the mainloop — inadvisable, but some APIs do so —</span>
465
 
  <span class="gtkdoc slc">// we would need to use g_simple_async_result_complete_in_idle().</span>
466
 
  <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-complete">g_simple_async_result_complete</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">);</span>
467
 
  <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">);</span>
468
 
<span class="gtkdoc opt">}</span>
469
 
 
470
 
<span class="gtkdoc kwb">void</span>
471
 
<span class="function">baker_bake_cake_async</span> <span class="gtkdoc opt">(</span>Baker              <span class="gtkdoc opt">*</span>self<span class="gtkdoc opt">,</span>
472
 
                       guint               radius<span class="gtkdoc opt">,</span>
473
 
                       GAsyncReadyCallback callback<span class="gtkdoc opt">,</span>
474
 
                       gpointer            user_data<span class="gtkdoc opt">)</span>
475
 
<span class="gtkdoc opt">{</span>
476
 
  GSimpleAsyncResult <span class="gtkdoc opt">*</span>simple<span class="gtkdoc opt">;</span>
477
 
  Cake               <span class="gtkdoc opt">*</span>cake<span class="gtkdoc opt">;</span>
478
 
 
479
 
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>radius <span class="gtkdoc opt">&lt;</span> <span class="number">3</span><span class="gtkdoc opt">)</span>
480
 
    <span class="gtkdoc opt">{</span>
481
 
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-report-error-in-idle">g_simple_async_report_error_in_idle</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">),</span>
482
 
                                           callback<span class="gtkdoc opt">,</span>
483
 
                                           user_data<span class="gtkdoc opt">,</span>
484
 
                                           BAKER_ERRORS<span class="gtkdoc opt">,</span>
485
 
                                           BAKER_ERROR_TOO_SMALL<span class="gtkdoc opt">,</span>
486
 
                                           <span class="string">&quot;%ucm radius cakes are silly&quot;</span><span class="gtkdoc opt">,</span>
487
 
                                           radius<span class="gtkdoc opt">);</span>
488
 
      <span class="keyword">return</span><span class="gtkdoc opt">;</span>
489
 
    <span class="gtkdoc opt">}</span>
490
 
 
491
 
  simple <span class="gtkdoc opt">=</span> <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-new">g_simple_async_result_new</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">),</span>
492
 
                                      callback<span class="gtkdoc opt">,</span>
493
 
                                      user_data<span class="gtkdoc opt">,</span>
494
 
                                      baker_bake_cake_async<span class="gtkdoc opt">);</span>
495
 
  cake <span class="gtkdoc opt">=</span> <span class="function">_baker_get_cached_cake</span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">,</span> radius<span class="gtkdoc opt">);</span>
496
 
 
497
 
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span>cake <span class="gtkdoc opt">!=</span> NULL<span class="gtkdoc opt">)</span>
498
 
    <span class="gtkdoc opt">{</span>
499
 
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer">g_simple_async_result_set_op_res_gpointer</a></span> <span class="gtkdoc opt">(</span>simple<span class="gtkdoc opt">,</span>
500
 
                                                 <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> <span class="gtkdoc opt">(</span>cake<span class="gtkdoc opt">),</span>
501
 
                                                 g_object_unref<span class="gtkdoc opt">);</span>
502
 
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-complete-in-idle">g_simple_async_result_complete_in_idle</a></span> <span class="gtkdoc opt">(</span>simple<span class="gtkdoc opt">);</span>
503
 
      <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> <span class="gtkdoc opt">(</span>simple<span class="gtkdoc opt">);</span>
504
 
      <span class="gtkdoc slc">// Drop the reference returned by _baker_get_cached_cake();</span>
505
 
      <span class="gtkdoc slc">// the GSimpleAsyncResult has taken its own reference.</span>
506
 
      <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> <span class="gtkdoc opt">(</span>cake<span class="gtkdoc opt">);</span>
507
 
      <span class="keyword">return</span><span class="gtkdoc opt">;</span>
508
 
    <span class="gtkdoc opt">}</span>
509
 
 
510
 
  <span class="function">_baker_prepare_cake</span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">,</span> radius<span class="gtkdoc opt">,</span> baked_cb<span class="gtkdoc opt">,</span> simple<span class="gtkdoc opt">);</span>
511
 
<span class="gtkdoc opt">}</span>
512
 
 
513
 
Cake <span class="gtkdoc opt">*</span>
514
 
<span class="function">baker_bake_cake_finish</span> <span class="gtkdoc opt">(</span>Baker        <span class="gtkdoc opt">*</span>self<span class="gtkdoc opt">,</span>
515
 
                        GAsyncResult <span class="gtkdoc opt">*</span>result<span class="gtkdoc opt">,</span>
516
 
                        GError      <span class="gtkdoc opt">**</span>error<span class="gtkdoc opt">)</span>
517
 
<span class="gtkdoc opt">{</span>
518
 
  GSimpleAsyncResult <span class="gtkdoc opt">*</span>simple<span class="gtkdoc opt">;</span>
519
 
  Cake               <span class="gtkdoc opt">*</span>cake<span class="gtkdoc opt">;</span>
520
 
 
521
 
  <span class="function"><a href="https://developer.gnome.org/glib/unstable/glib-Warnings-and-Assertions.html#g-return-val-if-fail">g_return_val_if_fail</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-is-valid">g_simple_async_result_is_valid</a></span> <span class="gtkdoc opt">(</span>result<span class="gtkdoc opt">,</span>
522
 
                                                        <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span> <span class="gtkdoc opt">(</span>self<span class="gtkdoc opt">),</span>
523
 
                                                        baker_bake_cake_async<span class="gtkdoc opt">),</span>
524
 
                        NULL<span class="gtkdoc opt">);</span>
525
 
 
526
 
  simple <span class="gtkdoc opt">= (</span>GSimpleAsyncResult <span class="gtkdoc opt">*)</span> result<span class="gtkdoc opt">;</span>
527
 
 
528
 
  <span class="keyword">if</span> <span class="gtkdoc opt">(</span><span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-propagate-error">g_simple_async_result_propagate_error</a></span> <span class="gtkdoc opt">(</span>simple<span class="gtkdoc opt">,</span> error<span class="gtkdoc opt">))</span>
529
 
    <span class="keyword">return</span> NULL<span class="gtkdoc opt">;</span>
530
 
 
531
 
  cake <span class="gtkdoc opt">=</span> <span class="function">CAKE</span> <span class="gtkdoc opt">(</span><span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-get-op-res-gpointer">g_simple_async_result_get_op_res_gpointer</a></span> <span class="gtkdoc opt">(</span>simple<span class="gtkdoc opt">));</span>
532
 
  <span class="keyword">return</span> <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> <span class="gtkdoc opt">(</span>cake<span class="gtkdoc opt">);</span>
533
 
<span class="gtkdoc opt">}</span></pre></td>
 
456
    <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer">g_simple_async_result_set_op_res_gpointer</a></span> (result,
 
457
                                               <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> (cake),
 
458
                                               <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span>);
 
459
 
 
460
 
 
461
  <span class="comment">// In this example, we assume that baked_cb is called as a callback from</span>
 
462
  <span class="comment">// the mainloop, so it's safe to complete the operation synchronously here.</span>
 
463
  <span class="comment">// If, however, _baker_prepare_cake () might call its callback without</span>
 
464
  <span class="comment">// first returning to the mainloop — inadvisable, but some APIs do so —</span>
 
465
  <span class="comment">// we would need to use g_simple_async_result_complete_in_idle().</span>
 
466
  <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-complete">g_simple_async_result_complete</a></span> (result);
 
467
  <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> (result);
 
468
}
 
469
 
 
470
<span class="type">void</span>
 
471
baker_bake_cake_async (Baker              *self,
 
472
                       <span class="type">guint</span>               radius,
 
473
                       <span class="type">GAsyncReadyCallback</span> callback,
 
474
                       <span class="type">gpointer</span>            user_data)
 
475
{
 
476
  <span class="type">GSimpleAsyncResult</span> *simple;
 
477
  Cake               *cake;
 
478
 
 
479
  <span class="keyword">if</span> (radius &lt; <span class="number">3</span>)
 
480
    {
 
481
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-report-error-in-idle">g_simple_async_report_error_in_idle</a></span> (<span class="preproc">G_OBJECT</span> (self),
 
482
                                           callback,
 
483
                                           user_data,
 
484
                                           BAKER_ERRORS,
 
485
                                           BAKER_ERROR_TOO_SMALL,
 
486
                                           <span class="number">&quot;</span><span class="symbol">%u</span><span class="number">cm radius cakes are silly&quot;</span>,
 
487
                                           radius);
 
488
      <span class="keyword">return</span>;
 
489
    }
 
490
 
 
491
  simple = <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-new">g_simple_async_result_new</a></span> (<span class="preproc">G_OBJECT</span> (self),
 
492
                                      callback,
 
493
                                      user_data,
 
494
                                      baker_bake_cake_async);
 
495
  cake = _baker_get_cached_cake (self, radius);
 
496
 
 
497
  <span class="keyword">if</span> (cake != <span class="number">NULL</span>)
 
498
    {
 
499
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer">g_simple_async_result_set_op_res_gpointer</a></span> (simple,
 
500
                                                 <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> (cake),
 
501
                                                 <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span>);
 
502
      <span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-complete-in-idle">g_simple_async_result_complete_in_idle</a></span> (simple);
 
503
      <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> (simple);
 
504
      <span class="comment">// Drop the reference returned by _baker_get_cached_cake();</span>
 
505
      <span class="comment">// the GSimpleAsyncResult has taken its own reference.</span>
 
506
      <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> (cake);
 
507
      <span class="keyword">return</span>;
 
508
    }
 
509
 
 
510
  _baker_prepare_cake (self, radius, baked_cb, simple);
 
511
}
 
512
 
 
513
Cake *
 
514
baker_bake_cake_finish (Baker        *self,
 
515
                        <span class="type">GAsyncResult</span> *result,
 
516
                        <span class="type">GError</span>      **error)
 
517
{
 
518
  <span class="type">GSimpleAsyncResult</span> *simple;
 
519
  Cake               *cake;
 
520
 
 
521
  <span class="preproc">g_return_val_if_fail</span> (<span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-is-valid">g_simple_async_result_is_valid</a></span> (result,
 
522
                                                        <span class="preproc">G_OBJECT</span> (self),
 
523
                                                        baker_bake_cake_async),
 
524
                        <span class="number">NULL</span>);
 
525
 
 
526
  simple = (<span class="type">GSimpleAsyncResult</span> *) result;
 
527
 
 
528
  <span class="keyword">if</span> (<span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-propagate-error">g_simple_async_result_propagate_error</a></span> (simple, error))
 
529
    <span class="keyword">return</span> <span class="number">NULL</span>;
 
530
 
 
531
  cake = CAKE (<span class="function"><a href="GSimpleAsyncResult.html#g-simple-async-result-get-op-res-gpointer">g_simple_async_result_get_op_res_gpointer</a></span> (simple));
 
532
  <span class="keyword">return</span> <span class="function"><a href="https://developer.gnome.org/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-ref">g_object_ref</a></span> (cake);
 
533
}</pre></td>
534
534
      </tr>
535
535
    </tbody>
536
536
  </table>
1629
1629
</div>
1630
1630
<div class="footer">
1631
1631
<hr>
1632
 
          Generated by GTK-Doc V1.21</div>
 
1632
          Generated by GTK-Doc V1.21.1</div>
1633
1633
</body>
1634
1634
</html>
 
 
b'\\ No newline at end of file'