gmain.h 24.4 KB
Newer Older
1 2
/* gmain.h - the GLib Main loop
 * 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 10
 *
 * This library is distributed in the hope that it will be useful,
 * 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 15
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
16 17
 */

18 19 20
#ifndef __G_MAIN_H__
#define __G_MAIN_H__

21
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
22 23 24
#error "Only <glib.h> can be included directly."
#endif

25
#include <glib/gpoll.h>
26 27
#include <glib/gslist.h>
#include <glib/gthread.h>
28 29 30

G_BEGIN_DECLS

31 32 33 34 35 36 37 38 39 40 41
typedef enum /*< flags >*/
{
  G_IO_IN	GLIB_SYSDEF_POLLIN,
  G_IO_OUT	GLIB_SYSDEF_POLLOUT,
  G_IO_PRI	GLIB_SYSDEF_POLLPRI,
  G_IO_ERR	GLIB_SYSDEF_POLLERR,
  G_IO_HUP	GLIB_SYSDEF_POLLHUP,
  G_IO_NVAL	GLIB_SYSDEF_POLLNVAL
} GIOCondition;


42 43 44
/**
 * GMainContext:
 *
45
 * The `GMainContext` struct is an opaque data
46 47 48 49 50 51 52
 * type representing a set of sources to be handled in a main loop.
 */
typedef struct _GMainContext            GMainContext;

/**
 * GMainLoop:
 *
53
 * The `GMainLoop` struct is an opaque data type
54 55 56 57 58 59 60
 * representing the main event loop of a GLib or GTK+ application.
 */
typedef struct _GMainLoop               GMainLoop;

/**
 * GSource:
 *
61
 * The `GSource` struct is an opaque data type
62 63 64
 * representing an event source.
 */
typedef struct _GSource                 GSource;
65
typedef struct _GSourcePrivate          GSourcePrivate;
66 67 68 69 70 71 72

/**
 * GSourceCallbackFuncs:
 * @ref: Called when a reference is added to the callback object
 * @unref: Called when a reference to the callback object is dropped
 * @get: Called to extract the callback function and data from the
 *     callback object.
73
 *
74
 * The `GSourceCallbackFuncs` struct contains
75 76 77 78 79 80 81 82 83 84 85
 * functions for managing callback objects.
 */
typedef struct _GSourceCallbackFuncs    GSourceCallbackFuncs;

/**
 * GSourceFuncs:
 * @prepare: Called before all the file descriptors are polled. If the
 *     source can determine that it is ready here (without waiting for the
 *     results of the poll() call) it should return %TRUE. It can also return
 *     a @timeout_ value which should be the maximum timeout (in milliseconds)
 *     which should be passed to the poll() call. The actual timeout used will
86 87 88 89
 *     be -1 if all sources returned -1, or it will be the minimum of all
 *     the @timeout_ values returned which were >= 0.  Since 2.36 this may
 *     be %NULL, in which case the effect is as if the function always returns
 *     %FALSE with a timeout of -1.  If @prepare returns a
90 91
 *     timeout and the source also has a ready time set, then the
 *     lower of the two will be used.
92 93 94
 * @check: Called after all the file descriptors are polled. The source
 *     should return %TRUE if it is ready to be dispatched. Note that some
 *     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 97
 *     be %NULL, in which case the effect is as if the function always returns
 *     %FALSE.
98
 * @dispatch: Called to dispatch the event source, after it has returned
99 100 101 102 103 104 105 106
 *     %TRUE in either its @prepare or its @check function, or if a ready time
 *     has been reached. The @dispatch function receives a callback function and
 *     user data. The callback function may be %NULL if the source was never
 *     connected to a callback using g_source_set_callback(). The @dispatch
 *     function should call the callback function with @user_data and whatever
 *     additional parameters are needed for this type of event source. The
 *     return value of the @dispatch function should be #G_SOURCE_REMOVE if the
 *     source should be removed or #G_SOURCE_CONTINUE to keep it.
107 108
 * @finalize: Called when the source is finalized. At this point, the source
 *     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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
 * functions used to handle event sources in a generic manner.
 *
 * For idle sources, the prepare and check functions always return %TRUE
 * to indicate that the source is always ready to be processed. The prepare
 * function also returns a timeout value of 0 to ensure that the poll() call
 * doesn't block (since that would be time wasted which could have been spent
 * running the idle function).
 *
 * For timeout sources, the prepare and check functions both return %TRUE
 * if the timeout interval has expired. The prepare function also returns
 * a timeout value to ensure that the poll() call doesn't block too long
 * and miss the next timeout.
 *
 * For file descriptor sources, the prepare function typically returns %FALSE,
 * since it must wait until poll() has been called before it knows whether
 * any events need to be processed. It sets the returned timeout to -1 to
 * indicate that it doesn't mind how long the poll() call blocks. In the
 * check function, it tests the results of the poll() call to see if the
 * required condition has been met, and returns %TRUE if so.
 */
