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