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