typedef struct _GSourceFuncs            GSourceFuncs;

/**
 * GPid:
 *
 * A type which is used to hold a process identification.
 *
 * On UNIX, processes are identified by a process id (an integer),
 * while Windows uses process handles (which are pointers).
142 143 144
 *
 * GPid is used in GLib only for descendant processes spawned with
 * the g_spawn functions.
145
 */
146 147 148 149 150 151 152 153 154 155 156
/* defined in glibconfig.h */

/**
 * G_PID_FORMAT:
 *
 * A format specifier that can be used in printf()-style format strings
 * when printing a #GPid.
 *
 * Since: 2.50
 */
/* defined in glibconfig.h */
157

Matthias Clasen's avatar
Matthias Clasen committed
158 159
/**
 * GSourceFunc:
160
 * @user_data: data passed to the function, set when the source was
Matthias Clasen's avatar
Matthias Clasen committed
161 162 163 164 165
 *     created with one of the above functions
 *
 * Specifies the type of function passed to g_timeout_add(),
 * g_timeout_add_full(), g_idle_add(), and g_idle_add_full().
 *
166 167 168 169
 * When calling g_source_set_callback(), you may need to cast a function of a
 * different type to this type. Use G_SOURCE_FUNC() to avoid warnings about
 * incompatible function types.
 *
170 171
 * Returns: %FALSE if the source should be removed. #G_SOURCE_CONTINUE and
 * #G_SOURCE_REMOVE are more memorable names for the return value.
Matthias Clasen's avatar
Matthias Clasen committed
172
 */
173
typedef gboolean (*GSourceFunc)       (gpointer user_data);
174

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
/**
 * G_SOURCE_FUNC:
 * @f: a function pointer.
 *
 * Cast a function pointer to a #GSourceFunc, suppressing warnings from GCC 8
 * onwards with `-Wextra` or `-Wcast-function-type` enabled about the function
 * types being incompatible.
 *
 * For example, the correct type of callback for a source created by
 * g_child_watch_source_new() is #GChildWatchFunc, which accepts more arguments
 * than #GSourceFunc. Casting the function with `(GSourceFunc)` to call
 * g_source_set_callback() will trigger a warning, even though it will be cast
 * back to the correct type before it is called by the source.
 *
 * Since: 2.58
 */
#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))

193 194 195
/**
 * GChildWatchFunc:
 * @pid: the process id of the child process
196 197
 * @status: Status information about the child process, encoded
 *     in a platform-specific manner
198
 * @user_data: user data passed to g_child_watch_add()
199
 *
200 201 202
 * Prototype of a #GChildWatchSource callback, called when a child
 * process has exited.  To interpret @status, see the documentation
 * for g_spawn_check_exit_status().
203
 */
204
typedef void     (*GChildWatchFunc)   (GPid     pid,
205
                                       gint     status,
206
                                       gpointer user_data);
