Coverage Report

Created: 2024-09-08 06:48

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