/usr/include/glib-2.0/glib/gmain.h
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  | static inline GMainContextPusher *  | 
503  |  | g_main_context_pusher_new (GMainContext *main_context)  | 
504  | 0  | { | 
505  | 0  |   g_main_context_push_thread_default (main_context);  | 
506  | 0  |   return (GMainContextPusher *) main_context;  | 
507  | 0  | } Unexecuted instantiation: cac-aca.c:g_main_context_pusher_new Unexecuted instantiation: cac.c:g_main_context_pusher_new Unexecuted instantiation: card_7816.c:g_main_context_pusher_new Unexecuted instantiation: common.c:g_main_context_pusher_new Unexecuted instantiation: event.c:g_main_context_pusher_new Unexecuted instantiation: gp.c:g_main_context_pusher_new Unexecuted instantiation: msft.c:g_main_context_pusher_new Unexecuted instantiation: simpletlv.c:g_main_context_pusher_new Unexecuted instantiation: vcard.c:g_main_context_pusher_new Unexecuted instantiation: vcard_emul_nss.c:g_main_context_pusher_new Unexecuted instantiation: vcard_emul_type.c:g_main_context_pusher_new Unexecuted instantiation: vcardt.c:g_main_context_pusher_new Unexecuted instantiation: vreader.c:g_main_context_pusher_new Unexecuted instantiation: fuzz_simpletlv.c:g_main_context_pusher_new  | 
508  |  | G_GNUC_END_IGNORE_DEPRECATIONS  | 
509  |  |  | 
510  |  | /**  | 
511  |  |  * g_main_context_pusher_free:  | 
512  |  |  * @pusher: (transfer full): a #GMainContextPusher  | 
513  |  |  *  | 
514  |  |  * Pop @pusher’s main context as the thread default main context.  | 
515  |  |  * See g_main_context_pusher_new() for details.  | 
516  |  |  *  | 
517  |  |  * This will pop the #GMainContext as the current thread-default main context,  | 
518  |  |  * but will not call g_main_context_unref() on it.  | 
519  |  |  *  | 
520  |  |  * Since: 2.64  | 
521  |  |  */  | 
522  |  | G_GNUC_BEGIN_IGNORE_DEPRECATIONS  | 
523  |  | static inline void  | 
524  |  | g_main_context_pusher_free (GMainContextPusher *pusher)  | 
525  | 0  | { | 
526  | 0  |   g_main_context_pop_thread_default ((GMainContext *) pusher);  | 
527  | 0  | } Unexecuted instantiation: cac-aca.c:g_main_context_pusher_free Unexecuted instantiation: cac.c:g_main_context_pusher_free Unexecuted instantiation: card_7816.c:g_main_context_pusher_free Unexecuted instantiation: common.c:g_main_context_pusher_free Unexecuted instantiation: event.c:g_main_context_pusher_free Unexecuted instantiation: gp.c:g_main_context_pusher_free Unexecuted instantiation: msft.c:g_main_context_pusher_free Unexecuted instantiation: simpletlv.c:g_main_context_pusher_free Unexecuted instantiation: vcard.c:g_main_context_pusher_free Unexecuted instantiation: vcard_emul_nss.c:g_main_context_pusher_free Unexecuted instantiation: vcard_emul_type.c:g_main_context_pusher_free Unexecuted instantiation: vcardt.c:g_main_context_pusher_free Unexecuted instantiation: vreader.c:g_main_context_pusher_free Unexecuted instantiation: fuzz_simpletlv.c:g_main_context_pusher_free  | 
528  |  | G_GNUC_END_IGNORE_DEPRECATIONS  | 
529  |  |  | 
530  |  | /* GMainLoop: */  | 
531  |  |  | 
532  |  | GLIB_AVAILABLE_IN_ALL  | 
533  |  | GMainLoop *g_main_loop_new        (GMainContext *context,  | 
534  |  |                                    gboolean      is_running);  | 
535  |  | GLIB_AVAILABLE_IN_ALL  | 
536  |  | void       g_main_loop_run        (GMainLoop    *loop);  | 
537  |  | GLIB_AVAILABLE_IN_ALL  | 
538  |  | void       g_main_loop_quit       (GMainLoop    *loop);  | 
539  |  | GLIB_AVAILABLE_IN_ALL  | 
540  |  | GMainLoop *g_main_loop_ref        (GMainLoop    *loop);  | 
541  |  | GLIB_AVAILABLE_IN_ALL  | 
542  |  | void       g_main_loop_unref      (GMainLoop    *loop);  | 
543  |  | GLIB_AVAILABLE_IN_ALL  | 
544  |  | gboolean   g_main_loop_is_running (GMainLoop    *loop);  | 
545  |  | GLIB_AVAILABLE_IN_ALL  | 
546  |  | GMainContext *g_main_loop_get_context (GMainLoop    *loop);  | 
547  |  |  | 
548  |  | /* GSource: */  | 
549  |  |  | 
550  |  | GLIB_AVAILABLE_IN_ALL  | 
551  |  | GSource *g_source_new             (GSourceFuncs   *source_funcs,  | 
552  |  |                                    guint           struct_size);  | 
553  |  |  | 
554  |  | G_GNUC_BEGIN_IGNORE_DEPRECATIONS  | 
555  |  | GLIB_AVAILABLE_IN_2_64  | 
556  |  | void     g_source_set_dispose_function (GSource            *source,  | 
557  |  |                                         GSourceDisposeFunc  dispose);  | 
558  |  | G_GNUC_END_IGNORE_DEPRECATIONS  | 
559  |  |  | 
560  |  | GLIB_AVAILABLE_IN_ALL  | 
561  |  | GSource *g_source_ref             (GSource        *source);  | 
562  |  | GLIB_AVAILABLE_IN_ALL  | 
563  |  | void     g_source_unref           (GSource        *source);  | 
564  |  |  | 
565  |  | GLIB_AVAILABLE_IN_ALL  | 
566  |  | guint    g_source_attach          (GSource        *source,  | 
567  |  |                                    GMainContext   *context);  | 
568  |  | GLIB_AVAILABLE_IN_ALL  | 
569  |  | void     g_source_destroy         (GSource        *source);  | 
570  |  |  | 
571  |  | GLIB_AVAILABLE_IN_ALL  | 
572  |  | void     g_source_set_priority    (GSource        *source,  | 
573  |  |                                    gint            priority);  | 
574  |  | GLIB_AVAILABLE_IN_ALL  | 
575  |  | gint     g_source_get_priority    (GSource        *source);  | 
576  |  | GLIB_AVAILABLE_IN_ALL  | 
577  |  | void     g_source_set_can_recurse (GSource        *source,  | 
578  |  |                                    gboolean        can_recurse);  | 
579  |  | GLIB_AVAILABLE_IN_ALL  | 
580  |  | gboolean g_source_get_can_recurse (GSource        *source);  | 
581  |  | GLIB_AVAILABLE_IN_ALL  | 
582  |  | guint    g_source_get_id          (GSource        *source);  | 
583  |  |  | 
584  |  | GLIB_AVAILABLE_IN_ALL  | 
585  |  | GMainContext *g_source_get_context (GSource       *source);  | 
586  |  |  | 
587  |  | GLIB_AVAILABLE_IN_ALL  | 
588  |  | void     g_source_set_callback    (GSource        *source,  | 
589  |  |                                    GSourceFunc     func,  | 
590  |  |                                    gpointer        data,  | 
591  |  |                                    GDestroyNotify  notify);  | 
592  |  |  | 
593  |  | GLIB_AVAILABLE_IN_ALL  | 
594  |  | void     g_source_set_funcs       (GSource        *source,  | 
595  |  |                                    GSourceFuncs   *funcs);  | 
596  |  | GLIB_AVAILABLE_IN_ALL  | 
597  |  | gboolean g_source_is_destroyed    (GSource        *source);  | 
598  |  |  | 
599  |  | GLIB_AVAILABLE_IN_ALL  | 
600  |  | void                 g_source_set_name       (GSource        *source,  | 
601  |  |                                               const char     *name);  | 
602  |  | GLIB_AVAILABLE_IN_ALL  | 
603  |  | const char *         g_source_get_name       (GSource        *source);  | 
604  |  | GLIB_AVAILABLE_IN_ALL  | 
605  |  | void                 g_source_set_name_by_id (guint           tag,  | 
606  |  |                                               const char     *name);  | 
607  |  |  | 
608  |  | GLIB_AVAILABLE_IN_2_36  | 
609  |  | void                 g_source_set_ready_time (GSource        *source,  | 
610  |  |                                               gint64          ready_time);  | 
611  |  | GLIB_AVAILABLE_IN_2_36  | 
612  |  | gint64               g_source_get_ready_time (GSource        *source);  | 
613  |  |  | 
614  |  | #ifdef G_OS_UNIX  | 
615  |  | GLIB_AVAILABLE_IN_2_36  | 
616  |  | gpointer             g_source_add_unix_fd    (GSource        *source,  | 
617  |  |                                               gint            fd,  | 
618  |  |                                               GIOCondition    events);  | 
619  |  | GLIB_AVAILABLE_IN_2_36  | 
620  |  | void                 g_source_modify_unix_fd (GSource        *source,  | 
621  |  |                                               gpointer        tag,  | 
622  |  |                                               GIOCondition    new_events);  | 
623  |  | GLIB_AVAILABLE_IN_2_36  | 
624  |  | void                 g_source_remove_unix_fd (GSource        *source,  | 
625  |  |                                               gpointer        tag);  | 
626  |  | GLIB_AVAILABLE_IN_2_36  | 
627  |  | GIOCondition         g_source_query_unix_fd  (GSource        *source,  | 
628  |  |                                               gpointer        tag);  | 
629  |  | #endif  | 
630  |  |  | 
631  |  | /* Used to implement g_source_connect_closure and internally*/  | 
632  |  | GLIB_AVAILABLE_IN_ALL  | 
633  |  | void g_source_set_callback_indirect (GSource              *source,  | 
634  |  |                                      gpointer              callback_data,  | 
635  |  |                                      GSourceCallbackFuncs *callback_funcs);  | 
636  |  |  | 
637  |  | GLIB_AVAILABLE_IN_ALL  | 
638  |  | void     g_source_add_poll            (GSource        *source,  | 
639  |  |                GPollFD        *fd);  | 
640  |  | GLIB_AVAILABLE_IN_ALL  | 
641  |  | void     g_source_remove_poll         (GSource        *source,  | 
642  |  |                GPollFD        *fd);  | 
643  |  |  | 
644  |  | GLIB_AVAILABLE_IN_ALL  | 
645  |  | void     g_source_add_child_source    (GSource        *source,  | 
646  |  |                GSource        *child_source);  | 
647  |  | GLIB_AVAILABLE_IN_ALL  | 
648  |  | void     g_source_remove_child_source (GSource        *source,  | 
649  |  |                GSource        *child_source);  | 
650  |  |  | 
651  |  | G_GNUC_BEGIN_IGNORE_DEPRECATIONS  | 
652  |  | GLIB_DEPRECATED_IN_2_28_FOR(g_source_get_time)  | 
653  |  | void     g_source_get_current_time (GSource        *source,  | 
654  |  |                                     GTimeVal       *timeval);  | 
655  |  | G_GNUC_END_IGNORE_DEPRECATIONS  | 
656  |  |  | 
657  |  | GLIB_AVAILABLE_IN_ALL  | 
658  |  | gint64   g_source_get_time         (GSource        *source);  | 
659  |  |  | 
660  |  |  /* void g_source_connect_closure (GSource        *source,  | 
661  |  |                                   GClosure       *closure);  | 
662  |  |  */  | 
663  |  |  | 
664  |  | /* Specific source types  | 
665  |  |  */  | 
666  |  | GLIB_AVAILABLE_IN_ALL  | 
667  |  | GSource *g_idle_source_new        (void);  | 
668  |  | GLIB_AVAILABLE_IN_ALL  | 
669  |  | GSource *g_child_watch_source_new (GPid pid);  | 
670  |  | GLIB_AVAILABLE_IN_ALL  | 
671  |  | GSource *g_timeout_source_new     (guint interval);  | 
672  |  | GLIB_AVAILABLE_IN_ALL  | 
673  |  | GSource *g_timeout_source_new_seconds (guint interval);  | 
674  |  |  | 
675  |  | /* Miscellaneous functions  | 
676  |  |  */  | 
677  |  | G_GNUC_BEGIN_IGNORE_DEPRECATIONS  | 
678  |  | GLIB_DEPRECATED_IN_2_62_FOR(g_get_real_time)  | 
679  |  | void   g_get_current_time                 (GTimeVal       *result);  | 
680  |  | G_GNUC_END_IGNORE_DEPRECATIONS  | 
681  |  |  | 
682  |  | GLIB_AVAILABLE_IN_ALL  | 
683  |  | gint64 g_get_monotonic_time               (void);  | 
684  |  | GLIB_AVAILABLE_IN_ALL  | 
685  |  | gint64 g_get_real_time                    (void);  | 
686  |  |  | 
687  |  |  | 
688  |  | /* Source manipulation by ID */  | 
689  |  | GLIB_AVAILABLE_IN_ALL  | 
690  |  | gboolean g_source_remove                     (guint          tag);  | 
691  |  | GLIB_AVAILABLE_IN_ALL  | 
692  |  | gboolean g_source_remove_by_user_data        (gpointer       user_data);  | 
693  |  | GLIB_AVAILABLE_IN_ALL  | 
694  |  | gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,  | 
695  |  |                                               gpointer       user_data);  | 
696  |  |  | 
697  |  | /**  | 
698  |  |  * GClearHandleFunc:  | 
699  |  |  * @handle_id: the handle ID to clear  | 
700  |  |  *  | 
701  |  |  * Specifies the type of function passed to g_clear_handle_id().  | 
702  |  |  * The implementation is expected to free the resource identified  | 
703  |  |  * by @handle_id; for instance, if @handle_id is a #GSource ID,  | 
704  |  |  * g_source_remove() can be used.  | 
705  |  |  *  | 
706  |  |  * Since: 2.56  | 
707  |  |  */  | 
708  |  | typedef void (* GClearHandleFunc) (guint handle_id);  | 
709  |  |  | 
710  |  | GLIB_AVAILABLE_IN_2_56  | 
711  |  | void    g_clear_handle_id (guint           *tag_ptr,  | 
712  |  |                            GClearHandleFunc clear_func);  | 
713  |  |  | 
714  |  | #define g_clear_handle_id(tag_ptr, clear_func)             \  | 
715  |  |   G_STMT_START {                                           \ | 
716  |  |     G_STATIC_ASSERT (sizeof *(tag_ptr) == sizeof (guint)); \  | 
717  |  |     guint *_tag_ptr = (guint *) (tag_ptr);                 \  | 
718  |  |     guint _handle_id;                                      \  | 
719  |  |                                                            \  | 
720  |  |     _handle_id = *_tag_ptr;                                \  | 
721  |  |     if (_handle_id > 0)                                    \  | 
722  |  |       {                                                    \ | 
723  |  |         *_tag_ptr = 0;                                     \  | 
724  |  |         clear_func (_handle_id);                           \  | 
725  |  |       }                                                    \  | 
726  |  |   } G_STMT_END                                             \  | 
727  |  |   GLIB_AVAILABLE_MACRO_IN_2_56  | 
728  |  |  | 
729  |  | /* Idles, child watchers and timeouts */  | 
730  |  | GLIB_AVAILABLE_IN_ALL  | 
731  |  | guint    g_timeout_add_full         (gint            priority,  | 
732  |  |                                      guint           interval,  | 
733  |  |                                      GSourceFunc     function,  | 
734  |  |                                      gpointer        data,  | 
735  |  |                                      GDestroyNotify  notify);  | 
736  |  | GLIB_AVAILABLE_IN_ALL  | 
737  |  | guint    g_timeout_add              (guint           interval,  | 
738  |  |                                      GSourceFunc     function,  | 
739  |  |                                      gpointer        data);  | 
740  |  | GLIB_AVAILABLE_IN_ALL  | 
741  |  | guint    g_timeout_add_seconds_full (gint            priority,  | 
742  |  |                                      guint           interval,  | 
743  |  |                                      GSourceFunc     function,  | 
744  |  |                                      gpointer        data,  | 
745  |  |                                      GDestroyNotify  notify);  | 
746  |  | GLIB_AVAILABLE_IN_ALL  | 
747  |  | guint    g_timeout_add_seconds      (guint           interval,  | 
748  |  |                                      GSourceFunc     function,  | 
749  |  |                                      gpointer        data);  | 
750  |  | GLIB_AVAILABLE_IN_ALL  | 
751  |  | guint    g_child_watch_add_full     (gint            priority,  | 
752  |  |                                      GPid            pid,  | 
753  |  |                                      GChildWatchFunc function,  | 
754  |  |                                      gpointer        data,  | 
755  |  |                                      GDestroyNotify  notify);  | 
756  |  | GLIB_AVAILABLE_IN_ALL  | 
757  |  | guint    g_child_watch_add          (GPid            pid,  | 
758  |  |                                      GChildWatchFunc function,  | 
759  |  |                                      gpointer        data);  | 
760  |  | GLIB_AVAILABLE_IN_ALL  | 
761  |  | guint    g_idle_add                 (GSourceFunc     function,  | 
762  |  |                                      gpointer        data);  | 
763  |  | GLIB_AVAILABLE_IN_ALL  | 
764  |  | guint    g_idle_add_full            (gint            priority,  | 
765  |  |                                      GSourceFunc     function,  | 
766  |  |                                      gpointer        data,  | 
767  |  |                                      GDestroyNotify  notify);  | 
768  |  | GLIB_AVAILABLE_IN_ALL  | 
769  |  | gboolean g_idle_remove_by_data      (gpointer        data);  | 
770  |  |  | 
771  |  | GLIB_AVAILABLE_IN_ALL  | 
772  |  | void     g_main_context_invoke_full (GMainContext   *context,  | 
773  |  |                                      gint            priority,  | 
774  |  |                                      GSourceFunc     function,  | 
775  |  |                                      gpointer        data,  | 
776  |  |                                      GDestroyNotify  notify);  | 
777  |  | GLIB_AVAILABLE_IN_ALL  | 
778  |  | void     g_main_context_invoke      (GMainContext   *context,  | 
779  |  |                                      GSourceFunc     function,  | 
780  |  |                                      gpointer        data);  | 
781  |  |  | 
782  |  | /* Hook for GClosure / GSource integration. Don't touch */  | 
783  |  | GLIB_VAR GSourceFuncs g_timeout_funcs;  | 
784  |  | GLIB_VAR GSourceFuncs g_child_watch_funcs;  | 
785  |  | GLIB_VAR GSourceFuncs g_idle_funcs;  | 
786  |  | #ifdef G_OS_UNIX  | 
787  |  | GLIB_VAR GSourceFuncs g_unix_signal_funcs;  | 
788  |  | GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;  | 
789  |  | #endif  | 
790  |  |  | 
791  |  | G_END_DECLS  | 
792  |  |  | 
793  |  | #endif /* __G_MAIN_H__ */  |