207 208 209 210 211
struct _GSource
{
  /*< private >*/
  gpointer callback_data;
  GSourceCallbackFuncs *callback_funcs;
212

213
  const GSourceFuncs *source_funcs;
214
  guint ref_count;
215

216
  GMainContext *context;
217

218 219
  gint priority;
  guint flags;
220
  guint source_id;
221

222 223 224 225
  GSList *poll_fds;
  
  GSource *prev;
  GSource *next;
226

227
  char    *name;
228 229

  GSourcePrivate *priv;
230
};
231

232 233 234 235 236
struct _GSourceCallbackFuncs
{
  void (*ref)   (gpointer     cb_data);
  void (*unref) (gpointer     cb_data);
  void (*get)   (gpointer     cb_data,
237 238 239
                 GSource     *source, 
                 GSourceFunc *func,
                 gpointer    *data);
240
};
241

Matthias Clasen's avatar
Matthias Clasen committed
242 243 244 245 246 247
/**
 * GSourceDummyMarshal:
 *
 * This is just a placeholder for #GClosureMarshal,
 * which cannot be used here for dependency reasons.
 */
248 249
typedef void (*GSourceDummyMarshal) (void);

250 251 252
struct _GSourceFuncs
{
  gboolean (*prepare)  (GSource    *source,
253
                        gint       *timeout_);
254 255
  gboolean (*check)    (GSource    *source);
  gboolean (*dispatch) (GSource    *source,
256 257
                        GSourceFunc callback,
                        gpointer    user_data);
258
  void     (*finalize) (GSource    *source); /* Can be NULL */
259

Stef Walter's avatar
Stef Walter committed
260
  /*< private >*/
261
  /* For use by g_source_set_closure */
262
  GSourceFunc     closure_callback;        
263
  GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
264
};
265

266
/* Standard priorities */
267

268 269 270 271 272 273 274
/**
 * G_PRIORITY_HIGH:
 *
 * Use this for high priority event sources.
 *
 * It is not used within GLib or GTK+.
 */
275
#define G_PRIORITY_HIGH            -100
276 277 278 279 280 281 282 283 284 285

/**
 * G_PRIORITY_DEFAULT:
 *
 * Use this for default priority event sources.
 *
 * In GLib this priority is used when adding timeout functions
 * with g_timeout_add(). In GDK this priority is used for events
 * from the X server.
 */
286
#define G_PRIORITY_DEFAULT          0
287 288 289 290 291 292 293 294 295 296 297

/**
 * G_PRIORITY_HIGH_IDLE:
 *
 * Use this for high priority idle functions.
 *
 * GTK+ uses #G_PRIORITY_HIGH_IDLE + 10 for resizing operations,
 * and #G_PRIORITY_HIGH_IDLE + 20 for redrawing operations. (This is
 * done to ensure that any pending resizes are processed before any
 * pending redraws, so that widgets are not redrawn twice unnecessarily.)
 */
298
#define G_PRIORITY_HIGH_IDLE        100
299 300 301 302 303 304 305 306 307

/**
 * G_PRIORITY_DEFAULT_IDLE:
 *
 * Use this for default priority idle functions.
 *
 * In GLib this priority is used when adding idle functions with
 * g_idle_add().
 */
308
#define G_PRIORITY_DEFAULT_IDLE     200
309 310 311 312 313 314 315 316 317

/**
 * G_PRIORITY_LOW:
 *
 * Use this for very low priority background tasks.
 *
 * It is not used within GLib or GTK+.
 */
#define G_PRIORITY_LOW              300
318

319 320 321 322 323 324
/**
 * G_SOURCE_REMOVE:
 *
 * Use this macro as the return value of a #GSourceFunc to remove
 * the #GSource from the main loop.
 *
325
 * Since: 2.32
326 327 328 329 330 331 332 333 334
 */
#define G_SOURCE_REMOVE         FALSE

/**
 * G_SOURCE_CONTINUE:
 *
 * Use this macro as the return value of a #GSourceFunc to leave
 * the #GSource in the main loop.
 *
335
 * Since: 2.32
336 337 338
 */
