gmain.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /* gmain.h - the GLib Main loop
  2. * Copyright (C) 1998-2000 Red Hat, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __G_MAIN_H__
  18. #define __G_MAIN_H__
  19. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  20. #error "Only <glib.h> can be included directly."
  21. #endif
  22. #include <glib/gpoll.h>
  23. #include <glib/gslist.h>
  24. #include <glib/gthread.h>
  25. G_BEGIN_DECLS
  26. typedef enum /*< flags >*/
  27. {
  28. G_IO_IN GLIB_SYSDEF_POLLIN,
  29. G_IO_OUT GLIB_SYSDEF_POLLOUT,
  30. G_IO_PRI GLIB_SYSDEF_POLLPRI,
  31. G_IO_ERR GLIB_SYSDEF_POLLERR,
  32. G_IO_HUP GLIB_SYSDEF_POLLHUP,
  33. G_IO_NVAL GLIB_SYSDEF_POLLNVAL
  34. } GIOCondition;
  35. /**
  36. * GMainContext:
  37. *
  38. * The `GMainContext` struct is an opaque data
  39. * type representing a set of sources to be handled in a main loop.
  40. */
  41. typedef struct _GMainContext GMainContext;
  42. /**
  43. * GMainLoop:
  44. *
  45. * The `GMainLoop` struct is an opaque data type
  46. * representing the main event loop of a GLib or GTK+ application.
  47. */
  48. typedef struct _GMainLoop GMainLoop;
  49. /**
  50. * GSource:
  51. *
  52. * The `GSource` struct is an opaque data type
  53. * representing an event source.
  54. */
  55. typedef struct _GSource GSource;
  56. typedef struct _GSourcePrivate GSourcePrivate;
  57. /**
  58. * GSourceCallbackFuncs:
  59. * @ref: Called when a reference is added to the callback object
  60. * @unref: Called when a reference to the callback object is dropped
  61. * @get: Called to extract the callback function and data from the
  62. * callback object.
  63. *
  64. * The `GSourceCallbackFuncs` struct contains
  65. * functions for managing callback objects.
  66. */
  67. typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs;
  68. /**
  69. * GSourceFuncs:
  70. * @prepare: Called before all the file descriptors are polled. If the
  71. * source can determine that it is ready here (without waiting for the
  72. * results of the poll() call) it should return %TRUE. It can also return
  73. * a @timeout_ value which should be the maximum timeout (in milliseconds)
  74. * which should be passed to the poll() call. The actual timeout used will
  75. * be -1 if all sources returned -1, or it will be the minimum of all
  76. * the @timeout_ values returned which were >= 0. Since 2.36 this may
  77. * be %NULL, in which case the effect is as if the function always returns
  78. * %FALSE with a timeout of -1. If @prepare returns a
  79. * timeout and the source also has a ready time set, then the
  80. * lower of the two will be used.
  81. * @check: Called after all the file descriptors are polled. The source
  82. * should return %TRUE if it is ready to be dispatched. Note that some
  83. * time may have passed since the previous prepare function was called,
  84. * so the source should be checked again here. Since 2.36 this may
  85. * be %NULL, in which case the effect is as if the function always returns
  86. * %FALSE.
  87. * @dispatch: Called to dispatch the event source, after it has returned
  88. * %TRUE in either its @prepare or its @check function, or if a ready time
  89. * has been reached. The @dispatch function receives a callback function and
  90. * user data. The callback function may be %NULL if the source was never
  91. * connected to a callback using g_source_set_callback(). The @dispatch
  92. * function should call the callback function with @user_data and whatever
  93. * additional parameters are needed for this type of event source. The
  94. * return value of the @dispatch function should be #G_SOURCE_REMOVE if the
  95. * source should be removed or #G_SOURCE_CONTINUE to keep it.
  96. * @finalize: Called when the source is finalized. At this point, the source
  97. * will have been destroyed, had its callback cleared, and have been removed
  98. * from its #GMainContext, but it will still have its final reference count,
  99. * so methods can be called on it from within this function.
  100. *
  101. * The `GSourceFuncs` struct contains a table of
  102. * functions used to handle event sources in a generic manner.
  103. *
  104. * For idle sources, the prepare and check functions always return %TRUE
  105. * to indicate that the source is always ready to be processed. The prepare
  106. * function also returns a timeout value of 0 to ensure that the poll() call
  107. * doesn't block (since that would be time wasted which could have been spent
  108. * running the idle function).
  109. *
  110. * For timeout sources, the prepare and check functions both return %TRUE
  111. * if the timeout interval has expired. The prepare function also returns
  112. * a timeout value to ensure that the poll() call doesn't block too long
  113. * and miss the next timeout.
  114. *
  115. * For file descriptor sources, the prepare function typically returns %FALSE,
  116. * since it must wait until poll() has been called before it knows whether
  117. * any events need to be processed. It sets the returned timeout to -1 to
  118. * indicate that it doesn't mind how long the poll() call blocks. In the
  119. * check function, it tests the results of the poll() call to see if the
  120. * required condition has been met, and returns %TRUE if so.
  121. */
  122. typedef struct _GSourceFuncs GSourceFuncs;
  123. /**
  124. * GPid:
  125. *
  126. * A type which is used to hold a process identification.
  127. *
  128. * On UNIX, processes are identified by a process id (an integer),
  129. * while Windows uses process handles (which are pointers).
  130. *
  131. * GPid is used in GLib only for descendant processes spawned with
  132. * the g_spawn functions.
  133. */
  134. /* defined in glibconfig.h */
  135. /**
  136. * G_PID_FORMAT:
  137. *
  138. * A format specifier that can be used in printf()-style format strings
  139. * when printing a #GPid.
  140. *
  141. * Since: 2.50
  142. */
  143. /* defined in glibconfig.h */
  144. /**
  145. * GSourceFunc:
  146. * @user_data: data passed to the function, set when the source was
  147. * created with one of the above functions
  148. *
  149. * Specifies the type of function passed to g_timeout_add(),
  150. * g_timeout_add_full(), g_idle_add(), and g_idle_add_full().
  151. *
  152. * When calling g_source_set_callback(), you may need to cast a function of a
  153. * different type to this type. Use G_SOURCE_FUNC() to avoid warnings about
  154. * incompatible function types.
  155. *
  156. * Returns: %FALSE if the source should be removed. #G_SOURCE_CONTINUE and
  157. * #G_SOURCE_REMOVE are more memorable names for the return value.
  158. */
  159. typedef gboolean (*GSourceFunc) (gpointer user_data);
  160. /**
  161. * G_SOURCE_FUNC:
  162. * @f: a function pointer.
  163. *
  164. * Cast a function pointer to a #GSourceFunc, suppressing warnings from GCC 8
  165. * onwards with `-Wextra` or `-Wcast-function-type` enabled about the function
  166. * types being incompatible.
  167. *
  168. * For example, the correct type of callback for a source created by
  169. * g_child_watch_source_new() is #GChildWatchFunc, which accepts more arguments
  170. * than #GSourceFunc. Casting the function with `(GSourceFunc)` to call
  171. * g_source_set_callback() will trigger a warning, even though it will be cast
  172. * back to the correct type before it is called by the source.
  173. *
  174. * Since: 2.58
  175. */
  176. #define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))
  177. /**
  178. * GChildWatchFunc:
  179. * @pid: the process id of the child process
  180. * @status: Status information about the child process, encoded
  181. * in a platform-specific manner
  182. * @user_data: user data passed to g_child_watch_add()
  183. *
  184. * Prototype of a #GChildWatchSource callback, called when a child
  185. * process has exited. To interpret @status, see the documentation
  186. * for g_spawn_check_exit_status().
  187. */
  188. typedef void (*GChildWatchFunc) (GPid pid,
  189. gint status,
  190. gpointer user_data);
  191. struct _GSource
  192. {
  193. /*< private >*/
  194. gpointer callback_data;
  195. GSourceCallbackFuncs *callback_funcs;
  196. const GSourceFuncs *source_funcs;
  197. guint ref_count;
  198. GMainContext *context;
  199. gint priority;
  200. guint flags;
  201. guint source_id;
  202. GSList *poll_fds;
  203. GSource *prev;
  204. GSource *next;
  205. char *name;
  206. GSourcePrivate *priv;
  207. };
  208. struct _GSourceCallbackFuncs
  209. {
  210. void (*ref) (gpointer cb_data);
  211. void (*unref) (gpointer cb_data);
  212. void (*get) (gpointer cb_data,
  213. GSource *source,
  214. GSourceFunc *func,
  215. gpointer *data);
  216. };
  217. /**
  218. * GSourceDummyMarshal:
  219. *
  220. * This is just a placeholder for #GClosureMarshal,
  221. * which cannot be used here for dependency reasons.
  222. */
  223. typedef void (*GSourceDummyMarshal) (void);
  224. struct _GSourceFuncs
  225. {
  226. gboolean (*prepare) (GSource *source,
  227. gint *timeout_);
  228. gboolean (*check) (GSource *source);
  229. gboolean (*dispatch) (GSource *source,
  230. GSourceFunc callback,
  231. gpointer user_data);
  232. void (*finalize) (GSource *source); /* Can be NULL */
  233. /*< private >*/
  234. /* For use by g_source_set_closure */
  235. GSourceFunc closure_callback;
  236. GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
  237. };
  238. /* Standard priorities */
  239. /**
  240. * G_PRIORITY_HIGH:
  241. *
  242. * Use this for high priority event sources.
  243. *
  244. * It is not used within GLib or GTK+.
  245. */
  246. #define G_PRIORITY_HIGH -100
  247. /**
  248. * G_PRIORITY_DEFAULT:
  249. *
  250. * Use this for default priority event sources.
  251. *
  252. * In GLib this priority is used when adding timeout functions
  253. * with g_timeout_add(). In GDK this priority is used for events
  254. * from the X server.
  255. */
  256. #define G_PRIORITY_DEFAULT 0
  257. /**
  258. * G_PRIORITY_HIGH_IDLE:
  259. *
  260. * Use this for high priority idle functions.
  261. *
  262. * GTK+ uses #G_PRIORITY_HIGH_IDLE + 10 for resizing operations,
  263. * and #G_PRIORITY_HIGH_IDLE + 20 for redrawing operations. (This is
  264. * done to ensure that any pending resizes are processed before any
  265. * pending redraws, so that widgets are not redrawn twice unnecessarily.)
  266. */
  267. #define G_PRIORITY_HIGH_IDLE 100
  268. /**
  269. * G_PRIORITY_DEFAULT_IDLE:
  270. *
  271. * Use this for default priority idle functions.
  272. *
  273. * In GLib this priority is used when adding idle functions with
  274. * g_idle_add().
  275. */
  276. #define G_PRIORITY_DEFAULT_IDLE 200
  277. /**
  278. * G_PRIORITY_LOW:
  279. *
  280. * Use this for very low priority background tasks.
  281. *
  282. * It is not used within GLib or GTK+.
  283. */
  284. #define G_PRIORITY_LOW 300
  285. /**
  286. * G_SOURCE_REMOVE:
  287. *
  288. * Use this macro as the return value of a #GSourceFunc to remove
  289. * the #GSource from the main loop.
  290. *
  291. * Since: 2.32
  292. */
  293. #define G_SOURCE_REMOVE FALSE
  294. /**
  295. * G_SOURCE_CONTINUE:
  296. *
  297. * Use this macro as the return value of a #GSourceFunc to leave
  298. * the #GSource in the main loop.
  299. *
  300. * Since: 2.32
  301. */
  302. #define G_SOURCE_CONTINUE TRUE
  303. /* GMainContext: */
  304. GLIB_AVAILABLE_IN_ALL
  305. GMainContext *g_main_context_new (void);
  306. GLIB_AVAILABLE_IN_ALL
  307. GMainContext *g_main_context_ref (GMainContext *context);
  308. GLIB_AVAILABLE_IN_ALL
  309. void g_main_context_unref (GMainContext *context);
  310. GLIB_AVAILABLE_IN_ALL
  311. GMainContext *g_main_context_default (void);
  312. GLIB_AVAILABLE_IN_ALL
  313. gboolean g_main_context_iteration (GMainContext *context,
  314. gboolean may_block);
  315. GLIB_AVAILABLE_IN_ALL
  316. gboolean g_main_context_pending (GMainContext *context);
  317. /* For implementation of legacy interfaces
  318. */
  319. GLIB_AVAILABLE_IN_ALL
  320. GSource *g_main_context_find_source_by_id (GMainContext *context,
  321. guint source_id);
  322. GLIB_AVAILABLE_IN_ALL
  323. GSource *g_main_context_find_source_by_user_data (GMainContext *context,
  324. gpointer user_data);
  325. GLIB_AVAILABLE_IN_ALL
  326. GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
  327. GSourceFuncs *funcs,
  328. gpointer user_data);
  329. /* Low level functions for implementing custom main loops.
  330. */
  331. GLIB_AVAILABLE_IN_ALL
  332. void g_main_context_wakeup (GMainContext *context);
  333. GLIB_AVAILABLE_IN_ALL
  334. gboolean g_main_context_acquire (GMainContext *context);
  335. GLIB_AVAILABLE_IN_ALL
  336. void g_main_context_release (GMainContext *context);
  337. GLIB_AVAILABLE_IN_ALL
  338. gboolean g_main_context_is_owner (GMainContext *context);
  339. GLIB_DEPRECATED_IN_2_58_FOR(g_main_context_is_owner)
  340. gboolean g_main_context_wait (GMainContext *context,
  341. GCond *cond,
  342. GMutex *mutex);
  343. GLIB_AVAILABLE_IN_ALL
  344. gboolean g_main_context_prepare (GMainContext *context,
  345. gint *priority);
  346. GLIB_AVAILABLE_IN_ALL
  347. gint g_main_context_query (GMainContext *context,
  348. gint max_priority,
  349. gint *timeout_,
  350. GPollFD *fds,
  351. gint n_fds);
  352. GLIB_AVAILABLE_IN_ALL
  353. gboolean g_main_context_check (GMainContext *context,
  354. gint max_priority,
  355. GPollFD *fds,
  356. gint n_fds);
  357. GLIB_AVAILABLE_IN_ALL
  358. void g_main_context_dispatch (GMainContext *context);
  359. GLIB_AVAILABLE_IN_ALL
  360. void g_main_context_set_poll_func (GMainContext *context,
  361. GPollFunc func);
  362. GLIB_AVAILABLE_IN_ALL
  363. GPollFunc g_main_context_get_poll_func (GMainContext *context);
  364. /* Low level functions for use by source implementations
  365. */
  366. GLIB_AVAILABLE_IN_ALL
  367. void g_main_context_add_poll (GMainContext *context,
  368. GPollFD *fd,
  369. gint priority);
  370. GLIB_AVAILABLE_IN_ALL
  371. void g_main_context_remove_poll (GMainContext *context,
  372. GPollFD *fd);
  373. GLIB_AVAILABLE_IN_ALL
  374. gint g_main_depth (void);
  375. GLIB_AVAILABLE_IN_ALL
  376. GSource *g_main_current_source (void);
  377. /* GMainContexts for other threads
  378. */
  379. GLIB_AVAILABLE_IN_ALL
  380. void g_main_context_push_thread_default (GMainContext *context);
  381. GLIB_AVAILABLE_IN_ALL
  382. void g_main_context_pop_thread_default (GMainContext *context);
  383. GLIB_AVAILABLE_IN_ALL
  384. GMainContext *g_main_context_get_thread_default (void);
  385. GLIB_AVAILABLE_IN_ALL
  386. GMainContext *g_main_context_ref_thread_default (void);
  387. /* GMainLoop: */
  388. GLIB_AVAILABLE_IN_ALL
  389. GMainLoop *g_main_loop_new (GMainContext *context,
  390. gboolean is_running);
  391. GLIB_AVAILABLE_IN_ALL
  392. void g_main_loop_run (GMainLoop *loop);
  393. GLIB_AVAILABLE_IN_ALL
  394. void g_main_loop_quit (GMainLoop *loop);
  395. GLIB_AVAILABLE_IN_ALL
  396. GMainLoop *g_main_loop_ref (GMainLoop *loop);
  397. GLIB_AVAILABLE_IN_ALL
  398. void g_main_loop_unref (GMainLoop *loop);
  399. GLIB_AVAILABLE_IN_ALL
  400. gboolean g_main_loop_is_running (GMainLoop *loop);
  401. GLIB_AVAILABLE_IN_ALL
  402. GMainContext *g_main_loop_get_context (GMainLoop *loop);
  403. /* GSource: */
  404. GLIB_AVAILABLE_IN_ALL
  405. GSource *g_source_new (GSourceFuncs *source_funcs,
  406. guint struct_size);
  407. GLIB_AVAILABLE_IN_ALL
  408. GSource *g_source_ref (GSource *source);
  409. GLIB_AVAILABLE_IN_ALL
  410. void g_source_unref (GSource *source);
  411. GLIB_AVAILABLE_IN_ALL
  412. guint g_source_attach (GSource *source,
  413. GMainContext *context);
  414. GLIB_AVAILABLE_IN_ALL
  415. void g_source_destroy (GSource *source);
  416. GLIB_AVAILABLE_IN_ALL
  417. void g_source_set_priority (GSource *source,
  418. gint priority);
  419. GLIB_AVAILABLE_IN_ALL
  420. gint g_source_get_priority (GSource *source);
  421. GLIB_AVAILABLE_IN_ALL
  422. void g_source_set_can_recurse (GSource *source,
  423. gboolean can_recurse);
  424. GLIB_AVAILABLE_IN_ALL
  425. gboolean g_source_get_can_recurse (GSource *source);
  426. GLIB_AVAILABLE_IN_ALL
  427. guint g_source_get_id (GSource *source);
  428. GLIB_AVAILABLE_IN_ALL
  429. GMainContext *g_source_get_context (GSource *source);
  430. GLIB_AVAILABLE_IN_ALL
  431. void g_source_set_callback (GSource *source,
  432. GSourceFunc func,
  433. gpointer data,
  434. GDestroyNotify notify);
  435. GLIB_AVAILABLE_IN_ALL
  436. void g_source_set_funcs (GSource *source,
  437. GSourceFuncs *funcs);
  438. GLIB_AVAILABLE_IN_ALL
  439. gboolean g_source_is_destroyed (GSource *source);
  440. GLIB_AVAILABLE_IN_ALL
  441. void g_source_set_name (GSource *source,
  442. const char *name);
  443. GLIB_AVAILABLE_IN_ALL
  444. const char * g_source_get_name (GSource *source);
  445. GLIB_AVAILABLE_IN_ALL
  446. void g_source_set_name_by_id (guint tag,
  447. const char *name);
  448. GLIB_AVAILABLE_IN_2_36
  449. void g_source_set_ready_time (GSource *source,
  450. gint64 ready_time);
  451. GLIB_AVAILABLE_IN_2_36
  452. gint64 g_source_get_ready_time (GSource *source);
  453. #ifdef G_OS_UNIX
  454. GLIB_AVAILABLE_IN_2_36
  455. gpointer g_source_add_unix_fd (GSource *source,
  456. gint fd,
  457. GIOCondition events);
  458. GLIB_AVAILABLE_IN_2_36
  459. void g_source_modify_unix_fd (GSource *source,
  460. gpointer tag,
  461. GIOCondition new_events);
  462. GLIB_AVAILABLE_IN_2_36
  463. void g_source_remove_unix_fd (GSource *source,
  464. gpointer tag);
  465. GLIB_AVAILABLE_IN_2_36
  466. GIOCondition g_source_query_unix_fd (GSource *source,
  467. gpointer tag);
  468. #endif
  469. /* Used to implement g_source_connect_closure and internally*/
  470. GLIB_AVAILABLE_IN_ALL
  471. void g_source_set_callback_indirect (GSource *source,
  472. gpointer callback_data,
  473. GSourceCallbackFuncs *callback_funcs);
  474. GLIB_AVAILABLE_IN_ALL
  475. void g_source_add_poll (GSource *source,
  476. GPollFD *fd);
  477. GLIB_AVAILABLE_IN_ALL
  478. void g_source_remove_poll (GSource *source,
  479. GPollFD *fd);
  480. GLIB_AVAILABLE_IN_ALL
  481. void g_source_add_child_source (GSource *source,
  482. GSource *child_source);
  483. GLIB_AVAILABLE_IN_ALL
  484. void g_source_remove_child_source (GSource *source,
  485. GSource *child_source);
  486. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  487. GLIB_DEPRECATED_IN_2_28_FOR(g_source_get_time)
  488. void g_source_get_current_time (GSource *source,
  489. GTimeVal *timeval);
  490. G_GNUC_END_IGNORE_DEPRECATIONS
  491. GLIB_AVAILABLE_IN_ALL
  492. gint64 g_source_get_time (GSource *source);
  493. /* void g_source_connect_closure (GSource *source,
  494. GClosure *closure);
  495. */
  496. /* Specific source types
  497. */
  498. GLIB_AVAILABLE_IN_ALL
  499. GSource *g_idle_source_new (void);
  500. GLIB_AVAILABLE_IN_ALL
  501. GSource *g_child_watch_source_new (GPid pid);
  502. GLIB_AVAILABLE_IN_ALL
  503. GSource *g_timeout_source_new (guint interval);
  504. GLIB_AVAILABLE_IN_ALL
  505. GSource *g_timeout_source_new_seconds (guint interval);
  506. /* Miscellaneous functions
  507. */
  508. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  509. GLIB_DEPRECATED_IN_2_62_FOR(g_get_real_time)
  510. void g_get_current_time (GTimeVal *result);
  511. G_GNUC_END_IGNORE_DEPRECATIONS
  512. GLIB_AVAILABLE_IN_ALL
  513. gint64 g_get_monotonic_time (void);
  514. GLIB_AVAILABLE_IN_ALL
  515. gint64 g_get_real_time (void);
  516. /* Source manipulation by ID */
  517. GLIB_AVAILABLE_IN_ALL
  518. gboolean g_source_remove (guint tag);
  519. GLIB_AVAILABLE_IN_ALL
  520. gboolean g_source_remove_by_user_data (gpointer user_data);
  521. GLIB_AVAILABLE_IN_ALL
  522. gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
  523. gpointer user_data);
  524. /**
  525. * GClearHandleFunc:
  526. * @handle_id: the handle ID to clear
  527. *
  528. * Specifies the type of function passed to g_clear_handle_id().
  529. * The implementation is expected to free the resource identified
  530. * by @handle_id; for instance, if @handle_id is a #GSource ID,
  531. * g_source_remove() can be used.
  532. *
  533. * Since: 2.56
  534. */
  535. typedef void (* GClearHandleFunc) (guint handle_id);
  536. GLIB_AVAILABLE_IN_2_56
  537. void g_clear_handle_id (guint *tag_ptr,
  538. GClearHandleFunc clear_func);
  539. #define g_clear_handle_id(tag_ptr, clear_func) \
  540. G_STMT_START { \
  541. G_STATIC_ASSERT (sizeof *(tag_ptr) == sizeof (guint)); \
  542. guint *_tag_ptr = (guint *) (tag_ptr); \
  543. guint _handle_id; \
  544. \
  545. _handle_id = *_tag_ptr; \
  546. if (_handle_id > 0) \
  547. { \
  548. *_tag_ptr = 0; \
  549. clear_func (_handle_id); \
  550. } \
  551. } G_STMT_END \
  552. GLIB_AVAILABLE_MACRO_IN_2_56
  553. /* Idles, child watchers and timeouts */
  554. GLIB_AVAILABLE_IN_ALL
  555. guint g_timeout_add_full (gint priority,
  556. guint interval,
  557. GSourceFunc function,
  558. gpointer data,
  559. GDestroyNotify notify);
  560. GLIB_AVAILABLE_IN_ALL
  561. guint g_timeout_add (guint interval,
  562. GSourceFunc function,
  563. gpointer data);
  564. GLIB_AVAILABLE_IN_ALL
  565. guint g_timeout_add_seconds_full (gint priority,
  566. guint interval,
  567. GSourceFunc function,
  568. gpointer data,
  569. GDestroyNotify notify);
  570. GLIB_AVAILABLE_IN_ALL
  571. guint g_timeout_add_seconds (guint interval,
  572. GSourceFunc function,
  573. gpointer data);
  574. GLIB_AVAILABLE_IN_ALL
  575. guint g_child_watch_add_full (gint priority,
  576. GPid pid,
  577. GChildWatchFunc function,
  578. gpointer data,
  579. GDestroyNotify notify);
  580. GLIB_AVAILABLE_IN_ALL
  581. guint g_child_watch_add (GPid pid,
  582. GChildWatchFunc function,
  583. gpointer data);
  584. GLIB_AVAILABLE_IN_ALL
  585. guint g_idle_add (GSourceFunc function,
  586. gpointer data);
  587. GLIB_AVAILABLE_IN_ALL
  588. guint g_idle_add_full (gint priority,
  589. GSourceFunc function,
  590. gpointer data,
  591. GDestroyNotify notify);
  592. GLIB_AVAILABLE_IN_ALL
  593. gboolean g_idle_remove_by_data (gpointer data);
  594. GLIB_AVAILABLE_IN_ALL
  595. void g_main_context_invoke_full (GMainContext *context,
  596. gint priority,
  597. GSourceFunc function,
  598. gpointer data,
  599. GDestroyNotify notify);
  600. GLIB_AVAILABLE_IN_ALL
  601. void g_main_context_invoke (GMainContext *context,
  602. GSourceFunc function,
  603. gpointer data);
  604. /* Hook for GClosure / GSource integration. Don't touch */
  605. GLIB_VAR GSourceFuncs g_timeout_funcs;
  606. GLIB_VAR GSourceFuncs g_child_watch_funcs;
  607. GLIB_VAR GSourceFuncs g_idle_funcs;
  608. #ifdef G_OS_UNIX
  609. GLIB_VAR GSourceFuncs g_unix_signal_funcs;
  610. GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;
  611. #endif
  612. G_END_DECLS
  613. #endif /* __G_MAIN_H__ */