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 * Conversion parameters: 26 * inFile = GTask.html 27 * outPack = gio 28 * outFile = Task 29 * strct = GTask 30 * realStrct= 31 * ctorStrct= 32 * clss = Task 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - AsyncResultIF 40 * prefixes: 41 * - g_task_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * - g_task_get_source_object 46 * omit signals: 47 * imports: 48 * - glib.ErrorG 49 * - glib.GException 50 * - glib.MainContext 51 * - glib.Source 52 * - gio.Cancellable 53 * - gio.AsyncResultIF 54 * - gio.AsyncResultT 55 * structWrap: 56 * - GCancellable* -> Cancellable 57 * - GMainContext* -> MainContext 58 * - GSource* -> Source 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gio.Task; 65 66 public import gtkc.giotypes; 67 68 private import gtkc.gio; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import glib.ErrorG; 73 private import glib.GException; 74 private import glib.MainContext; 75 private import glib.Source; 76 private import gio.Cancellable; 77 private import gio.AsyncResultIF; 78 private import gio.AsyncResultT; 79 80 81 private import gobject.ObjectG; 82 83 /** 84 * A GTask represents and manages a cancellable "task". 85 * 86 * Asynchronous operations 87 * 88 * The most common usage of GTask is as a GAsyncResult, to 89 * manage data during an asynchronous operation. You call 90 * g_task_new() in the "start" method, followed by 91 * g_task_set_task_data() and the like if you need to keep some 92 * additional data associated with the task, and then pass the 93 * task object around through your asynchronous operation. 94 * Eventually, you will call a method such as 95 * g_task_return_pointer() or g_task_return_error(), which will 96 * save the value you give it and then invoke the task's callback 97 * function (waiting until the next iteration of the main 98 * loop first, if necessary). The caller will pass the GTask back 99 * to the operation's finish function (as a GAsyncResult), and 100 * you can use g_task_propagate_pointer() or the like to extract 101 * the return value. 102 * 103 * $(DDOC_COMMENT example) 104 * 105 * <hr> 106 * 107 * Chained asynchronous operations 108 * 109 * GTask also tries to simplify asynchronous operations that 110 * internally chain together several smaller asynchronous 111 * operations. g_task_get_cancellable(), g_task_get_context(), and 112 * g_task_get_priority() allow you to get back the task's 113 * GCancellable, GMainContext, and I/O priority when starting a new 114 * subtask, so you don't have to keep track of them yourself. 115 * g_task_attach_source() simplifies the case of waiting for a 116 * source to fire (automatically using the correct GMainContext 117 * and priority). 118 * 119 * $(DDOC_COMMENT example) 120 * 121 * <hr> 122 * 123 * Asynchronous operations from synchronous ones 124 * 125 * You can use g_task_run_in_thread() to turn a synchronous 126 * operation into an asynchronous one, by running it in a thread 127 * which will then dispatch the result back to the caller's 128 * GMainContext when it completes. 129 * 130 * $(DDOC_COMMENT example) 131 * 132 * <hr> 133 * 134 * Adding cancellability to uncancellable tasks 135 * 136 * Finally, g_task_run_in_thread() and g_task_run_in_thread_sync() 137 * can be used to turn an uncancellable operation into a 138 * cancellable one. If you call g_task_set_return_on_cancel(), 139 * passing TRUE, then if the task's GCancellable is cancelled, 140 * it will return control back to the caller immediately, while 141 * allowing the task thread to continue running in the background 142 * (and simply discarding its result when it finally does finish). 143 * Provided that the task thread is careful about how it uses 144 * locks and other externally-visible resources, this allows you 145 * to make "GLib-friendly" asynchronous and cancellable 146 * synchronous variants of blocking APIs. 147 * 148 * $(DDOC_COMMENT example) 149 * 150 * <hr> 151 * 152 * Porting from GSimpleAsyncResult 153 * 154 * GTask's API attempts to be simpler than GSimpleAsyncResult's 155 * in several ways: 156 * 157 * You can save task-specific data with g_task_set_task_data(), and 158 * retrieve it later with g_task_get_task_data(). This replaces the 159 * abuse of g_simple_async_result_set_op_res_gpointer() for the same 160 * purpose with GSimpleAsyncResult. 161 * 162 * In addition to the task data, GTask also keeps track of the 163 * priority, GCancellable, and 164 * GMainContext associated with the task, so tasks that consist of 165 * a chain of simpler asynchronous operations will have easy access 166 * to those values when starting each sub-task. 167 * 168 * g_task_return_error_if_cancelled() provides simplified 169 * handling for cancellation. In addition, cancellation 170 * overrides any other GTask return value by default, like 171 * GSimpleAsyncResult does when 172 * g_simple_async_result_set_check_cancellable() is called. 173 * (You can use g_task_set_check_cancellable() to turn off that 174 * behavior.) On the other hand, g_task_run_in_thread() 175 * guarantees that it will always run your 176 * task_func, even if the task's GCancellable 177 * is already cancelled before the task gets a chance to run; 178 * you can start your task_func with a 179 * g_task_return_error_if_cancelled() check if you need the 180 * old behavior. 181 * 182 * The "return" methods (eg, g_task_return_pointer()) 183 * automatically cause the task to be "completed" as well, and 184 * there is no need to worry about the "complete" vs "complete 185 * in idle" distinction. (GTask automatically figures out 186 * whether the task's callback can be invoked directly, or 187 * if it needs to be sent to another GMainContext, or delayed 188 * until the next iteration of the current GMainContext.) 189 * 190 * The "finish" functions for GTask-based operations are generally 191 * much simpler than GSimpleAsyncResult ones, normally consisting 192 * of only a single call to g_task_propagate_pointer() or the like. 193 * Since g_task_propagate_pointer() "steals" the return value from 194 * the GTask, it is not necessary to juggle pointers around to 195 * prevent it from being freed twice. 196 * 197 * With GSimpleAsyncResult, it was common to call 198 * g_simple_async_result_propagate_error() from the 199 * _finish() wrapper function, and have 200 * virtual method implementations only deal with successful 201 * returns. This behavior is deprecated, because it makes it 202 * difficult for a subclass to chain to a parent class's async 203 * methods. Instead, the wrapper function should just be a 204 * simple wrapper, and the virtual method should call an 205 * appropriate g_task_propagate_ function. 206 * Note that wrapper methods can now use 207 * g_async_result_legacy_propagate_error() to do old-style 208 * GSimpleAsyncResult error-returning behavior, and 209 * g_async_result_is_tagged() to check if a result is tagged as 210 * having come from the _async() wrapper 211 * function (for "short-circuit" results, such as when passing 212 * 0 to g_input_stream_read_async()). 213 */ 214 public class Task : ObjectG, AsyncResultIF 215 { 216 217 /** the main Gtk struct */ 218 protected GTask* gTask; 219 220 221 /** Get the main Gtk struct */ 222 public GTask* getTaskStruct() 223 { 224 return gTask; 225 } 226 227 228 /** the main Gtk struct as a void* */ 229 protected override void* getStruct() 230 { 231 return cast(void*)gTask; 232 } 233 234 /** 235 * Sets our main struct and passes it to the parent class 236 */ 237 public this (GTask* gTask) 238 { 239 super(cast(GObject*)gTask); 240 this.gTask = gTask; 241 } 242 243 protected override void setStruct(GObject* obj) 244 { 245 super.setStruct(obj); 246 gTask = cast(GTask*)obj; 247 } 248 249 // add the AsyncResult capabilities 250 mixin AsyncResultT!(GSimpleAsyncResult); 251 252 /** 253 */ 254 255 /** 256 * Creates a GTask acting on source_object, which will eventually be 257 * used to invoke callback in the current thread-default main 258 * context. 259 * Call this in the "start" method of your asynchronous method, and 260 * pass the GTask around throughout the asynchronous operation. You 261 * can use g_task_set_task_data() to attach task-specific data to the 262 * object, which you can retrieve later via g_task_get_task_data(). 263 * By default, if cancellable is cancelled, then the return value of 264 * the task will always be G_IO_ERROR_CANCELLED, even if the task had 265 * already completed before the cancellation. This allows for 266 * simplified handling in cases where cancellation may imply that 267 * other objects that the task depends on have been destroyed. If you 268 * do not want this behavior, you can use 269 * g_task_set_check_cancellable() to change it. 270 * Since 2.36 271 * Params: 272 * sourceObject = the GObject that owns 273 * this task, or NULL. [allow-none][type GObject] 274 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 275 * callback = a GAsyncReadyCallback. [scope async] 276 * callbackData = user data passed to callback. [closure] 277 * Throws: ConstructionException GTK+ fails to create the object. 278 */ 279 public this (void* sourceObject, Cancellable cancellable, GAsyncReadyCallback callback, void* callbackData) 280 { 281 // GTask * g_task_new (gpointer source_object, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer callback_data); 282 auto p = g_task_new(sourceObject, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, callbackData); 283 if(p is null) 284 { 285 throw new ConstructionException("null returned by g_task_new(sourceObject, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, callbackData)"); 286 } 287 this(cast(GTask*) p); 288 } 289 290 /** 291 * Sets task's task data (freeing the existing task data, if any). 292 * Since 2.36 293 * Params: 294 * task = the GTask 295 * taskData = task-specific data. [allow-none] 296 * taskDataDestroy = GDestroyNotify for task_data. [allow-none] 297 */ 298 public void setTaskData(void* taskData, GDestroyNotify taskDataDestroy) 299 { 300 // void g_task_set_task_data (GTask *task, gpointer task_data, GDestroyNotify task_data_destroy); 301 g_task_set_task_data(gTask, taskData, taskDataDestroy); 302 } 303 304 /** 305 * Sets task's priority. If you do not call this, it will default to 306 * G_PRIORITY_DEFAULT. 307 * This will affect the priority of GSources created with 308 * g_task_attach_source() and the scheduling of tasks run in threads, 309 * and can also be explicitly retrieved later via 310 * g_task_get_priority(). 311 * Since 2.36 312 * Params: 313 * priority = the priority 314 * of the request. 315 */ 316 public void setPriority(int priority) 317 { 318 // void g_task_set_priority (GTask *task, gint priority); 319 g_task_set_priority(gTask, priority); 320 } 321 322 /** 323 * Sets or clears task's check-cancellable flag. If this is TRUE 324 * (the default), then g_task_propagate_pointer(), etc, and 325 * g_task_had_error() will check the task's GCancellable first, and 326 * if it has been cancelled, then they will consider the task to have 327 * returned an "Operation was cancelled" error 328 * (G_IO_ERROR_CANCELLED), regardless of any other error or return 329 * value the task may have had. 330 * If check_cancellable is FALSE, then the GTask will not check the 331 * cancellable itself, and it is up to task's owner to do this (eg, 332 * via g_task_return_error_if_cancelled()). 333 * If you are using g_task_set_return_on_cancel() as well, then 334 * you must leave check-cancellable set TRUE. 335 * Since 2.36 336 * Params: 337 * checkCancellable = whether GTask will check the state of 338 * its GCancellable for you. 339 */ 340 public void setCheckCancellable(int checkCancellable) 341 { 342 // void g_task_set_check_cancellable (GTask *task, gboolean check_cancellable); 343 g_task_set_check_cancellable(gTask, checkCancellable); 344 } 345 346 /** 347 * Sets or clears task's return-on-cancel flag. This is only 348 * meaningful for tasks run via g_task_run_in_thread() or 349 * g_task_run_in_thread_sync(). 350 * If return_on_cancel is TRUE, then cancelling task's 351 * GCancellable will immediately cause it to return, as though the 352 * task's GTaskThreadFunc had called 353 * g_task_return_error_if_cancelled() and then returned. 354 * This allows you to create a cancellable wrapper around an 355 * uninterruptable function. The GTaskThreadFunc just needs to be 356 * careful that it does not modify any externally-visible state after 357 * it has been cancelled. To do that, the thread should call 358 * g_task_set_return_on_cancel() again to (atomically) set 359 * return-on-cancel FALSE before making externally-visible changes; 360 * if the task gets cancelled before the return-on-cancel flag could 361 * be changed, g_task_set_return_on_cancel() will indicate this by 362 * returning FALSE. 363 * You can disable and re-enable this flag multiple times if you wish. 364 * If the task's GCancellable is cancelled while return-on-cancel is 365 * FALSE, then calling g_task_set_return_on_cancel() to set it TRUE 366 * again will cause the task to be cancelled at that point. 367 * If the task's GCancellable is already cancelled before you call 368 * g_task_run_in_thread()/g_task_run_in_thread_sync(), then the 369 * GTaskThreadFunc will still be run (for consistency), but the task 370 * will also be completed right away. 371 * Since 2.36 372 * Params: 373 * returnOnCancel = whether the task returns automatically when 374 * it is cancelled. 375 * Returns: TRUE if task's return-on-cancel flag was changed to match return_on_cancel. FALSE if task has already been cancelled. 376 */ 377 public int setReturnOnCancel(int returnOnCancel) 378 { 379 // gboolean g_task_set_return_on_cancel (GTask *task, gboolean return_on_cancel); 380 return g_task_set_return_on_cancel(gTask, returnOnCancel); 381 } 382 383 /** 384 * Sets task's source tag. You can use this to tag a task return 385 * value with a particular pointer (usually a pointer to the function 386 * doing the tagging) and then later check it using 387 * g_task_get_source_tag() (or g_async_result_is_tagged()) in the 388 * task's "finish" function, to figure out if the response came from a 389 * particular place. 390 * Since 2.36 391 * Params: 392 * sourceTag = an opaque pointer indicating the source of this task 393 */ 394 public void setSourceTag(void* sourceTag) 395 { 396 // void g_task_set_source_tag (GTask *task, gpointer source_tag); 397 g_task_set_source_tag(gTask, sourceTag); 398 } 399 400 /** 401 * Creates a GTask and then immediately calls g_task_return_error() 402 * on it. Use this in the wrapper function of an asynchronous method 403 * when you want to avoid even calling the virtual method. You can 404 * then use g_async_result_is_tagged() in the finish method wrapper to 405 * check if the result there is tagged as having been created by the 406 * wrapper method, and deal with it appropriately if so. 407 * See also g_task_report_new_error(). 408 * Since 2.36 409 * Params: 410 * sourceObject = the GObject that owns 411 * this task, or NULL. [allow-none][type GObject] 412 * callback = a GAsyncReadyCallback. [scope async] 413 * callbackData = user data passed to callback. [closure] 414 * sourceTag = an opaque pointer indicating the source of this task 415 * error = error to report. [transfer full] 416 */ 417 public static void reportError(void* sourceObject, GAsyncReadyCallback callback, void* callbackData, void* sourceTag, GError* error) 418 { 419 // void g_task_report_error (gpointer source_object, GAsyncReadyCallback callback, gpointer callback_data, gpointer source_tag, GError *error); 420 g_task_report_error(sourceObject, callback, callbackData, sourceTag, error); 421 } 422 423 /** 424 * Gets task's task_data. 425 * Since 2.36 426 * Returns: task's task_data. [transfer none] 427 */ 428 public void* getTaskData() 429 { 430 // gpointer g_task_get_task_data (GTask *task); 431 return g_task_get_task_data(gTask); 432 } 433 434 /** 435 * Gets task's priority 436 * Since 2.36 437 * Returns: task's priority 438 */ 439 public int getPriority() 440 { 441 // gint g_task_get_priority (GTask *task); 442 return g_task_get_priority(gTask); 443 } 444 445 /** 446 * Gets task's GCancellable 447 * Since 2.36 448 * Returns: task's GCancellable. [transfer none] 449 */ 450 public Cancellable getCancellable() 451 { 452 // GCancellable * g_task_get_cancellable (GTask *task); 453 auto p = g_task_get_cancellable(gTask); 454 455 if(p is null) 456 { 457 return null; 458 } 459 460 return ObjectG.getDObject!(Cancellable)(cast(GCancellable*) p); 461 } 462 463 /** 464 * Gets task's check-cancellable flag. See 465 * g_task_set_check_cancellable() for more details. 466 * Since 2.36 467 */ 468 public int getCheckCancellable() 469 { 470 // gboolean g_task_get_check_cancellable (GTask *task); 471 return g_task_get_check_cancellable(gTask); 472 } 473 474 /** 475 * Gets task's return-on-cancel flag. See 476 * g_task_set_return_on_cancel() for more details. 477 * Since 2.36 478 */ 479 public int getReturnOnCancel() 480 { 481 // gboolean g_task_get_return_on_cancel (GTask *task); 482 return g_task_get_return_on_cancel(gTask); 483 } 484 485 /** 486 * Gets the GMainContext that task will return its result in (that 487 * is, the context that was the thread-default main 488 * context at the point when task was created). 489 * This will always return a non-NULL value, even if the task's 490 * context is the default GMainContext. 491 * Since 2.36 492 * Returns: task's GMainContext. [transfer none] 493 */ 494 public MainContext getContext() 495 { 496 // GMainContext * g_task_get_context (GTask *task); 497 auto p = g_task_get_context(gTask); 498 499 if(p is null) 500 { 501 return null; 502 } 503 504 return ObjectG.getDObject!(MainContext)(cast(GMainContext*) p); 505 } 506 507 /** 508 * Gets task's source tag. See g_task_set_source_tag(). 509 * Since 2.36 510 * Returns: task's source tag. [transfer none] 511 */ 512 public void* getSourceTag() 513 { 514 // gpointer g_task_get_source_tag (GTask *task); 515 return g_task_get_source_tag(gTask); 516 } 517 518 /** 519 * Sets task's result to result and completes the task (see 520 * g_task_return_pointer() for more discussion of exactly what this 521 * means). 522 * Since 2.36 523 * Params: 524 * result = the gboolean result of a task function. 525 */ 526 public void returnBoolean(int result) 527 { 528 // void g_task_return_boolean (GTask *task, gboolean result); 529 g_task_return_boolean(gTask, result); 530 } 531 532 /** 533 * Sets task's result to result and completes the task (see 534 * g_task_return_pointer() for more discussion of exactly what this 535 * means). 536 * Since 2.36 537 * Params: 538 * result = the integer (gssize) result of a task function. 539 */ 540 public void returnInt(gssize result) 541 { 542 // void g_task_return_int (GTask *task, gssize result); 543 g_task_return_int(gTask, result); 544 } 545 546 /** 547 * Sets task's result to result and completes the task. If result 548 * is not NULL, then result_destroy will be used to free result if 549 * the caller does not take ownership of it with 550 * g_task_propagate_pointer(). 551 * "Completes the task" means that for an ordinary asynchronous task 552 * it will either invoke the task's callback, or else queue that 553 * callback to be invoked in the proper GMainContext, or in the next 554 * iteration of the current GMainContext. For a task run via 555 * g_task_run_in_thread() or g_task_run_in_thread_sync(), calling this 556 * method will save result to be returned to the caller later, but 557 * the task will not actually be completed until the GTaskThreadFunc 558 * exits. 559 * Note that since the task may be completed before returning from 560 * g_task_return_pointer(), you cannot assume that result is still 561 * valid after calling this, unless you are still holding another 562 * reference on it. 563 * Since 2.36 564 * Params: 565 * result = the pointer result of a task 566 * function. [allow-none][transfer full] 567 * resultDestroy = a GDestroyNotify function. [allow-none] 568 */ 569 public void returnPointer(void* result, GDestroyNotify resultDestroy) 570 { 571 // void g_task_return_pointer (GTask *task, gpointer result, GDestroyNotify result_destroy); 572 g_task_return_pointer(gTask, result, resultDestroy); 573 } 574 575 /** 576 * Sets task's result to error (which task assumes ownership of) 577 * and completes the task (see g_task_return_pointer() for more 578 * discussion of exactly what this means). 579 * Note that since the task takes ownership of error, and since the 580 * task may be completed before returning from g_task_return_error(), 581 * you cannot assume that error is still valid after calling this. 582 * Call g_error_copy() on the error if you need to keep a local copy 583 * as well. 584 * See also g_task_return_new_error(). 585 * Since 2.36 586 * Params: 587 * error = the GError result of a task function. [transfer full] 588 */ 589 public void returnError(GError* error) 590 { 591 // void g_task_return_error (GTask *task, GError *error); 592 g_task_return_error(gTask, error); 593 } 594 595 /** 596 * Checks if task's GCancellable has been cancelled, and if so, sets 597 * task's error accordingly and completes the task (see 598 * g_task_return_pointer() for more discussion of exactly what this 599 * means). 600 * Since 2.36 601 * Returns: TRUE if task has been cancelled, FALSE if not 602 */ 603 public int returnErrorIfCancelled() 604 { 605 // gboolean g_task_return_error_if_cancelled (GTask *task); 606 return g_task_return_error_if_cancelled(gTask); 607 } 608 609 /** 610 * Gets the result of task as a gboolean. 611 * If the task resulted in an error, or was cancelled, then this will 612 * instead return FALSE and set error. 613 * Since this method transfers ownership of the return value (or 614 * error) to the caller, you may only call it once. 615 * Since 2.36 616 * Returns: the task result, or FALSE on error 617 * Throws: GException on failure. 618 */ 619 public int propagateBoolean() 620 { 621 // gboolean g_task_propagate_boolean (GTask *task, GError **error); 622 GError* err = null; 623 624 auto p = g_task_propagate_boolean(gTask, &err); 625 626 if (err !is null) 627 { 628 throw new GException( new ErrorG(err) ); 629 } 630 631 return p; 632 } 633 634 /** 635 * Gets the result of task as an integer (gssize). 636 * If the task resulted in an error, or was cancelled, then this will 637 * instead return -1 and set error. 638 * Since this method transfers ownership of the return value (or 639 * error) to the caller, you may only call it once. 640 * Since 2.36 641 * Returns: the task result, or -1 on error 642 * Throws: GException on failure. 643 */ 644 public gssize propagateInt() 645 { 646 // gssize g_task_propagate_int (GTask *task, GError **error); 647 GError* err = null; 648 649 auto p = g_task_propagate_int(gTask, &err); 650 651 if (err !is null) 652 { 653 throw new GException( new ErrorG(err) ); 654 } 655 656 return p; 657 } 658 659 /** 660 * Gets the result of task as a pointer, and transfers ownership 661 * of that value to the caller. 662 * If the task resulted in an error, or was cancelled, then this will 663 * instead return NULL and set error. 664 * Since this method transfers ownership of the return value (or 665 * error) to the caller, you may only call it once. 666 * Since 2.36 667 * Returns: the task result, or NULL on error. [transfer full] 668 * Throws: GException on failure. 669 */ 670 public void* propagatePointer() 671 { 672 // gpointer g_task_propagate_pointer (GTask *task, GError **error); 673 GError* err = null; 674 675 auto p = g_task_propagate_pointer(gTask, &err); 676 677 if (err !is null) 678 { 679 throw new GException( new ErrorG(err) ); 680 } 681 682 return p; 683 } 684 685 /** 686 * Tests if task resulted in an error. 687 * Since 2.36 688 * Returns: TRUE if the task resulted in an error, FALSE otherwise. 689 */ 690 public int hadError() 691 { 692 // gboolean g_task_had_error (GTask *task); 693 return g_task_had_error(gTask); 694 } 695 696 /** 697 * Runs task_func in another thread. When task_func returns, task's 698 * GAsyncReadyCallback will be invoked in task's GMainContext. 699 * This takes a ref on task until the task completes. 700 * See GTaskThreadFunc for more details about how task_func is handled. 701 * Since 2.36 702 * Params: 703 * task = a GTask 704 * taskFunc = a GTaskThreadFunc 705 */ 706 public void runInThread(GTaskThreadFunc taskFunc) 707 { 708 // void g_task_run_in_thread (GTask *task, GTaskThreadFunc task_func); 709 g_task_run_in_thread(gTask, taskFunc); 710 } 711 712 /** 713 * Runs task_func in another thread, and waits for it to return or be 714 * cancelled. You can use g_task_propagate_pointer(), etc, afterward 715 * to get the result of task_func. 716 * See GTaskThreadFunc for more details about how task_func is handled. 717 * Normally this is used with tasks created with a NULL 718 * callback, but note that even if the task does 719 * have a callback, it will not be invoked when task_func returns. 720 * Since 2.36 721 * Params: 722 * task = a GTask 723 * taskFunc = a GTaskThreadFunc 724 */ 725 public void runInThreadSync(GTaskThreadFunc taskFunc) 726 { 727 // void g_task_run_in_thread_sync (GTask *task, GTaskThreadFunc task_func); 728 g_task_run_in_thread_sync(gTask, taskFunc); 729 } 730 731 /** 732 * A utility function for dealing with async operations where you need 733 * to wait for a GSource to trigger. Attaches source to task's 734 * GMainContext with task's priority, and sets source's callback 735 * to callback, with task as the callback's 736 * user_data. 737 * This takes a reference on task until source is destroyed. 738 * Since 2.36 739 * Params: 740 * source = the source to attach 741 * callback = the callback to invoke when source triggers 742 */ 743 public void attachSource(Source source, GSourceFunc callback) 744 { 745 // void g_task_attach_source (GTask *task, GSource *source, GSourceFunc callback); 746 g_task_attach_source(gTask, (source is null) ? null : source.getSourceStruct(), callback); 747 } 748 749 /** 750 * Checks that result is a GTask, and that source_object is its 751 * source object (or that source_object is NULL and result has no 752 * source object). This can be used in g_return_if_fail() checks. 753 * Since 2.36 754 * Params: 755 * result = A GAsyncResult. [type Gio.AsyncResult] 756 * sourceObject = the source object 757 * expected to be associated with the task. [allow-none][type GObject] 758 * Returns: TRUE if result and source_object are valid, FALSE if not 759 */ 760 public static int isValid(void* result, void* sourceObject) 761 { 762 // gboolean g_task_is_valid (gpointer result, gpointer source_object); 763 return g_task_is_valid(result, sourceObject); 764 } 765 }