#define G_SOURCE_CONTINUE       TRUE

339
/* GMainContext: */
340

341
GLIB_AVAILABLE_IN_ALL
342
GMainContext *g_main_context_new       (void);
343
GLIB_AVAILABLE_IN_ALL
344
GMainContext *g_main_context_ref       (GMainContext *context);
345
GLIB_AVAILABLE_IN_ALL
346
void          g_main_context_unref     (GMainContext *context);
347
GLIB_AVAILABLE_IN_ALL
348
GMainContext *g_main_context_default   (void);
349

350
GLIB_AVAILABLE_IN_ALL
351
gboolean      g_main_context_iteration (GMainContext *context,
352
                                        gboolean      may_block);
353
GLIB_AVAILABLE_IN_ALL
354 355 356 357
gboolean      g_main_context_pending   (GMainContext *context);

/* For implementation of legacy interfaces
 */
358
GLIB_AVAILABLE_IN_ALL
359
GSource      *g_main_context_find_source_by_id              (GMainContext *context,
360
                                                             guint         source_id);
361
GLIB_AVAILABLE_IN_ALL
362
GSource      *g_main_context_find_source_by_user_data       (GMainContext *context,
363
                                                             gpointer      user_data);
364
GLIB_AVAILABLE_IN_ALL
365
GSource      *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
366 367
                                                             GSourceFuncs *funcs,
                                                             gpointer      user_data);
368 369 370

/* Low level functions for implementing custom main loops.
 */
371
GLIB_AVAILABLE_IN_ALL
372
void     g_main_context_wakeup  (GMainContext *context);
373
GLIB_AVAILABLE_IN_ALL
374
gboolean g_main_context_acquire (GMainContext *context);
375
GLIB_AVAILABLE_IN_ALL
376
void     g_main_context_release (GMainContext *context);
377
GLIB_AVAILABLE_IN_ALL
Matthias Clasen's avatar
Matthias Clasen committed
378
gboolean g_main_context_is_owner (GMainContext *context);
379
GLIB_DEPRECATED_IN_2_58_FOR(g_main_context_is_owner)
380
gboolean g_main_context_wait    (GMainContext *context,
381 382
                                 GCond        *cond,
                                 GMutex       *mutex);
383

384
GLIB_AVAILABLE_IN_ALL
385
gboolean g_main_context_prepare  (GMainContext *context,
386
                                  gint         *priority);
387
GLIB_AVAILABLE_IN_ALL
388
gint     g_main_context_query    (GMainContext *context,
389 390 391 392
                                  gint          max_priority,
                                  gint         *timeout_,
                                  GPollFD      *fds,
                                  gint          n_fds);
393
GLIB_AVAILABLE_IN_ALL
394 395 396 397
gboolean     g_main_context_check    (GMainContext *context,
                                      gint          max_priority,
                                      GPollFD      *fds,
                                      gint          n_fds);
398
GLIB_AVAILABLE_IN_ALL
399
void     g_main_context_dispatch (GMainContext *context);
400

401
GLIB_AVAILABLE_IN_ALL
402
void     g_main_context_set_poll_func (GMainContext *context,
403
                                       GPollFunc     func);
404
GLIB_AVAILABLE_IN_ALL
405 406 407 408
GPollFunc g_main_context_get_poll_func (GMainContext *context);

/* Low level functions for use by source implementations
 */
409
GLIB_AVAILABLE_IN_ALL
410
void     g_main_context_add_poll    (GMainContext *context,
411 412
                                     GPollFD      *fd,
                                     gint          priority);
413
GLIB_AVAILABLE_IN_ALL
414
void     g_main_context_remove_poll (GMainContext *context,
415
                                     GPollFD      *fd);
416

417
GLIB_AVAILABLE_IN_ALL
418
gint     g_main_depth               (void);
419
GLIB_AVAILABLE_IN_ALL
420
GSource *g_main_current_source      (void);
421

