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 | |
18 | #ifndef __G_MAIN_H__ |
19 | #define __G_MAIN_H__ |
20 | |
21 | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
22 | #error "Only <glib.h> can be included directly." |
23 | #endif |
24 | |
25 | #include <glib/gpoll.h> |
26 | #include <glib/gslist.h> |
27 | #include <glib/gthread.h> |
28 | |
29 | G_BEGIN_DECLS |
30 | |
31 | typedef enum /*< flags >*/ |
32 | { |
33 | G_IO_IN GLIB_SYSDEF_POLLIN, |
34 | G_IO_OUT GLIB_SYSDEF_POLLOUT, |
35 | G_IO_PRI GLIB_SYSDEF_POLLPRI, |
36 | G_IO_ERR GLIB_SYSDEF_POLLERR, |
37 | G_IO_HUP GLIB_SYSDEF_POLLHUP, |
38 | G_IO_NVAL GLIB_SYSDEF_POLLNVAL |
39 | } GIOCondition; |
40 | |
41 | |
42 | /** |
43 | * GMainContext: |
44 | * |
45 | * The `GMainContext` struct is an opaque data |
46 | * type representing a set of sources to be handled in a main loop. |
47 | */ |
48 | typedef struct _GMainContext GMainContext; |
49 | |
50 | /** |
51 | * GMainLoop: |
52 | * |
53 | * The `GMainLoop` struct is an opaque data type |
54 | * representing the main event loop of a GLib or GTK+ application. |
55 | */ |
56 | typedef struct _GMainLoop GMainLoop; |
57 | |
58 | /** |
59 | * GSource: |
60 | * |
61 | * The `GSource` struct is an opaque data type |
62 | * representing an event source. |
63 | */ |
64 | typedef struct _GSource GSource; |
65 | typedef struct _GSourcePrivate GSourcePrivate; |
66 | |
67 | /** |
68 | * GSourceCallbackFuncs: |
69 | * @ref: Called when a reference is added to the callback object |
70 | * @unref: Called when a reference to the callback object is dropped |
71 | * @get: Called to extract the callback function and data from the |
72 | * callback object. |
73 | * |
74 | * The `GSourceCallbackFuncs` struct contains |
75 | * functions for managing callback objects. |
76 | */ |
77 | typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs; |
78 | |
79 | /** |
80 | * GSourceFuncs: |
81 | * @prepare: Called before all the file descriptors are polled. If the |
82 | * source can determine that it is ready here (without waiting for the |
83 | * results of the poll() call) it should return %TRUE. It can also return |
84 | * a @timeout_ value which should be the maximum timeout (in milliseconds) |
85 | * which should be passed to the poll() call. The actual timeout used will |
86 | * be -1 if all sources returned -1, or it will be the minimum of all |
87 | * the @timeout_ values returned which were >= 0. Since 2.36 this may |
88 | * be %NULL, in which case the effect is as if the function always returns |
89 | * %FALSE with a timeout of -1. If @prepare returns a |
90 | * timeout and the source also has a ready time set, then the |
91 | * lower of the two will be used. |
92 | * @check: Called after all the file descriptors are polled. The source |
93 | * should return %TRUE if it is ready to be dispatched. Note that some |
94 | * time may have passed since the previous prepare function was called, |
95 | * so the source should be checked again here. Since 2.36 this may |
96 | * be %NULL, in which case the effect is as if the function always returns |
97 | * %FALSE. |
98 | * @dispatch: Called to dispatch the event source, after it has returned |
99 | * %TRUE in either its @prepare or its @check function, or if a ready time |
100 | * has been reached. The @dispatch function receives a callback function and |
101 | * user data. The callback function may be %NULL if the source was never |
102 | * connected to a callback using g_source_set_callback(). The @dispatch |
103 | * function should call the callback function with @user_data and whatever |
104 | * additional parameters are needed for this type of event source. The |
105 | * return value of the @dispatch function should be #G_SOURCE_REMOVE if the |
106 | * source should be removed or #G_SOURCE_CONTINUE to keep it. |
107 | * @finalize: Called when the source is finalized. At this point, the source |
108 | * will have been destroyed, had its callback cleared, and have been removed |
109 | * from its #GMainContext, but it will still have its final reference count, |
110 | * so methods can be called on it from within this function. |
111 | * |
112 | * The `GSourceFuncs` struct contains a table of |
113 | * functions used to handle event sources in a generic manner. |
114 | * |
115 | * For idle sources, the prepare and check functions always return %TRUE |
116 | * to indicate that the source is always ready to be processed. The prepare |
117 | * function also returns a timeout value of 0 to ensure that the poll() call |
118 | * doesn't block (since that would be time wasted which could have been spent |
119 | * running the idle function). |
120 | * |
121 | * For timeout sources, the prepare and check functions both return %TRUE |
122 | * if the timeout interval has expired. The prepare function also returns |
123 | * a timeout value to ensure that the poll() call doesn't block too long |
124 | * and miss the next timeout. |
125 | * |
126 | * For file descriptor sources, the prepare function typically returns %FALSE, |
127 | * since it must wait until poll() has been called before it knows whether |
128 | * any events need to be processed. It sets the returned timeout to -1 to |
129 | * indicate that it doesn't mind how long the poll() call blocks. In the |
130 | * check function, it tests the results of the poll() call to see if the |
131 | * required condition has been met, and returns %TRUE if so. |
132 | */ |
133 | typedef struct _GSourceFuncs GSourceFuncs; |
134 | |
135 | /** |
136 | * GPid: |
137 | * |
138 | * A type which is used to hold a process identification. |
139 | * |
140 | * On UNIX, processes are identified by a process id (an integer), |
141 | * while Windows uses process handles (which are pointers). |
142 | * |
143 | * GPid is used in GLib only for descendant processes spawned with |
144 | * the g_spawn functions. |
145 | */ |
146 | /* defined in glibconfig.h */ |
147 | |
148 | /** |
149 | * G_PID_FORMAT: |
150 | * |
151 | * A format specifier that can be used in printf()-style format strings |
152 | * when printing a #GPid. |
153 | * |
154 | * Since: 2.50 |
155 | */ |
156 | /* defined in glibconfig.h */ |
157 | |
158 | /** |
159 | * GSourceFunc: |
160 | * @user_data: data passed to the function, set when the source was |
161 | * created with one of the above functions |
162 | * |
163 | * Specifies the type of function passed to g_timeout_add(), |
164 | * g_timeout_add_full(), g_idle_add(), and g_idle_add_full(). |
165 | * |
166 | * When calling g_source_set_callback(), you may need to cast a function of a |
167 | * different type to this type. Use G_SOURCE_FUNC() to avoid warnings about |
168 | * incompatible function types. |
169 | * |
170 | * Returns: %FALSE if the source should be removed. #G_SOURCE_CONTINUE and |
171 | * #G_SOURCE_REMOVE are more memorable names for the return value. |
172 | */ |
173 | typedef gboolean (*GSourceFunc) (gpointer user_data); |
174 | |
175 | /** |
176 | * G_SOURCE_FUNC: |
177 | * @f: a function pointer. |
178 | * |
179 | * Cast a function pointer to a #GSourceFunc, suppressing warnings from GCC 8 |
180 | * onwards with `-Wextra` or `-Wcast-function-type` enabled about the function |
181 | * types being incompatible. |
182 | * |
183 | * For example, the correct type of callback for a source created by |
184 | * g_child_watch_source_new() is #GChildWatchFunc, which accepts more arguments |
185 | * than #GSourceFunc. Casting the function with `(GSourceFunc)` to call |
186 | * g_source_set_callback() will trigger a warning, even though it will be cast |
187 | * back to the correct type before it is called by the source. |
188 | * |
189 | * Since: 2.58 |
190 | */ |
191 | #define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) GLIB_AVAILABLE_MACRO_IN_2_58 |
192 | |
193 | /** |
194 | * GChildWatchFunc: |
195 | * @pid: the process id of the child process |
196 | * @status: Status information about the child process, encoded |
197 | * in a platform-specific manner |
198 | * @user_data: user data passed to g_child_watch_add() |
199 | * |
200 | * Prototype of a #GChildWatchSource callback, called when a child |
201 | * process has exited. To interpret @status, see the documentation |
202 | * for g_spawn_check_exit_status(). |
203 | */ |
204 | typedef void (*GChildWatchFunc) (GPid pid, |
205 | gint status, |
206 | gpointer user_data); |
207 | |
208 | |
209 | /** |
210 | * GSourceDisposeFunc: |
211 | * @source: #GSource that is currently being disposed |
212 | * |
213 | * Dispose function for @source. See g_source_set_dispose_function() for |
214 | * details. |
215 | * |
216 | * Since: 2.64 |
217 | */ |
218 | GLIB_AVAILABLE_TYPE_IN_2_64 |
219 | typedef void (*GSourceDisposeFunc) (GSource *source); |
220 | |
221 | struct _GSource |
222 | { |
223 | /*< private >*/ |
224 | gpointer callback_data; |
225 | GSourceCallbackFuncs *callback_funcs; |
226 | |
227 | const GSourceFuncs *source_funcs; |
228 | guint ref_count; |
229 | |
230 | GMainContext *context; |
231 | |
232 | gint priority; |
233 | guint flags; |
234 | guint source_id; |
235 | |
236 | GSList *poll_fds; |
237 | |
238 | GSource *prev; |
239 | GSource *next; |
240 | |
241 | char *name; |
242 | |
243 | GSourcePrivate *priv; |
244 | }; |
245 | |
246 | struct _GSourceCallbackFuncs |
247 | { |
248 | void (*ref) (gpointer cb_data); |
249 | void (*unref) (gpointer cb_data); |
250 | void (*get) (gpointer cb_data, |
251 | GSource *source, |
252 | GSourceFunc *func, |
253 | gpointer *data); |
254 | }; |
255 | |
256 | /** |
257 | * GSourceDummyMarshal: |
258 | * |
259 | * This is just a placeholder for #GClosureMarshal, |
260 | * which cannot be used here for dependency reasons. |
261 | */ |
262 | typedef void (*GSourceDummyMarshal) (void); |
263 | |
264 | struct _GSourceFuncs |
265 | { |
266 | gboolean (*prepare) (GSource *source, |
267 | gint *timeout_); |
268 | gboolean (*check) (GSource *source); |
269 | gboolean (*dispatch) (GSource *source, |
270 | GSourceFunc callback, |
271 | gpointer user_data); |
272 | void (*finalize) (GSource *source); /* Can be NULL */ |
273 | |
274 | /*< private >*/ |
275 | /* For use by g_source_set_closure */ |
276 | GSourceFunc closure_callback; |
277 | GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */ |
278 | }; |
279 | |
280 | /* Standard priorities */ |
281 | |
282 | /** |
283 | * G_PRIORITY_HIGH: |
284 | * |
285 | * Use this for high priority event sources. |
286 | * |
287 | * It is not used within GLib or GTK+. |
288 | */ |
289 | #define G_PRIORITY_HIGH -100 |
290 | |
291 | /** |
292 | * G_PRIORITY_DEFAULT: |
293 | * |
294 | * Use this for default priority event sources. |
295 | * |
296 | * In GLib this priority is used when adding timeout functions |
297 | * with g_timeout_add(). In GDK this priority is used for events |
298 | * from the X server. |
299 | */ |
300 | #define G_PRIORITY_DEFAULT 0 |
301 | |
302 | /** |
303 | * G_PRIORITY_HIGH_IDLE: |
304 | * |
305 | * Use this for high priority idle functions. |
306 | * |
307 | * GTK+ uses #G_PRIORITY_HIGH_IDLE + 10 for resizing operations, |
308 | * and #G_PRIORITY_HIGH_IDLE + 20 for redrawing operations. (This is |
309 | * done to ensure that any pending resizes are processed before any |
310 | * pending redraws, so that widgets are not redrawn twice unnecessarily.) |
311 | */ |
312 | #define G_PRIORITY_HIGH_IDLE 100 |
313 | |
314 | /** |
315 | * G_PRIORITY_DEFAULT_IDLE: |
316 | * |
317 | * Use this for default priority idle functions. |
318 | * |
319 | * In GLib this priority is used when adding idle functions with |
320 | * g_idle_add(). |
321 | */ |
322 | #define G_PRIORITY_DEFAULT_IDLE 200 |
323 | |
324 | /** |
325 | * G_PRIORITY_LOW: |
326 | * |
327 | * Use this for very low priority background tasks. |
328 | * |
329 | * It is not used within GLib or GTK+. |
330 | */ |
331 | #define G_PRIORITY_LOW 300 |
332 | |
333 | /** |
334 | * G_SOURCE_REMOVE: |
335 | * |
336 | * Use this macro as the return value of a #GSourceFunc to remove |
337 | * the #GSource from the main loop. |
338 | * |
339 | * Since: 2.32 |
340 | */ |
341 | #define G_SOURCE_REMOVE FALSE |
342 | |
343 | /** |
344 | * G_SOURCE_CONTINUE: |
345 | * |
346 | * Use this macro as the return value of a #GSourceFunc to leave |
347 | * the #GSource in the main loop. |
348 | * |
349 | * Since: 2.32 |
350 | */ |
351 | #define G_SOURCE_CONTINUE TRUE |
352 | |
353 | /* GMainContext: */ |
354 | |
355 | GLIB_AVAILABLE_IN_ALL |
356 | GMainContext *g_main_context_new (void); |
357 | GLIB_AVAILABLE_IN_ALL |
358 | GMainContext *g_main_context_ref (GMainContext *context); |
359 | GLIB_AVAILABLE_IN_ALL |
360 | void g_main_context_unref (GMainContext *context); |
361 | GLIB_AVAILABLE_IN_ALL |
362 | GMainContext *g_main_context_default (void); |
363 | |
364 | GLIB_AVAILABLE_IN_ALL |
365 | gboolean g_main_context_iteration (GMainContext *context, |
366 | gboolean may_block); |
367 | GLIB_AVAILABLE_IN_ALL |
368 | gboolean g_main_context_pending (GMainContext *context); |
369 | |
370 | /* For implementation of legacy interfaces |
371 | */ |
372 | GLIB_AVAILABLE_IN_ALL |
373 | GSource *g_main_context_find_source_by_id (GMainContext *context, |
374 | guint source_id); |
375 | GLIB_AVAILABLE_IN_ALL |
376 | GSource *g_main_context_find_source_by_user_data (GMainContext *context, |
377 | gpointer user_data); |
378 | GLIB_AVAILABLE_IN_ALL |
379 | GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context, |
380 | GSourceFuncs *funcs, |
381 | gpointer user_data); |
382 | |
383 | /* Low level functions for implementing custom main loops. |
384 | */ |
385 | GLIB_AVAILABLE_IN_ALL |
386 | void g_main_context_wakeup (GMainContext *context); |
387 | GLIB_AVAILABLE_IN_ALL |
388 | gboolean g_main_context_acquire (GMainContext *context); |
389 | GLIB_AVAILABLE_IN_ALL |
390 | void g_main_context_release (GMainContext *context); |
391 | GLIB_AVAILABLE_IN_ALL |
392 | gboolean g_main_context_is_owner (GMainContext *context); |
393 | GLIB_DEPRECATED_IN_2_58_FOR(g_main_context_is_owner) |
394 | gboolean g_main_context_wait (GMainContext *context, |
395 | GCond *cond, |
396 | GMutex *mutex); |
397 | |
398 | GLIB_AVAILABLE_IN_ALL |
399 | gboolean g_main_context_prepare (GMainContext *context, |
400 | gint *priority); |
401 | GLIB_AVAILABLE_IN_ALL |
402 | gint g_main_context_query (GMainContext *context, |
403 | gint max_priority, |
404 | gint *timeout_, |
405 | GPollFD *fds, |
406 | gint n_fds); |
407 | GLIB_AVAILABLE_IN_ALL |
408 | gboolean g_main_context_check (GMainContext *context, |
409 | gint max_priority, |
410 | GPollFD *fds, |
411 | gint n_fds); |
412 | GLIB_AVAILABLE_IN_ALL |
413 | void g_main_context_dispatch (GMainContext *context); |
414 | |
415 | GLIB_AVAILABLE_IN_ALL |
416 | void g_main_context_set_poll_func (GMainContext *context, |
417 | GPollFunc func); |
418 | GLIB_AVAILABLE_IN_ALL |
419 | GPollFunc g_main_context_get_poll_func (GMainContext *context); |
420 | |
421 | /* Low level functions for use by source implementations |
422 | */ |
423 | GLIB_AVAILABLE_IN_ALL |
424 | void g_main_context_add_poll (GMainContext *context, |
425 | GPollFD *fd, |
426 | gint priority); |
427 | GLIB_AVAILABLE_IN_ALL |
428 | void g_main_context_remove_poll (GMainContext *context, |
429 | GPollFD *fd); |
430 | |
431 | GLIB_AVAILABLE_IN_ALL |
432 | gint g_main_depth (void); |
433 | GLIB_AVAILABLE_IN_ALL |
434 | GSource *g_main_current_source (void); |
435 | |
436 | /* GMainContexts for other threads |
437 | */ |
438 | GLIB_AVAILABLE_IN_ALL |
439 | void g_main_context_push_thread_default (GMainContext *context); |
440 | GLIB_AVAILABLE_IN_ALL |
441 | void g_main_context_pop_thread_default (GMainContext *context); |
442 | GLIB_AVAILABLE_IN_ALL |
443 | GMainContext *g_main_context_get_thread_default (void); |
444 | GLIB_AVAILABLE_IN_ALL |
445 | GMainContext *g_main_context_ref_thread_default (void); |
446 | |
447 | /** |
448 | * GMainContextPusher: |
449 | * |
450 | * Opaque type. See g_main_context_pusher_new() for details. |
451 | * |
452 | * Since: 2.64 |
453 | */ |
454 | typedef void GMainContextPusher GLIB_AVAILABLE_TYPE_IN_2_64; |
455 | |
456 | /** |
457 | * g_main_context_pusher_new: |
458 | * @main_context: (transfer none): a main context to push |
459 | * |
460 | * Push @main_context as the new thread-default main context for the current |
461 | * thread, using g_main_context_push_thread_default(), and return a new |
462 | * #GMainContextPusher. Pop with g_main_context_pusher_free(). Using |
463 | * g_main_context_pop_thread_default() on @main_context while a |
464 | * #GMainContextPusher exists for it can lead to undefined behaviour. |
465 | * |
466 | * Using two #GMainContextPushers in the same scope is not allowed, as it leads |
467 | * to an undefined pop order. |
468 | * |
469 | * This is intended to be used with g_autoptr(). Note that g_autoptr() |
470 | * is only available when using GCC or clang, so the following example |
471 | * will only work with those compilers: |
472 | * |[ |
473 | * typedef struct |
474 | * { |
475 | * ... |
476 | * GMainContext *context; |
477 | * ... |
478 | * } MyObject; |
479 | * |
480 | * static void |
481 | * my_object_do_stuff (MyObject *self) |
482 | * { |
483 | * g_autoptr(GMainContextPusher) pusher = g_main_context_pusher_new (self->context); |
484 | * |
485 | * // Code with main context as the thread default here |
486 | * |
487 | * if (cond) |
488 | * // No need to pop |
489 | * return; |
490 | * |
491 | * // Optionally early pop |
492 | * g_clear_pointer (&pusher, g_main_context_pusher_free); |
493 | * |
494 | * // Code with main context no longer the thread default here |
495 | * } |
496 | * ]| |
497 | * |
498 | * Returns: (transfer full): a #GMainContextPusher |
499 | * Since: 2.64 |
500 | */ |
501 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
502 | GLIB_AVAILABLE_STATIC_INLINE_IN_2_64 |
503 | static inline GMainContextPusher * |
504 | g_main_context_pusher_new (GMainContext *main_context) |
505 | { |
506 | g_main_context_push_thread_default (context: main_context); |
507 | return (GMainContextPusher *) main_context; |
508 | } |
509 | G_GNUC_END_IGNORE_DEPRECATIONS |
510 | |
511 | /** |
512 | * g_main_context_pusher_free: |
513 | * @pusher: (transfer full): a #GMainContextPusher |
514 | * |
515 | * Pop @pusher’s main context as the thread default main context. |
516 | * See g_main_context_pusher_new() for details. |
517 | * |
518 | * This will pop the #GMainContext as the current thread-default main context, |
519 | * but will not call g_main_context_unref() on it. |
520 | * |
521 | * Since: 2.64 |
522 | */ |
523 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
524 | GLIB_AVAILABLE_STATIC_INLINE_IN_2_64 |
525 | static inline void |
526 | g_main_context_pusher_free (GMainContextPusher *pusher) |
527 | { |
528 | g_main_context_pop_thread_default (context: (GMainContext *) pusher); |
529 | } |
530 | G_GNUC_END_IGNORE_DEPRECATIONS |
531 | |
532 | /* GMainLoop: */ |
533 | |
534 | GLIB_AVAILABLE_IN_ALL |
535 | GMainLoop *g_main_loop_new (GMainContext *context, |
536 | gboolean is_running); |
537 | GLIB_AVAILABLE_IN_ALL |
538 | void g_main_loop_run (GMainLoop *loop); |
539 | GLIB_AVAILABLE_IN_ALL |
540 | void g_main_loop_quit (GMainLoop *loop); |
541 | GLIB_AVAILABLE_IN_ALL |
542 | GMainLoop *g_main_loop_ref (GMainLoop *loop); |
543 | GLIB_AVAILABLE_IN_ALL |
544 | void g_main_loop_unref (GMainLoop *loop); |
545 | GLIB_AVAILABLE_IN_ALL |
546 | gboolean g_main_loop_is_running (GMainLoop *loop); |
547 | GLIB_AVAILABLE_IN_ALL |
548 | GMainContext *g_main_loop_get_context (GMainLoop *loop); |
549 | |
550 | /* GSource: */ |
551 | |
552 | GLIB_AVAILABLE_IN_ALL |
553 | GSource *g_source_new (GSourceFuncs *source_funcs, |
554 | guint struct_size); |
555 | |
556 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
557 | GLIB_AVAILABLE_IN_2_64 |
558 | void g_source_set_dispose_function (GSource *source, |
559 | GSourceDisposeFunc dispose); |
560 | G_GNUC_END_IGNORE_DEPRECATIONS |
561 | |
562 | GLIB_AVAILABLE_IN_ALL |
563 | GSource *g_source_ref (GSource *source); |
564 | GLIB_AVAILABLE_IN_ALL |
565 | void g_source_unref (GSource *source); |
566 | |
567 | GLIB_AVAILABLE_IN_ALL |
568 | guint g_source_attach (GSource *source, |
569 | GMainContext *context); |
570 | GLIB_AVAILABLE_IN_ALL |
571 | void g_source_destroy (GSource *source); |
572 | |
573 | GLIB_AVAILABLE_IN_ALL |
574 | void g_source_set_priority (GSource *source, |
575 | gint priority); |
576 | GLIB_AVAILABLE_IN_ALL |
577 | gint g_source_get_priority (GSource *source); |
578 | GLIB_AVAILABLE_IN_ALL |
579 | void g_source_set_can_recurse (GSource *source, |
580 | gboolean can_recurse); |
581 | GLIB_AVAILABLE_IN_ALL |
582 | gboolean g_source_get_can_recurse (GSource *source); |
583 | GLIB_AVAILABLE_IN_ALL |
584 | guint g_source_get_id (GSource *source); |
585 | |
586 | GLIB_AVAILABLE_IN_ALL |
587 | GMainContext *g_source_get_context (GSource *source); |
588 | |
589 | GLIB_AVAILABLE_IN_ALL |
590 | void g_source_set_callback (GSource *source, |
591 | GSourceFunc func, |
592 | gpointer data, |
593 | GDestroyNotify notify); |
594 | |
595 | GLIB_AVAILABLE_IN_ALL |
596 | void g_source_set_funcs (GSource *source, |
597 | GSourceFuncs *funcs); |
598 | GLIB_AVAILABLE_IN_ALL |
599 | gboolean g_source_is_destroyed (GSource *source); |
600 | |
601 | GLIB_AVAILABLE_IN_ALL |
602 | void g_source_set_name (GSource *source, |
603 | const char *name); |
604 | GLIB_AVAILABLE_IN_ALL |
605 | const char * g_source_get_name (GSource *source); |
606 | GLIB_AVAILABLE_IN_ALL |
607 | void g_source_set_name_by_id (guint tag, |
608 | const char *name); |
609 | |
610 | GLIB_AVAILABLE_IN_2_36 |
611 | void g_source_set_ready_time (GSource *source, |
612 | gint64 ready_time); |
613 | GLIB_AVAILABLE_IN_2_36 |
614 | gint64 g_source_get_ready_time (GSource *source); |
615 | |
616 | #ifdef G_OS_UNIX |
617 | GLIB_AVAILABLE_IN_2_36 |
618 | gpointer g_source_add_unix_fd (GSource *source, |
619 | gint fd, |
620 | GIOCondition events); |
621 | GLIB_AVAILABLE_IN_2_36 |
622 | void g_source_modify_unix_fd (GSource *source, |
623 | gpointer tag, |
624 | GIOCondition new_events); |
625 | GLIB_AVAILABLE_IN_2_36 |
626 | void g_source_remove_unix_fd (GSource *source, |
627 | gpointer tag); |
628 | GLIB_AVAILABLE_IN_2_36 |
629 | GIOCondition g_source_query_unix_fd (GSource *source, |
630 | gpointer tag); |
631 | #endif |
632 | |
633 | /* Used to implement g_source_connect_closure and internally*/ |
634 | GLIB_AVAILABLE_IN_ALL |
635 | void g_source_set_callback_indirect (GSource *source, |
636 | gpointer callback_data, |
637 | GSourceCallbackFuncs *callback_funcs); |
638 | |
639 | GLIB_AVAILABLE_IN_ALL |
640 | void g_source_add_poll (GSource *source, |
641 | GPollFD *fd); |
642 | GLIB_AVAILABLE_IN_ALL |
643 | void g_source_remove_poll (GSource *source, |
644 | GPollFD *fd); |
645 | |
646 | GLIB_AVAILABLE_IN_ALL |
647 | void g_source_add_child_source (GSource *source, |
648 | GSource *child_source); |
649 | GLIB_AVAILABLE_IN_ALL |
650 | void g_source_remove_child_source (GSource *source, |
651 | GSource *child_source); |
652 | |
653 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
654 | GLIB_DEPRECATED_IN_2_28_FOR(g_source_get_time) |
655 | void g_source_get_current_time (GSource *source, |
656 | GTimeVal *timeval); |
657 | G_GNUC_END_IGNORE_DEPRECATIONS |
658 | |
659 | GLIB_AVAILABLE_IN_ALL |
660 | gint64 g_source_get_time (GSource *source); |
661 | |
662 | /* void g_source_connect_closure (GSource *source, |
663 | GClosure *closure); |
664 | */ |
665 | |
666 | /* Specific source types |
667 | */ |
668 | GLIB_AVAILABLE_IN_ALL |
669 | GSource *g_idle_source_new (void); |
670 | GLIB_AVAILABLE_IN_ALL |
671 | GSource *g_child_watch_source_new (GPid pid); |
672 | GLIB_AVAILABLE_IN_ALL |
673 | GSource *g_timeout_source_new (guint interval); |
674 | GLIB_AVAILABLE_IN_ALL |
675 | GSource *g_timeout_source_new_seconds (guint interval); |
676 | |
677 | /* Miscellaneous functions |
678 | */ |
679 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
680 | GLIB_DEPRECATED_IN_2_62_FOR(g_get_real_time) |
681 | void g_get_current_time (GTimeVal *result); |
682 | G_GNUC_END_IGNORE_DEPRECATIONS |
683 | |
684 | GLIB_AVAILABLE_IN_ALL |
685 | gint64 g_get_monotonic_time (void); |
686 | GLIB_AVAILABLE_IN_ALL |
687 | gint64 g_get_real_time (void); |
688 | |
689 | |
690 | /* Source manipulation by ID */ |
691 | GLIB_AVAILABLE_IN_ALL |
692 | gboolean g_source_remove (guint tag); |
693 | GLIB_AVAILABLE_IN_ALL |
694 | gboolean g_source_remove_by_user_data (gpointer user_data); |
695 | GLIB_AVAILABLE_IN_ALL |
696 | gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs, |
697 | gpointer user_data); |
698 | |
699 | /** |
700 | * GClearHandleFunc: |
701 | * @handle_id: the handle ID to clear |
702 | * |
703 | * Specifies the type of function passed to g_clear_handle_id(). |
704 | * The implementation is expected to free the resource identified |
705 | * by @handle_id; for instance, if @handle_id is a #GSource ID, |
706 | * g_source_remove() can be used. |
707 | * |
708 | * Since: 2.56 |
709 | */ |
710 | typedef void (* GClearHandleFunc) (guint handle_id); |
711 | |
712 | GLIB_AVAILABLE_IN_2_56 |
713 | void g_clear_handle_id (guint *tag_ptr, |
714 | GClearHandleFunc clear_func); |
715 | |
716 | #define g_clear_handle_id(tag_ptr, clear_func) \ |
717 | G_STMT_START { \ |
718 | G_STATIC_ASSERT (sizeof *(tag_ptr) == sizeof (guint)); \ |
719 | guint *_tag_ptr = (guint *) (tag_ptr); \ |
720 | guint _handle_id; \ |
721 | \ |
722 | _handle_id = *_tag_ptr; \ |
723 | if (_handle_id > 0) \ |
724 | { \ |
725 | *_tag_ptr = 0; \ |
726 | clear_func (_handle_id); \ |
727 | } \ |
728 | } G_STMT_END \ |
729 | GLIB_AVAILABLE_MACRO_IN_2_56 |
730 | |
731 | /* Idles, child watchers and timeouts */ |
732 | GLIB_AVAILABLE_IN_ALL |
733 | guint g_timeout_add_full (gint priority, |
734 | guint interval, |
735 | GSourceFunc function, |
736 | gpointer data, |
737 | GDestroyNotify notify); |
738 | GLIB_AVAILABLE_IN_ALL |
739 | guint g_timeout_add (guint interval, |
740 | GSourceFunc function, |
741 | gpointer data); |
742 | GLIB_AVAILABLE_IN_ALL |
743 | guint g_timeout_add_seconds_full (gint priority, |
744 | guint interval, |
745 | GSourceFunc function, |
746 | gpointer data, |
747 | GDestroyNotify notify); |
748 | GLIB_AVAILABLE_IN_ALL |
749 | guint g_timeout_add_seconds (guint interval, |
750 | GSourceFunc function, |
751 | gpointer data); |
752 | GLIB_AVAILABLE_IN_ALL |
753 | guint g_child_watch_add_full (gint priority, |
754 | GPid pid, |
755 | GChildWatchFunc function, |
756 | gpointer data, |
757 | GDestroyNotify notify); |
758 | GLIB_AVAILABLE_IN_ALL |
759 | guint g_child_watch_add (GPid pid, |
760 | GChildWatchFunc function, |
761 | gpointer data); |
762 | GLIB_AVAILABLE_IN_ALL |
763 | guint g_idle_add (GSourceFunc function, |
764 | gpointer data); |
765 | GLIB_AVAILABLE_IN_ALL |
766 | guint g_idle_add_full (gint priority, |
767 | GSourceFunc function, |
768 | gpointer data, |
769 | GDestroyNotify notify); |
770 | GLIB_AVAILABLE_IN_ALL |
771 | gboolean g_idle_remove_by_data (gpointer data); |
772 | |
773 | GLIB_AVAILABLE_IN_ALL |
774 | void g_main_context_invoke_full (GMainContext *context, |
775 | gint priority, |
776 | GSourceFunc function, |
777 | gpointer data, |
778 | GDestroyNotify notify); |
779 | GLIB_AVAILABLE_IN_ALL |
780 | void g_main_context_invoke (GMainContext *context, |
781 | GSourceFunc function, |
782 | gpointer data); |
783 | |
784 | /* Hook for GClosure / GSource integration. Don't touch */ |
785 | GLIB_VAR GSourceFuncs g_timeout_funcs; |
786 | GLIB_VAR GSourceFuncs g_child_watch_funcs; |
787 | GLIB_VAR GSourceFuncs g_idle_funcs; |
788 | #ifdef G_OS_UNIX |
789 | GLIB_VAR GSourceFuncs g_unix_signal_funcs; |
790 | GLIB_VAR GSourceFuncs g_unix_fd_source_funcs; |
791 | #endif |
792 | |
793 | G_END_DECLS |
794 | |
795 | #endif /* __G_MAIN_H__ */ |
796 | |