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