1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Source;
26 
27 private import glib.ConstructionException;
28 private import glib.MainContext;
29 private import glib.Str;
30 private import glib.TimeVal;
31 private import glib.c.functions;
32 public  import glib.c.types;
33 private import gtkd.Loader;
34 
35 
36 /**
37  * The `GSource` struct is an opaque data type
38  * representing an event source.
39  */
40 public class Source
41 {
42 	/** the main Gtk struct */
43 	protected GSource* gSource;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public GSource* getSourceStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return gSource;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)gSource;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (GSource* gSource, bool ownedRef = false)
64 	{
65 		this.gSource = gSource;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 	~this ()
70 	{
71 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
72 			g_source_unref(gSource);
73 	}
74 
75 
76 	/**
77 	 * Creates a new #GSource structure. The size is specified to
78 	 * allow creating structures derived from #GSource that contain
79 	 * additional data. The size passed in must be at least
80 	 * `sizeof (GSource)`.
81 	 *
82 	 * The source will not initially be associated with any #GMainContext
83 	 * and must be added to one with g_source_attach() before it will be
84 	 * executed.
85 	 *
86 	 * Params:
87 	 *     sourceFuncs = structure containing functions that implement
88 	 *         the sources behavior.
89 	 *     structSize = size of the #GSource structure to create.
90 	 *
91 	 * Returns: the newly-created #GSource.
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(GSourceFuncs* sourceFuncs, uint structSize)
96 	{
97 		auto __p = g_source_new(sourceFuncs, structSize);
98 
99 		if(__p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GSource*) __p);
105 	}
106 
107 	/**
108 	 * Adds @child_source to @source as a "polled" source; when @source is
109 	 * added to a #GMainContext, @child_source will be automatically added
110 	 * with the same priority, when @child_source is triggered, it will
111 	 * cause @source to dispatch (in addition to calling its own
112 	 * callback), and when @source is destroyed, it will destroy
113 	 * @child_source as well. (@source will also still be dispatched if
114 	 * its own prepare/check functions indicate that it is ready.)
115 	 *
116 	 * If you don't need @child_source to do anything on its own when it
117 	 * triggers, you can call g_source_set_dummy_callback() on it to set a
118 	 * callback that does nothing (except return %TRUE if appropriate).
119 	 *
120 	 * @source will hold a reference on @child_source while @child_source
121 	 * is attached to it.
122 	 *
123 	 * This API is only intended to be used by implementations of #GSource.
124 	 * Do not call this API on a #GSource that you did not create.
125 	 *
126 	 * Params:
127 	 *     childSource = a second #GSource that @source should "poll"
128 	 *
129 	 * Since: 2.28
130 	 */
131 	public void addChildSource(Source childSource)
132 	{
133 		g_source_add_child_source(gSource, (childSource is null) ? null : childSource.getSourceStruct());
134 	}
135 
136 	/**
137 	 * Adds a file descriptor to the set of file descriptors polled for
138 	 * this source. This is usually combined with g_source_new() to add an
139 	 * event source. The event source's check function will typically test
140 	 * the @revents field in the #GPollFD struct and return %TRUE if events need
141 	 * to be processed.
142 	 *
143 	 * This API is only intended to be used by implementations of #GSource.
144 	 * Do not call this API on a #GSource that you did not create.
145 	 *
146 	 * Using this API forces the linear scanning of event sources on each
147 	 * main loop iteration.  Newly-written event sources should try to use
148 	 * g_source_add_unix_fd() instead of this API.
149 	 *
150 	 * Params:
151 	 *     fd = a #GPollFD structure holding information about a file
152 	 *         descriptor to watch.
153 	 */
154 	public void addPoll(GPollFD* fd)
155 	{
156 		g_source_add_poll(gSource, fd);
157 	}
158 
159 	/**
160 	 * Monitors @fd for the IO events in @events.
161 	 *
162 	 * The tag returned by this function can be used to remove or modify the
163 	 * monitoring of the fd using g_source_remove_unix_fd() or
164 	 * g_source_modify_unix_fd().
165 	 *
166 	 * It is not necessary to remove the fd before destroying the source; it
167 	 * will be cleaned up automatically.
168 	 *
169 	 * This API is only intended to be used by implementations of #GSource.
170 	 * Do not call this API on a #GSource that you did not create.
171 	 *
172 	 * As the name suggests, this function is not available on Windows.
173 	 *
174 	 * Params:
175 	 *     fd = the fd to monitor
176 	 *     events = an event mask
177 	 *
178 	 * Returns: an opaque tag
179 	 *
180 	 * Since: 2.36
181 	 */
182 	public void* addUnixFd(int fd, GIOCondition events)
183 	{
184 		return g_source_add_unix_fd(gSource, fd, events);
185 	}
186 
187 	/**
188 	 * Adds a #GSource to a @context so that it will be executed within
189 	 * that context. Remove it by calling g_source_destroy().
190 	 *
191 	 * This function is safe to call from any thread, regardless of which thread
192 	 * the @context is running in.
193 	 *
194 	 * Params:
195 	 *     context = a #GMainContext (if %NULL, the default context will be used)
196 	 *
197 	 * Returns: the ID (greater than 0) for the source within the
198 	 *     #GMainContext.
199 	 */
200 	public uint attach(MainContext context)
201 	{
202 		return g_source_attach(gSource, (context is null) ? null : context.getMainContextStruct());
203 	}
204 
205 	/**
206 	 * Removes a source from its #GMainContext, if any, and mark it as
207 	 * destroyed.  The source cannot be subsequently added to another
208 	 * context. It is safe to call this on sources which have already been
209 	 * removed from their context.
210 	 *
211 	 * This does not unref the #GSource: if you still hold a reference, use
212 	 * g_source_unref() to drop it.
213 	 *
214 	 * This function is safe to call from any thread, regardless of which thread
215 	 * the #GMainContext is running in.
216 	 */
217 	public void destroy()
218 	{
219 		g_source_destroy(gSource);
220 	}
221 
222 	/**
223 	 * Checks whether a source is allowed to be called recursively.
224 	 * see g_source_set_can_recurse().
225 	 *
226 	 * Returns: whether recursion is allowed.
227 	 */
228 	public bool getCanRecurse()
229 	{
230 		return g_source_get_can_recurse(gSource) != 0;
231 	}
232 
233 	/**
234 	 * Gets the #GMainContext with which the source is associated.
235 	 *
236 	 * You can call this on a source that has been destroyed, provided
237 	 * that the #GMainContext it was attached to still exists (in which
238 	 * case it will return that #GMainContext). In particular, you can
239 	 * always call this function on the source returned from
240 	 * g_main_current_source(). But calling this function on a source
241 	 * whose #GMainContext has been destroyed is an error.
242 	 *
243 	 * Returns: the #GMainContext with which the
244 	 *     source is associated, or %NULL if the context has not
245 	 *     yet been added to a source.
246 	 */
247 	public MainContext getContext()
248 	{
249 		auto __p = g_source_get_context(gSource);
250 
251 		if(__p is null)
252 		{
253 			return null;
254 		}
255 
256 		return new MainContext(cast(GMainContext*) __p);
257 	}
258 
259 	/**
260 	 * This function ignores @source and is otherwise the same as
261 	 * g_get_current_time().
262 	 *
263 	 * Deprecated: use g_source_get_time() instead
264 	 *
265 	 * Params:
266 	 *     timeval = #GTimeVal structure in which to store current time.
267 	 */
268 	public void getCurrentTime(TimeVal timeval)
269 	{
270 		g_source_get_current_time(gSource, (timeval is null) ? null : timeval.getTimeValStruct());
271 	}
272 
273 	/**
274 	 * Returns the numeric ID for a particular source. The ID of a source
275 	 * is a positive integer which is unique within a particular main loop
276 	 * context. The reverse
277 	 * mapping from ID to source is done by g_main_context_find_source_by_id().
278 	 *
279 	 * You can only call this function while the source is associated to a
280 	 * #GMainContext instance; calling this function before g_source_attach()
281 	 * or after g_source_destroy() yields undefined behavior. The ID returned
282 	 * is unique within the #GMainContext instance passed to g_source_attach().
283 	 *
284 	 * Returns: the ID (greater than 0) for the source
285 	 */
286 	public uint getId()
287 	{
288 		return g_source_get_id(gSource);
289 	}
290 
291 	/**
292 	 * Gets a name for the source, used in debugging and profiling.  The
293 	 * name may be #NULL if it has never been set with g_source_set_name().
294 	 *
295 	 * Returns: the name of the source
296 	 *
297 	 * Since: 2.26
298 	 */
299 	public string getName()
300 	{
301 		return Str.toString(g_source_get_name(gSource));
302 	}
303 
304 	/**
305 	 * Gets the priority of a source.
306 	 *
307 	 * Returns: the priority of the source
308 	 */
309 	public int getPriority()
310 	{
311 		return g_source_get_priority(gSource);
312 	}
313 
314 	/**
315 	 * Gets the "ready time" of @source, as set by
316 	 * g_source_set_ready_time().
317 	 *
318 	 * Any time before the current monotonic time (including 0) is an
319 	 * indication that the source will fire immediately.
320 	 *
321 	 * Returns: the monotonic ready time, -1 for "never"
322 	 */
323 	public long getReadyTime()
324 	{
325 		return g_source_get_ready_time(gSource);
326 	}
327 
328 	/**
329 	 * Gets the time to be used when checking this source. The advantage of
330 	 * calling this function over calling g_get_monotonic_time() directly is
331 	 * that when checking multiple sources, GLib can cache a single value
332 	 * instead of having to repeatedly get the system monotonic time.
333 	 *
334 	 * The time here is the system monotonic time, if available, or some
335 	 * other reasonable alternative otherwise.  See g_get_monotonic_time().
336 	 *
337 	 * Returns: the monotonic time in microseconds
338 	 *
339 	 * Since: 2.28
340 	 */
341 	public long getTime()
342 	{
343 		return g_source_get_time(gSource);
344 	}
345 
346 	/**
347 	 * Returns whether @source has been destroyed.
348 	 *
349 	 * This is important when you operate upon your objects
350 	 * from within idle handlers, but may have freed the object
351 	 * before the dispatch of your idle handler.
352 	 *
353 	 * |[<!-- language="C" -->
354 	 * static gboolean
355 	 * idle_callback (gpointer data)
356 	 * {
357 	 * SomeWidget *self = data;
358 	 *
359 	 * g_mutex_lock (&self->idle_id_mutex);
360 	 * // do stuff with self
361 	 * self->idle_id = 0;
362 	 * g_mutex_unlock (&self->idle_id_mutex);
363 	 *
364 	 * return G_SOURCE_REMOVE;
365 	 * }
366 	 *
367 	 * static void
368 	 * some_widget_do_stuff_later (SomeWidget *self)
369 	 * {
370 	 * g_mutex_lock (&self->idle_id_mutex);
371 	 * self->idle_id = g_idle_add (idle_callback, self);
372 	 * g_mutex_unlock (&self->idle_id_mutex);
373 	 * }
374 	 *
375 	 * static void
376 	 * some_widget_init (SomeWidget *self)
377 	 * {
378 	 * g_mutex_init (&self->idle_id_mutex);
379 	 *
380 	 * // ...
381 	 * }
382 	 *
383 	 * static void
384 	 * some_widget_finalize (GObject *object)
385 	 * {
386 	 * SomeWidget *self = SOME_WIDGET (object);
387 	 *
388 	 * if (self->idle_id)
389 	 * g_source_remove (self->idle_id);
390 	 *
391 	 * g_mutex_clear (&self->idle_id_mutex);
392 	 *
393 	 * G_OBJECT_CLASS (parent_class)->finalize (object);
394 	 * }
395 	 * ]|
396 	 *
397 	 * This will fail in a multi-threaded application if the
398 	 * widget is destroyed before the idle handler fires due
399 	 * to the use after free in the callback. A solution, to
400 	 * this particular problem, is to check to if the source
401 	 * has already been destroy within the callback.
402 	 *
403 	 * |[<!-- language="C" -->
404 	 * static gboolean
405 	 * idle_callback (gpointer data)
406 	 * {
407 	 * SomeWidget *self = data;
408 	 *
409 	 * g_mutex_lock (&self->idle_id_mutex);
410 	 * if (!g_source_is_destroyed (g_main_current_source ()))
411 	 * {
412 	 * // do stuff with self
413 	 * }
414 	 * g_mutex_unlock (&self->idle_id_mutex);
415 	 *
416 	 * return FALSE;
417 	 * }
418 	 * ]|
419 	 *
420 	 * Calls to this function from a thread other than the one acquired by the
421 	 * #GMainContext the #GSource is attached to are typically redundant, as the
422 	 * source could be destroyed immediately after this function returns. However,
423 	 * once a source is destroyed it cannot be un-destroyed, so this function can be
424 	 * used for opportunistic checks from any thread.
425 	 *
426 	 * Returns: %TRUE if the source has been destroyed
427 	 *
428 	 * Since: 2.12
429 	 */
430 	public bool isDestroyed()
431 	{
432 		return g_source_is_destroyed(gSource) != 0;
433 	}
434 
435 	/**
436 	 * Updates the event mask to watch for the fd identified by @tag.
437 	 *
438 	 * @tag is the tag returned from g_source_add_unix_fd().
439 	 *
440 	 * If you want to remove a fd, don't set its event mask to zero.
441 	 * Instead, call g_source_remove_unix_fd().
442 	 *
443 	 * This API is only intended to be used by implementations of #GSource.
444 	 * Do not call this API on a #GSource that you did not create.
445 	 *
446 	 * As the name suggests, this function is not available on Windows.
447 	 *
448 	 * Params:
449 	 *     tag = the tag from g_source_add_unix_fd()
450 	 *     newEvents = the new event mask to watch
451 	 *
452 	 * Since: 2.36
453 	 */
454 	public void modifyUnixFd(void* tag, GIOCondition newEvents)
455 	{
456 		g_source_modify_unix_fd(gSource, tag, newEvents);
457 	}
458 
459 	/**
460 	 * Queries the events reported for the fd corresponding to @tag on
461 	 * @source during the last poll.
462 	 *
463 	 * The return value of this function is only defined when the function
464 	 * is called from the check or dispatch functions for @source.
465 	 *
466 	 * This API is only intended to be used by implementations of #GSource.
467 	 * Do not call this API on a #GSource that you did not create.
468 	 *
469 	 * As the name suggests, this function is not available on Windows.
470 	 *
471 	 * Params:
472 	 *     tag = the tag from g_source_add_unix_fd()
473 	 *
474 	 * Returns: the conditions reported on the fd
475 	 *
476 	 * Since: 2.36
477 	 */
478 	public GIOCondition queryUnixFd(void* tag)
479 	{
480 		return g_source_query_unix_fd(gSource, tag);
481 	}
482 
483 	alias doref = ref_;
484 	/**
485 	 * Increases the reference count on a source by one.
486 	 *
487 	 * Returns: @source
488 	 */
489 	public Source ref_()
490 	{
491 		auto __p = g_source_ref(gSource);
492 
493 		if(__p is null)
494 		{
495 			return null;
496 		}
497 
498 		return new Source(cast(GSource*) __p, true);
499 	}
500 
501 	/**
502 	 * Detaches @child_source from @source and destroys it.
503 	 *
504 	 * This API is only intended to be used by implementations of #GSource.
505 	 * Do not call this API on a #GSource that you did not create.
506 	 *
507 	 * Params:
508 	 *     childSource = a #GSource previously passed to
509 	 *         g_source_add_child_source().
510 	 *
511 	 * Since: 2.28
512 	 */
513 	public void removeChildSource(Source childSource)
514 	{
515 		g_source_remove_child_source(gSource, (childSource is null) ? null : childSource.getSourceStruct());
516 	}
517 
518 	/**
519 	 * Removes a file descriptor from the set of file descriptors polled for
520 	 * this source.
521 	 *
522 	 * This API is only intended to be used by implementations of #GSource.
523 	 * Do not call this API on a #GSource that you did not create.
524 	 *
525 	 * Params:
526 	 *     fd = a #GPollFD structure previously passed to g_source_add_poll().
527 	 */
528 	public void removePoll(GPollFD* fd)
529 	{
530 		g_source_remove_poll(gSource, fd);
531 	}
532 
533 	/**
534 	 * Reverses the effect of a previous call to g_source_add_unix_fd().
535 	 *
536 	 * You only need to call this if you want to remove an fd from being
537 	 * watched while keeping the same source around.  In the normal case you
538 	 * will just want to destroy the source.
539 	 *
540 	 * This API is only intended to be used by implementations of #GSource.
541 	 * Do not call this API on a #GSource that you did not create.
542 	 *
543 	 * As the name suggests, this function is not available on Windows.
544 	 *
545 	 * Params:
546 	 *     tag = the tag from g_source_add_unix_fd()
547 	 *
548 	 * Since: 2.36
549 	 */
550 	public void removeUnixFd(void* tag)
551 	{
552 		g_source_remove_unix_fd(gSource, tag);
553 	}
554 
555 	/**
556 	 * Sets the callback function for a source. The callback for a source is
557 	 * called from the source's dispatch function.
558 	 *
559 	 * The exact type of @func depends on the type of source; ie. you
560 	 * should not count on @func being called with @data as its first
561 	 * parameter. Cast @func with G_SOURCE_FUNC() to avoid warnings about
562 	 * incompatible function types.
563 	 *
564 	 * See [memory management of sources][mainloop-memory-management] for details
565 	 * on how to handle memory management of @data.
566 	 *
567 	 * Typically, you won't use this function. Instead use functions specific
568 	 * to the type of source you are using, such as g_idle_add() or g_timeout_add().
569 	 *
570 	 * It is safe to call this function multiple times on a source which has already
571 	 * been attached to a context. The changes will take effect for the next time
572 	 * the source is dispatched after this call returns.
573 	 *
574 	 * Params:
575 	 *     func = a callback function
576 	 *     data = the data to pass to callback function
577 	 *     notify = a function to call when @data is no longer in use, or %NULL.
578 	 */
579 	public void setCallback(GSourceFunc func, void* data, GDestroyNotify notify)
580 	{
581 		g_source_set_callback(gSource, func, data, notify);
582 	}
583 
584 	/**
585 	 * Sets the callback function storing the data as a refcounted callback
586 	 * "object". This is used internally. Note that calling
587 	 * g_source_set_callback_indirect() assumes
588 	 * an initial reference count on @callback_data, and thus
589 	 * @callback_funcs->unref will eventually be called once more
590 	 * than @callback_funcs->ref.
591 	 *
592 	 * It is safe to call this function multiple times on a source which has already
593 	 * been attached to a context. The changes will take effect for the next time
594 	 * the source is dispatched after this call returns.
595 	 *
596 	 * Params:
597 	 *     callbackData = pointer to callback data "object"
598 	 *     callbackFuncs = functions for reference counting @callback_data
599 	 *         and getting the callback and data
600 	 */
601 	public void setCallbackIndirect(void* callbackData, GSourceCallbackFuncs* callbackFuncs)
602 	{
603 		g_source_set_callback_indirect(gSource, callbackData, callbackFuncs);
604 	}
605 
606 	/**
607 	 * Sets whether a source can be called recursively. If @can_recurse is
608 	 * %TRUE, then while the source is being dispatched then this source
609 	 * will be processed normally. Otherwise, all processing of this
610 	 * source is blocked until the dispatch function returns.
611 	 *
612 	 * Params:
613 	 *     canRecurse = whether recursion is allowed for this source
614 	 */
615 	public void setCanRecurse(bool canRecurse)
616 	{
617 		g_source_set_can_recurse(gSource, canRecurse);
618 	}
619 
620 	/**
621 	 * Set @dispose as dispose function on @source. @dispose will be called once
622 	 * the reference count of @source reaches 0 but before any of the state of the
623 	 * source is freed, especially before the finalize function is called.
624 	 *
625 	 * This means that at this point @source is still a valid #GSource and it is
626 	 * allow for the reference count to increase again until @dispose returns.
627 	 *
628 	 * The dispose function can be used to clear any "weak" references to the
629 	 * @source in other data structures in a thread-safe way where it is possible
630 	 * for another thread to increase the reference count of @source again while
631 	 * it is being freed.
632 	 *
633 	 * The finalize function can not be used for this purpose as at that point
634 	 * @source is already partially freed and not valid anymore.
635 	 *
636 	 * This should only ever be called from #GSource implementations.
637 	 *
638 	 * Params:
639 	 *     dispose = #GSourceDisposeFunc to set on the source
640 	 *
641 	 * Since: 2.64
642 	 */
643 	public void setDisposeFunction(GSourceDisposeFunc dispose)
644 	{
645 		g_source_set_dispose_function(gSource, dispose);
646 	}
647 
648 	/**
649 	 * Sets the source functions (can be used to override
650 	 * default implementations) of an unattached source.
651 	 *
652 	 * Params:
653 	 *     funcs = the new #GSourceFuncs
654 	 *
655 	 * Since: 2.12
656 	 */
657 	public void setFuncs(GSourceFuncs* funcs)
658 	{
659 		g_source_set_funcs(gSource, funcs);
660 	}
661 
662 	/**
663 	 * Sets a name for the source, used in debugging and profiling.
664 	 * The name defaults to #NULL.
665 	 *
666 	 * The source name should describe in a human-readable way
667 	 * what the source does. For example, "X11 event queue"
668 	 * or "GTK+ repaint idle handler" or whatever it is.
669 	 *
670 	 * It is permitted to call this function multiple times, but is not
671 	 * recommended due to the potential performance impact.  For example,
672 	 * one could change the name in the "check" function of a #GSourceFuncs
673 	 * to include details like the event type in the source name.
674 	 *
675 	 * Use caution if changing the name while another thread may be
676 	 * accessing it with g_source_get_name(); that function does not copy
677 	 * the value, and changing the value will free it while the other thread
678 	 * may be attempting to use it.
679 	 *
680 	 * Params:
681 	 *     name = debug name for the source
682 	 *
683 	 * Since: 2.26
684 	 */
685 	public void setName(string name)
686 	{
687 		g_source_set_name(gSource, Str.toStringz(name));
688 	}
689 
690 	/**
691 	 * Sets the priority of a source. While the main loop is being run, a
692 	 * source will be dispatched if it is ready to be dispatched and no
693 	 * sources at a higher (numerically smaller) priority are ready to be
694 	 * dispatched.
695 	 *
696 	 * A child source always has the same priority as its parent.  It is not
697 	 * permitted to change the priority of a source once it has been added
698 	 * as a child of another source.
699 	 *
700 	 * Params:
701 	 *     priority = the new priority.
702 	 */
703 	public void setPriority(int priority)
704 	{
705 		g_source_set_priority(gSource, priority);
706 	}
707 
708 	/**
709 	 * Sets a #GSource to be dispatched when the given monotonic time is
710 	 * reached (or passed).  If the monotonic time is in the past (as it
711 	 * always will be if @ready_time is 0) then the source will be
712 	 * dispatched immediately.
713 	 *
714 	 * If @ready_time is -1 then the source is never woken up on the basis
715 	 * of the passage of time.
716 	 *
717 	 * Dispatching the source does not reset the ready time.  You should do
718 	 * so yourself, from the source dispatch function.
719 	 *
720 	 * Note that if you have a pair of sources where the ready time of one
721 	 * suggests that it will be delivered first but the priority for the
722 	 * other suggests that it would be delivered first, and the ready time
723 	 * for both sources is reached during the same main context iteration,
724 	 * then the order of dispatch is undefined.
725 	 *
726 	 * It is a no-op to call this function on a #GSource which has already been
727 	 * destroyed with g_source_destroy().
728 	 *
729 	 * This API is only intended to be used by implementations of #GSource.
730 	 * Do not call this API on a #GSource that you did not create.
731 	 *
732 	 * Params:
733 	 *     readyTime = the monotonic time at which the source will be ready,
734 	 *         0 for "immediately", -1 for "never"
735 	 *
736 	 * Since: 2.36
737 	 */
738 	public void setReadyTime(long readyTime)
739 	{
740 		g_source_set_ready_time(gSource, readyTime);
741 	}
742 
743 	/**
744 	 * Decreases the reference count of a source by one. If the
745 	 * resulting reference count is zero the source and associated
746 	 * memory will be destroyed.
747 	 */
748 	public void unref()
749 	{
750 		g_source_unref(gSource);
751 	}
752 
753 	/**
754 	 * Removes the source with the given ID from the default main context. You must
755 	 * use g_source_destroy() for sources added to a non-default main context.
756 	 *
757 	 * The ID of a #GSource is given by g_source_get_id(), or will be
758 	 * returned by the functions g_source_attach(), g_idle_add(),
759 	 * g_idle_add_full(), g_timeout_add(), g_timeout_add_full(),
760 	 * g_child_watch_add(), g_child_watch_add_full(), g_io_add_watch(), and
761 	 * g_io_add_watch_full().
762 	 *
763 	 * It is a programmer error to attempt to remove a non-existent source.
764 	 *
765 	 * More specifically: source IDs can be reissued after a source has been
766 	 * destroyed and therefore it is never valid to use this function with a
767 	 * source ID which may have already been removed.  An example is when
768 	 * scheduling an idle to run in another thread with g_idle_add(): the
769 	 * idle may already have run and been removed by the time this function
770 	 * is called on its (now invalid) source ID.  This source ID may have
771 	 * been reissued, leading to the operation being performed against the
772 	 * wrong source.
773 	 *
774 	 * Params:
775 	 *     tag = the ID of the source to remove.
776 	 *
777 	 * Returns: For historical reasons, this function always returns %TRUE
778 	 */
779 	public static bool remove(uint tag)
780 	{
781 		return g_source_remove(tag) != 0;
782 	}
783 
784 	/**
785 	 * Removes a source from the default main loop context given the
786 	 * source functions and user data. If multiple sources exist with the
787 	 * same source functions and user data, only one will be destroyed.
788 	 *
789 	 * Params:
790 	 *     funcs = The @source_funcs passed to g_source_new()
791 	 *     userData = the user data for the callback
792 	 *
793 	 * Returns: %TRUE if a source was found and removed.
794 	 */
795 	public static bool removeByFuncsUserData(GSourceFuncs* funcs, void* userData)
796 	{
797 		return g_source_remove_by_funcs_user_data(funcs, userData) != 0;
798 	}
799 
800 	/**
801 	 * Removes a source from the default main loop context given the user
802 	 * data for the callback. If multiple sources exist with the same user
803 	 * data, only one will be destroyed.
804 	 *
805 	 * Params:
806 	 *     userData = the user_data for the callback.
807 	 *
808 	 * Returns: %TRUE if a source was found and removed.
809 	 */
810 	public static bool removeByUserData(void* userData)
811 	{
812 		return g_source_remove_by_user_data(userData) != 0;
813 	}
814 
815 	/**
816 	 * Sets the name of a source using its ID.
817 	 *
818 	 * This is a convenience utility to set source names from the return
819 	 * value of g_idle_add(), g_timeout_add(), etc.
820 	 *
821 	 * It is a programmer error to attempt to set the name of a non-existent
822 	 * source.
823 	 *
824 	 * More specifically: source IDs can be reissued after a source has been
825 	 * destroyed and therefore it is never valid to use this function with a
826 	 * source ID which may have already been removed.  An example is when
827 	 * scheduling an idle to run in another thread with g_idle_add(): the
828 	 * idle may already have run and been removed by the time this function
829 	 * is called on its (now invalid) source ID.  This source ID may have
830 	 * been reissued, leading to the operation being performed against the
831 	 * wrong source.
832 	 *
833 	 * Params:
834 	 *     tag = a #GSource ID
835 	 *     name = debug name for the source
836 	 *
837 	 * Since: 2.26
838 	 */
839 	public static void setNameById(uint tag, string name)
840 	{
841 		g_source_set_name_by_id(tag, Str.toStringz(name));
842 	}
843 }