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