213
213
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-callback-indirect" title="g_source_set_callback_indirect ()">g_source_set_callback_indirect</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
214
214
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> callback_data</code></em>,
215
215
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSourceCallbackFuncs" title="struct GSourceCallbackFuncs"><span class="type">GSourceCallbackFuncs</span></a> *callback_funcs</code></em>);
216
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-ready-time" title="g_source_set_ready_time ()">g_source_set_ready_time</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
217
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="type">gint64</span></a> ready_time</code></em>);
218
<a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="returnvalue">gint64</span></a> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-get-ready-time" title="g_source_get_ready_time ()">g_source_get_ready_time</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>);
219
<a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()">g_source_add_unix_fd</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
220
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
221
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> events</code></em>);
222
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-unix-fd" title="g_source_remove_unix_fd ()">g_source_remove_unix_fd</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
223
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>);
224
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-modify-unix-fd" title="g_source_modify_unix_fd ()">g_source_modify_unix_fd</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
225
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>,
226
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> new_events</code></em>);
227
<a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="returnvalue">GIOCondition</span></a> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-query-unix-fd" title="g_source_query_unix_fd ()">g_source_query_unix_fd</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
228
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>);
216
229
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-poll" title="g_source_add_poll ()">g_source_add_poll</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
217
230
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a> *fd</code></em>);
218
231
<span class="returnvalue">void</span> <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-poll" title="g_source_remove_poll ()">g_source_remove_poll</a> (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
832
845
checking to see if any event sources are ready to be processed,
833
846
then if no events sources are ready and <em class="parameter"><code>may_block</code></em> is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, waiting
834
847
for a source to become ready, then dispatching the highest priority
835
events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em> is <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>
836
sources are not waited to become ready, only those highest priority
837
events sources will be dispatched (if any), that are ready at this
848
events sources that are ready. Otherwise, if <em class="parameter"><code>may_block</code></em> is <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>
849
sources are not waited to become ready, only those highest priority
850
events sources will be dispatched (if any), that are ready at this
838
851
given moment without further waiting.
841
Note that even when <em class="parameter"><code>may_block</code></em> is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, it is still possible for
842
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> to return <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>, since the the wait may
854
Note that even when <em class="parameter"><code>may_block</code></em> is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>, it is still possible for
855
<a class="link" href="glib-The-Main-Event-Loop.html#g-main-context-iteration" title="g_main_context_iteration ()"><code class="function">g_main_context_iteration()</code></a> to return <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>, since the wait may
843
856
be interrupted for other reasons than an event source becoming ready.
845
858
<div class="variablelist"><table border="0" class="variablelist">
2843
2863
void (*finalize) (GSource *source); /* Can be NULL */
2847
The <span class="structname">GSourceFuncs</span> struct contains a table of
2848
functions used to handle event sources in a generic manner.
2851
For idle sources, the prepare and check functions always return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>
2852
to indicate that the source is always ready to be processed. The prepare
2853
function also returns a timeout value of 0 to ensure that the <code class="function">poll()</code> call
2854
doesn't block (since that would be time wasted which could have been spent
2855
running the idle function).
2858
For timeout sources, the prepare and check functions both return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>
2859
if the timeout interval has expired. The prepare function also returns
2860
a timeout value to ensure that the <code class="function">poll()</code> call doesn't block too long
2861
and miss the next timeout.
2864
For file descriptor sources, the prepare function typically returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>,
2865
since it must wait until <code class="function">poll()</code> has been called before it knows whether
2866
any events need to be processed. It sets the returned timeout to -1 to
2867
indicate that it doesn't mind how long the <code class="function">poll()</code> call blocks. In the
2868
check function, it tests the results of the <code class="function">poll()</code> call to see if the
2869
required condition has been met, and returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if so.
2871
2866
<div class="variablelist"><table border="0" class="variablelist">
2873
2868
<col align="left" valign="top">
2882
2877
a <em class="parameter"><code>timeout_</code></em> value which should be the maximum timeout (in milliseconds)
2883
2878
which should be passed to the <code class="function">poll()</code> call. The actual timeout used will
2884
2879
be -1 if all sources returned -1, or it will be the minimum of all the
2885
<em class="parameter"><code>timeout_</code></em> values returned which were >= 0.</td>
2880
<em class="parameter"><code>timeout_</code></em> values returned which were >= 0. Since 2.36 this may
2881
be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, in which case the effect is as if the function always</td>
2888
2884
<td><p><span class="term"><em class="structfield"><code><a name="GSourceFuncs.check"></a>check</code></em> ()</span></p></td>
2889
<td>Called after all the file descriptors are polled. The source
2890
should return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if it is ready to be dispatched. Note that some
2891
time may have passed since the previous prepare function was called,
2892
so the source should be checked again here.</td>
2895
2888
<td><p><span class="term"><em class="structfield"><code><a name="GSourceFuncs.dispatch"></a>dispatch</code></em> ()</span></p></td>
2896
<td>Called to dispatch the event source, after it has returned
2897
<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> in either its <em class="parameter"><code>prepare</code></em> or its <em class="parameter"><code>check</code></em> function. The <em class="parameter"><code>dispatch</code></em>
2898
function is passed in a callback function and data. The callback
2899
function may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> if the source was never connected to a callback
2900
using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-callback" title="g_source_set_callback ()"><code class="function">g_source_set_callback()</code></a>. The <em class="parameter"><code>dispatch</code></em> function should call the
2901
callback function with <em class="parameter"><code>user_data</code></em> and whatever additional parameters
2902
are needed for this type of event source.</td>
2905
2892
<td><p><span class="term"><em class="structfield"><code><a name="GSourceFuncs.finalize"></a>finalize</code></em> ()</span></p></td>
2906
<td>Called when the source is finalized.</td>
3640
3634
<div class="refsect2">
3635
<a name="g-source-set-ready-time"></a><h3>g_source_set_ready_time ()</h3>
3636
<pre class="programlisting"><span class="returnvalue">void</span> g_source_set_ready_time (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3637
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="type">gint64</span></a> ready_time</code></em>);</pre>
3639
Sets a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> to be dispatched when the given monotonic time is
3640
reached (or passed). If the monotonic time is in the past (as it
3641
always will be if <em class="parameter"><code>ready_time</code></em> is 0) then the source will be
3642
dispatched immediately.
3645
If <em class="parameter"><code>ready_time</code></em> is -1 then the source is never woken up on the basis
3646
of the passage of time.
3649
Dispatching the source does not reset the ready time. You should do
3650
so yourself, from the source dispatch function.
3653
Note that if you have a pair of sources where the ready time of one
3654
suggests that it will be delivered first but the priority for the
3655
other suggests that it would be delivered first, and the ready time
3656
for both sources is reached during the same main context iteration
3657
then the order of dispatch is undefined.
3659
<div class="variablelist"><table border="0" class="variablelist">
3661
<col align="left" valign="top">
3666
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3667
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3671
<td><p><span class="term"><em class="parameter"><code>ready_time</code></em> :</span></p></td>
3672
<td>the monotonic time at which the source will be ready,
3673
0 for "immediately", -1 for "never"</td>
3677
<p class="since">Since 2.36</p>
3680
<div class="refsect2">
3681
<a name="g-source-get-ready-time"></a><h3>g_source_get_ready_time ()</h3>
3682
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint64" title="gint64"><span class="returnvalue">gint64</span></a> g_source_get_ready_time (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>);</pre>
3684
Gets the "ready time" of <em class="parameter"><code>source</code></em>, as set by
3685
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-set-ready-time" title="g_source_set_ready_time ()"><code class="function">g_source_set_ready_time()</code></a>.
3688
Any time before the current monotonic time (including 0) is an
3689
indication that the source will fire immediately.
3691
<div class="variablelist"><table border="0" class="variablelist">
3693
<col align="left" valign="top">
3698
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3699
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3703
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
3704
<td>the monotonic ready time, -1 for "never"</td>
3710
<div class="refsect2">
3711
<a name="g-source-add-unix-fd"></a><h3>g_source_add_unix_fd ()</h3>
3712
<pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_source_add_unix_fd (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3713
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> fd</code></em>,
3714
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> events</code></em>);</pre>
3716
Monitors <em class="parameter"><code>fd</code></em> for the IO events in <em class="parameter"><code>events</code></em>.
3719
The tag returned by this function can be used to remove or modify the
3720
monitoring of the fd using <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-unix-fd" title="g_source_remove_unix_fd ()"><code class="function">g_source_remove_unix_fd()</code></a> or
3721
<a class="link" href="glib-The-Main-Event-Loop.html#g-source-modify-unix-fd" title="g_source_modify_unix_fd ()"><code class="function">g_source_modify_unix_fd()</code></a>.
3724
It is not necessary to remove the fd before destroying the source; it
3725
will be cleaned up automatically.
3728
As the name suggests, this function is not available on Windows.
3730
<div class="variablelist"><table border="0" class="variablelist">
3732
<col align="left" valign="top">
3737
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3738
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3742
<td><p><span class="term"><em class="parameter"><code>fd</code></em> :</span></p></td>
3743
<td>the fd to monitor</td>
3746
<td><p><span class="term"><em class="parameter"><code>events</code></em> :</span></p></td>
3747
<td>an event mask</td>
3750
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
3751
<td>an opaque tag</td>
3755
<p class="since">Since 2.36</p>
3758
<div class="refsect2">
3759
<a name="g-source-remove-unix-fd"></a><h3>g_source_remove_unix_fd ()</h3>
3760
<pre class="programlisting"><span class="returnvalue">void</span> g_source_remove_unix_fd (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3761
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>);</pre>
3763
Reverses the effect of a previous call to <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()"><code class="function">g_source_add_unix_fd()</code></a>.
3766
You only need to call this if you want to remove an fd from being
3767
watched while keeping the same source around. In the normal case you
3768
will just want to destroy the source.
3771
As the name suggests, this function is not available on Windows.
3773
<div class="variablelist"><table border="0" class="variablelist">
3775
<col align="left" valign="top">
3780
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3781
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3785
<td><p><span class="term"><em class="parameter"><code>tag</code></em> :</span></p></td>
3786
<td>the tag from <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()"><code class="function">g_source_add_unix_fd()</code></a>
3791
<p class="since">Since 2.36</p>
3794
<div class="refsect2">
3795
<a name="g-source-modify-unix-fd"></a><h3>g_source_modify_unix_fd ()</h3>
3796
<pre class="programlisting"><span class="returnvalue">void</span> g_source_modify_unix_fd (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3797
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>,
3798
<em class="parameter"><code><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="type">GIOCondition</span></a> new_events</code></em>);</pre>
3800
Updates the event mask to watch for the fd identified by <em class="parameter"><code>tag</code></em>.
3803
<em class="parameter"><code>tag</code></em> is the tag returned from <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()"><code class="function">g_source_add_unix_fd()</code></a>.
3806
If you want to remove a fd, don't set its event mask to zero.
3807
Instead, call <a class="link" href="glib-The-Main-Event-Loop.html#g-source-remove-unix-fd" title="g_source_remove_unix_fd ()"><code class="function">g_source_remove_unix_fd()</code></a>.
3810
As the name suggests, this function is not available on Windows.
3812
<div class="variablelist"><table border="0" class="variablelist">
3814
<col align="left" valign="top">
3819
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3820
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3824
<td><p><span class="term"><em class="parameter"><code>tag</code></em> :</span></p></td>
3825
<td>the tag from <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()"><code class="function">g_source_add_unix_fd()</code></a>
3829
<td><p><span class="term"><em class="parameter"><code>new_events</code></em> :</span></p></td>
3830
<td>the new event mask to watch</td>
3834
<p class="since">Since 2.36</p>
3837
<div class="refsect2">
3838
<a name="g-source-query-unix-fd"></a><h3>g_source_query_unix_fd ()</h3>
3839
<pre class="programlisting"><a class="link" href="glib-IO-Channels.html#GIOCondition" title="enum GIOCondition"><span class="returnvalue">GIOCondition</span></a> g_source_query_unix_fd (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3840
<em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="type">gpointer</span></a> tag</code></em>);</pre>
3842
Queries the events reported for the fd corresponding to <em class="parameter"><code>tag</code></em> on
3843
<em class="parameter"><code>source</code></em> during the last poll.
3846
The return value of this function is only defined when the function
3847
is called from the check or dispatch functions for <em class="parameter"><code>source</code></em>.
3850
As the name suggests, this function is not available on Windows.
3852
<div class="variablelist"><table border="0" class="variablelist">
3854
<col align="left" valign="top">
3859
<td><p><span class="term"><em class="parameter"><code>source</code></em> :</span></p></td>
3860
<td>a <a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a>
3864
<td><p><span class="term"><em class="parameter"><code>tag</code></em> :</span></p></td>
3865
<td>the tag from <a class="link" href="glib-The-Main-Event-Loop.html#g-source-add-unix-fd" title="g_source_add_unix_fd ()"><code class="function">g_source_add_unix_fd()</code></a>
3869
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
3870
<td>the conditions reported on the fd</td>
3874
<p class="since">Since 2.36</p>
3877
<div class="refsect2">
3641
3878
<a name="g-source-add-poll"></a><h3>g_source_add_poll ()</h3>
3642
3879
<pre class="programlisting"><span class="returnvalue">void</span> g_source_add_poll (<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GSource" title="struct GSource"><span class="type">GSource</span></a> *source</code></em>,
3643
3880
<em class="parameter"><code><a class="link" href="glib-The-Main-Event-Loop.html#GPollFD" title="struct GPollFD"><span class="type">GPollFD</span></a> *fd</code></em>);</pre>