re58.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>&lt;GSource&gt;: </title>
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.2">
  7. <link rel="home" href="index.html" title="">
  8. <link rel="up" href="ch01.html" title="GLib">
  9. <link rel="prev" href="re57.html" title="&lt;%GLibSliceConfig&gt;">
  10. <link rel="next" href="re59.html" title="&lt;%GLibSpawnError&gt;">
  11. <meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
  12. <link rel="stylesheet" href="style.css" type="text/css">
  13. </head>
  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="5"><tr valign="middle">
  16. <td width="100%" align="left" class="shortcuts"></td>
  17. <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
  18. <td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
  19. <td><a accesskey="p" href="re57.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
  20. <td><a accesskey="n" href="re59.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
  21. </tr></table>
  22. <div class="refentry">
  23. <a name="id-1.1.59"></a><div class="titlepage"></div>
  24. <div class="refnamediv">
  25. <h2>&lt;GSource&gt;</h2>
  26. <p>&lt;GSource&gt;</p>
  27. </div>
  28. <div class="refsect1">
  29. <a name="id-1.1.59.2"></a><h2>Description</h2>
  30. <p>The <code class="code">GSource</code> struct is an opaque data type
  31. representing an event source.</p>
  32. </div>
  33. <div class="refsect1">
  34. <a name="id-1.1.59.3"></a><h2>Functions</h2>
  35. <div class="refsect2">
  36. <a name="id-1.1.59.3.2"></a><h3>add-child-source</h3>
  37. <div class="informalexample"><pre class="programlisting">(define-values () (source:add-child-source self child-source))
  38. </pre></div>
  39. <p>Adds <em class="parameter"><code>child_source</code></em> to <em class="parameter"><code>source</code></em> as a "polled" source; when <em class="parameter"><code>source</code></em> is
  40. added to a <span class="type">GMainContext</span>, <em class="parameter"><code>child_source</code></em> will be automatically added
  41. with the same priority, when <em class="parameter"><code>child_source</code></em> is triggered, it will
  42. cause <em class="parameter"><code>source</code></em> to dispatch (in addition to calling its own
  43. callback), and when <em class="parameter"><code>source</code></em> is destroyed, it will destroy
  44. <em class="parameter"><code>child_source</code></em> as well. (<em class="parameter"><code>source</code></em> will also still be dispatched if
  45. its own prepare/check functions indicate that it is ready.)
  46. </p>
  47. <p>If you don't need <em class="parameter"><code>child_source</code></em> to do anything on its own when it
  48. triggers, you can call <code class="function">g_source_set_dummy_callback()</code> on it to set a
  49. callback that does nothing (except return <code class="constant">TRUE</code> if appropriate).
  50. </p>
  51. <p><em class="parameter"><code>source</code></em> will hold a reference on <em class="parameter"><code>child_source</code></em> while <em class="parameter"><code>child_source</code></em>
  52. is attached to it.
  53. </p>
  54. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  55. Do not call this API on a <span class="type">GSource</span> that you did not create.</p>
  56. <div class="refsect3">
  57. <a name="id-1.1.59.3.2.7"></a><h4>Parameters</h4>
  58. <div class="informaltable"><table>
  59. <tr>
  60. <td class="parameter_name"><p>source</p></td>
  61. <td class="parameter_description">
  62. <p>a <span class="type">GSource</span></p>
  63. <p>Passed as <code class="code">self</code></p>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td class="parameter_name"><p>child_source</p></td>
  68. <td class="parameter_description">
  69. <p>a second <span class="type">GSource</span> that <em class="parameter"><code>source</code></em> should "poll"</p>
  70. <p>Passed as <code class="code">child-source</code></p>
  71. </td>
  72. </tr>
  73. </table></div>
  74. </div>
  75. </div>
  76. <div class="refsect2">
  77. <a name="id-1.1.59.3.3"></a><h3>add-poll</h3>
  78. <div class="informalexample"><pre class="programlisting">(define-values () (source:add-poll self fd))
  79. </pre></div>
  80. <p>Adds a file descriptor to the set of file descriptors polled for
  81. this source. This is usually combined with <code class="function">g_source_new()</code> to add an
  82. event source. The event source's check function will typically test
  83. the <em class="parameter"><code>revents</code></em> field in the <span class="type">GPollFD</span> struct and return <code class="constant">TRUE</code> if events need
  84. to be processed.
  85. </p>
  86. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  87. Do not call this API on a <span class="type">GSource</span> that you did not create.
  88. </p>
  89. <p>Using this API forces the linear scanning of event sources on each
  90. main loop iteration. Newly-written event sources should try to use
  91. <code class="function">g_source_add_unix_fd()</code> instead of this API.</p>
  92. <div class="refsect3">
  93. <a name="id-1.1.59.3.3.6"></a><h4>Parameters</h4>
  94. <div class="informaltable"><table>
  95. <tr>
  96. <td class="parameter_name"><p>source</p></td>
  97. <td class="parameter_description">
  98. <p>a <span class="type">GSource</span></p>
  99. <p>Passed as <code class="code">self</code></p>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td class="parameter_name"><p>fd</p></td>
  104. <td class="parameter_description">
  105. <p>a <span class="type">GPollFD</span> structure holding information about a file
  106. descriptor to watch.</p>
  107. <p>Passed as <code class="code">fd</code></p>
  108. </td>
  109. </tr>
  110. </table></div>
  111. </div>
  112. </div>
  113. <div class="refsect2">
  114. <a name="id-1.1.59.3.4"></a><h3>add-unix-fd</h3>
  115. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:add-unix-fd self fd events))
  116. </pre></div>
  117. <p>Monitors <em class="parameter"><code>fd</code></em> for the IO events in <em class="parameter"><code>events</code></em>.
  118. </p>
  119. <p>The tag returned by this function can be used to remove or modify the
  120. monitoring of the fd using <code class="function">g_source_remove_unix_fd()</code> or
  121. <code class="function">g_source_modify_unix_fd()</code>.
  122. </p>
  123. <p>It is not necessary to remove the fd before destroying the source; it
  124. will be cleaned up automatically.
  125. </p>
  126. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  127. Do not call this API on a <span class="type">GSource</span> that you did not create.
  128. </p>
  129. <p>As the name suggests, this function is not available on Windows.</p>
  130. <div class="refsect3">
  131. <a name="id-1.1.59.3.4.8"></a><h4>Parameters</h4>
  132. <div class="informaltable"><table>
  133. <tr>
  134. <td class="parameter_name"><p>source</p></td>
  135. <td class="parameter_description">
  136. <p>a <span class="type">GSource</span></p>
  137. <p>Passed as <code class="code">self</code></p>
  138. </td>
  139. </tr>
  140. <tr>
  141. <td class="parameter_name"><p>fd</p></td>
  142. <td class="parameter_description">
  143. <p>the fd to monitor</p>
  144. <p>Passed as <code class="code">fd</code></p>
  145. </td>
  146. </tr>
  147. <tr>
  148. <td class="parameter_name"><p>events</p></td>
  149. <td class="parameter_description">
  150. <p>an event mask</p>
  151. <p>Passed as <code class="code">events</code></p>
  152. </td>
  153. </tr>
  154. </table></div>
  155. </div>
  156. </div>
  157. <div class="refsect2">
  158. <a name="id-1.1.59.3.5"></a><h3>attach</h3>
  159. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:attach self context))
  160. </pre></div>
  161. <p>Adds a <span class="type">GSource</span> to a <em class="parameter"><code>context</code></em> so that it will be executed within
  162. that context. Remove it by calling <code class="function">g_source_destroy()</code>.
  163. </p>
  164. <p>This function is safe to call from any thread, regardless of which thread
  165. the <em class="parameter"><code>context</code></em> is running in.</p>
  166. <div class="refsect3">
  167. <a name="id-1.1.59.3.5.5"></a><h4>Parameters</h4>
  168. <div class="informaltable"><table>
  169. <tr>
  170. <td class="parameter_name"><p>source</p></td>
  171. <td class="parameter_description">
  172. <p>a <span class="type">GSource</span></p>
  173. <p>Passed as <code class="code">self</code></p>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td class="parameter_name"><p>context</p></td>
  178. <td class="parameter_description">
  179. <p>a <span class="type">GMainContext</span> (if <code class="constant">NULL</code>, the default context will be used)</p>
  180. <p>Passed as <code class="code">context</code></p>
  181. </td>
  182. </tr>
  183. </table></div>
  184. </div>
  185. </div>
  186. <div class="refsect2">
  187. <a name="id-1.1.59.3.6"></a><h3>destroy</h3>
  188. <div class="informalexample"><pre class="programlisting">(define-values () (source:destroy self))
  189. </pre></div>
  190. <p>Removes a source from its <span class="type">GMainContext</span>, if any, and mark it as
  191. destroyed. The source cannot be subsequently added to another
  192. context. It is safe to call this on sources which have already been
  193. removed from their context.
  194. </p>
  195. <p>This does not unref the #GSource: if you still hold a reference, use
  196. <code class="function">g_source_unref()</code> to drop it.
  197. </p>
  198. <p>This function is safe to call from any thread, regardless of which thread
  199. the <span class="type">GMainContext</span> is running in.</p>
  200. <div class="refsect3">
  201. <a name="id-1.1.59.3.6.6"></a><h4>Parameters</h4>
  202. <div class="informaltable"><table><tr>
  203. <td class="parameter_name"><p>source</p></td>
  204. <td class="parameter_description">
  205. <p>a <span class="type">GSource</span></p>
  206. <p>Passed as <code class="code">self</code></p>
  207. </td>
  208. </tr></table></div>
  209. </div>
  210. </div>
  211. <div class="refsect2">
  212. <a name="id-1.1.59.3.7"></a><h3>get-can-recurse?</h3>
  213. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-can-recurse? self))
  214. </pre></div>
  215. <p>Checks whether a source is allowed to be called recursively.
  216. see <code class="function">g_source_set_can_recurse()</code>.</p>
  217. <div class="refsect3">
  218. <a name="id-1.1.59.3.7.4"></a><h4>Parameters</h4>
  219. <div class="informaltable"><table><tr>
  220. <td class="parameter_name"><p>source</p></td>
  221. <td class="parameter_description">
  222. <p>a <span class="type">GSource</span></p>
  223. <p>Passed as <code class="code">self</code></p>
  224. </td>
  225. </tr></table></div>
  226. </div>
  227. </div>
  228. <div class="refsect2">
  229. <a name="id-1.1.59.3.8"></a><h3>get-context</h3>
  230. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-context self))
  231. </pre></div>
  232. <p>Gets the <span class="type">GMainContext</span> with which the source is associated.
  233. </p>
  234. <p>You can call this on a source that has been destroyed, provided
  235. that the <span class="type">GMainContext</span> it was attached to still exists (in which
  236. case it will return that <span class="type">GMainContext</span>). In particular, you can
  237. always call this function on the source returned from
  238. <code class="function">g_main_current_source()</code>. But calling this function on a source
  239. whose <span class="type">GMainContext</span> has been destroyed is an error.</p>
  240. <div class="refsect3">
  241. <a name="id-1.1.59.3.8.5"></a><h4>Parameters</h4>
  242. <div class="informaltable"><table><tr>
  243. <td class="parameter_name"><p>source</p></td>
  244. <td class="parameter_description">
  245. <p>a <span class="type">GSource</span></p>
  246. <p>Passed as <code class="code">self</code></p>
  247. </td>
  248. </tr></table></div>
  249. </div>
  250. </div>
  251. <div class="refsect2">
  252. <a name="id-1.1.59.3.9"></a><h3>get-id</h3>
  253. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-id self))
  254. </pre></div>
  255. <p>Returns the numeric ID for a particular source. The ID of a source
  256. is a positive integer which is unique within a particular main loop
  257. context. The reverse
  258. mapping from ID to source is done by <code class="function">g_main_context_find_source_by_id()</code>.
  259. </p>
  260. <p>You can only call this function while the source is associated to a
  261. <span class="type">GMainContext</span> instance; calling this function before <code class="function">g_source_attach()</code>
  262. or after <code class="function">g_source_destroy()</code> yields undefined behavior. The ID returned
  263. is unique within the <span class="type">GMainContext</span> instance passed to <code class="function">g_source_attach()</code>.</p>
  264. <div class="refsect3">
  265. <a name="id-1.1.59.3.9.5"></a><h4>Parameters</h4>
  266. <div class="informaltable"><table><tr>
  267. <td class="parameter_name"><p>source</p></td>
  268. <td class="parameter_description">
  269. <p>a <span class="type">GSource</span></p>
  270. <p>Passed as <code class="code">self</code></p>
  271. </td>
  272. </tr></table></div>
  273. </div>
  274. </div>
  275. <div class="refsect2">
  276. <a name="id-1.1.59.3.10"></a><h3>get-name</h3>
  277. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-name self))
  278. </pre></div>
  279. <p>Gets a name for the source, used in debugging and profiling. The
  280. name may be <span class="type">NULL</span> if it has never been set with <code class="function">g_source_set_name()</code>.</p>
  281. <div class="refsect3">
  282. <a name="id-1.1.59.3.10.4"></a><h4>Parameters</h4>
  283. <div class="informaltable"><table><tr>
  284. <td class="parameter_name"><p>source</p></td>
  285. <td class="parameter_description">
  286. <p>a <span class="type">GSource</span></p>
  287. <p>Passed as <code class="code">self</code></p>
  288. </td>
  289. </tr></table></div>
  290. </div>
  291. </div>
  292. <div class="refsect2">
  293. <a name="id-1.1.59.3.11"></a><h3>get-priority</h3>
  294. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-priority self))
  295. </pre></div>
  296. <p>Gets the priority of a source.</p>
  297. <div class="refsect3">
  298. <a name="id-1.1.59.3.11.4"></a><h4>Parameters</h4>
  299. <div class="informaltable"><table><tr>
  300. <td class="parameter_name"><p>source</p></td>
  301. <td class="parameter_description">
  302. <p>a <span class="type">GSource</span></p>
  303. <p>Passed as <code class="code">self</code></p>
  304. </td>
  305. </tr></table></div>
  306. </div>
  307. </div>
  308. <div class="refsect2">
  309. <a name="id-1.1.59.3.12"></a><h3>get-ready-time</h3>
  310. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-ready-time self))
  311. </pre></div>
  312. <p>Gets the "ready time" of <em class="parameter"><code>source</code></em>, as set by
  313. <code class="function">g_source_set_ready_time()</code>.
  314. </p>
  315. <p>Any time before the current monotonic time (including 0) is an
  316. indication that the source will fire immediately.</p>
  317. <div class="refsect3">
  318. <a name="id-1.1.59.3.12.5"></a><h4>Parameters</h4>
  319. <div class="informaltable"><table><tr>
  320. <td class="parameter_name"><p>source</p></td>
  321. <td class="parameter_description">
  322. <p>a <span class="type">GSource</span></p>
  323. <p>Passed as <code class="code">self</code></p>
  324. </td>
  325. </tr></table></div>
  326. </div>
  327. </div>
  328. <div class="refsect2">
  329. <a name="id-1.1.59.3.13"></a><h3>get-time</h3>
  330. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:get-time self))
  331. </pre></div>
  332. <p>Gets the time to be used when checking this source. The advantage of
  333. calling this function over calling <code class="function">g_get_monotonic_time()</code> directly is
  334. that when checking multiple sources, GLib can cache a single value
  335. instead of having to repeatedly get the system monotonic time.
  336. </p>
  337. <p>The time here is the system monotonic time, if available, or some
  338. other reasonable alternative otherwise. See <code class="function">g_get_monotonic_time()</code>.</p>
  339. <div class="refsect3">
  340. <a name="id-1.1.59.3.13.5"></a><h4>Parameters</h4>
  341. <div class="informaltable"><table><tr>
  342. <td class="parameter_name"><p>source</p></td>
  343. <td class="parameter_description">
  344. <p>a <span class="type">GSource</span></p>
  345. <p>Passed as <code class="code">self</code></p>
  346. </td>
  347. </tr></table></div>
  348. </div>
  349. </div>
  350. <div class="refsect2">
  351. <a name="id-1.1.59.3.14"></a><h3>is-destroyed?</h3>
  352. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:is-destroyed? self))
  353. </pre></div>
  354. <p>Returns whether <em class="parameter"><code>source</code></em> has been destroyed.
  355. </p>
  356. <p>This is important when you operate upon your objects
  357. from within idle handlers, but may have freed the object
  358. before the dispatch of your idle handler.
  359. </p>
  360. <div class="informalexample"><pre class="programlisting">
  361. static gboolean
  362. idle_callback (gpointer data)
  363. {
  364. SomeWidget *self = data;
  365. GDK_THREADS_ENTER ();
  366. // do stuff with self
  367. self-&gt;idle_id = 0;
  368. GDK_THREADS_LEAVE ();
  369. return G_SOURCE_REMOVE;
  370. }
  371. static void
  372. some_widget_do_stuff_later (SomeWidget *self)
  373. {
  374. self-&gt;idle_id = g_idle_add (idle_callback, self);
  375. }
  376. static void
  377. some_widget_finalize (GObject *object)
  378. {
  379. SomeWidget *self = SOME_WIDGET (object);
  380. if (self-&gt;idle_id)
  381. g_source_remove (self-&gt;idle_id);
  382. G_OBJECT_CLASS (parent_class)-&gt;finalize (object);
  383. }
  384. </pre></div>
  385. <p>This will fail in a multi-threaded application if the
  386. widget is destroyed before the idle handler fires due
  387. to the use after free in the callback. A solution, to
  388. this particular problem, is to check to if the source
  389. has already been destroy within the callback.
  390. </p>
  391. <div class="informalexample"><pre class="programlisting">
  392. static gboolean
  393. idle_callback (gpointer data)
  394. {
  395. SomeWidget *self = data;
  396. GDK_THREADS_ENTER ();
  397. if (!g_source_is_destroyed (g_main_current_source ()))
  398. {
  399. // do stuff with self
  400. }
  401. GDK_THREADS_LEAVE ();
  402. return FALSE;
  403. }
  404. </pre></div>
  405. <p>Calls to this function from a thread other than the one acquired by the
  406. <span class="type">GMainContext</span> the <span class="type">GSource</span> is attached to are typically redundant, as the
  407. source could be destroyed immediately after this function returns. However,
  408. once a source is destroyed it cannot be un-destroyed, so this function can be
  409. used for opportunistic checks from any thread.</p>
  410. <div class="refsect3">
  411. <a name="id-1.1.59.3.14.9"></a><h4>Parameters</h4>
  412. <div class="informaltable"><table><tr>
  413. <td class="parameter_name"><p>source</p></td>
  414. <td class="parameter_description">
  415. <p>a <span class="type">GSource</span></p>
  416. <p>Passed as <code class="code">self</code></p>
  417. </td>
  418. </tr></table></div>
  419. </div>
  420. </div>
  421. <div class="refsect2">
  422. <a name="id-1.1.59.3.15"></a><h3>modify-unix-fd</h3>
  423. <div class="informalexample"><pre class="programlisting">(define-values () (source:modify-unix-fd self tag new-events))
  424. </pre></div>
  425. <p>Updates the event mask to watch for the fd identified by <em class="parameter"><code>tag</code></em>.
  426. </p>
  427. <p><em class="parameter"><code>tag</code></em> is the tag returned from <code class="function">g_source_add_unix_fd()</code>.
  428. </p>
  429. <p>If you want to remove a fd, don't set its event mask to zero.
  430. Instead, call <code class="function">g_source_remove_unix_fd()</code>.
  431. </p>
  432. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  433. Do not call this API on a <span class="type">GSource</span> that you did not create.
  434. </p>
  435. <p>As the name suggests, this function is not available on Windows.</p>
  436. <div class="refsect3">
  437. <a name="id-1.1.59.3.15.8"></a><h4>Parameters</h4>
  438. <div class="informaltable"><table>
  439. <tr>
  440. <td class="parameter_name"><p>source</p></td>
  441. <td class="parameter_description">
  442. <p>a <span class="type">GSource</span></p>
  443. <p>Passed as <code class="code">self</code></p>
  444. </td>
  445. </tr>
  446. <tr>
  447. <td class="parameter_name"><p>tag</p></td>
  448. <td class="parameter_description">
  449. <p>the tag from <code class="function">g_source_add_unix_fd()</code></p>
  450. <p>Passed as <code class="code">tag</code></p>
  451. </td>
  452. </tr>
  453. <tr>
  454. <td class="parameter_name"><p>new_events</p></td>
  455. <td class="parameter_description">
  456. <p>the new event mask to watch</p>
  457. <p>Passed as <code class="code">new-events</code></p>
  458. </td>
  459. </tr>
  460. </table></div>
  461. </div>
  462. </div>
  463. <div class="refsect2">
  464. <a name="id-1.1.59.3.16"></a><h3>query-unix-fd</h3>
  465. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:query-unix-fd self tag))
  466. </pre></div>
  467. <p>Queries the events reported for the fd corresponding to <em class="parameter"><code>tag</code></em> on
  468. <em class="parameter"><code>source</code></em> during the last poll.
  469. </p>
  470. <p>The return value of this function is only defined when the function
  471. is called from the check or dispatch functions for <em class="parameter"><code>source</code></em>.
  472. </p>
  473. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  474. Do not call this API on a <span class="type">GSource</span> that you did not create.
  475. </p>
  476. <p>As the name suggests, this function is not available on Windows.</p>
  477. <div class="refsect3">
  478. <a name="id-1.1.59.3.16.7"></a><h4>Parameters</h4>
  479. <div class="informaltable"><table>
  480. <tr>
  481. <td class="parameter_name"><p>source</p></td>
  482. <td class="parameter_description">
  483. <p>a <span class="type">GSource</span></p>
  484. <p>Passed as <code class="code">self</code></p>
  485. </td>
  486. </tr>
  487. <tr>
  488. <td class="parameter_name"><p>tag</p></td>
  489. <td class="parameter_description">
  490. <p>the tag from <code class="function">g_source_add_unix_fd()</code></p>
  491. <p>Passed as <code class="code">tag</code></p>
  492. </td>
  493. </tr>
  494. </table></div>
  495. </div>
  496. </div>
  497. <div class="refsect2">
  498. <a name="id-1.1.59.3.17"></a><h3>ref</h3>
  499. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:ref self))
  500. </pre></div>
  501. <p>Increases the reference count on a source by one.</p>
  502. <div class="refsect3">
  503. <a name="id-1.1.59.3.17.4"></a><h4>Parameters</h4>
  504. <div class="informaltable"><table><tr>
  505. <td class="parameter_name"><p>source</p></td>
  506. <td class="parameter_description">
  507. <p>a <span class="type">GSource</span></p>
  508. <p>Passed as <code class="code">self</code></p>
  509. </td>
  510. </tr></table></div>
  511. </div>
  512. </div>
  513. <div class="refsect2">
  514. <a name="id-1.1.59.3.18"></a><h3>remove-child-source</h3>
  515. <div class="informalexample"><pre class="programlisting">(define-values () (source:remove-child-source self child-source))
  516. </pre></div>
  517. <p>Detaches <em class="parameter"><code>child_source</code></em> from <em class="parameter"><code>source</code></em> and destroys it.
  518. </p>
  519. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  520. Do not call this API on a <span class="type">GSource</span> that you did not create.</p>
  521. <div class="refsect3">
  522. <a name="id-1.1.59.3.18.5"></a><h4>Parameters</h4>
  523. <div class="informaltable"><table>
  524. <tr>
  525. <td class="parameter_name"><p>source</p></td>
  526. <td class="parameter_description">
  527. <p>a <span class="type">GSource</span></p>
  528. <p>Passed as <code class="code">self</code></p>
  529. </td>
  530. </tr>
  531. <tr>
  532. <td class="parameter_name"><p>child_source</p></td>
  533. <td class="parameter_description">
  534. <p>a <span class="type">GSource</span> previously passed to
  535. <code class="function">g_source_add_child_source()</code>.</p>
  536. <p>Passed as <code class="code">child-source</code></p>
  537. </td>
  538. </tr>
  539. </table></div>
  540. </div>
  541. </div>
  542. <div class="refsect2">
  543. <a name="id-1.1.59.3.19"></a><h3>remove-poll</h3>
  544. <div class="informalexample"><pre class="programlisting">(define-values () (source:remove-poll self fd))
  545. </pre></div>
  546. <p>Removes a file descriptor from the set of file descriptors polled for
  547. this source.
  548. </p>
  549. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  550. Do not call this API on a <span class="type">GSource</span> that you did not create.</p>
  551. <div class="refsect3">
  552. <a name="id-1.1.59.3.19.5"></a><h4>Parameters</h4>
  553. <div class="informaltable"><table>
  554. <tr>
  555. <td class="parameter_name"><p>source</p></td>
  556. <td class="parameter_description">
  557. <p>a <span class="type">GSource</span></p>
  558. <p>Passed as <code class="code">self</code></p>
  559. </td>
  560. </tr>
  561. <tr>
  562. <td class="parameter_name"><p>fd</p></td>
  563. <td class="parameter_description">
  564. <p>a <span class="type">GPollFD</span> structure previously passed to <code class="function">g_source_add_poll()</code>.</p>
  565. <p>Passed as <code class="code">fd</code></p>
  566. </td>
  567. </tr>
  568. </table></div>
  569. </div>
  570. </div>
  571. <div class="refsect2">
  572. <a name="id-1.1.59.3.20"></a><h3>remove-unix-fd</h3>
  573. <div class="informalexample"><pre class="programlisting">(define-values () (source:remove-unix-fd self tag))
  574. </pre></div>
  575. <p>Reverses the effect of a previous call to <code class="function">g_source_add_unix_fd()</code>.
  576. </p>
  577. <p>You only need to call this if you want to remove an fd from being
  578. watched while keeping the same source around. In the normal case you
  579. will just want to destroy the source.
  580. </p>
  581. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  582. Do not call this API on a <span class="type">GSource</span> that you did not create.
  583. </p>
  584. <p>As the name suggests, this function is not available on Windows.</p>
  585. <div class="refsect3">
  586. <a name="id-1.1.59.3.20.7"></a><h4>Parameters</h4>
  587. <div class="informaltable"><table>
  588. <tr>
  589. <td class="parameter_name"><p>source</p></td>
  590. <td class="parameter_description">
  591. <p>a <span class="type">GSource</span></p>
  592. <p>Passed as <code class="code">self</code></p>
  593. </td>
  594. </tr>
  595. <tr>
  596. <td class="parameter_name"><p>tag</p></td>
  597. <td class="parameter_description">
  598. <p>the tag from <code class="function">g_source_add_unix_fd()</code></p>
  599. <p>Passed as <code class="code">tag</code></p>
  600. </td>
  601. </tr>
  602. </table></div>
  603. </div>
  604. </div>
  605. <div class="refsect2">
  606. <a name="id-1.1.59.3.21"></a><h3>set-callback</h3>
  607. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-callback self func data notify))
  608. </pre></div>
  609. <p>Sets the callback function for a source. The callback for a source is
  610. called from the source's dispatch function.
  611. </p>
  612. <p>The exact type of <em class="parameter"><code>func</code></em> depends on the type of source; ie. you
  613. should not count on <em class="parameter"><code>func</code></em> being called with <em class="parameter"><code>data</code></em> as its first
  614. parameter. Cast <em class="parameter"><code>func</code></em> with <code class="function">G_SOURCE_FUNC()</code> to avoid warnings about
  615. incompatible function types.
  616. </p>
  617. <p>See [memory management of sources][mainloop-memory-management] for details
  618. on how to handle memory management of <em class="parameter"><code>data</code></em>.
  619. </p>
  620. <p>Typically, you won't use this function. Instead use functions specific
  621. to the type of source you are using, such as <code class="function">g_idle_add()</code> or <code class="function">g_timeout_add()</code>.
  622. </p>
  623. <p>It is safe to call this function multiple times on a source which has already
  624. been attached to a context. The changes will take effect for the next time
  625. the source is dispatched after this call returns.</p>
  626. <div class="refsect3">
  627. <a name="id-1.1.59.3.21.8"></a><h4>Parameters</h4>
  628. <div class="informaltable"><table>
  629. <tr>
  630. <td class="parameter_name"><p>source</p></td>
  631. <td class="parameter_description">
  632. <p>the source</p>
  633. <p>Passed as <code class="code">self</code></p>
  634. </td>
  635. </tr>
  636. <tr>
  637. <td class="parameter_name"><p>func</p></td>
  638. <td class="parameter_description">
  639. <p>a callback function</p>
  640. <p>Passed as <code class="code">func</code></p>
  641. </td>
  642. </tr>
  643. <tr>
  644. <td class="parameter_name"><p>data</p></td>
  645. <td class="parameter_description">
  646. <p>the data to pass to callback function</p>
  647. <p>Passed as <code class="code">data</code></p>
  648. </td>
  649. </tr>
  650. <tr>
  651. <td class="parameter_name"><p>notify</p></td>
  652. <td class="parameter_description">
  653. <p>a function to call when <em class="parameter"><code>data</code></em> is no longer in use, or <code class="constant">NULL</code>.</p>
  654. <p>Passed as <code class="code">notify</code></p>
  655. </td>
  656. </tr>
  657. </table></div>
  658. </div>
  659. </div>
  660. <div class="refsect2">
  661. <a name="id-1.1.59.3.22"></a><h3>set-can-recurse</h3>
  662. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-can-recurse self can-recurse))
  663. </pre></div>
  664. <p>Sets whether a source can be called recursively. If <em class="parameter"><code>can_recurse</code></em> is
  665. <code class="constant">TRUE</code>, then while the source is being dispatched then this source
  666. will be processed normally. Otherwise, all processing of this
  667. source is blocked until the dispatch function returns.</p>
  668. <div class="refsect3">
  669. <a name="id-1.1.59.3.22.4"></a><h4>Parameters</h4>
  670. <div class="informaltable"><table>
  671. <tr>
  672. <td class="parameter_name"><p>source</p></td>
  673. <td class="parameter_description">
  674. <p>a <span class="type">GSource</span></p>
  675. <p>Passed as <code class="code">self</code></p>
  676. </td>
  677. </tr>
  678. <tr>
  679. <td class="parameter_name"><p>can_recurse</p></td>
  680. <td class="parameter_description">
  681. <p>whether recursion is allowed for this source</p>
  682. <p>Passed as <code class="code">can-recurse</code></p>
  683. </td>
  684. </tr>
  685. </table></div>
  686. </div>
  687. </div>
  688. <div class="refsect2">
  689. <a name="id-1.1.59.3.23"></a><h3>set-name</h3>
  690. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-name self name))
  691. </pre></div>
  692. <p>Sets a name for the source, used in debugging and profiling.
  693. The name defaults to <span class="type">NULL</span>.
  694. </p>
  695. <p>The source name should describe in a human-readable way
  696. what the source does. For example, "X11 event queue"
  697. or "GTK+ repaint idle handler" or whatever it is.
  698. </p>
  699. <p>It is permitted to call this function multiple times, but is not
  700. recommended due to the potential performance impact. For example,
  701. one could change the name in the "check" function of a <span class="type">GSourceFuncs</span>
  702. to include details like the event type in the source name.
  703. </p>
  704. <p>Use caution if changing the name while another thread may be
  705. accessing it with <code class="function">g_source_get_name()</code>; that function does not copy
  706. the value, and changing the value will free it while the other thread
  707. may be attempting to use it.</p>
  708. <div class="refsect3">
  709. <a name="id-1.1.59.3.23.7"></a><h4>Parameters</h4>
  710. <div class="informaltable"><table>
  711. <tr>
  712. <td class="parameter_name"><p>source</p></td>
  713. <td class="parameter_description">
  714. <p>a <span class="type">GSource</span></p>
  715. <p>Passed as <code class="code">self</code></p>
  716. </td>
  717. </tr>
  718. <tr>
  719. <td class="parameter_name"><p>name</p></td>
  720. <td class="parameter_description">
  721. <p>debug name for the source</p>
  722. <p>Passed as <code class="code">name</code></p>
  723. </td>
  724. </tr>
  725. </table></div>
  726. </div>
  727. </div>
  728. <div class="refsect2">
  729. <a name="id-1.1.59.3.24"></a><h3>set-priority</h3>
  730. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-priority self priority))
  731. </pre></div>
  732. <p>Sets the priority of a source. While the main loop is being run, a
  733. source will be dispatched if it is ready to be dispatched and no
  734. sources at a higher (numerically smaller) priority are ready to be
  735. dispatched.
  736. </p>
  737. <p>A child source always has the same priority as its parent. It is not
  738. permitted to change the priority of a source once it has been added
  739. as a child of another source.</p>
  740. <div class="refsect3">
  741. <a name="id-1.1.59.3.24.5"></a><h4>Parameters</h4>
  742. <div class="informaltable"><table>
  743. <tr>
  744. <td class="parameter_name"><p>source</p></td>
  745. <td class="parameter_description">
  746. <p>a <span class="type">GSource</span></p>
  747. <p>Passed as <code class="code">self</code></p>
  748. </td>
  749. </tr>
  750. <tr>
  751. <td class="parameter_name"><p>priority</p></td>
  752. <td class="parameter_description">
  753. <p>the new priority.</p>
  754. <p>Passed as <code class="code">priority</code></p>
  755. </td>
  756. </tr>
  757. </table></div>
  758. </div>
  759. </div>
  760. <div class="refsect2">
  761. <a name="id-1.1.59.3.25"></a><h3>set-ready-time</h3>
  762. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-ready-time self ready-time))
  763. </pre></div>
  764. <p>Sets a <span class="type">GSource</span> to be dispatched when the given monotonic time is
  765. reached (or passed). If the monotonic time is in the past (as it
  766. always will be if <em class="parameter"><code>ready_time</code></em> is 0) then the source will be
  767. dispatched immediately.
  768. </p>
  769. <p>If <em class="parameter"><code>ready_time</code></em> is -1 then the source is never woken up on the basis
  770. of the passage of time.
  771. </p>
  772. <p>Dispatching the source does not reset the ready time. You should do
  773. so yourself, from the source dispatch function.
  774. </p>
  775. <p>Note that if you have a pair of sources where the ready time of one
  776. suggests that it will be delivered first but the priority for the
  777. other suggests that it would be delivered first, and the ready time
  778. for both sources is reached during the same main context iteration,
  779. then the order of dispatch is undefined.
  780. </p>
  781. <p>It is a no-op to call this function on a <span class="type">GSource</span> which has already been
  782. destroyed with <code class="function">g_source_destroy()</code>.
  783. </p>
  784. <p>This API is only intended to be used by implementations of <span class="type">GSource</span>.
  785. Do not call this API on a <span class="type">GSource</span> that you did not create.</p>
  786. <div class="refsect3">
  787. <a name="id-1.1.59.3.25.9"></a><h4>Parameters</h4>
  788. <div class="informaltable"><table>
  789. <tr>
  790. <td class="parameter_name"><p>source</p></td>
  791. <td class="parameter_description">
  792. <p>a <span class="type">GSource</span></p>
  793. <p>Passed as <code class="code">self</code></p>
  794. </td>
  795. </tr>
  796. <tr>
  797. <td class="parameter_name"><p>ready_time</p></td>
  798. <td class="parameter_description">
  799. <p>the monotonic time at which the source will be ready,
  800. 0 for "immediately", -1 for "never"</p>
  801. <p>Passed as <code class="code">ready-time</code></p>
  802. </td>
  803. </tr>
  804. </table></div>
  805. </div>
  806. </div>
  807. <div class="refsect2">
  808. <a name="id-1.1.59.3.26"></a><h3>set-static-name</h3>
  809. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-static-name self name))
  810. </pre></div>
  811. <p>Undocumented</p>
  812. <div class="refsect3">
  813. <a name="id-1.1.59.3.26.4"></a><h4>Parameters</h4>
  814. <div class="informaltable"><table>
  815. <tr>
  816. <td class="parameter_name"><p>source</p></td>
  817. <td class="parameter_description">
  818. <p></p>
  819. <p>Passed as <code class="code">self</code></p>
  820. </td>
  821. </tr>
  822. <tr>
  823. <td class="parameter_name"><p>name</p></td>
  824. <td class="parameter_description">
  825. <p></p>
  826. <p>Passed as <code class="code">name</code></p>
  827. </td>
  828. </tr>
  829. </table></div>
  830. </div>
  831. </div>
  832. <div class="refsect2">
  833. <a name="id-1.1.59.3.27"></a><h3>unref</h3>
  834. <div class="informalexample"><pre class="programlisting">(define-values () (source:unref self))
  835. </pre></div>
  836. <p>Decreases the reference count of a source by one. If the
  837. resulting reference count is zero the source and associated
  838. memory will be destroyed.</p>
  839. <div class="refsect3">
  840. <a name="id-1.1.59.3.27.4"></a><h4>Parameters</h4>
  841. <div class="informaltable"><table><tr>
  842. <td class="parameter_name"><p>source</p></td>
  843. <td class="parameter_description">
  844. <p>a <span class="type">GSource</span></p>
  845. <p>Passed as <code class="code">self</code></p>
  846. </td>
  847. </tr></table></div>
  848. </div>
  849. </div>
  850. <div class="refsect2">
  851. <a name="id-1.1.59.3.28"></a><h3>source:remove?</h3>
  852. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:remove? tag))
  853. </pre></div>
  854. <p>Removes the source with the given ID from the default main context. You must
  855. use <code class="function">g_source_destroy()</code> for sources added to a non-default main context.
  856. </p>
  857. <p>The ID of a <span class="type">GSource</span> is given by <code class="function">g_source_get_id()</code>, or will be
  858. returned by the functions <code class="function">g_source_attach()</code>, <code class="function">g_idle_add()</code>,
  859. <code class="function">g_idle_add_full()</code>, <code class="function">g_timeout_add()</code>, <code class="function">g_timeout_add_full()</code>,
  860. <code class="function">g_child_watch_add()</code>, <code class="function">g_child_watch_add_full()</code>, <code class="function">g_io_add_watch()</code>, and
  861. <code class="function">g_io_add_watch_full()</code>.
  862. </p>
  863. <p>It is a programmer error to attempt to remove a non-existent source.
  864. </p>
  865. <p>More specifically: source IDs can be reissued after a source has been
  866. destroyed and therefore it is never valid to use this function with a
  867. source ID which may have already been removed. An example is when
  868. scheduling an idle to run in another thread with <code class="function">g_idle_add()</code>: the
  869. idle may already have run and been removed by the time this function
  870. is called on its (now invalid) source ID. This source ID may have
  871. been reissued, leading to the operation being performed against the
  872. wrong source.</p>
  873. <div class="refsect3">
  874. <a name="id-1.1.59.3.28.7"></a><h4>Parameters</h4>
  875. <div class="informaltable"><table><tr>
  876. <td class="parameter_name"><p>tag</p></td>
  877. <td class="parameter_description">
  878. <p>the ID of the source to remove.</p>
  879. <p>Passed as <code class="code">tag</code></p>
  880. </td>
  881. </tr></table></div>
  882. </div>
  883. </div>
  884. <div class="refsect2">
  885. <a name="id-1.1.59.3.29"></a><h3>source:remove-by-user-data?</h3>
  886. <div class="informalexample"><pre class="programlisting">(define-values (%return) (source:remove-by-user-data? user-data))
  887. </pre></div>
  888. <p>Removes a source from the default main loop context given the user
  889. data for the callback. If multiple sources exist with the same user
  890. data, only one will be destroyed.</p>
  891. <div class="refsect3">
  892. <a name="id-1.1.59.3.29.4"></a><h4>Parameters</h4>
  893. <div class="informaltable"><table><tr>
  894. <td class="parameter_name"><p>user_data</p></td>
  895. <td class="parameter_description">
  896. <p>the user_data for the callback.</p>
  897. <p>Passed as <code class="code">user-data</code></p>
  898. </td>
  899. </tr></table></div>
  900. </div>
  901. </div>
  902. <div class="refsect2">
  903. <a name="id-1.1.59.3.30"></a><h3>source:set-name-by-id</h3>
  904. <div class="informalexample"><pre class="programlisting">(define-values () (source:set-name-by-id tag name))
  905. </pre></div>
  906. <p>Sets the name of a source using its ID.
  907. </p>
  908. <p>This is a convenience utility to set source names from the return
  909. value of <code class="function">g_idle_add()</code>, <code class="function">g_timeout_add()</code>, etc.
  910. </p>
  911. <p>It is a programmer error to attempt to set the name of a non-existent
  912. source.
  913. </p>
  914. <p>More specifically: source IDs can be reissued after a source has been
  915. destroyed and therefore it is never valid to use this function with a
  916. source ID which may have already been removed. An example is when
  917. scheduling an idle to run in another thread with <code class="function">g_idle_add()</code>: the
  918. idle may already have run and been removed by the time this function
  919. is called on its (now invalid) source ID. This source ID may have
  920. been reissued, leading to the operation being performed against the
  921. wrong source.</p>
  922. <div class="refsect3">
  923. <a name="id-1.1.59.3.30.7"></a><h4>Parameters</h4>
  924. <div class="informaltable"><table>
  925. <tr>
  926. <td class="parameter_name"><p>tag</p></td>
  927. <td class="parameter_description">
  928. <p>a <span class="type">GSource</span> ID</p>
  929. <p>Passed as <code class="code">tag</code></p>
  930. </td>
  931. </tr>
  932. <tr>
  933. <td class="parameter_name"><p>name</p></td>
  934. <td class="parameter_description">
  935. <p>debug name for the source</p>
  936. <p>Passed as <code class="code">name</code></p>
  937. </td>
  938. </tr>
  939. </table></div>
  940. </div>
  941. </div>
  942. </div>
  943. </div>
  944. <div class="footer">
  945. <hr>Generated by GTK-Doc V1.33.1</div>
  946. </body>
  947. </html>