422 423
/* GMainContexts for other threads
 */
424
GLIB_AVAILABLE_IN_ALL
425
void          g_main_context_push_thread_default (GMainContext *context);
426
GLIB_AVAILABLE_IN_ALL
427
void          g_main_context_pop_thread_default  (GMainContext *context);
428
GLIB_AVAILABLE_IN_ALL
429
GMainContext *g_main_context_get_thread_default  (void);
430
GLIB_AVAILABLE_IN_ALL
431
GMainContext *g_main_context_ref_thread_default  (void);
432

433 434
/* GMainLoop: */

435
GLIB_AVAILABLE_IN_ALL
436
GMainLoop *g_main_loop_new        (GMainContext *context,
437
                                   gboolean      is_running);
438
GLIB_AVAILABLE_IN_ALL
439
void       g_main_loop_run        (GMainLoop    *loop);
440
GLIB_AVAILABLE_IN_ALL
441
void       g_main_loop_quit       (GMainLoop    *loop);
442
GLIB_AVAILABLE_IN_ALL
443
GMainLoop *g_main_loop_ref        (GMainLoop    *loop);
444
GLIB_AVAILABLE_IN_ALL
445
void       g_main_loop_unref      (GMainLoop    *loop);
446
GLIB_AVAILABLE_IN_ALL
447
gboolean   g_main_loop_is_running (GMainLoop    *loop);
448
GLIB_AVAILABLE_IN_ALL
449
GMainContext *g_main_loop_get_context (GMainLoop    *loop);
450 451 452

/* GSource: */

453
GLIB_AVAILABLE_IN_ALL
454
GSource *g_source_new             (GSourceFuncs   *source_funcs,
455
                                   guint           struct_size);
456
GLIB_AVAILABLE_IN_ALL
457
GSource *g_source_ref             (GSource        *source);
458
GLIB_AVAILABLE_IN_ALL
459 460
void     g_source_unref           (GSource        *source);

461
GLIB_AVAILABLE_IN_ALL
462
guint    g_source_attach          (GSource        *source,
463
                                   GMainContext   *context);
464
GLIB_AVAILABLE_IN_ALL
465 466
void     g_source_destroy         (GSource        *source);

467
GLIB_AVAILABLE_IN_ALL
468
void     g_source_set_priority    (GSource        *source,
469
                                   gint            priority);
470
GLIB_AVAILABLE_IN_ALL
471
gint     g_source_get_priority    (GSource        *source);
472
GLIB_AVAILABLE_IN_ALL
473
void     g_source_set_can_recurse (GSource        *source,
474
                                   gboolean        can_recurse);
475
GLIB_AVAILABLE_IN_ALL
476
gboolean g_source_get_can_recurse (GSource        *source);
477
GLIB_AVAILABLE_IN_ALL
478 479
guint    g_source_get_id          (GSource        *source);

480
GLIB_AVAILABLE_IN_ALL
481 482
GMainContext *g_source_get_context (GSource       *source);

483
GLIB_AVAILABLE_IN_ALL
484
void     g_source_set_callback    (GSource        *source,
485 486 487
                                   GSourceFunc     func,
                                   gpointer        data,
                                   GDestroyNotify  notify);
488

489
GLIB_AVAILABLE_IN_ALL
490 491
void     g_source_set_funcs       (GSource        *source,
                                   GSourceFuncs   *funcs);
492
GLIB_AVAILABLE_IN_ALL
493
gboolean g_source_is_destroyed    (GSource        *source);
494

495
GLIB_AVAILABLE_IN_ALL
496 497
void                 g_source_set_name       (GSource        *source,
                                              const char     *name);
498
GLIB_AVAILABLE_IN_ALL
499
const char *         g_source_get_name       (GSource        *source);
500
GLIB_AVAILABLE_IN_ALL
501 502 503
void                 g_source_set_name_by_id (guint           tag,
                                              const char     *name);

