v0.2.1 c0399be

gtask.go RawHistoryFolder

1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5	"structs"
6	"unsafe"
7
8	"github.com/ebitengine/purego"
9
10	"github.com/bnema/puregotk/pkg/core"
11	"github.com/bnema/puregotk/v4/glib"
12	"github.com/bnema/puregotk/v4/gobject"
13	"github.com/bnema/puregotk/v4/gobject/types"
14)
15
16// The prototype for a task function to be run in a thread via
17// g_task_run_in_thread() or g_task_run_in_thread_sync().
18//
19// If the return-on-cancel flag is set on @task, and @cancellable gets
20// cancelled, then the #GTask will be completed immediately (as though
21// g_task_return_error_if_cancelled() had been called), without
22// waiting for the task function to complete. However, the task
23// function will continue running in its thread in the background. The
24// function therefore needs to be careful about how it uses
25// externally-visible state in this case. See
26// g_task_set_return_on_cancel() for more details.
27//
28// Other than in that case, @task will be completed when the
29// #GTaskThreadFunc returns, not when it calls a
30// `g_task_return_` function.
31type TaskThreadFunc func(uintptr, uintptr, uintptr, uintptr)
32
33type TaskClass struct {
34	_ structs.HostLayout
35}
36
37func (x *TaskClass) GoPointer() uintptr {
38	return uintptr(unsafe.Pointer(x))
39}
40
41// A `GTask` represents and manages a cancellable ‘task’.
42//
43// ## Asynchronous operations
44//
45// The most common usage of `GTask` is as a [iface@Gio.AsyncResult], to
46// manage data during an asynchronous operation. You call
47// [ctor@Gio.Task.new] in the ‘start’ method, followed by
48// [method@Gio.Task.set_task_data] and the like if you need to keep some
49// additional data associated with the task, and then pass the
50// task object around through your asynchronous operation.
51// Eventually, you will call a method such as
52// [method@Gio.Task.return_pointer] or [method@Gio.Task.return_error], which
53// will save the value you give it and then invoke the task’s callback
54// function in the thread-default main context (see
55// [method@GLib.MainContext.push_thread_default])
56// where it was created (waiting until the next iteration of the main
57// loop first, if necessary). The caller will pass the `GTask` back to
58// the operation’s finish function (as a [iface@Gio.AsyncResult]), and you can
59// use [method@Gio.Task.propagate_pointer] or the like to extract the
60// return value.
61//
62// Using `GTask` requires the thread-default [struct@GLib.MainContext] from when
63// the `GTask` was constructed to be running at least until the task has
64// completed and its data has been freed.
65//
66// If a `GTask` has been constructed and its callback set, it is an error to
67// not call `g_task_return_*()` on it. GLib will warn at runtime if this happens
68// (since 2.76).
69//
70// Here is an example for using `GTask` as a [iface@Gio.AsyncResult]:
71// ```c
72//
73//	typedef struct {
74//	  CakeFrostingType frosting;
75//	  char *message;
76//	} DecorationData;
77//
78// static void
79// decoration_data_free (DecorationData *decoration)
80//
81//	{
82//	  g_free (decoration->message);
83//	  g_slice_free (DecorationData, decoration);
84//	}
85//
86// static void
87// baked_cb (Cake     *cake,
88//
89//	gpointer  user_data)
90//
91//	{
92//	  GTask *task = user_data;
93//	  DecorationData *decoration = g_task_get_task_data (task);
94//	  GError *error = NULL;
95//
96//	  if (cake == NULL)
97//	    {
98//	      g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
99//	                               "Go to the supermarket");
100//	      g_object_unref (task);
101//	      return;
102//	    }
103//
104//	  if (!cake_decorate (cake, decoration->frosting, decoration->message, &error))
105//	    {
106//	      g_object_unref (cake);
107//	      // g_task_return_error() takes ownership of error
108//	      g_task_return_error (task, error);
109//	      g_object_unref (task);
110//	      return;
111//	    }
112//
113//	  g_task_return_pointer (task, cake, g_object_unref);
114//	  g_object_unref (task);
115//	}
116//
117// void
118// baker_bake_cake_async (Baker               *self,
119//
120//	guint                radius,
121//	CakeFlavor           flavor,
122//	CakeFrostingType     frosting,
123//	const char          *message,
124//	GCancellable        *cancellable,
125//	GAsyncReadyCallback  callback,
126//	gpointer             user_data)
127//
128//	{
129//	  GTask *task;
130//	  DecorationData *decoration;
131//	  Cake  *cake;
132//
133//	  task = g_task_new (self, cancellable, callback, user_data);
134//	  if (radius < 3)
135//	    {
136//	      g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_TOO_SMALL,
137//	                               "%ucm radius cakes are silly",
138//	                               radius);
139//	      g_object_unref (task);
140//	      return;
141//	    }
142//
143//	  cake = _baker_get_cached_cake (self, radius, flavor, frosting, message);
144//	  if (cake != NULL)
145//	    {
146//	      // _baker_get_cached_cake() returns a reffed cake
147//	      g_task_return_pointer (task, cake, g_object_unref);
148//	      g_object_unref (task);
149//	      return;
150//	    }
151//
152//	  decoration = g_slice_new (DecorationData);
153//	  decoration->frosting = frosting;
154//	  decoration->message = g_strdup (message);
155//	  g_task_set_task_data (task, decoration, (GDestroyNotify) decoration_data_free);
156//
157//	  _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
158//	}
159//
160// Cake *
161// baker_bake_cake_finish (Baker         *self,
162//
163//	GAsyncResult  *result,
164//	GError       **error)
165//
166//	{
167//	  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
168//
169//	  return g_task_propagate_pointer (G_TASK (result), error);
170//	}
171//
172// ```
173//
174// ## Chained asynchronous operations
175//
176// `GTask` also tries to simplify asynchronous operations that
177// internally chain together several smaller asynchronous
178// operations. [method@Gio.Task.get_cancellable], [method@Gio.Task.get_context],
179// and [method@Gio.Task.get_priority] allow you to get back the task’s
180// [class@Gio.Cancellable], [struct@GLib.MainContext], and
181// [I/O priority](iface.AsyncResult.html#io-priority)
182// when starting a new subtask, so you don’t have to keep track
183// of them yourself. [method@Gio.Task.attach_source] simplifies the case
184// of waiting for a source to fire (automatically using the correct
185// [struct@GLib.MainContext] and priority).
186//
187// Here is an example for chained asynchronous operations:
188// ```c
189//
190//	typedef struct {
191//	  Cake *cake;
192//	  CakeFrostingType frosting;
193//	  char *message;
194//	} BakingData;
195//
196// static void
197// decoration_data_free (BakingData *bd)
198//
199//	{
200//	  if (bd->cake)
201//	    g_object_unref (bd->cake);
202//	  g_free (bd->message);
203//	  g_slice_free (BakingData, bd);
204//	}
205//
206// static void
207// decorated_cb (Cake         *cake,
208//
209//	GAsyncResult *result,
210//	gpointer      user_data)
211//
212//	{
213//	  GTask *task = user_data;
214//	  GError *error = NULL;
215//
216//	  if (!cake_decorate_finish (cake, result, &error))
217//	    {
218//	      g_object_unref (cake);
219//	      g_task_return_error (task, error);
220//	      g_object_unref (task);
221//	      return;
222//	    }
223//
224//	  // baking_data_free() will drop its ref on the cake, so we have to
225//	  // take another here to give to the caller.
226//	  g_task_return_pointer (task, g_object_ref (cake), g_object_unref);
227//	  g_object_unref (task);
228//	}
229//
230// static gboolean
231// decorator_ready (gpointer user_data)
232//
233//	{
234//	  GTask *task = user_data;
235//	  BakingData *bd = g_task_get_task_data (task);
236//
237//	  cake_decorate_async (bd->cake, bd->frosting, bd->message,
238//	                       g_task_get_cancellable (task),
239//	                       decorated_cb, task);
240//
241//	  return G_SOURCE_REMOVE;
242//	}
243//
244// static void
245// baked_cb (Cake     *cake,
246//
247//	gpointer  user_data)
248//
249//	{
250//	  GTask *task = user_data;
251//	  BakingData *bd = g_task_get_task_data (task);
252//	  GError *error = NULL;
253//
254//	  if (cake == NULL)
255//	    {
256//	      g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
257//	                               "Go to the supermarket");
258//	      g_object_unref (task);
259//	      return;
260//	    }
261//
262//	  bd->cake = cake;
263//
264//	  // Bail out now if the user has already cancelled
265//	  if (g_task_return_error_if_cancelled (task))
266//	    {
267//	      g_object_unref (task);
268//	      return;
269//	    }
270//
271//	  if (cake_decorator_available (cake))
272//	    decorator_ready (task);
273//	  else
274//	    {
275//	      GSource *source;
276//
277//	      source = cake_decorator_wait_source_new (cake);
278//	      // Attach @source to @task’s GMainContext and have it call
279//	      // decorator_ready() when it is ready.
280//	      g_task_attach_source (task, source, decorator_ready);
281//	      g_source_unref (source);
282//	    }
283//	}
284//
285// void
286// baker_bake_cake_async (Baker               *self,
287//
288//	guint                radius,
289//	CakeFlavor           flavor,
290//	CakeFrostingType     frosting,
291//	const char          *message,
292//	gint                 priority,
293//	GCancellable        *cancellable,
294//	GAsyncReadyCallback  callback,
295//	gpointer             user_data)
296//
297//	{
298//	  GTask *task;
299//	  BakingData *bd;
300//
301//	  task = g_task_new (self, cancellable, callback, user_data);
302//	  g_task_set_priority (task, priority);
303//
304//	  bd = g_slice_new0 (BakingData);
305//	  bd->frosting = frosting;
306//	  bd->message = g_strdup (message);
307//	  g_task_set_task_data (task, bd, (GDestroyNotify) baking_data_free);
308//
309//	  _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
310//	}
311//
312// Cake *
313// baker_bake_cake_finish (Baker         *self,
314//
315//	GAsyncResult  *result,
316//	GError       **error)
317//
318//	{
319//	  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
320//
321//	  return g_task_propagate_pointer (G_TASK (result), error);
322//	}
323//
324// ```
325//
326// ## Asynchronous operations from synchronous ones
327//
328// You can use [method@Gio.Task.run_in_thread] to turn a synchronous
329// operation into an asynchronous one, by running it in a thread.
330// When it completes, the result will be dispatched to the thread-default
331// main context (see [method@GLib.MainContext.push_thread_default])
332// where the `GTask` was created.
333//
334// Running a task in a thread:
335// ```c
336//
337//	typedef struct {
338//	  guint radius;
339//	  CakeFlavor flavor;
340//	  CakeFrostingType frosting;
341//	  char *message;
342//	} CakeData;
343//
344// static void
345// cake_data_free (CakeData *cake_data)
346//
347//	{
348//	  g_free (cake_data->message);
349//	  g_slice_free (CakeData, cake_data);
350//	}
351//
352// static void
353// bake_cake_thread (GTask         *task,
354//
355//	gpointer       source_object,
356//	gpointer       task_data,
357//	GCancellable  *cancellable)
358//
359//	{
360//	  Baker *self = source_object;
361//	  CakeData *cake_data = task_data;
362//	  Cake *cake;
363//	  GError *error = NULL;
364//
365//	  cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
366//	                    cake_data->frosting, cake_data->message,
367//	                    cancellable, &error);
368//	  if (cake)
369//	    g_task_return_pointer (task, cake, g_object_unref);
370//	  else
371//	    g_task_return_error (task, error);
372//	}
373//
374// void
375// baker_bake_cake_async (Baker               *self,
376//
377//	guint                radius,
378//	CakeFlavor           flavor,
379//	CakeFrostingType     frosting,
380//	const char          *message,
381//	GCancellable        *cancellable,
382//	GAsyncReadyCallback  callback,
383//	gpointer             user_data)
384//
385//	{
386//	  CakeData *cake_data;
387//	  GTask *task;
388//
389//	  cake_data = g_slice_new (CakeData);
390//	  cake_data->radius = radius;
391//	  cake_data->flavor = flavor;
392//	  cake_data->frosting = frosting;
393//	  cake_data->message = g_strdup (message);
394//	  task = g_task_new (self, cancellable, callback, user_data);
395//	  g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
396//	  g_task_run_in_thread (task, bake_cake_thread);
397//	  g_object_unref (task);
398//	}
399//
400// Cake *
401// baker_bake_cake_finish (Baker         *self,
402//
403//	GAsyncResult  *result,
404//	GError       **error)
405//
406//	{
407//	  g_return_val_if_fail (g_task_is_valid (result, self), NULL);
408//
409//	  return g_task_propagate_pointer (G_TASK (result), error);
410//	}
411//
412// ```
413//
414// ## Adding cancellability to uncancellable tasks
415//
416// Finally, [method@Gio.Task.run_in_thread] and
417// [method@Gio.Task.run_in_thread_sync] can be used to turn an uncancellable
418// operation into a cancellable one. If you call
419// [method@Gio.Task.set_return_on_cancel], passing `TRUE`, then if the task’s
420// [class@Gio.Cancellable] is cancelled, it will return control back to the
421// caller immediately, while allowing the task thread to continue running in the
422// background (and simply discarding its result when it finally does finish).
423// Provided that the task thread is careful about how it uses
424// locks and other externally-visible resources, this allows you
425// to make ‘GLib-friendly’ asynchronous and cancellable
426// synchronous variants of blocking APIs.
427//
428// Cancelling a task:
429// ```c
430// static void
431// bake_cake_thread (GTask         *task,
432//
433//	gpointer       source_object,
434//	gpointer       task_data,
435//	GCancellable  *cancellable)
436//
437//	{
438//	  Baker *self = source_object;
439//	  CakeData *cake_data = task_data;
440//	  Cake *cake;
441//	  GError *error = NULL;
442//
443//	  cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
444//	                    cake_data->frosting, cake_data->message,
445//	                    &error);
446//	  if (error)
447//	    {
448//	      g_task_return_error (task, error);
449//	      return;
450//	    }
451//
452//	  // If the task has already been cancelled, then we don’t want to add
453//	  // the cake to the cake cache. Likewise, we don’t  want to have the
454//	  // task get cancelled in the middle of updating the cache.
455//	  // g_task_set_return_on_cancel() will return %TRUE here if it managed
456//	  // to disable return-on-cancel, or %FALSE if the task was cancelled
457//	  // before it could.
458//	  if (g_task_set_return_on_cancel (task, FALSE))
459//	    {
460//	      // If the caller cancels at this point, their
461//	      // GAsyncReadyCallback won’t be invoked until we return,
462//	      // so we don’t have to worry that this code will run at
463//	      // the same time as that code does. But if there were
464//	      // other functions that might look at the cake cache,
465//	      // then we’d probably need a GMutex here as well.
466//	      baker_add_cake_to_cache (baker, cake);
467//	      g_task_return_pointer (task, cake, g_object_unref);
468//	    }
469//	}
470//
471// void
472// baker_bake_cake_async (Baker               *self,
473//
474//	guint                radius,
475//	CakeFlavor           flavor,
476//	CakeFrostingType     frosting,
477//	const char          *message,
478//	GCancellable        *cancellable,
479//	GAsyncReadyCallback  callback,
480//	gpointer             user_data)
481//
482//	{
483//	  CakeData *cake_data;
484//	  GTask *task;
485//
486//	  cake_data = g_slice_new (CakeData);
487//
488//	  ...
489//
490//	  task = g_task_new (self, cancellable, callback, user_data);
491//	  g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
492//	  g_task_set_return_on_cancel (task, TRUE);
493//	  g_task_run_in_thread (task, bake_cake_thread);
494//	}
495//
496// Cake *
497// baker_bake_cake_sync (Baker               *self,
498//
499//	guint                radius,
500//	CakeFlavor           flavor,
501//	CakeFrostingType     frosting,
502//	const char          *message,
503//	GCancellable        *cancellable,
504//	GError             **error)
505//
506//	{
507//	  CakeData *cake_data;
508//	  GTask *task;
509//	  Cake *cake;
510//
511//	  cake_data = g_slice_new (CakeData);
512//
513//	  ...
514//
515//	  task = g_task_new (self, cancellable, NULL, NULL);
516//	  g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
517//	  g_task_set_return_on_cancel (task, TRUE);
518//	  g_task_run_in_thread_sync (task, bake_cake_thread);
519//
520//	  cake = g_task_propagate_pointer (task, error);
521//	  g_object_unref (task);
522//	  return cake;
523//	}
524//
525// ```
526//
527// ## Porting from [class@Gio.SimpleAsyncResult]
528//
529// `GTask`’s API attempts to be simpler than [class@Gio.SimpleAsyncResult]’s
530// in several ways:
531//
532//   - You can save task-specific data with [method@Gio.Task.set_task_data], and
533//     retrieve it later with [method@Gio.Task.get_task_data]. This replaces the
534//     abuse of [method@Gio.SimpleAsyncResult.set_op_res_gpointer] for the same
535//     purpose with [class@Gio.SimpleAsyncResult].
536//   - In addition to the task data, `GTask` also keeps track of the
537//     [priority](iface.AsyncResult.html#io-priority), [class@Gio.Cancellable],
538//     and [struct@GLib.MainContext] associated with the task, so tasks that
539//     consist of a chain of simpler asynchronous operations will have easy access
540//     to those values when starting each sub-task.
541//   - [method@Gio.Task.return_error_if_cancelled] provides simplified
542//     handling for cancellation. In addition, cancellation
543//     overrides any other `GTask` return value by default, like
544//     [class@Gio.SimpleAsyncResult] does when
545//     [method@Gio.SimpleAsyncResult.set_check_cancellable] is called.
546//     (You can use [method@Gio.Task.set_check_cancellable] to turn off that
547//     behavior.) On the other hand, [method@Gio.Task.run_in_thread]
548//     guarantees that it will always run your
549//     `task_func`, even if the task’s [class@Gio.Cancellable]
550//     is already cancelled before the task gets a chance to run;
551//     you can start your `task_func` with a
552//     [method@Gio.Task.return_error_if_cancelled] check if you need the
553//     old behavior.
554//   - The ‘return’ methods (eg, [method@Gio.Task.return_pointer])
555//     automatically cause the task to be ‘completed’ as well, and
556//     there is no need to worry about the ‘complete’ vs ‘complete in idle’
557//     distinction. (`GTask` automatically figures out
558//     whether the task’s callback can be invoked directly, or
559//     if it needs to be sent to another [struct@GLib.MainContext], or delayed
560//     until the next iteration of the current [struct@GLib.MainContext].)
561//   - The ‘finish’ functions for `GTask` based operations are generally
562//     much simpler than [class@Gio.SimpleAsyncResult] ones, normally consisting
563//     of only a single call to [method@Gio.Task.propagate_pointer] or the like.
564//     Since [method@Gio.Task.propagate_pointer] ‘steals’ the return value from
565//     the `GTask`, it is not necessary to juggle pointers around to
566//     prevent it from being freed twice.
567//   - With [class@Gio.SimpleAsyncResult], it was common to call
568//     [method@Gio.SimpleAsyncResult.propagate_error] from the
569//     `_finish()` wrapper function, and have
570//     virtual method implementations only deal with successful
571//     returns. This behavior is deprecated, because it makes it
572//     difficult for a subclass to chain to a parent class’s async
573//     methods. Instead, the wrapper function should just be a
574//     simple wrapper, and the virtual method should call an
575//     appropriate `g_task_propagate_` function.
576//     Note that wrapper methods can now use
577//     [method@Gio.AsyncResult.legacy_propagate_error] to do old-style
578//     [class@Gio.SimpleAsyncResult] error-returning behavior, and
579//     [method@Gio.AsyncResult.is_tagged] to check if a result is tagged as
580//     having come from the `_async()` wrapper
581//     function (for ‘short-circuit’ results, such as when passing
582//     `0` to [method@Gio.InputStream.read_async]).
583//
584// ## Thread-safety considerations
585//
586// Due to some infelicities in the API design, there is a
587// thread-safety concern that users of `GTask` have to be aware of:
588//
589// If the `main` thread drops its last reference to the source object
590// or the task data before the task is finalized, then the finalizers
591// of these objects may be called on the worker thread.
592//
593// This is a problem if the finalizers use non-threadsafe API, and
594// can lead to hard-to-debug crashes. Possible workarounds include:
595//
596//   - Clear task data in a signal handler for `notify::completed`
597//   - Keep iterating a main context in the main thread and defer
598//     dropping the reference to the source object to that main
599//     context when the task is finalized
600type Task struct {
601	gobject.Object
602}
603
604var xTaskGLibType func() types.GType
605
606func TaskGLibType() types.GType {
607	return xTaskGLibType()
608}
609
610func TaskNewFromInternalPtr(ptr uintptr) *Task {
611	cls := &Task{}
612	cls.Ptr = ptr
613	return cls
614}
615
616var xNewTask func(uintptr, uintptr, uintptr, uintptr) uintptr
617
618// Creates a #GTask acting on @source_object, which will eventually be
619// used to invoke @callback in the current thread-default main context
620// (see [method@GLib.MainContext.push_thread_default]).
621//
622// Call this in the "start" method of your asynchronous method, and
623// pass the #GTask around throughout the asynchronous operation. You
624// can use g_task_set_task_data() to attach task-specific data to the
625// object, which you can retrieve later via g_task_get_task_data().
626//
627// By default, if @cancellable is cancelled, then the return value of
628// the task will always be %G_IO_ERROR_CANCELLED, even if the task had
629// already completed before the cancellation. This allows for
630// simplified handling in cases where cancellation may imply that
631// other objects that the task depends on have been destroyed. If you
632// do not want this behavior, you can use
633// g_task_set_check_cancellable() to change it.
634func NewTask(SourceObjectVar *gobject.Object, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, CallbackDataVar uintptr) *Task {
635	var cls *Task
636
637	var CallbackVarRef uintptr
638	if CallbackVar != nil {
639		CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
640		if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
641			CallbackVarRef = cbRefPtr
642		} else {
643			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
644				cbFn := *CallbackVar
645				cbFn(arg0, arg1, arg2)
646			}
647			CallbackVarRef = purego.NewCallback(fcb)
648			glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
649		}
650	}
651
652	cret := xNewTask(SourceObjectVar.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, CallbackDataVar)
653
654	if cret == 0 {
655		return nil
656	}
657	cls = &Task{}
658	cls.Ptr = cret
659	return cls
660}
661
662var xTaskAttachSource func(uintptr, *glib.Source, uintptr)
663
664// A utility function for dealing with async operations where you need
665// to wait for a #GSource to trigger. Attaches @source to @task's
666// #GMainContext with @task's [priority](iface.AsyncResult.html#io-priority),
667// and sets @source's callback to @callback, with @task as the callback's
668// `user_data`.
669//
670// It will set the @source’s name to the task’s name (as set with
671// g_task_set_name()), if one has been set on the task and the source doesn’t
672// yet have a name.
673//
674// This takes a reference on @task until @source is destroyed.
675func (x *Task) AttachSource(SourceVar *glib.Source, CallbackVar *glib.SourceFunc) {
676
677	var CallbackVarRef uintptr
678	if CallbackVar != nil {
679		CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
680		if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
681			CallbackVarRef = cbRefPtr
682		} else {
683			fcb := func(arg0 uintptr) bool {
684				cbFn := *CallbackVar
685				return cbFn(arg0)
686			}
687			CallbackVarRef = purego.NewCallback(fcb)
688			glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
689		}
690	}
691
692	xTaskAttachSource(x.GoPointer(), SourceVar, CallbackVarRef)
693
694}
695
696var xTaskGetCancellable func(uintptr) uintptr
697
698// Gets @task's #GCancellable
699func (x *Task) GetCancellable() *Cancellable {
700	var cls *Cancellable
701
702	cret := xTaskGetCancellable(x.GoPointer())
703
704	if cret == 0 {
705		return nil
706	}
707	gobject.IncreaseRef(cret)
708	cls = &Cancellable{}
709	cls.Ptr = cret
710	return cls
711}
712
713var xTaskGetCheckCancellable func(uintptr) bool
714
715// Gets @task's check-cancellable flag. See
716// g_task_set_check_cancellable() for more details.
717func (x *Task) GetCheckCancellable() bool {
718
719	cret := xTaskGetCheckCancellable(x.GoPointer())
720	return cret
721}
722
723var xTaskGetCompleted func(uintptr) bool
724
725// Gets the value of #GTask:completed. This changes from %FALSE to %TRUE after
726// the task’s callback is invoked, and will return %FALSE if called from inside
727// the callback.
728func (x *Task) GetCompleted() bool {
729
730	cret := xTaskGetCompleted(x.GoPointer())
731	return cret
732}
733
734var xTaskGetContext func(uintptr) *glib.MainContext
735
736// Gets the #GMainContext that @task will return its result in (that
737// is, the context that was the thread-default main context
738// (see [method@GLib.MainContext.push_thread_default])
739// at the point when @task was created).
740//
741// This will always return a non-%NULL value, even if the task's
742// context is the default #GMainContext.
743func (x *Task) GetContext() *glib.MainContext {
744
745	cret := xTaskGetContext(x.GoPointer())
746	return cret
747}
748
749var xTaskGetName func(uintptr) string
750
751// Gets @task’s name. See g_task_set_name().
752func (x *Task) GetName() string {
753
754	cret := xTaskGetName(x.GoPointer())
755	return cret
756}
757
758var xTaskGetPriority func(uintptr) int
759
760// Gets @task's priority
761func (x *Task) GetPriority() int {
762
763	cret := xTaskGetPriority(x.GoPointer())
764	return cret
765}
766
767var xTaskGetReturnOnCancel func(uintptr) bool
768
769// Gets @task's return-on-cancel flag. See
770// g_task_set_return_on_cancel() for more details.
771func (x *Task) GetReturnOnCancel() bool {
772
773	cret := xTaskGetReturnOnCancel(x.GoPointer())
774	return cret
775}
776
777var xTaskGetSourceObject func(uintptr) uintptr
778
779// Gets the source object from @task. Like
780// g_async_result_get_source_object(), but does not ref the object.
781func (x *Task) GetSourceObject() *gobject.Object {
782	var cls *gobject.Object
783
784	cret := xTaskGetSourceObject(x.GoPointer())
785
786	if cret == 0 {
787		return nil
788	}
789	gobject.IncreaseRef(cret)
790	cls = &gobject.Object{}
791	cls.Ptr = cret
792	return cls
793}
794
795var xTaskGetSourceTag func(uintptr) uintptr
796
797// Gets @task's source tag. See g_task_set_source_tag().
798func (x *Task) GetSourceTag() uintptr {
799
800	cret := xTaskGetSourceTag(x.GoPointer())
801	return cret
802}
803
804var xTaskGetTaskData func(uintptr) uintptr
805
806// Gets @task's `task_data`.
807func (x *Task) GetTaskData() uintptr {
808
809	cret := xTaskGetTaskData(x.GoPointer())
810	return cret
811}
812
813var xTaskHadError func(uintptr) bool
814
815// Tests if @task resulted in an error.
816func (x *Task) HadError() bool {
817
818	cret := xTaskHadError(x.GoPointer())
819	return cret
820}
821
822var xTaskPropagateBoolean func(uintptr) bool
823
824// Gets the result of @task as a #gboolean.
825//
826// If the task resulted in an error, or was cancelled, then this will
827// instead return %FALSE and set @error.
828//
829// Since this method transfers ownership of the return value (or
830// error) to the caller, you may only call it once.
831func (x *Task) PropagateBoolean() (bool, error) {
832	var cerr *glib.Error
833
834	cret := xTaskPropagateBoolean(x.GoPointer())
835	if cerr == nil {
836		return cret, nil
837	}
838	return cret, cerr
839
840}
841
842var xTaskPropagateInt func(uintptr) int
843
844// Gets the result of @task as an integer (#gssize).
845//
846// If the task resulted in an error, or was cancelled, then this will
847// instead return -1 and set @error.
848//
849// Since this method transfers ownership of the return value (or
850// error) to the caller, you may only call it once.
851func (x *Task) PropagateInt() (int, error) {
852	var cerr *glib.Error
853
854	cret := xTaskPropagateInt(x.GoPointer())
855	if cerr == nil {
856		return cret, nil
857	}
858	return cret, cerr
859
860}
861
862var xTaskPropagatePointer func(uintptr) uintptr
863
864// Gets the result of @task as a pointer, and transfers ownership
865// of that value to the caller.
866//
867// If the task resulted in an error, or was cancelled, then this will
868// instead return %NULL and set @error.
869//
870// Since this method transfers ownership of the return value (or
871// error) to the caller, you may only call it once.
872func (x *Task) PropagatePointer() (uintptr, error) {
873	var cerr *glib.Error
874
875	cret := xTaskPropagatePointer(x.GoPointer())
876	if cerr == nil {
877		return cret, nil
878	}
879	return cret, cerr
880
881}
882
883var xTaskPropagateValue func(uintptr, *gobject.Value, **glib.Error) bool
884
885// Gets the result of @task as a #GValue, and transfers ownership of
886// that value to the caller. As with g_task_return_value(), this is
887// a generic low-level method; g_task_propagate_pointer() and the like
888// will usually be more useful for C code.
889//
890// If the task resulted in an error, or was cancelled, then this will
891// instead set @error and return %FALSE.
892//
893// Since this method transfers ownership of the return value (or
894// error) to the caller, you may only call it once.
895func (x *Task) PropagateValue(ValueVar *gobject.Value) (bool, error) {
896	var cerr *glib.Error
897
898	cret := xTaskPropagateValue(x.GoPointer(), ValueVar, &cerr)
899	if cerr == nil {
900		return cret, nil
901	}
902	return cret, cerr
903
904}
905
906var xTaskReturnBoolean func(uintptr, bool)
907
908// Sets @task's result to @result and completes the task (see
909// g_task_return_pointer() for more discussion of exactly what this
910// means).
911func (x *Task) ReturnBoolean(ResultVar bool) {
912
913	xTaskReturnBoolean(x.GoPointer(), ResultVar)
914
915}
916
917var xTaskReturnError func(uintptr, *glib.Error)
918
919// Sets @task's result to @error (which @task assumes ownership of)
920// and completes the task (see g_task_return_pointer() for more
921// discussion of exactly what this means).
922//
923// Note that since the task takes ownership of @error, and since the
924// task may be completed before returning from g_task_return_error(),
925// you cannot assume that @error is still valid after calling this.
926// Call g_error_copy() on the error if you need to keep a local copy
927// as well.
928//
929// See also [method@Gio.Task.return_new_error],
930// [method@Gio.Task.return_new_error_literal].
931func (x *Task) ReturnError(ErrorVar *glib.Error) {
932
933	xTaskReturnError(x.GoPointer(), ErrorVar)
934
935}
936
937var xTaskReturnErrorIfCancelled func(uintptr) bool
938
939// Checks if @task's #GCancellable has been cancelled, and if so, sets
940// @task's error accordingly and completes the task (see
941// g_task_return_pointer() for more discussion of exactly what this
942// means).
943func (x *Task) ReturnErrorIfCancelled() bool {
944
945	cret := xTaskReturnErrorIfCancelled(x.GoPointer())
946	return cret
947}
948
949var xTaskReturnInt func(uintptr, int)
950
951// Sets @task's result to @result and completes the task (see
952// g_task_return_pointer() for more discussion of exactly what this
953// means).
954func (x *Task) ReturnInt(ResultVar int) {
955
956	xTaskReturnInt(x.GoPointer(), ResultVar)
957
958}
959
960var xTaskReturnNewError func(uintptr, glib.Quark, int, string, ...interface{})
961
962// Sets @task's result to a new #GError created from @domain, @code,
963// @format, and the remaining arguments, and completes the task (see
964// g_task_return_pointer() for more discussion of exactly what this
965// means).
966//
967// See also g_task_return_error().
968func (x *Task) ReturnNewError(DomainVar glib.Quark, CodeVar int, FormatVar string, varArgs ...interface{}) {
969
970	xTaskReturnNewError(x.GoPointer(), DomainVar, CodeVar, FormatVar, varArgs...)
971
972}
973
974var xTaskReturnNewErrorLiteral func(uintptr, glib.Quark, int, string)
975
976// Sets @task’s result to a new [type@GLib.Error] created from @domain, @code,
977// @message and completes the task.
978//
979// See [method@Gio.Task.return_pointer] for more discussion of exactly what
980// ‘completing the task’ means.
981//
982// See also [method@Gio.Task.return_new_error].
983func (x *Task) ReturnNewErrorLiteral(DomainVar glib.Quark, CodeVar int, MessageVar string) {
984
985	xTaskReturnNewErrorLiteral(x.GoPointer(), DomainVar, CodeVar, MessageVar)
986
987}
988
989var xTaskReturnPointer func(uintptr, uintptr, uintptr)
990
991// Sets @task's result to @result and completes the task. If @result
992// is not %NULL, then @result_destroy will be used to free @result if
993// the caller does not take ownership of it with
994// g_task_propagate_pointer().
995//
996// "Completes the task" means that for an ordinary asynchronous task
997// it will either invoke the task's callback, or else queue that
998// callback to be invoked in the proper #GMainContext, or in the next
999// iteration of the current #GMainContext. For a task run via
1000// g_task_run_in_thread() or g_task_run_in_thread_sync(), calling this
1001// method will save @result to be returned to the caller later, but
1002// the task will not actually be completed until the #GTaskThreadFunc
1003// exits.
1004//
1005// Note that since the task may be completed before returning from
1006// g_task_return_pointer(), you cannot assume that @result is still
1007// valid after calling this, unless you are still holding another
1008// reference on it.
1009func (x *Task) ReturnPointer(ResultVar uintptr, ResultDestroyVar *glib.DestroyNotify) {
1010
1011	var ResultDestroyVarRef uintptr
1012	if ResultDestroyVar != nil {
1013		ResultDestroyVarPtr := uintptr(unsafe.Pointer(ResultDestroyVar))
1014		if cbRefPtr, ok := glib.GetCallback(ResultDestroyVarPtr); ok {
1015			ResultDestroyVarRef = cbRefPtr
1016		} else {
1017			fcb := func(arg0 uintptr) {
1018				cbFn := *ResultDestroyVar
1019				cbFn(arg0)
1020			}
1021			ResultDestroyVarRef = purego.NewCallback(fcb)
1022			glib.SaveCallbackWithClosure(ResultDestroyVarPtr, ResultDestroyVarRef, ResultDestroyVar)
1023		}
1024	}
1025
1026	xTaskReturnPointer(x.GoPointer(), ResultVar, ResultDestroyVarRef)
1027
1028}
1029
1030var xTaskReturnPrefixedError func(uintptr, *glib.Error, string, ...interface{})
1031
1032// Sets @task's result to @error (which @task assumes ownership of), with
1033// the message prefixed according to @format, and completes the task
1034// (see g_task_return_pointer() for more discussion of exactly what this
1035// means).
1036//
1037// Note that since the task takes ownership of @error, and since the
1038// task may be completed before returning from g_task_return_prefixed_error(),
1039// you cannot assume that @error is still valid after calling this.
1040// Call g_error_copy() on the error if you need to keep a local copy
1041// as well.
1042//
1043// See also g_task_return_error(), g_prefix_error().
1044func (x *Task) ReturnPrefixedError(ErrorVar *glib.Error, FormatVar string, varArgs ...interface{}) {
1045
1046	xTaskReturnPrefixedError(x.GoPointer(), ErrorVar, FormatVar, varArgs...)
1047
1048}
1049
1050var xTaskReturnValue func(uintptr, *gobject.Value)
1051
1052// Sets @task's result to @result (by copying it) and completes the task.
1053//
1054// If @result is %NULL then a #GValue of type %G_TYPE_POINTER
1055// with a value of %NULL will be used for the result.
1056//
1057// This is a very generic low-level method intended primarily for use
1058// by language bindings; for C code, g_task_return_pointer() and the
1059// like will normally be much easier to use.
1060func (x *Task) ReturnValue(ResultVar *gobject.Value) {
1061
1062	xTaskReturnValue(x.GoPointer(), ResultVar)
1063
1064}
1065
1066var xTaskRunInThread func(uintptr, uintptr)
1067
1068// Runs @task_func in another thread. When @task_func returns, @task's
1069// #GAsyncReadyCallback will be invoked in @task's #GMainContext.
1070//
1071// This takes a ref on @task until the task completes.
1072//
1073// See #GTaskThreadFunc for more details about how @task_func is handled.
1074//
1075// Although GLib currently rate-limits the tasks queued via
1076// g_task_run_in_thread(), you should not assume that it will always
1077// do this. If you have a very large number of tasks to run (several tens of
1078// tasks), but don't want them to all run at once, you should only queue a
1079// limited number of them (around ten) at a time.
1080//
1081// Be aware that if your task depends on other tasks to complete, use of this
1082// function could lead to a livelock if the other tasks also use this function
1083// and enough of them (around 10) execute in a dependency chain, as that will
1084// exhaust the thread pool. If this situation is possible, consider using a
1085// separate worker thread or thread pool explicitly, rather than using
1086// g_task_run_in_thread().
1087func (x *Task) RunInThread(TaskFuncVar *TaskThreadFunc) {
1088
1089	var TaskFuncVarRef uintptr
1090	if TaskFuncVar != nil {
1091		TaskFuncVarPtr := uintptr(unsafe.Pointer(TaskFuncVar))
1092		if cbRefPtr, ok := glib.GetCallback(TaskFuncVarPtr); ok {
1093			TaskFuncVarRef = cbRefPtr
1094		} else {
1095			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr, arg3 uintptr) {
1096				cbFn := *TaskFuncVar
1097				cbFn(arg0, arg1, arg2, arg3)
1098			}
1099			TaskFuncVarRef = purego.NewCallback(fcb)
1100			glib.SaveCallbackWithClosure(TaskFuncVarPtr, TaskFuncVarRef, TaskFuncVar)
1101		}
1102	}
1103
1104	xTaskRunInThread(x.GoPointer(), TaskFuncVarRef)
1105
1106}
1107
1108var xTaskRunInThreadSync func(uintptr, uintptr)
1109
1110// Runs @task_func in another thread, and waits for it to return or be
1111// cancelled. You can use g_task_propagate_pointer(), etc, afterward
1112// to get the result of @task_func.
1113//
1114// See #GTaskThreadFunc for more details about how @task_func is handled.
1115//
1116// Normally this is used with tasks created with a %NULL
1117// `callback`, but note that even if the task does
1118// have a callback, it will not be invoked when @task_func returns.
1119// #GTask:completed will be set to %TRUE just before this function returns.
1120//
1121// Although GLib currently rate-limits the tasks queued via
1122// g_task_run_in_thread_sync(), you should not assume that it will
1123// always do this. If you have a very large number of tasks to run,
1124// but don't want them to all run at once, you should only queue a
1125// limited number of them at a time.
1126func (x *Task) RunInThreadSync(TaskFuncVar *TaskThreadFunc) {
1127
1128	var TaskFuncVarRef uintptr
1129	if TaskFuncVar != nil {
1130		TaskFuncVarPtr := uintptr(unsafe.Pointer(TaskFuncVar))
1131		if cbRefPtr, ok := glib.GetCallback(TaskFuncVarPtr); ok {
1132			TaskFuncVarRef = cbRefPtr
1133		} else {
1134			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr, arg3 uintptr) {
1135				cbFn := *TaskFuncVar
1136				cbFn(arg0, arg1, arg2, arg3)
1137			}
1138			TaskFuncVarRef = purego.NewCallback(fcb)
1139			glib.SaveCallbackWithClosure(TaskFuncVarPtr, TaskFuncVarRef, TaskFuncVar)
1140		}
1141	}
1142
1143	xTaskRunInThreadSync(x.GoPointer(), TaskFuncVarRef)
1144
1145}
1146
1147var xTaskSetCheckCancellable func(uintptr, bool)
1148
1149// Sets or clears @task's check-cancellable flag. If this is %TRUE
1150// (the default), then g_task_propagate_pointer(), etc, and
1151// g_task_had_error() will check the task's #GCancellable first, and
1152// if it has been cancelled, then they will consider the task to have
1153// returned an "Operation was cancelled" error
1154// (%G_IO_ERROR_CANCELLED), regardless of any other error or return
1155// value the task may have had.
1156//
1157// If @check_cancellable is %FALSE, then the #GTask will not check the
1158// cancellable itself, and it is up to @task's owner to do this (eg,
1159// via g_task_return_error_if_cancelled()).
1160//
1161// If you are using g_task_set_return_on_cancel() as well, then
1162// you must leave check-cancellable set %TRUE.
1163func (x *Task) SetCheckCancellable(CheckCancellableVar bool) {
1164
1165	xTaskSetCheckCancellable(x.GoPointer(), CheckCancellableVar)
1166
1167}
1168
1169var xTaskSetName func(uintptr, uintptr)
1170
1171// Sets @task’s name, used in debugging and profiling. The name defaults to
1172// %NULL.
1173//
1174// The task name should describe in a human readable way what the task does.
1175// For example, ‘Open file’ or ‘Connect to network host’. It is used to set the
1176// name of the #GSource used for idle completion of the task.
1177//
1178// This function may only be called before the @task is first used in a thread
1179// other than the one it was constructed in.
1180func (x *Task) SetName(NameVar *string) {
1181
1182	NameVarPtr := core.GStrdupNullable(NameVar)
1183	defer core.GFreeNullable(NameVarPtr)
1184
1185	xTaskSetName(x.GoPointer(), NameVarPtr)
1186
1187}
1188
1189var xTaskSetPriority func(uintptr, int)
1190
1191// Sets @task's priority. If you do not call this, it will default to
1192// %G_PRIORITY_DEFAULT.
1193//
1194// This will affect the priority of #GSources created with
1195// g_task_attach_source() and the scheduling of tasks run in threads,
1196// and can also be explicitly retrieved later via
1197// g_task_get_priority().
1198func (x *Task) SetPriority(PriorityVar int) {
1199
1200	xTaskSetPriority(x.GoPointer(), PriorityVar)
1201
1202}
1203
1204var xTaskSetReturnOnCancel func(uintptr, bool) bool
1205
1206// Sets or clears @task's return-on-cancel flag. This is only
1207// meaningful for tasks run via g_task_run_in_thread() or
1208// g_task_run_in_thread_sync().
1209//
1210// If @return_on_cancel is %TRUE, then cancelling @task's
1211// #GCancellable will immediately cause it to return, as though the
1212// task's #GTaskThreadFunc had called
1213// g_task_return_error_if_cancelled() and then returned.
1214//
1215// This allows you to create a cancellable wrapper around an
1216// uninterruptible function. The #GTaskThreadFunc just needs to be
1217// careful that it does not modify any externally-visible state after
1218// it has been cancelled. To do that, the thread should call
1219// g_task_set_return_on_cancel() again to (atomically) set
1220// return-on-cancel %FALSE before making externally-visible changes;
1221// if the task gets cancelled before the return-on-cancel flag could
1222// be changed, g_task_set_return_on_cancel() will indicate this by
1223// returning %FALSE.
1224//
1225// You can disable and re-enable this flag multiple times if you wish.
1226// If the task's #GCancellable is cancelled while return-on-cancel is
1227// %FALSE, then calling g_task_set_return_on_cancel() to set it %TRUE
1228// again will cause the task to be cancelled at that point.
1229//
1230// If the task's #GCancellable is already cancelled before you call
1231// g_task_run_in_thread()/g_task_run_in_thread_sync(), then the
1232// #GTaskThreadFunc will still be run (for consistency), but the task
1233// will also be completed right away.
1234func (x *Task) SetReturnOnCancel(ReturnOnCancelVar bool) bool {
1235
1236	cret := xTaskSetReturnOnCancel(x.GoPointer(), ReturnOnCancelVar)
1237	return cret
1238}
1239
1240var xTaskSetSourceTag func(uintptr, uintptr)
1241
1242// Sets @task's source tag.
1243//
1244// You can use this to tag a task return
1245// value with a particular pointer (usually a pointer to the function
1246// doing the tagging) and then later check it using
1247// g_task_get_source_tag() (or g_async_result_is_tagged()) in the
1248// task's "finish" function, to figure out if the response came from a
1249// particular place.
1250//
1251// A macro wrapper around this function will automatically set the
1252// task’s name to the string form of @source_tag if it’s not already
1253// set, for convenience.
1254func (x *Task) SetSourceTag(SourceTagVar uintptr) {
1255
1256	xTaskSetSourceTag(x.GoPointer(), SourceTagVar)
1257
1258}
1259
1260var xTaskSetStaticName func(uintptr, uintptr)
1261
1262// Sets @task’s name, used in debugging and profiling.
1263//
1264// This is a variant of g_task_set_name() that avoids copying @name.
1265//
1266// This function is called automatically by [method@Gio.Task.set_source_tag]
1267// unless a name is set.
1268func (x *Task) SetStaticName(NameVar *string) {
1269
1270	NameVarPtr := core.GStrdupNullable(NameVar)
1271	defer core.GFreeNullable(NameVarPtr)
1272
1273	xTaskSetStaticName(x.GoPointer(), NameVarPtr)
1274
1275}
1276
1277var xTaskSetTaskData func(uintptr, uintptr, uintptr)
1278
1279// Sets @task's task data (freeing the existing task data, if any).
1280func (x *Task) SetTaskData(TaskDataVar uintptr, TaskDataDestroyVar *glib.DestroyNotify) {
1281
1282	var TaskDataDestroyVarRef uintptr
1283	if TaskDataDestroyVar != nil {
1284		TaskDataDestroyVarPtr := uintptr(unsafe.Pointer(TaskDataDestroyVar))
1285		if cbRefPtr, ok := glib.GetCallback(TaskDataDestroyVarPtr); ok {
1286			TaskDataDestroyVarRef = cbRefPtr
1287		} else {
1288			fcb := func(arg0 uintptr) {
1289				cbFn := *TaskDataDestroyVar
1290				cbFn(arg0)
1291			}
1292			TaskDataDestroyVarRef = purego.NewCallback(fcb)
1293			glib.SaveCallbackWithClosure(TaskDataDestroyVarPtr, TaskDataDestroyVarRef, TaskDataDestroyVar)
1294		}
1295	}
1296
1297	xTaskSetTaskData(x.GoPointer(), TaskDataVar, TaskDataDestroyVarRef)
1298
1299}
1300
1301func (c *Task) GoPointer() uintptr {
1302	if c == nil {
1303		return 0
1304	}
1305	return c.Ptr
1306}
1307
1308func (c *Task) SetGoPointer(ptr uintptr) {
1309	c.Ptr = ptr
1310}
1311
1312// GetPropertyCompleted gets the "completed" property.
1313// Whether the task has completed, meaning its callback (if set) has been
1314// invoked.
1315//
1316// This can only happen after g_task_return_pointer(),
1317// g_task_return_error() or one of the other return functions have been called
1318// on the task. However, it is not guaranteed to happen immediately after
1319// those functions are called, as the task’s callback may need to be scheduled
1320// to run in a different thread.
1321//
1322// That means it is **not safe** to use this property to track whether a
1323// return function has been called on the #GTask. Callers must do that
1324// tracking themselves, typically by linking the lifetime of the #GTask to the
1325// control flow of their code.
1326//
1327// This property is guaranteed to change from %FALSE to %TRUE exactly once.
1328//
1329// The #GObject::notify signal for this change is emitted in the same main
1330// context as the task’s callback, immediately after that callback is invoked.
1331func (x *Task) GetPropertyCompleted() bool {
1332	var v gobject.Value
1333	x.GetProperty("completed", &v)
1334	return v.GetBoolean()
1335}
1336
1337// Gets the user data from a [iface@Gio.AsyncResult].
1338func (x *Task) GetUserData() uintptr {
1339
1340	cret := XGAsyncResultGetUserData(x.GoPointer())
1341	return cret
1342}
1343
1344// Checks if @res has the given @source_tag (generally a function
1345// pointer indicating the function @res was created by).
1346func (x *Task) IsTagged(SourceTagVar uintptr) bool {
1347
1348	cret := XGAsyncResultIsTagged(x.GoPointer(), SourceTagVar)
1349	return cret
1350}
1351
1352// If @res is a [class@Gio.SimpleAsyncResult], this is equivalent to
1353// [method@Gio.SimpleAsyncResult.propagate_error]. Otherwise it returns
1354// `FALSE`.
1355//
1356// This can be used for legacy error handling in async `*_finish()`
1357// wrapper functions that traditionally handled [class@Gio.SimpleAsyncResult]
1358// error returns themselves rather than calling into the virtual method.
1359// This should not be used in new code; [iface@Gio.AsyncResult] errors that are
1360// set by virtual methods should also be extracted by virtual methods,
1361// to enable subclasses to chain up correctly.
1362func (x *Task) LegacyPropagateError() (bool, error) {
1363	var cerr *glib.Error
1364
1365	cret := XGAsyncResultLegacyPropagateError(x.GoPointer())
1366	if cerr == nil {
1367		return cret, nil
1368	}
1369	return cret, cerr
1370
1371}
1372
1373var xTaskIsValid func(uintptr, uintptr) bool
1374
1375// Checks that @result is a #GTask, and that @source_object is its
1376// source object (or that @source_object is %NULL and @result has no
1377// source object). This can be used in g_return_if_fail() checks.
1378func TaskIsValid(ResultVar AsyncResult, SourceObjectVar *gobject.Object) bool {
1379
1380	cret := xTaskIsValid(ResultVar.GoPointer(), SourceObjectVar.GoPointer())
1381	return cret
1382}
1383
1384var xTaskReportError func(uintptr, uintptr, uintptr, uintptr, *glib.Error)
1385
1386// Creates a #GTask and then immediately calls g_task_return_error()
1387// on it. Use this in the wrapper function of an asynchronous method
1388// when you want to avoid even calling the virtual method. You can
1389// then use g_async_result_is_tagged() in the finish method wrapper to
1390// check if the result there is tagged as having been created by the
1391// wrapper method, and deal with it appropriately if so.
1392//
1393// See also g_task_report_new_error().
1394func TaskReportError(SourceObjectVar *gobject.Object, CallbackVar *AsyncReadyCallback, CallbackDataVar uintptr, SourceTagVar uintptr, ErrorVar *glib.Error) {
1395
1396	var CallbackVarRef uintptr
1397	if CallbackVar != nil {
1398		CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
1399		if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
1400			CallbackVarRef = cbRefPtr
1401		} else {
1402			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
1403				cbFn := *CallbackVar
1404				cbFn(arg0, arg1, arg2)
1405			}
1406			CallbackVarRef = purego.NewCallback(fcb)
1407			glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
1408		}
1409	}
1410
1411	xTaskReportError(SourceObjectVar.GoPointer(), CallbackVarRef, CallbackDataVar, SourceTagVar, ErrorVar)
1412
1413}
1414
1415var xTaskReportNewError func(uintptr, uintptr, uintptr, uintptr, glib.Quark, int, string, ...interface{})
1416
1417// Creates a #GTask and then immediately calls
1418// g_task_return_new_error() on it. Use this in the wrapper function
1419// of an asynchronous method when you want to avoid even calling the
1420// virtual method. You can then use g_async_result_is_tagged() in the
1421// finish method wrapper to check if the result there is tagged as
1422// having been created by the wrapper method, and deal with it
1423// appropriately if so.
1424//
1425// See also g_task_report_error().
1426func TaskReportNewError(SourceObjectVar *gobject.Object, CallbackVar *AsyncReadyCallback, CallbackDataVar uintptr, SourceTagVar uintptr, DomainVar glib.Quark, CodeVar int, FormatVar string, varArgs ...interface{}) {
1427
1428	var CallbackVarRef uintptr
1429	if CallbackVar != nil {
1430		CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
1431		if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
1432			CallbackVarRef = cbRefPtr
1433		} else {
1434			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
1435				cbFn := *CallbackVar
1436				cbFn(arg0, arg1, arg2)
1437			}
1438			CallbackVarRef = purego.NewCallback(fcb)
1439			glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
1440		}
1441	}
1442
1443	xTaskReportNewError(SourceObjectVar.GoPointer(), CallbackVarRef, CallbackDataVar, SourceTagVar, DomainVar, CodeVar, FormatVar, varArgs...)
1444
1445}
1446
1447func init() {
1448	core.SetPackageName("GIO", "gio-2.0")
1449	core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
1450	var libs []uintptr
1451	for _, libPath := range core.GetPaths("GIO") {
1452		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
1453		if err != nil {
1454			panic(err)
1455		}
1456		libs = append(libs, lib)
1457	}
1458
1459	core.PuregoSafeRegister(&xTaskGLibType, libs, "g_task_get_type")
1460
1461	core.PuregoSafeRegister(&xNewTask, libs, "g_task_new")
1462
1463	core.PuregoSafeRegister(&xTaskAttachSource, libs, "g_task_attach_source")
1464	core.PuregoSafeRegister(&xTaskGetCancellable, libs, "g_task_get_cancellable")
1465	core.PuregoSafeRegister(&xTaskGetCheckCancellable, libs, "g_task_get_check_cancellable")
1466	core.PuregoSafeRegister(&xTaskGetCompleted, libs, "g_task_get_completed")
1467	core.PuregoSafeRegister(&xTaskGetContext, libs, "g_task_get_context")
1468	core.PuregoSafeRegister(&xTaskGetName, libs, "g_task_get_name")
1469	core.PuregoSafeRegister(&xTaskGetPriority, libs, "g_task_get_priority")
1470	core.PuregoSafeRegister(&xTaskGetReturnOnCancel, libs, "g_task_get_return_on_cancel")
1471	core.PuregoSafeRegister(&xTaskGetSourceObject, libs, "g_task_get_source_object")
1472	core.PuregoSafeRegister(&xTaskGetSourceTag, libs, "g_task_get_source_tag")
1473	core.PuregoSafeRegister(&xTaskGetTaskData, libs, "g_task_get_task_data")
1474	core.PuregoSafeRegister(&xTaskHadError, libs, "g_task_had_error")
1475	core.PuregoSafeRegister(&xTaskPropagateBoolean, libs, "g_task_propagate_boolean")
1476	core.PuregoSafeRegister(&xTaskPropagateInt, libs, "g_task_propagate_int")
1477	core.PuregoSafeRegister(&xTaskPropagatePointer, libs, "g_task_propagate_pointer")
1478	core.PuregoSafeRegister(&xTaskPropagateValue, libs, "g_task_propagate_value")
1479	core.PuregoSafeRegister(&xTaskReturnBoolean, libs, "g_task_return_boolean")
1480	core.PuregoSafeRegister(&xTaskReturnError, libs, "g_task_return_error")
1481	core.PuregoSafeRegister(&xTaskReturnErrorIfCancelled, libs, "g_task_return_error_if_cancelled")
1482	core.PuregoSafeRegister(&xTaskReturnInt, libs, "g_task_return_int")
1483	core.PuregoSafeRegister(&xTaskReturnNewError, libs, "g_task_return_new_error")
1484	core.PuregoSafeRegister(&xTaskReturnNewErrorLiteral, libs, "g_task_return_new_error_literal")
1485	core.PuregoSafeRegister(&xTaskReturnPointer, libs, "g_task_return_pointer")
1486	core.PuregoSafeRegister(&xTaskReturnPrefixedError, libs, "g_task_return_prefixed_error")
1487	core.PuregoSafeRegister(&xTaskReturnValue, libs, "g_task_return_value")
1488	core.PuregoSafeRegister(&xTaskRunInThread, libs, "g_task_run_in_thread")
1489	core.PuregoSafeRegister(&xTaskRunInThreadSync, libs, "g_task_run_in_thread_sync")
1490	core.PuregoSafeRegister(&xTaskSetCheckCancellable, libs, "g_task_set_check_cancellable")
1491	core.PuregoSafeRegister(&xTaskSetName, libs, "g_task_set_name")
1492	core.PuregoSafeRegister(&xTaskSetPriority, libs, "g_task_set_priority")
1493	core.PuregoSafeRegister(&xTaskSetReturnOnCancel, libs, "g_task_set_return_on_cancel")
1494	core.PuregoSafeRegister(&xTaskSetSourceTag, libs, "g_task_set_source_tag")
1495	core.PuregoSafeRegister(&xTaskSetStaticName, libs, "g_task_set_static_name")
1496	core.PuregoSafeRegister(&xTaskSetTaskData, libs, "g_task_set_task_data")
1497
1498	core.PuregoSafeRegister(&xTaskIsValid, libs, "g_task_is_valid")
1499	core.PuregoSafeRegister(&xTaskReportError, libs, "g_task_report_error")
1500	core.PuregoSafeRegister(&xTaskReportNewError, libs, "g_task_report_new_error")
1501
1502}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close