1121 * @source:a #GSource
1122 * @fd: a #GPollFD structure holding information about a file
1123 * descriptor to watch.
1124 *
1125 * Adds a file descriptor to the set of file descriptors polled for
1126 * this source. This is usually combined with g_source_new() to add an
1127 * event source. The event source's check function will typically test
1128 * the @revents field in the #GPollFD struct and return %TRUE if events need
1129 * to be processed.
1130 **/
1131 void
1132 g_source_add_poll (GSource *source,
1133 GPollFD *fd)
1134 {
1135 GMainContext *context;
1136
1137 g_return_if_fail (source != NULL);
1138 g_return_if_fail (fd != NULL);
1139 g_return_if_fail (!SOURCE_DESTROYED (source));
1140
1141 context = source->context;
1142
1143 if (context)
1144 LOCK_CONTEXT (context);
1145
1146 source->poll_fds = g_slist_prepend (source->poll_fds, fd);
1147
1148 if (context)
1149 {
1150 if (!SOURCE_BLOCKED (source))
1151 g_main_context_add_poll_unlocked (context, source->priority, fd);
1152 UNLOCK_CONTEXT (context);
1153 }
1154 }
1155
1156 /**
1157 * g_source_remove_poll:
1158 * @source:a #GSource
1159 * @fd: a #GPollFD structure previously passed to g_source_add_poll().
1160 *
1161 * Removes a file descriptor from the set of file descriptors polled for
1162 * this source.
1163 **/
1164 void
1165 g_source_remove_poll (GSource *source,
1166 GPollFD *fd)
1167 {
1168 GMainContext *context;
1169
1170 g_return_if_fail (source != NULL);
1171 g_return_if_fail (fd != NULL);
1172 g_return_if_fail (!SOURCE_DESTROYED (source));
1173
1174 context = source->context;
1175
1176 if (context)
1177 LOCK_CONTEXT (context);
1178
1179 source->poll_fds = g_slist_remove (source->poll_fds, fd);
1180
1181 if (context)
1182 {
1183 if (!SOURCE_BLOCKED (source))
1184 g_main_context_remove_poll_unlocked (context, fd);
1185 UNLOCK_CONTEXT (context);
1186 }
1187 }
1188
1189 /**
1190 * g_source_add_child_source:
1191 * @source:a #GSource
1192 * @child_source: a second #GSource that @source should "poll"
1193 *
1372 *
1373 * Sets the callback function for a source. The callback for a source is
1374 * called from the source's dispatch function.
1375 *
1376 * The exact type of @func depends on the type of source; ie. you
1377 * should not count on @func being called with @data as its first
1378 * parameter.
1379 *
1380 * Typically, you won't use this function. Instead use functions specific
1381 * to the type of source you are using.
1382 **/
1383 void
1384 g_source_set_callback (GSource *source,
1385 GSourceFunc func,
1386 gpointer data,
1387 GDestroyNotify notify)
1388 {
1389 GSourceCallback *new_callback;
1390
1391 g_return_if_fail (source != NULL);
1392
1393 new_callback = g_new (GSourceCallback, 1);
1394
1395 new_callback->ref_count = 1;
1396 new_callback->func = func;
1397 new_callback->data = data;
1398 new_callback->notify = notify;
1399
1400 g_source_set_callback_indirect (source, new_callback, &g_source_callback_funcs);
1401 }
1402
1403
1404 /**
1405 * g_source_set_funcs:
1406 * @source: a #GSource
1407 * @funcs: the new #GSourceFuncs
1408 *
1409 * Sets the source functions (can be used to override
1410 * default implementations) of an unattached source.
1411 *
1463 }
1464 }
1465 }
1466
1467 /**
1468 * g_source_set_priority:
1469 * @source: a #GSource
1470 * @priority: the new priority.
1471 *
1472 * Sets the priority of a source. While the main loop is being run, a
1473 * source will be dispatched if it is ready to be dispatched and no
1474 * sources at a higher (numerically smaller) priority are ready to be
1475 * dispatched.
1476 **/
1477 void
1478 g_source_set_priority (GSource *source,
1479 gint priority)
1480 {
1481 GMainContext *context;
1482
1483 g_return_if_fail (source != NULL);
1484
1485 context = source->context;
1486
1487 if (context)
1488 LOCK_CONTEXT (context);
1489 g_source_set_priority_unlocked (source, context, priority);
1490 if (context)
1491 UNLOCK_CONTEXT (source->context);
1492 }
1493
1494 /**
1495 * g_source_get_priority:
1496 * @source: a #GSource
1497 *
1498 * Gets the priority of a source.
1499 *
1500 * Return value: the priority of the source
1501 **/
1502 gint
1724
1725 old_cb_funcs->unref (old_cb_data);
1726
1727 if (have_lock)
1728 LOCK_CONTEXT (context);
1729 }
1730 }
1731
1732 /**
1733 * g_source_unref:
1734 * @source: a #GSource
1735 *
1736 * Decreases the reference count of a source by one. If the
1737 * resulting reference count is zero the source and associated
1738 * memory will be destroyed.
1739 **/
1740 void
1741 g_source_unref (GSource *source)
1742 {
1743 g_return_if_fail (source != NULL);
1744
1745 g_source_unref_internal (source, source->context, FALSE);
1746 }
1747
1748 /**
1749 * g_main_context_find_source_by_id:
1750 * @context: a #GMainContext (if %NULL, the default context will be used)
1751 * @source_id: the source ID, as returned by g_source_get_id().
1752 *
1753 * Finds a #GSource given a pair of context and ID.
1754 *
1755 * Return value: the #GSource if found, otherwise, %NULL
1756 **/
1757 GSource *
1758 g_main_context_find_source_by_id (GMainContext *context,
1759 guint source_id)
1760 {
1761 GSource *source;
1762
1763 g_return_val_if_fail (source_id > 0, NULL);
3914
3915 return again;
3916 }
3917
3918 /**
3919 * g_timeout_source_new:
3920 * @interval: the timeout interval in milliseconds.
3921 *
3922 * Creates a new timeout source.
3923 *
3924 * The source will not initially be associated with any #GMainContext
3925 * and must be added to one with g_source_attach() before it will be
3926 * executed.
3927 *
3928 * Return value: the newly-created timeout source
3929 **/
3930 GSource *
3931 g_timeout_source_new (guint interval)
3932 {
3933 GSource *source = g_source_new (&g_timeout_funcs, sizeof (GTimeoutSource));
3934 GTimeoutSource *timeout_source = (GTimeoutSource *)source;
3935
3936 timeout_source->interval = interval;
3937 g_timeout_set_expiration (timeout_source, g_get_monotonic_time ());
3938
3939 return source;
3940 }
3941
3942 /**
3943 * g_timeout_source_new_seconds:
3944 * @interval: the timeout interval in seconds
3945 *
3946 * Creates a new timeout source.
3947 *
3948 * The source will not initially be associated with any #GMainContext
3949 * and must be added to one with g_source_attach() before it will be
3950 * executed.
3951 *
3952 * The scheduling granularity/accuracy of this timeout source will be
3953 * in seconds.
3954 *
3955 * Return value: the newly-created timeout source
3956 *
3957 * Since: 2.14
3958 **/
3959 GSource *
3960 g_timeout_source_new_seconds (guint interval)
3961 {
3962 GSource *source = g_source_new (&g_timeout_funcs, sizeof (GTimeoutSource));
3963 GTimeoutSource *timeout_source = (GTimeoutSource *)source;
3964
3965 timeout_source->interval = 1000 * interval;
3966 timeout_source->seconds = TRUE;
3967
3968 g_timeout_set_expiration (timeout_source, g_get_monotonic_time ());
3969
3970 return source;
3971 }
3972
3973
3974 /**
3975 * g_timeout_add_full:
3976 * @priority: the priority of the timeout source. Typically this will be in
3977 * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
3978 * @interval: the time between calls to the function, in milliseconds
3979 * (1/1000ths of a second)
3980 * @function: function to call
3981 * @data: data to pass to @function
3982 * @notify: function to call when the timeout is removed, or %NULL
3983 *
3984 * Sets a function to be called at regular intervals, with the given
3985 * priority. The function is called repeatedly until it returns
3986 * %FALSE, at which point the timeout is automatically destroyed and
3987 * the function will not be called again. The @notify function is
3988 * called when the timeout is destroyed. The first call to the
3989 * function will be at the end of the first @interval.
3990 *
3991 * Note that timeout functions may be delayed, due to the processing of other
3992 * event sources. Thus they should not be relied on for precise timing.
3996 *
3997 * This internally creates a main loop source using g_timeout_source_new()
3998 * and attaches it to the main loop context using g_source_attach(). You can
3999 * do these steps manually if you need greater control.
4000 *
4001 * Return value: the ID (greater than 0) of the event source.
4002 **/
4003 guint
4004 g_timeout_add_full (gint priority,
4005 guint interval,
4006 GSourceFunc function,
4007 gpointer data,
4008 GDestroyNotify notify)
4009 {
4010 GSource *source;
4011 guint id;
4012
4013 g_return_val_if_fail (function != NULL, 0);
4014
4015 source = g_timeout_source_new (interval);
4016
4017 if (priority != G_PRIORITY_DEFAULT)
4018 g_source_set_priority (source, priority);
4019
4020 g_source_set_callback (source, function, data, notify);
4021 id = g_source_attach (source, NULL);
4022 g_source_unref (source);
4023
4024 return id;
4025 }
4026
4027 /**
4028 * g_timeout_add:
4029 * @interval: the time between calls to the function, in milliseconds
4030 * (1/1000ths of a second)
4031 * @function: function to call
4032 * @data: data to pass to @function
4033 *
4034 * Sets a function to be called at regular intervals, with the default
4035 * priority, #G_PRIORITY_DEFAULT. The function is called repeatedly
4046 * If you want to have a timer in the "seconds" range and do not care
4047 * about the exact time of the first call of the timer, use the
4048 * g_timeout_add_seconds() function; this function allows for more
4049 * optimizations and more efficient system power usage.
4050 *
4051 * This internally creates a main loop source using g_timeout_source_new()
4052 * and attaches it to the main loop context using g_source_attach(). You can
4053 * do these steps manually if you need greater control.
4054 *
4055 * Return value: the ID (greater than 0) of the event source.
4056 **/
4057 guint
4058 g_timeout_add (guint32 interval,
4059 GSourceFunc function,
4060 gpointer data)
4061 {
4062 return g_timeout_add_full (G_PRIORITY_DEFAULT,
4063 interval, function, data, NULL);
4064 }
4065
4066 /**
4067 * g_timeout_add_seconds_full:
4068 * @priority: the priority of the timeout source. Typically this will be in
4069 * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
4070 * @interval: the time between calls to the function, in seconds
4071 * @function: function to call
4072 * @data: data to pass to @function
4073 * @notify: function to call when the timeout is removed, or %NULL
4074 *
4075 * Sets a function to be called at regular intervals, with @priority.
4076 * The function is called repeatedly until it returns %FALSE, at which
4077 * point the timeout is automatically destroyed and the function will
4078 * not be called again.
4079 *
4080 * Unlike g_timeout_add(), this function operates at whole second granularity.
4081 * The initial starting point of the timer is determined by the implementation
4082 * and the implementation is expected to group multiple timers together so that
4083 * they fire all at the same time.
4084 * To allow this grouping, the @interval to the first timer is rounded
4085 * and can deviate up to one second from the specified interval.
4147 * using g_source_attach(). You can do these steps manually if you need
4148 * greater control. Also see g_timout_add_seconds_full().
4149 *
4150 * Note that the first call of the timer may not be precise for timeouts
4151 * of one second. If you need finer precision and have such a timeout,
4152 * you may want to use g_timeout_add() instead.
4153 *
4154 * Return value: the ID (greater than 0) of the event source.
4155 *
4156 * Since: 2.14
4157 **/
4158 guint
4159 g_timeout_add_seconds (guint interval,
4160 GSourceFunc function,
4161 gpointer data)
4162 {
4163 g_return_val_if_fail (function != NULL, 0);
4164
4165 return g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval, function, data, NULL);
4166 }
4167
4168 /* Child watch functions */
4169
4170 #ifdef G_OS_WIN32
4171
4172 static gboolean
4173 g_child_watch_prepare (GSource *source,
4174 gint *timeout)
4175 {
4176 *timeout = -1;
4177 return FALSE;
4178 }
4179
4180
4181 static gboolean
4182 g_child_watch_check (GSource *source)
4183 {
4184 GChildWatchSource *child_watch_source;
4185 gboolean child_exited;
4186
4413 *
4414 * Note that on platforms where #GPid must be explicitly closed
4415 * (see g_spawn_close_pid()) @pid must not be closed while the
4416 * source is still active. Typically, you will want to call
4417 * g_spawn_close_pid() in the callback function for the source.
4418 *
4419 * Note further that using g_child_watch_source_new() is not
4420 * compatible with calling <literal>waitpid(-1)</literal> in
4421 * the application. Calling waitpid() for individual pids will
4422 * still work fine.
4423 *
4424 * Return value: the newly-created child watch source
4425 *
4426 * Since: 2.4
4427 **/
4428 GSource *
4429 g_child_watch_source_new (GPid pid)
4430 {
4431 GSource *source = g_source_new (&g_child_watch_funcs, sizeof (GChildWatchSource));
4432 GChildWatchSource *child_watch_source = (GChildWatchSource *)source;
4433
4434 #ifdef G_OS_WIN32
4435 child_watch_source->poll.fd = (gintptr) pid;
4436 child_watch_source->poll.events = G_IO_IN;
4437
4438 g_source_add_poll (source, &child_watch_source->poll);
4439 #else /* G_OS_WIN32 */
4440 g_child_watch_source_init ();
4441 #endif /* G_OS_WIN32 */
4442
4443 child_watch_source->pid = pid;
4444
4445 return source;
4446 }
4447
4448 /**
4449 * g_child_watch_add_full:
4450 * @priority: the priority of the idle source. Typically this will be in the
4451 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
4452 * @pid: process to watch. On POSIX the pid of a child process. On
|
1121 * @source:a #GSource
1122 * @fd: a #GPollFD structure holding information about a file
1123 * descriptor to watch.
1124 *
1125 * Adds a file descriptor to the set of file descriptors polled for
1126 * this source. This is usually combined with g_source_new() to add an
1127 * event source. The event source's check function will typically test
1128 * the @revents field in the #GPollFD struct and return %TRUE if events need
1129 * to be processed.
1130 **/
1131 void
1132 g_source_add_poll (GSource *source,
1133 GPollFD *fd)
1134 {
1135 GMainContext *context;
1136
1137 g_return_if_fail (source != NULL);
1138 g_return_if_fail (fd != NULL);
1139 g_return_if_fail (!SOURCE_DESTROYED (source));
1140
1141 #ifdef GSTREAMER_LITE
1142 if (source == NULL)
1143 return;
1144 #endif // GSTREAMER_LITE
1145
1146 context = source->context;
1147
1148 if (context)
1149 LOCK_CONTEXT (context);
1150
1151 source->poll_fds = g_slist_prepend (source->poll_fds, fd);
1152
1153 if (context)
1154 {
1155 if (!SOURCE_BLOCKED (source))
1156 g_main_context_add_poll_unlocked (context, source->priority, fd);
1157 UNLOCK_CONTEXT (context);
1158 }
1159 }
1160
1161 /**
1162 * g_source_remove_poll:
1163 * @source:a #GSource
1164 * @fd: a #GPollFD structure previously passed to g_source_add_poll().
1165 *
1166 * Removes a file descriptor from the set of file descriptors polled for
1167 * this source.
1168 **/
1169 void
1170 g_source_remove_poll (GSource *source,
1171 GPollFD *fd)
1172 {
1173 GMainContext *context;
1174
1175 g_return_if_fail (source != NULL);
1176 g_return_if_fail (fd != NULL);
1177 g_return_if_fail (!SOURCE_DESTROYED (source));
1178
1179 #ifdef GSTREAMER_LITE
1180 if (source == NULL)
1181 return;
1182 #endif // GSTREAMER_LITE
1183
1184 context = source->context;
1185
1186 if (context)
1187 LOCK_CONTEXT (context);
1188
1189 source->poll_fds = g_slist_remove (source->poll_fds, fd);
1190
1191 if (context)
1192 {
1193 if (!SOURCE_BLOCKED (source))
1194 g_main_context_remove_poll_unlocked (context, fd);
1195 UNLOCK_CONTEXT (context);
1196 }
1197 }
1198
1199 /**
1200 * g_source_add_child_source:
1201 * @source:a #GSource
1202 * @child_source: a second #GSource that @source should "poll"
1203 *
1382 *
1383 * Sets the callback function for a source. The callback for a source is
1384 * called from the source's dispatch function.
1385 *
1386 * The exact type of @func depends on the type of source; ie. you
1387 * should not count on @func being called with @data as its first
1388 * parameter.
1389 *
1390 * Typically, you won't use this function. Instead use functions specific
1391 * to the type of source you are using.
1392 **/
1393 void
1394 g_source_set_callback (GSource *source,
1395 GSourceFunc func,
1396 gpointer data,
1397 GDestroyNotify notify)
1398 {
1399 GSourceCallback *new_callback;
1400
1401 g_return_if_fail (source != NULL);
1402 #ifdef GSTREAMER_LITE
1403 if (source == NULL)
1404 return;
1405 #endif // GSTREAMER_LITE
1406
1407 new_callback = g_new (GSourceCallback, 1);
1408
1409 new_callback->ref_count = 1;
1410 new_callback->func = func;
1411 new_callback->data = data;
1412 new_callback->notify = notify;
1413
1414 g_source_set_callback_indirect (source, new_callback, &g_source_callback_funcs);
1415 }
1416
1417
1418 /**
1419 * g_source_set_funcs:
1420 * @source: a #GSource
1421 * @funcs: the new #GSourceFuncs
1422 *
1423 * Sets the source functions (can be used to override
1424 * default implementations) of an unattached source.
1425 *
1477 }
1478 }
1479 }
1480
1481 /**
1482 * g_source_set_priority:
1483 * @source: a #GSource
1484 * @priority: the new priority.
1485 *
1486 * Sets the priority of a source. While the main loop is being run, a
1487 * source will be dispatched if it is ready to be dispatched and no
1488 * sources at a higher (numerically smaller) priority are ready to be
1489 * dispatched.
1490 **/
1491 void
1492 g_source_set_priority (GSource *source,
1493 gint priority)
1494 {
1495 GMainContext *context;
1496
1497 #ifdef GSTREAMER_LITE
1498 if (source == NULL || source->priv == NULL || source->priv->parent_source == NULL)
1499 return;
1500 #endif // GSTREAMER_LITE
1501
1502 g_return_if_fail (source != NULL);
1503
1504 context = source->context;
1505
1506 if (context)
1507 LOCK_CONTEXT (context);
1508 g_source_set_priority_unlocked (source, context, priority);
1509 if (context)
1510 UNLOCK_CONTEXT (source->context);
1511 }
1512
1513 /**
1514 * g_source_get_priority:
1515 * @source: a #GSource
1516 *
1517 * Gets the priority of a source.
1518 *
1519 * Return value: the priority of the source
1520 **/
1521 gint
1743
1744 old_cb_funcs->unref (old_cb_data);
1745
1746 if (have_lock)
1747 LOCK_CONTEXT (context);
1748 }
1749 }
1750
1751 /**
1752 * g_source_unref:
1753 * @source: a #GSource
1754 *
1755 * Decreases the reference count of a source by one. If the
1756 * resulting reference count is zero the source and associated
1757 * memory will be destroyed.
1758 **/
1759 void
1760 g_source_unref (GSource *source)
1761 {
1762 g_return_if_fail (source != NULL);
1763 #ifdef GSTREAMER_LITE
1764 if (source == NULL)
1765 return;
1766 #endif // GSTREAMER_LITE
1767
1768 g_source_unref_internal (source, source->context, FALSE);
1769 }
1770
1771 /**
1772 * g_main_context_find_source_by_id:
1773 * @context: a #GMainContext (if %NULL, the default context will be used)
1774 * @source_id: the source ID, as returned by g_source_get_id().
1775 *
1776 * Finds a #GSource given a pair of context and ID.
1777 *
1778 * Return value: the #GSource if found, otherwise, %NULL
1779 **/
1780 GSource *
1781 g_main_context_find_source_by_id (GMainContext *context,
1782 guint source_id)
1783 {
1784 GSource *source;
1785
1786 g_return_val_if_fail (source_id > 0, NULL);
3937
3938 return again;
3939 }
3940
3941 /**
3942 * g_timeout_source_new:
3943 * @interval: the timeout interval in milliseconds.
3944 *
3945 * Creates a new timeout source.
3946 *
3947 * The source will not initially be associated with any #GMainContext
3948 * and must be added to one with g_source_attach() before it will be
3949 * executed.
3950 *
3951 * Return value: the newly-created timeout source
3952 **/
3953 GSource *
3954 g_timeout_source_new (guint interval)
3955 {
3956 GSource *source = g_source_new (&g_timeout_funcs, sizeof (GTimeoutSource));
3957 #ifdef GSTREAMER_LITE
3958 if (source == NULL)
3959 return NULL;
3960 #endif // GSTREAMER_LITE
3961 GTimeoutSource *timeout_source = (GTimeoutSource *)source;
3962
3963 timeout_source->interval = interval;
3964 g_timeout_set_expiration (timeout_source, g_get_monotonic_time ());
3965
3966 return source;
3967 }
3968
3969 #ifndef GSTREAMER_LITE
3970 /**
3971 * g_timeout_source_new_seconds:
3972 * @interval: the timeout interval in seconds
3973 *
3974 * Creates a new timeout source.
3975 *
3976 * The source will not initially be associated with any #GMainContext
3977 * and must be added to one with g_source_attach() before it will be
3978 * executed.
3979 *
3980 * The scheduling granularity/accuracy of this timeout source will be
3981 * in seconds.
3982 *
3983 * Return value: the newly-created timeout source
3984 *
3985 * Since: 2.14
3986 **/
3987 GSource *
3988 g_timeout_source_new_seconds (guint interval)
3989 {
3990 GSource *source = g_source_new (&g_timeout_funcs, sizeof (GTimeoutSource));
3991 GTimeoutSource *timeout_source = (GTimeoutSource *)source;
3992
3993 timeout_source->interval = 1000 * interval;
3994 timeout_source->seconds = TRUE;
3995
3996 g_timeout_set_expiration (timeout_source, g_get_monotonic_time ());
3997
3998 return source;
3999 }
4000 #endif // GSTREAMER_LITE
4001
4002 /**
4003 * g_timeout_add_full:
4004 * @priority: the priority of the timeout source. Typically this will be in
4005 * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
4006 * @interval: the time between calls to the function, in milliseconds
4007 * (1/1000ths of a second)
4008 * @function: function to call
4009 * @data: data to pass to @function
4010 * @notify: function to call when the timeout is removed, or %NULL
4011 *
4012 * Sets a function to be called at regular intervals, with the given
4013 * priority. The function is called repeatedly until it returns
4014 * %FALSE, at which point the timeout is automatically destroyed and
4015 * the function will not be called again. The @notify function is
4016 * called when the timeout is destroyed. The first call to the
4017 * function will be at the end of the first @interval.
4018 *
4019 * Note that timeout functions may be delayed, due to the processing of other
4020 * event sources. Thus they should not be relied on for precise timing.
4024 *
4025 * This internally creates a main loop source using g_timeout_source_new()
4026 * and attaches it to the main loop context using g_source_attach(). You can
4027 * do these steps manually if you need greater control.
4028 *
4029 * Return value: the ID (greater than 0) of the event source.
4030 **/
4031 guint
4032 g_timeout_add_full (gint priority,
4033 guint interval,
4034 GSourceFunc function,
4035 gpointer data,
4036 GDestroyNotify notify)
4037 {
4038 GSource *source;
4039 guint id;
4040
4041 g_return_val_if_fail (function != NULL, 0);
4042
4043 source = g_timeout_source_new (interval);
4044 #ifdef GSTREAMER_LITE
4045 if (source == NULL)
4046 return 0;
4047 #endif // GSTREAMER_LITE
4048
4049 if (priority != G_PRIORITY_DEFAULT)
4050 g_source_set_priority (source, priority);
4051
4052 g_source_set_callback (source, function, data, notify);
4053 id = g_source_attach (source, NULL);
4054 g_source_unref (source);
4055
4056 return id;
4057 }
4058
4059 /**
4060 * g_timeout_add:
4061 * @interval: the time between calls to the function, in milliseconds
4062 * (1/1000ths of a second)
4063 * @function: function to call
4064 * @data: data to pass to @function
4065 *
4066 * Sets a function to be called at regular intervals, with the default
4067 * priority, #G_PRIORITY_DEFAULT. The function is called repeatedly
4078 * If you want to have a timer in the "seconds" range and do not care
4079 * about the exact time of the first call of the timer, use the
4080 * g_timeout_add_seconds() function; this function allows for more
4081 * optimizations and more efficient system power usage.
4082 *
4083 * This internally creates a main loop source using g_timeout_source_new()
4084 * and attaches it to the main loop context using g_source_attach(). You can
4085 * do these steps manually if you need greater control.
4086 *
4087 * Return value: the ID (greater than 0) of the event source.
4088 **/
4089 guint
4090 g_timeout_add (guint32 interval,
4091 GSourceFunc function,
4092 gpointer data)
4093 {
4094 return g_timeout_add_full (G_PRIORITY_DEFAULT,
4095 interval, function, data, NULL);
4096 }
4097
4098 #ifndef GSTREAMER_LITE
4099 /**
4100 * g_timeout_add_seconds_full:
4101 * @priority: the priority of the timeout source. Typically this will be in
4102 * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
4103 * @interval: the time between calls to the function, in seconds
4104 * @function: function to call
4105 * @data: data to pass to @function
4106 * @notify: function to call when the timeout is removed, or %NULL
4107 *
4108 * Sets a function to be called at regular intervals, with @priority.
4109 * The function is called repeatedly until it returns %FALSE, at which
4110 * point the timeout is automatically destroyed and the function will
4111 * not be called again.
4112 *
4113 * Unlike g_timeout_add(), this function operates at whole second granularity.
4114 * The initial starting point of the timer is determined by the implementation
4115 * and the implementation is expected to group multiple timers together so that
4116 * they fire all at the same time.
4117 * To allow this grouping, the @interval to the first timer is rounded
4118 * and can deviate up to one second from the specified interval.
4180 * using g_source_attach(). You can do these steps manually if you need
4181 * greater control. Also see g_timout_add_seconds_full().
4182 *
4183 * Note that the first call of the timer may not be precise for timeouts
4184 * of one second. If you need finer precision and have such a timeout,
4185 * you may want to use g_timeout_add() instead.
4186 *
4187 * Return value: the ID (greater than 0) of the event source.
4188 *
4189 * Since: 2.14
4190 **/
4191 guint
4192 g_timeout_add_seconds (guint interval,
4193 GSourceFunc function,
4194 gpointer data)
4195 {
4196 g_return_val_if_fail (function != NULL, 0);
4197
4198 return g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval, function, data, NULL);
4199 }
4200 #endif // GSTREAMER_LITE
4201
4202 /* Child watch functions */
4203
4204 #ifdef G_OS_WIN32
4205
4206 static gboolean
4207 g_child_watch_prepare (GSource *source,
4208 gint *timeout)
4209 {
4210 *timeout = -1;
4211 return FALSE;
4212 }
4213
4214
4215 static gboolean
4216 g_child_watch_check (GSource *source)
4217 {
4218 GChildWatchSource *child_watch_source;
4219 gboolean child_exited;
4220
4447 *
4448 * Note that on platforms where #GPid must be explicitly closed
4449 * (see g_spawn_close_pid()) @pid must not be closed while the
4450 * source is still active. Typically, you will want to call
4451 * g_spawn_close_pid() in the callback function for the source.
4452 *
4453 * Note further that using g_child_watch_source_new() is not
4454 * compatible with calling <literal>waitpid(-1)</literal> in
4455 * the application. Calling waitpid() for individual pids will
4456 * still work fine.
4457 *
4458 * Return value: the newly-created child watch source
4459 *
4460 * Since: 2.4
4461 **/
4462 GSource *
4463 g_child_watch_source_new (GPid pid)
4464 {
4465 GSource *source = g_source_new (&g_child_watch_funcs, sizeof (GChildWatchSource));
4466 GChildWatchSource *child_watch_source = (GChildWatchSource *)source;
4467
4468 #ifdef GSTREAMER_LITE
4469 if (source == NULL)
4470 return NULL;
4471 #endif // GSTREAMER_LITE
4472
4473 #ifdef G_OS_WIN32
4474 child_watch_source->poll.fd = (gintptr) pid;
4475 child_watch_source->poll.events = G_IO_IN;
4476
4477 g_source_add_poll (source, &child_watch_source->poll);
4478 #else /* G_OS_WIN32 */
4479 g_child_watch_source_init ();
4480 #endif /* G_OS_WIN32 */
4481
4482 child_watch_source->pid = pid;
4483
4484 return source;
4485 }
4486
4487 /**
4488 * g_child_watch_add_full:
4489 * @priority: the priority of the idle source. Typically this will be in the
4490 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
4491 * @pid: process to watch. On POSIX the pid of a child process. On
|