504 505 506 507 508
GLIB_AVAILABLE_IN_2_36
void                 g_source_set_ready_time (GSource        *source,
                                              gint64          ready_time);
GLIB_AVAILABLE_IN_2_36
gint64               g_source_get_ready_time (GSource        *source);
509

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
#ifdef G_OS_UNIX
GLIB_AVAILABLE_IN_2_36
gpointer             g_source_add_unix_fd    (GSource        *source,
                                              gint            fd,
                                              GIOCondition    events);
GLIB_AVAILABLE_IN_2_36
void                 g_source_modify_unix_fd (GSource        *source,
                                              gpointer        tag,
                                              GIOCondition    new_events);
GLIB_AVAILABLE_IN_2_36
void                 g_source_remove_unix_fd (GSource        *source,
                                              gpointer        tag);
GLIB_AVAILABLE_IN_2_36
GIOCondition         g_source_query_unix_fd  (GSource        *source,
                                              gpointer        tag);
#endif

527
/* Used to implement g_source_connect_closure and internally*/
528
GLIB_AVAILABLE_IN_ALL
529
void g_source_set_callback_indirect (GSource              *source,
530 531
                                     gpointer              callback_data,
                                     GSourceCallbackFuncs *callback_funcs);
532

533
GLIB_AVAILABLE_IN_ALL
534 535
void     g_source_add_poll            (GSource        *source,
				       GPollFD        *fd);
536
GLIB_AVAILABLE_IN_ALL
537 538 539
void     g_source_remove_poll         (GSource        *source,
				       GPollFD        *fd);

540
GLIB_AVAILABLE_IN_ALL
541 542
void     g_source_add_child_source    (GSource        *source,
				       GSource        *child_source);
543
GLIB_AVAILABLE_IN_ALL
544 545
void     g_source_remove_child_source (GSource        *source,
				       GSource        *child_source);
546

547
GLIB_DEPRECATED_IN_2_28_FOR(g_source_get_time)
548
void     g_source_get_current_time (GSource        *source,
549
                                    GTimeVal       *timeval);
550

551
GLIB_AVAILABLE_IN_ALL
552
gint64   g_source_get_time         (GSource        *source);
553 554 555 556 557 558 559

 /* void g_source_connect_closure (GSource        *source,
                                  GClosure       *closure);
 */

/* Specific source types
 */
560
GLIB_AVAILABLE_IN_ALL
561
GSource *g_idle_source_new        (void);
562
GLIB_AVAILABLE_IN_ALL
563
GSource *g_child_watch_source_new (GPid pid);
564
GLIB_AVAILABLE_IN_ALL
565
GSource *g_timeout_source_new     (guint interval);
566
GLIB_AVAILABLE_IN_ALL
567
GSource *g_timeout_source_new_seconds (guint interval);
568 569 570

/* Miscellaneous functions
 */
571
GLIB_AVAILABLE_IN_ALL
572
void   g_get_current_time                 (GTimeVal       *result);
573
GLIB_AVAILABLE_IN_ALL
574
gint64 g_get_monotonic_time               (void);
575
GLIB_AVAILABLE_IN_ALL
576
gint64 g_get_real_time                    (void);
577

Owen Taylor's avatar
Owen Taylor committed
578 579

/* Source manipulation by ID */
580
GLIB_AVAILABLE_IN_ALL
Owen Taylor's avatar
Owen Taylor committed
581
gboolean g_source_remove                     (guint          tag);
582
GLIB_AVAILABLE_IN_ALL
Owen Taylor's avatar
Owen Taylor committed
583
gboolean g_source_remove_by_user_data        (gpointer       user_data);
584
GLIB_AVAILABLE_IN_ALL
Owen Taylor's avatar
Owen Taylor committed
585
gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
586
                                              gpointer       user_data);
Owen Taylor's avatar
Owen Taylor committed
587

