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
29G_BEGIN_DECLS
30
31typedef 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 */
48typedef 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 */
56typedef struct _GMainLoop GMainLoop;
57
58/**
59 * GSource:
60 *
61 * The `GSource` struct is an opaque data type
62 * representing an event source.
63 */
64typedef struct _GSource GSource;
65typedef 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 */
77typedef 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 */
133typedef 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 */
173typedef 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 */
204typedef 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 */
218GLIB_AVAILABLE_TYPE_IN_2_64
219typedef void (*GSourceDisposeFunc) (GSource *source);
220
221struct _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
246struct _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 */
262typedef void (*GSourceDummyMarshal) (void);
263
264struct _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
355GLIB_AVAILABLE_IN_ALL
356GMainContext *g_main_context_new (void);
357GLIB_AVAILABLE_IN_ALL
358GMainContext *g_main_context_ref (GMainContext *context);
359GLIB_AVAILABLE_IN_ALL
360void g_main_context_unref (GMainContext *context);
361GLIB_AVAILABLE_IN_ALL
362GMainContext *g_main_context_default (void);
363
364GLIB_AVAILABLE_IN_ALL
365gboolean g_main_context_iteration (GMainContext *context,
366 gboolean may_block);
367GLIB_AVAILABLE_IN_ALL
368gboolean g_main_context_pending (GMainContext *context);
369
370/* For implementation of legacy interfaces
371 */
372GLIB_AVAILABLE_IN_ALL
373GSource *g_main_context_find_source_by_id (GMainContext *context,
374 guint source_id);
375GLIB_AVAILABLE_IN_ALL
376GSource *g_main_context_find_source_by_user_data (GMainContext *context,
377 gpointer user_data);
378GLIB_AVAILABLE_IN_ALL
379GSource *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 */
385GLIB_AVAILABLE_IN_ALL
386void g_main_context_wakeup (GMainContext *context);
387GLIB_AVAILABLE_IN_ALL
388gboolean g_main_context_acquire (GMainContext *context);
389GLIB_AVAILABLE_IN_ALL
390void g_main_context_release (GMainContext *context);
391GLIB_AVAILABLE_IN_ALL
392gboolean g_main_context_is_owner (GMainContext *context);
393GLIB_DEPRECATED_IN_2_58_FOR(g_main_context_is_owner)
394gboolean g_main_context_wait (GMainContext *context,
395 GCond *cond,
396 GMutex *mutex);
397
398GLIB_AVAILABLE_IN_ALL
399gboolean g_main_context_prepare (GMainContext *context,
400 gint *priority);
401GLIB_AVAILABLE_IN_ALL
402gint g_main_context_query (GMainContext *context,
403 gint max_priority,
404 gint *timeout_,
405 GPollFD *fds,
406 gint n_fds);
407GLIB_AVAILABLE_IN_ALL
408gboolean g_main_context_check (GMainContext *context,
409 gint max_priority,
410 GPollFD *fds,
411 gint n_fds);
412GLIB_AVAILABLE_IN_ALL
413void g_main_context_dispatch (GMainContext *context);
414
415GLIB_AVAILABLE_IN_ALL
416void g_main_context_set_poll_func (GMainContext *context,
417 GPollFunc func);
418GLIB_AVAILABLE_IN_ALL
419GPollFunc g_main_context_get_poll_func (GMainContext *context);
420
421/* Low level functions for use by source implementations
422 */
423GLIB_AVAILABLE_IN_ALL
424void g_main_context_add_poll (GMainContext *context,
425 GPollFD *fd,
426 gint priority);
427GLIB_AVAILABLE_IN_ALL
428void g_main_context_remove_poll (GMainContext *context,
429 GPollFD *fd);
430
431GLIB_AVAILABLE_IN_ALL
432gint g_main_depth (void);
433GLIB_AVAILABLE_IN_ALL
434GSource *g_main_current_source (void);
435
436/* GMainContexts for other threads
437 */
438GLIB_AVAILABLE_IN_ALL
439void g_main_context_push_thread_default (GMainContext *context);
440GLIB_AVAILABLE_IN_ALL
441void g_main_context_pop_thread_default (GMainContext *context);
442GLIB_AVAILABLE_IN_ALL
443GMainContext *g_main_context_get_thread_default (void);
444GLIB_AVAILABLE_IN_ALL
445GMainContext *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 */
454typedef 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 */
501G_GNUC_BEGIN_IGNORE_DEPRECATIONS
502GLIB_AVAILABLE_STATIC_INLINE_IN_2_64
503static inline GMainContextPusher *
504g_main_context_pusher_new (GMainContext *main_context)
505{
506 g_main_context_push_thread_default (context: main_context);
507 return (GMainContextPusher *) main_context;
508}
509G_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 */
523G_GNUC_BEGIN_IGNORE_DEPRECATIONS
524GLIB_AVAILABLE_STATIC_INLINE_IN_2_64
525static inline void
526g_main_context_pusher_free (GMainContextPusher *pusher)
527{
528 g_main_context_pop_thread_default (context: (GMainContext *) pusher);
529}
530G_GNUC_END_IGNORE_DEPRECATIONS
531
532/* GMainLoop: */
533
534GLIB_AVAILABLE_IN_ALL
535GMainLoop *g_main_loop_new (GMainContext *context,
536 gboolean is_running);
537GLIB_AVAILABLE_IN_ALL
538void g_main_loop_run (GMainLoop *loop);
539GLIB_AVAILABLE_IN_ALL
540void g_main_loop_quit (GMainLoop *loop);
541GLIB_AVAILABLE_IN_ALL
542GMainLoop *g_main_loop_ref (GMainLoop *loop);
543GLIB_AVAILABLE_IN_ALL
544void g_main_loop_unref (GMainLoop *loop);
545GLIB_AVAILABLE_IN_ALL
546gboolean g_main_loop_is_running (GMainLoop *loop);
547GLIB_AVAILABLE_IN_ALL
548GMainContext *g_main_loop_get_context (GMainLoop *loop);
549
550/* GSource: */
551
552GLIB_AVAILABLE_IN_ALL
553GSource *g_source_new (GSourceFuncs *source_funcs,
554 guint struct_size);
555
556G_GNUC_BEGIN_IGNORE_DEPRECATIONS
557GLIB_AVAILABLE_IN_2_64
558void g_source_set_dispose_function (GSource *source,
559 GSourceDisposeFunc dispose);
560G_GNUC_END_IGNORE_DEPRECATIONS
561
562GLIB_AVAILABLE_IN_ALL
563GSource *g_source_ref (GSource *source);
564GLIB_AVAILABLE_IN_ALL
565void g_source_unref (GSource *source);
566
567GLIB_AVAILABLE_IN_ALL
568guint g_source_attach (GSource *source,
569 GMainContext *context);
570GLIB_AVAILABLE_IN_ALL
571void g_source_destroy (GSource *source);
572
573GLIB_AVAILABLE_IN_ALL
574void g_source_set_priority (GSource *source,
575 gint priority);
576GLIB_AVAILABLE_IN_ALL
577gint g_source_get_priority (GSource *source);
578GLIB_AVAILABLE_IN_ALL
579void g_source_set_can_recurse (GSource *source,
580 gboolean can_recurse);
581GLIB_AVAILABLE_IN_ALL
582gboolean g_source_get_can_recurse (GSource *source);
583GLIB_AVAILABLE_IN_ALL
584guint g_source_get_id (GSource *source);
585
586GLIB_AVAILABLE_IN_ALL
587GMainContext *g_source_get_context (GSource *source);
588
589GLIB_AVAILABLE_IN_ALL
590void g_source_set_callback (GSource *source,
591 GSourceFunc func,
592 gpointer data,
593 GDestroyNotify notify);
594
595GLIB_AVAILABLE_IN_ALL
596void g_source_set_funcs (GSource *source,
597 GSourceFuncs *funcs);
598GLIB_AVAILABLE_IN_ALL
599gboolean g_source_is_destroyed (GSource *source);
600
601GLIB_AVAILABLE_IN_ALL
602void g_source_set_name (GSource *source,
603 const char *name);
604GLIB_AVAILABLE_IN_ALL
605const char * g_source_get_name (GSource *source);
606GLIB_AVAILABLE_IN_ALL
607void g_source_set_name_by_id (guint tag,
608 const char *name);
609
610GLIB_AVAILABLE_IN_2_36
611void g_source_set_ready_time (GSource *source,
612 gint64 ready_time);
613GLIB_AVAILABLE_IN_2_36
614gint64 g_source_get_ready_time (GSource *source);
615
616#ifdef G_OS_UNIX
617GLIB_AVAILABLE_IN_2_36
618gpointer g_source_add_unix_fd (GSource *source,
619 gint fd,
620 GIOCondition events);
621GLIB_AVAILABLE_IN_2_36
622void g_source_modify_unix_fd (GSource *source,
623 gpointer tag,
624 GIOCondition new_events);
625GLIB_AVAILABLE_IN_2_36
626void g_source_remove_unix_fd (GSource *source,
627 gpointer tag);
628GLIB_AVAILABLE_IN_2_36
629GIOCondition g_source_query_unix_fd (GSource *source,
630 gpointer tag);
631#endif
632
633/* Used to implement g_source_connect_closure and internally*/
634GLIB_AVAILABLE_IN_ALL
635void g_source_set_callback_indirect (GSource *source,
636 gpointer callback_data,
637 GSourceCallbackFuncs *callback_funcs);
638
639GLIB_AVAILABLE_IN_ALL
640void g_source_add_poll (GSource *source,
641 GPollFD *fd);
642GLIB_AVAILABLE_IN_ALL
643void g_source_remove_poll (GSource *source,
644 GPollFD *fd);
645
646GLIB_AVAILABLE_IN_ALL
647void g_source_add_child_source (GSource *source,
648 GSource *child_source);
649GLIB_AVAILABLE_IN_ALL
650void g_source_remove_child_source (GSource *source,
651 GSource *child_source);
652
653G_GNUC_BEGIN_IGNORE_DEPRECATIONS
654GLIB_DEPRECATED_IN_2_28_FOR(g_source_get_time)
655void g_source_get_current_time (GSource *source,
656 GTimeVal *timeval);
657G_GNUC_END_IGNORE_DEPRECATIONS
658
659GLIB_AVAILABLE_IN_ALL
660gint64 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 */
668GLIB_AVAILABLE_IN_ALL
669GSource *g_idle_source_new (void);
670GLIB_AVAILABLE_IN_ALL
671GSource *g_child_watch_source_new (GPid pid);
672GLIB_AVAILABLE_IN_ALL
673GSource *g_timeout_source_new (guint interval);
674GLIB_AVAILABLE_IN_ALL
675GSource *g_timeout_source_new_seconds (guint interval);
676
677/* Miscellaneous functions
678 */
679G_GNUC_BEGIN_IGNORE_DEPRECATIONS
680GLIB_DEPRECATED_IN_2_62_FOR(g_get_real_time)
681void g_get_current_time (GTimeVal *result);
682G_GNUC_END_IGNORE_DEPRECATIONS
683
684GLIB_AVAILABLE_IN_ALL
685gint64 g_get_monotonic_time (void);
686GLIB_AVAILABLE_IN_ALL
687gint64 g_get_real_time (void);
688
689
690/* Source manipulation by ID */
691GLIB_AVAILABLE_IN_ALL
692gboolean g_source_remove (guint tag);
693GLIB_AVAILABLE_IN_ALL
694gboolean g_source_remove_by_user_data (gpointer user_data);
695GLIB_AVAILABLE_IN_ALL
696gboolean 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 */
710typedef void (* GClearHandleFunc) (guint handle_id);
711
712GLIB_AVAILABLE_IN_2_56
713void 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 */
732GLIB_AVAILABLE_IN_ALL
733guint g_timeout_add_full (gint priority,
734 guint interval,
735 GSourceFunc function,
736 gpointer data,
737 GDestroyNotify notify);
738GLIB_AVAILABLE_IN_ALL
739guint g_timeout_add (guint interval,
740 GSourceFunc function,
741 gpointer data);
742GLIB_AVAILABLE_IN_ALL
743guint g_timeout_add_seconds_full (gint priority,
744 guint interval,
745 GSourceFunc function,
746 gpointer data,
747 GDestroyNotify notify);
748GLIB_AVAILABLE_IN_ALL
749guint g_timeout_add_seconds (guint interval,
750 GSourceFunc function,
751 gpointer data);
752GLIB_AVAILABLE_IN_ALL
753guint g_child_watch_add_full (gint priority,
754 GPid pid,
755 GChildWatchFunc function,
756 gpointer data,
757 GDestroyNotify notify);
758GLIB_AVAILABLE_IN_ALL
759guint g_child_watch_add (GPid pid,
760 GChildWatchFunc function,
761 gpointer data);
762GLIB_AVAILABLE_IN_ALL
763guint g_idle_add (GSourceFunc function,
764 gpointer data);
765GLIB_AVAILABLE_IN_ALL
766guint g_idle_add_full (gint priority,
767 GSourceFunc function,
768 gpointer data,
769 GDestroyNotify notify);
770GLIB_AVAILABLE_IN_ALL
771gboolean g_idle_remove_by_data (gpointer data);
772
773GLIB_AVAILABLE_IN_ALL
774void g_main_context_invoke_full (GMainContext *context,
775 gint priority,
776 GSourceFunc function,
777 gpointer data,
778 GDestroyNotify notify);
779GLIB_AVAILABLE_IN_ALL
780void g_main_context_invoke (GMainContext *context,
781 GSourceFunc function,
782 gpointer data);
783
784/* Hook for GClosure / GSource integration. Don't touch */
785GLIB_VAR GSourceFuncs g_timeout_funcs;
786GLIB_VAR GSourceFuncs g_child_watch_funcs;
787GLIB_VAR GSourceFuncs g_idle_funcs;
788#ifdef G_OS_UNIX
789GLIB_VAR GSourceFuncs g_unix_signal_funcs;
790GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;
791#endif
792
793G_END_DECLS
794
795#endif /* __G_MAIN_H__ */
796

source code of gtk/subprojects/glib/glib/gmain.h