588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
/**
 * GClearHandleFunc:
 * @handle_id: the handle ID to clear
 *
 * Specifies the type of function passed to g_clear_handle_id().
 * The implementation is expected to free the resource identified
 * by @handle_id; for instance, if @handle_id is a #GSource ID,
 * g_source_remove() can be used.
 *
 * Since: 2.56
 */
typedef void (* GClearHandleFunc) (guint handle_id);

GLIB_AVAILABLE_IN_2_56
void    g_clear_handle_id (guint           *tag_ptr,
                           GClearHandleFunc clear_func);

#define g_clear_handle_id(tag_ptr, clear_func)             \
  G_STMT_START {                                           \
    G_STATIC_ASSERT (sizeof *(tag_ptr) == sizeof (guint)); \
    guint *_tag_ptr = (guint *) (tag_ptr);                 \
    guint _handle_id;                                      \
                                                           \
    _handle_id = *_tag_ptr;                                \
    if (_handle_id > 0)                                    \
      {                                                    \
        *_tag_ptr = 0;                                     \
615
        clear_func (_handle_id);                           \
616 617 618
      }                                                    \
  } G_STMT_END

619
/* Idles, child watchers and timeouts */
620
GLIB_AVAILABLE_IN_ALL
621
guint    g_timeout_add_full         (gint            priority,
622 623 624 625
                                     guint           interval,
                                     GSourceFunc     function,
                                     gpointer        data,
                                     GDestroyNotify  notify);
626
GLIB_AVAILABLE_IN_ALL
627
guint    g_timeout_add              (guint           interval,
628 629
                                     GSourceFunc     function,
                                     gpointer        data);
630
GLIB_AVAILABLE_IN_ALL
631 632 633 634 635
guint    g_timeout_add_seconds_full (gint            priority,
                                     guint           interval,
                                     GSourceFunc     function,
                                     gpointer        data,
                                     GDestroyNotify  notify);
636
GLIB_AVAILABLE_IN_ALL
637
guint    g_timeout_add_seconds      (guint           interval,
638 639
                                     GSourceFunc     function,
                                     gpointer        data);
640
GLIB_AVAILABLE_IN_ALL
641
guint    g_child_watch_add_full     (gint            priority,
642 643 644 645
                                     GPid            pid,
                                     GChildWatchFunc function,
                                     gpointer        data,
                                     GDestroyNotify  notify);
646
GLIB_AVAILABLE_IN_ALL
647
guint    g_child_watch_add          (GPid            pid,
648 649
                                     GChildWatchFunc function,
                                     gpointer        data);
650
GLIB_AVAILABLE_IN_ALL
651
guint    g_idle_add                 (GSourceFunc     function,
652
                                     gpointer        data);
653
GLIB_AVAILABLE_IN_ALL
654
guint    g_idle_add_full            (gint            priority,
655 656 657
                                     GSourceFunc     function,
                                     gpointer        data,
                                     GDestroyNotify  notify);
658
GLIB_AVAILABLE_IN_ALL
659
gboolean g_idle_remove_by_data      (gpointer        data);
660

661
GLIB_AVAILABLE_IN_ALL
662 663 664 665 666
void     g_main_context_invoke_full (GMainContext   *context,
                                     gint            priority,
                                     GSourceFunc     function,
                                     gpointer        data,
                                     GDestroyNotify  notify);
667
GLIB_AVAILABLE_IN_ALL
668 669 670 671
void     g_main_context_invoke      (GMainContext   *context,
                                     GSourceFunc     function,
                                     gpointer        data);

672 673
/* Hook for GClosure / GSource integration. Don't touch */
GLIB_VAR GSourceFuncs g_timeout_funcs;
674
GLIB_VAR GSourceFuncs g_child_watch_funcs;
675
GLIB_VAR GSourceFuncs g_idle_funcs;
676 677 678 679
#ifdef G_OS_UNIX
GLIB_VAR GSourceFuncs g_unix_signal_funcs;
GLIB_VAR GSourceFuncs g_unix_fd_source_funcs;
#endif
680

681 682 683
G_END_DECLS

#endif /* __G_MAIN_H__ */