{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

A 'GI.Gio.Objects.Task.Task' represents and manages a cancellable \"task\".

== Asynchronous operations

The most common usage of 'GI.Gio.Objects.Task.Task' is as a 'GI.Gio.Interfaces.AsyncResult.AsyncResult', to
manage data during an asynchronous operation. You call
'GI.Gio.Objects.Task.taskNew' in the \"start\" method, followed by
'GI.Gio.Objects.Task.taskSetTaskData' and the like if you need to keep some
additional data associated with the task, and then pass the
task object around through your asynchronous operation.
Eventually, you will call a method such as
'GI.Gio.Objects.Task.taskReturnPointer' or 'GI.Gio.Objects.Task.taskReturnError', which will
save the value you give it and then invoke the task\'s callback
function in the
[thread-default main context][g-main-context-push-thread-default]
where it was created (waiting until the next iteration of the main
loop first, if necessary). The caller will pass the 'GI.Gio.Objects.Task.Task' back to
the operation\'s finish function (as a 'GI.Gio.Interfaces.AsyncResult.AsyncResult'), and you can
use 'GI.Gio.Objects.Task.taskPropagatePointer' or the like to extract the
return value.

Here is an example for using GTask as a GAsyncResult:

=== /C code/
>
>    typedef struct {
>      CakeFrostingType frosting;
>      char *message;
>    } DecorationData;
>
>    static void
>    decoration_data_free (DecorationData *decoration)
>    {
>      g_free (decoration->message);
>      g_slice_free (DecorationData, decoration);
>    }
>
>    static void
>    baked_cb (Cake     *cake,
>              gpointer  user_data)
>    {
>      GTask *task = user_data;
>      DecorationData *decoration = g_task_get_task_data (task);
>      GError *error = NULL;
>
>      if (cake == NULL)
>        {
>          g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
>                                   "Go to the supermarket");
>          g_object_unref (task);
>          return;
>        }
>
>      if (!cake_decorate (cake, decoration->frosting, decoration->message, &error))
>        {
>          g_object_unref (cake);
>          // g_task_return_error() takes ownership of error
>          g_task_return_error (task, error);
>          g_object_unref (task);
>          return;
>        }
>
>      g_task_return_pointer (task, cake, g_object_unref);
>      g_object_unref (task);
>    }
>
>    void
>    baker_bake_cake_async (Baker               *self,
>                           guint                radius,
>                           CakeFlavor           flavor,
>                           CakeFrostingType     frosting,
>                           const char          *message,
>                           GCancellable        *cancellable,
>                           GAsyncReadyCallback  callback,
>                           gpointer             user_data)
>    {
>      GTask *task;
>      DecorationData *decoration;
>      Cake  *cake;
>
>      task = g_task_new (self, cancellable, callback, user_data);
>      if (radius < 3)
>        {
>          g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_TOO_SMALL,
>                                   "%ucm radius cakes are silly",
>                                   radius);
>          g_object_unref (task);
>          return;
>        }
>
>      cake = _baker_get_cached_cake (self, radius, flavor, frosting, message);
>      if (cake != NULL)
>        {
>          // _baker_get_cached_cake() returns a reffed cake
>          g_task_return_pointer (task, cake, g_object_unref);
>          g_object_unref (task);
>          return;
>        }
>
>      decoration = g_slice_new (DecorationData);
>      decoration->frosting = frosting;
>      decoration->message = g_strdup (message);
>      g_task_set_task_data (task, decoration, (GDestroyNotify) decoration_data_free);
>
>      _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
>    }
>
>    Cake *
>    baker_bake_cake_finish (Baker         *self,
>                            GAsyncResult  *result,
>                            GError       **error)
>    {
>      g_return_val_if_fail (g_task_is_valid (result, self), NULL);
>
>      return g_task_propagate_pointer (G_TASK (result), error);
>    }


== Chained asynchronous operations

'GI.Gio.Objects.Task.Task' also tries to simplify asynchronous operations that
internally chain together several smaller asynchronous
operations. 'GI.Gio.Objects.Task.taskGetCancellable', 'GI.Gio.Objects.Task.taskGetContext',
and 'GI.Gio.Objects.Task.taskGetPriority' allow you to get back the task\'s
'GI.Gio.Objects.Cancellable.Cancellable', 'GI.GLib.Structs.MainContext.MainContext', and [I\/O priority][io-priority]
when starting a new subtask, so you don\'t have to keep track
of them yourself. @/g_task_attach_source()/@ simplifies the case
of waiting for a source to fire (automatically using the correct
'GI.GLib.Structs.MainContext.MainContext' and priority).

Here is an example for chained asynchronous operations:
  
=== /C code/
>
>    typedef struct {
>      Cake *cake;
>      CakeFrostingType frosting;
>      char *message;
>    } BakingData;
>
>    static void
>    decoration_data_free (BakingData *bd)
>    {
>      if (bd->cake)
>        g_object_unref (bd->cake);
>      g_free (bd->message);
>      g_slice_free (BakingData, bd);
>    }
>
>    static void
>    decorated_cb (Cake         *cake,
>                  GAsyncResult *result,
>                  gpointer      user_data)
>    {
>      GTask *task = user_data;
>      GError *error = NULL;
>
>      if (!cake_decorate_finish (cake, result, &error))
>        {
>          g_object_unref (cake);
>          g_task_return_error (task, error);
>          g_object_unref (task);
>          return;
>        }
>
>      // baking_data_free() will drop its ref on the cake, so we have to
>      // take another here to give to the caller.
>      g_task_return_pointer (task, g_object_ref (cake), g_object_unref);
>      g_object_unref (task);
>    }
>
>    static gboolean
>    decorator_ready (gpointer user_data)
>    {
>      GTask *task = user_data;
>      BakingData *bd = g_task_get_task_data (task);
>
>      cake_decorate_async (bd->cake, bd->frosting, bd->message,
>                           g_task_get_cancellable (task),
>                           decorated_cb, task);
>
>      return G_SOURCE_REMOVE;
>    }
>
>    static void
>    baked_cb (Cake     *cake,
>              gpointer  user_data)
>    {
>      GTask *task = user_data;
>      BakingData *bd = g_task_get_task_data (task);
>      GError *error = NULL;
>
>      if (cake == NULL)
>        {
>          g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
>                                   "Go to the supermarket");
>          g_object_unref (task);
>          return;
>        }
>
>      bd->cake = cake;
>
>      // Bail out now if the user has already cancelled
>      if (g_task_return_error_if_cancelled (task))
>        {
>          g_object_unref (task);
>          return;
>        }
>
>      if (cake_decorator_available (cake))
>        decorator_ready (task);
>      else
>        {
>          GSource *source;
>
>          source = cake_decorator_wait_source_new (cake);
>          // Attach @source to @task's GMainContext and have it call
>          // decorator_ready() when it is ready.
>          g_task_attach_source (task, source, decorator_ready);
>          g_source_unref (source);
>        }
>    }
>
>    void
>    baker_bake_cake_async (Baker               *self,
>                           guint                radius,
>                           CakeFlavor           flavor,
>                           CakeFrostingType     frosting,
>                           const char          *message,
>                           gint                 priority,
>                           GCancellable        *cancellable,
>                           GAsyncReadyCallback  callback,
>                           gpointer             user_data)
>    {
>      GTask *task;
>      BakingData *bd;
>
>      task = g_task_new (self, cancellable, callback, user_data);
>      g_task_set_priority (task, priority);
>
>      bd = g_slice_new0 (BakingData);
>      bd->frosting = frosting;
>      bd->message = g_strdup (message);
>      g_task_set_task_data (task, bd, (GDestroyNotify) baking_data_free);
>
>      _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
>    }
>
>    Cake *
>    baker_bake_cake_finish (Baker         *self,
>                            GAsyncResult  *result,
>                            GError       **error)
>    {
>      g_return_val_if_fail (g_task_is_valid (result, self), NULL);
>
>      return g_task_propagate_pointer (G_TASK (result), error);
>    }


== Asynchronous operations from synchronous ones

You can use 'GI.Gio.Objects.Task.taskRunInThread' to turn a synchronous
operation into an asynchronous one, by running it in a thread.
When it completes, the result will be dispatched to the
[thread-default main context][g-main-context-push-thread-default]
where the 'GI.Gio.Objects.Task.Task' was created.

Running a task in a thread:
  
=== /C code/
>
>    typedef struct {
>      guint radius;
>      CakeFlavor flavor;
>      CakeFrostingType frosting;
>      char *message;
>    } CakeData;
>
>    static void
>    cake_data_free (CakeData *cake_data)
>    {
>      g_free (cake_data->message);
>      g_slice_free (CakeData, cake_data);
>    }
>
>    static void
>    bake_cake_thread (GTask         *task,
>                      gpointer       source_object,
>                      gpointer       task_data,
>                      GCancellable  *cancellable)
>    {
>      Baker *self = source_object;
>      CakeData *cake_data = task_data;
>      Cake *cake;
>      GError *error = NULL;
>
>      cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
>                        cake_data->frosting, cake_data->message,
>                        cancellable, &error);
>      if (cake)
>        g_task_return_pointer (task, cake, g_object_unref);
>      else
>        g_task_return_error (task, error);
>    }
>
>    void
>    baker_bake_cake_async (Baker               *self,
>                           guint                radius,
>                           CakeFlavor           flavor,
>                           CakeFrostingType     frosting,
>                           const char          *message,
>                           GCancellable        *cancellable,
>                           GAsyncReadyCallback  callback,
>                           gpointer             user_data)
>    {
>      CakeData *cake_data;
>      GTask *task;
>
>      cake_data = g_slice_new (CakeData);
>      cake_data->radius = radius;
>      cake_data->flavor = flavor;
>      cake_data->frosting = frosting;
>      cake_data->message = g_strdup (message);
>      task = g_task_new (self, cancellable, callback, user_data);
>      g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
>      g_task_run_in_thread (task, bake_cake_thread);
>      g_object_unref (task);
>    }
>
>    Cake *
>    baker_bake_cake_finish (Baker         *self,
>                            GAsyncResult  *result,
>                            GError       **error)
>    {
>      g_return_val_if_fail (g_task_is_valid (result, self), NULL);
>
>      return g_task_propagate_pointer (G_TASK (result), error);
>    }


== Adding cancellability to uncancellable tasks

Finally, 'GI.Gio.Objects.Task.taskRunInThread' and 'GI.Gio.Objects.Task.taskRunInThreadSync'
can be used to turn an uncancellable operation into a
cancellable one. If you call 'GI.Gio.Objects.Task.taskSetReturnOnCancel',
passing 'True', then if the task\'s 'GI.Gio.Objects.Cancellable.Cancellable' is cancelled,
it will return control back to the caller immediately, while
allowing the task thread to continue running in the background
(and simply discarding its result when it finally does finish).
Provided that the task thread is careful about how it uses
locks and other externally-visible resources, this allows you
to make \"GLib-friendly\" asynchronous and cancellable
synchronous variants of blocking APIs.

Cancelling a task:
  
=== /C code/
>
>    static void
>    bake_cake_thread (GTask         *task,
>                      gpointer       source_object,
>                      gpointer       task_data,
>                      GCancellable  *cancellable)
>    {
>      Baker *self = source_object;
>      CakeData *cake_data = task_data;
>      Cake *cake;
>      GError *error = NULL;
>
>      cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
>                        cake_data->frosting, cake_data->message,
>                        &error);
>      if (error)
>        {
>          g_task_return_error (task, error);
>          return;
>        }
>
>      // If the task has already been cancelled, then we don't want to add
>      // the cake to the cake cache. Likewise, we don't  want to have the
>      // task get cancelled in the middle of updating the cache.
>      // g_task_set_return_on_cancel() will return %TRUE here if it managed
>      // to disable return-on-cancel, or %FALSE if the task was cancelled
>      // before it could.
>      if (g_task_set_return_on_cancel (task, FALSE))
>        {
>          // If the caller cancels at this point, their
>          // GAsyncReadyCallback won't be invoked until we return,
>          // so we don't have to worry that this code will run at
>          // the same time as that code does. But if there were
>          // other functions that might look at the cake cache,
>          // then we'd probably need a GMutex here as well.
>          baker_add_cake_to_cache (baker, cake);
>          g_task_return_pointer (task, cake, g_object_unref);
>        }
>    }
>
>    void
>    baker_bake_cake_async (Baker               *self,
>                           guint                radius,
>                           CakeFlavor           flavor,
>                           CakeFrostingType     frosting,
>                           const char          *message,
>                           GCancellable        *cancellable,
>                           GAsyncReadyCallback  callback,
>                           gpointer             user_data)
>    {
>      CakeData *cake_data;
>      GTask *task;
>
>      cake_data = g_slice_new (CakeData);
>
>      ...
>
>      task = g_task_new (self, cancellable, callback, user_data);
>      g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
>      g_task_set_return_on_cancel (task, TRUE);
>      g_task_run_in_thread (task, bake_cake_thread);
>    }
>
>    Cake *
>    baker_bake_cake_sync (Baker               *self,
>                          guint                radius,
>                          CakeFlavor           flavor,
>                          CakeFrostingType     frosting,
>                          const char          *message,
>                          GCancellable        *cancellable,
>                          GError             **error)
>    {
>      CakeData *cake_data;
>      GTask *task;
>      Cake *cake;
>
>      cake_data = g_slice_new (CakeData);
>
>      ...
>
>      task = g_task_new (self, cancellable, NULL, NULL);
>      g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
>      g_task_set_return_on_cancel (task, TRUE);
>      g_task_run_in_thread_sync (task, bake_cake_thread);
>
>      cake = g_task_propagate_pointer (task, error);
>      g_object_unref (task);
>      return cake;
>    }


== Porting from GSimpleAsyncResult

'GI.Gio.Objects.Task.Task'\'s API attempts to be simpler than 'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult'\'s
in several ways:

* You can save task-specific data with 'GI.Gio.Objects.Task.taskSetTaskData', and
retrieve it later with 'GI.Gio.Objects.Task.taskGetTaskData'. This replaces the
abuse of @/g_simple_async_result_set_op_res_gpointer()/@ for the same
purpose with 'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult'.
* In addition to the task data, 'GI.Gio.Objects.Task.Task' also keeps track of the
[priority][io-priority], 'GI.Gio.Objects.Cancellable.Cancellable', and
'GI.GLib.Structs.MainContext.MainContext' associated with the task, so tasks that consist of
a chain of simpler asynchronous operations will have easy access
to those values when starting each sub-task.
* 'GI.Gio.Objects.Task.taskReturnErrorIfCancelled' provides simplified
handling for cancellation. In addition, cancellation
overrides any other 'GI.Gio.Objects.Task.Task' return value by default, like
'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult' does when
'GI.Gio.Objects.SimpleAsyncResult.simpleAsyncResultSetCheckCancellable' is called.
(You can use 'GI.Gio.Objects.Task.taskSetCheckCancellable' to turn off that
behavior.) On the other hand, 'GI.Gio.Objects.Task.taskRunInThread'
guarantees that it will always run your
@task_func@, even if the task\'s 'GI.Gio.Objects.Cancellable.Cancellable'
is already cancelled before the task gets a chance to run;
you can start your @task_func@ with a
'GI.Gio.Objects.Task.taskReturnErrorIfCancelled' check if you need the
old behavior.
* The \"return\" methods (eg, 'GI.Gio.Objects.Task.taskReturnPointer')
automatically cause the task to be \"completed\" as well, and
there is no need to worry about the \"complete\" vs \"complete
in idle\" distinction. ('GI.Gio.Objects.Task.Task' automatically figures out
whether the task\'s callback can be invoked directly, or
if it needs to be sent to another 'GI.GLib.Structs.MainContext.MainContext', or delayed
until the next iteration of the current 'GI.GLib.Structs.MainContext.MainContext'.)
* The \"finish\" functions for 'GI.Gio.Objects.Task.Task' based operations are generally
much simpler than 'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult' ones, normally consisting
of only a single call to 'GI.Gio.Objects.Task.taskPropagatePointer' or the like.
Since 'GI.Gio.Objects.Task.taskPropagatePointer' \"steals\" the return value from
the 'GI.Gio.Objects.Task.Task', it is not necessary to juggle pointers around to
prevent it from being freed twice.
* With 'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult', it was common to call
'GI.Gio.Objects.SimpleAsyncResult.simpleAsyncResultPropagateError' from the
@_finish()@ wrapper function, and have
virtual method implementations only deal with successful
returns. This behavior is deprecated, because it makes it
difficult for a subclass to chain to a parent class\'s async
methods. Instead, the wrapper function should just be a
simple wrapper, and the virtual method should call an
appropriate @g_task_propagate_@ function.
Note that wrapper methods can now use
'GI.Gio.Interfaces.AsyncResult.asyncResultLegacyPropagateError' to do old-style
'GI.Gio.Objects.SimpleAsyncResult.SimpleAsyncResult' error-returning behavior, and
'GI.Gio.Interfaces.AsyncResult.asyncResultIsTagged' to check if a result is tagged as
having come from the @_async()@ wrapper
function (for \"short-circuit\" results, such as when passing
0 to 'GI.Gio.Objects.InputStream.inputStreamReadAsync').

-}

#define ENABLE_OVERLOADING \
       (!defined(__HADDOCK_VERSION__))

module GI.Gio.Objects.Task
    ( 

-- * Exported types
    Task(..)                                ,
    IsTask                                  ,
    toTask                                  ,
    noTask                                  ,


 -- * Methods
-- ** getCancellable #method:getCancellable#

#if ENABLE_OVERLOADING
    TaskGetCancellableMethodInfo            ,
#endif
    taskGetCancellable                      ,


-- ** getCheckCancellable #method:getCheckCancellable#

#if ENABLE_OVERLOADING
    TaskGetCheckCancellableMethodInfo       ,
#endif
    taskGetCheckCancellable                 ,


-- ** getCompleted #method:getCompleted#

#if ENABLE_OVERLOADING
    TaskGetCompletedMethodInfo              ,
#endif
    taskGetCompleted                        ,


-- ** getContext #method:getContext#

#if ENABLE_OVERLOADING
    TaskGetContextMethodInfo                ,
#endif
    taskGetContext                          ,


-- ** getName #method:getName#

#if ENABLE_OVERLOADING
    TaskGetNameMethodInfo                   ,
#endif
    taskGetName                             ,


-- ** getPriority #method:getPriority#

#if ENABLE_OVERLOADING
    TaskGetPriorityMethodInfo               ,
#endif
    taskGetPriority                         ,


-- ** getReturnOnCancel #method:getReturnOnCancel#

#if ENABLE_OVERLOADING
    TaskGetReturnOnCancelMethodInfo         ,
#endif
    taskGetReturnOnCancel                   ,


-- ** getSourceObject #method:getSourceObject#

#if ENABLE_OVERLOADING
    TaskGetSourceObjectMethodInfo           ,
#endif
    taskGetSourceObject                     ,


-- ** getSourceTag #method:getSourceTag#

#if ENABLE_OVERLOADING
    TaskGetSourceTagMethodInfo              ,
#endif
    taskGetSourceTag                        ,


-- ** getTaskData #method:getTaskData#

#if ENABLE_OVERLOADING
    TaskGetTaskDataMethodInfo               ,
#endif
    taskGetTaskData                         ,


-- ** hadError #method:hadError#

#if ENABLE_OVERLOADING
    TaskHadErrorMethodInfo                  ,
#endif
    taskHadError                            ,


-- ** isValid #method:isValid#

    taskIsValid                             ,


-- ** new #method:new#

    taskNew                                 ,


-- ** propagateBoolean #method:propagateBoolean#

#if ENABLE_OVERLOADING
    TaskPropagateBooleanMethodInfo          ,
#endif
    taskPropagateBoolean                    ,


-- ** propagateInt #method:propagateInt#

#if ENABLE_OVERLOADING
    TaskPropagateIntMethodInfo              ,
#endif
    taskPropagateInt                        ,


-- ** propagatePointer #method:propagatePointer#

#if ENABLE_OVERLOADING
    TaskPropagatePointerMethodInfo          ,
#endif
    taskPropagatePointer                    ,


-- ** propagateValue #method:propagateValue#

#if ENABLE_OVERLOADING
    TaskPropagateValueMethodInfo            ,
#endif
    taskPropagateValue                      ,


-- ** reportError #method:reportError#

    taskReportError                         ,


-- ** returnBoolean #method:returnBoolean#

#if ENABLE_OVERLOADING
    TaskReturnBooleanMethodInfo             ,
#endif
    taskReturnBoolean                       ,


-- ** returnError #method:returnError#

#if ENABLE_OVERLOADING
    TaskReturnErrorMethodInfo               ,
#endif
    taskReturnError                         ,


-- ** returnErrorIfCancelled #method:returnErrorIfCancelled#

#if ENABLE_OVERLOADING
    TaskReturnErrorIfCancelledMethodInfo    ,
#endif
    taskReturnErrorIfCancelled              ,


-- ** returnInt #method:returnInt#

#if ENABLE_OVERLOADING
    TaskReturnIntMethodInfo                 ,
#endif
    taskReturnInt                           ,


-- ** returnPointer #method:returnPointer#

#if ENABLE_OVERLOADING
    TaskReturnPointerMethodInfo             ,
#endif
    taskReturnPointer                       ,


-- ** returnValue #method:returnValue#

#if ENABLE_OVERLOADING
    TaskReturnValueMethodInfo               ,
#endif
    taskReturnValue                         ,


-- ** runInThread #method:runInThread#

#if ENABLE_OVERLOADING
    TaskRunInThreadMethodInfo               ,
#endif
    taskRunInThread                         ,


-- ** runInThreadSync #method:runInThreadSync#

#if ENABLE_OVERLOADING
    TaskRunInThreadSyncMethodInfo           ,
#endif
    taskRunInThreadSync                     ,


-- ** setCheckCancellable #method:setCheckCancellable#

#if ENABLE_OVERLOADING
    TaskSetCheckCancellableMethodInfo       ,
#endif
    taskSetCheckCancellable                 ,


-- ** setName #method:setName#

#if ENABLE_OVERLOADING
    TaskSetNameMethodInfo                   ,
#endif
    taskSetName                             ,


-- ** setPriority #method:setPriority#

#if ENABLE_OVERLOADING
    TaskSetPriorityMethodInfo               ,
#endif
    taskSetPriority                         ,


-- ** setReturnOnCancel #method:setReturnOnCancel#

#if ENABLE_OVERLOADING
    TaskSetReturnOnCancelMethodInfo         ,
#endif
    taskSetReturnOnCancel                   ,


-- ** setSourceTag #method:setSourceTag#

#if ENABLE_OVERLOADING
    TaskSetSourceTagMethodInfo              ,
#endif
    taskSetSourceTag                        ,


-- ** setTaskData #method:setTaskData#

#if ENABLE_OVERLOADING
    TaskSetTaskDataMethodInfo               ,
#endif
    taskSetTaskData                         ,




 -- * Properties
-- ** completed #attr:completed#
{- | Whether the task has completed, meaning its callback (if set) has been
invoked. This can only happen after 'GI.Gio.Objects.Task.taskReturnPointer',
'GI.Gio.Objects.Task.taskReturnError' or one of the other return functions have been called
on the task.

This property is guaranteed to change from 'False' to 'True' exactly once.

The 'GI.GObject.Objects.Object.Object'::@/notify/@ signal for this change is emitted in the same main
context as the task’s callback, immediately after that callback is invoked.

/Since: 2.44/
-}
#if ENABLE_OVERLOADING
    TaskCompletedPropertyInfo               ,
#endif
    getTaskCompleted                        ,
#if ENABLE_OVERLOADING
    taskCompleted                           ,
#endif




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.MainContext as GLib.MainContext
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gio.Callbacks as Gio.Callbacks
import {-# SOURCE #-} qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable

-- | Memory-managed wrapper type.
newtype Task = Task (ManagedPtr Task)
foreign import ccall "g_task_get_type"
    c_g_task_get_type :: IO GType

instance GObject Task where
    gobjectType :: Task -> IO GType
gobjectType _ = IO GType
c_g_task_get_type
    

-- | Type class for types which can be safely cast to `Task`, for instance with `toTask`.
class GObject o => IsTask o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Task a) =>
    IsTask a
#endif
instance IsTask Task
instance GObject.Object.IsObject Task
instance Gio.AsyncResult.IsAsyncResult Task

-- | Cast to `Task`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toTask :: (MonadIO m, IsTask o) => o -> m Task
toTask :: o -> m Task
toTask = IO Task -> m Task
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Task -> m Task) -> (o -> IO Task) -> o -> m Task
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Task -> Task) -> o -> IO Task
forall o o'.
(HasCallStack, GObject o, GObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr Task -> Task
Task

-- | A convenience alias for `Nothing` :: `Maybe` `Task`.
noTask :: Maybe Task
noTask :: Maybe Task
noTask = Maybe Task
forall a. Maybe a
Nothing

#if ENABLE_OVERLOADING
type family ResolveTaskMethod (t :: Symbol) (o :: *) :: * where
    ResolveTaskMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTaskMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTaskMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTaskMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTaskMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveTaskMethod "hadError" o = TaskHadErrorMethodInfo
    ResolveTaskMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTaskMethod "isTagged" o = Gio.AsyncResult.AsyncResultIsTaggedMethodInfo
    ResolveTaskMethod "legacyPropagateError" o = Gio.AsyncResult.AsyncResultLegacyPropagateErrorMethodInfo
    ResolveTaskMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTaskMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTaskMethod "propagateBoolean" o = TaskPropagateBooleanMethodInfo
    ResolveTaskMethod "propagateInt" o = TaskPropagateIntMethodInfo
    ResolveTaskMethod "propagatePointer" o = TaskPropagatePointerMethodInfo
    ResolveTaskMethod "propagateValue" o = TaskPropagateValueMethodInfo
    ResolveTaskMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveTaskMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTaskMethod "returnBoolean" o = TaskReturnBooleanMethodInfo
    ResolveTaskMethod "returnError" o = TaskReturnErrorMethodInfo
    ResolveTaskMethod "returnErrorIfCancelled" o = TaskReturnErrorIfCancelledMethodInfo
    ResolveTaskMethod "returnInt" o = TaskReturnIntMethodInfo
    ResolveTaskMethod "returnPointer" o = TaskReturnPointerMethodInfo
    ResolveTaskMethod "returnValue" o = TaskReturnValueMethodInfo
    ResolveTaskMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTaskMethod "runInThread" o = TaskRunInThreadMethodInfo
    ResolveTaskMethod "runInThreadSync" o = TaskRunInThreadSyncMethodInfo
    ResolveTaskMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTaskMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTaskMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTaskMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveTaskMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTaskMethod "getCancellable" o = TaskGetCancellableMethodInfo
    ResolveTaskMethod "getCheckCancellable" o = TaskGetCheckCancellableMethodInfo
    ResolveTaskMethod "getCompleted" o = TaskGetCompletedMethodInfo
    ResolveTaskMethod "getContext" o = TaskGetContextMethodInfo
    ResolveTaskMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTaskMethod "getName" o = TaskGetNameMethodInfo
    ResolveTaskMethod "getPriority" o = TaskGetPriorityMethodInfo
    ResolveTaskMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTaskMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTaskMethod "getReturnOnCancel" o = TaskGetReturnOnCancelMethodInfo
    ResolveTaskMethod "getSourceObject" o = TaskGetSourceObjectMethodInfo
    ResolveTaskMethod "getSourceTag" o = TaskGetSourceTagMethodInfo
    ResolveTaskMethod "getTaskData" o = TaskGetTaskDataMethodInfo
    ResolveTaskMethod "getUserData" o = Gio.AsyncResult.AsyncResultGetUserDataMethodInfo
    ResolveTaskMethod "setCheckCancellable" o = TaskSetCheckCancellableMethodInfo
    ResolveTaskMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTaskMethod "setName" o = TaskSetNameMethodInfo
    ResolveTaskMethod "setPriority" o = TaskSetPriorityMethodInfo
    ResolveTaskMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTaskMethod "setReturnOnCancel" o = TaskSetReturnOnCancelMethodInfo
    ResolveTaskMethod "setSourceTag" o = TaskSetSourceTagMethodInfo
    ResolveTaskMethod "setTaskData" o = TaskSetTaskDataMethodInfo
    ResolveTaskMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTaskMethod t Task, O.MethodInfo info Task p) => O.IsLabelProxy t (Task -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveTaskMethod t Task, O.MethodInfo info Task p) => O.IsLabel t (Task -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif
#endif

#endif

-- VVV Prop "completed"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

{- |
Get the value of the “@completed@” property.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' task #completed
@
-}
getTaskCompleted :: (MonadIO m, IsTask o) => o -> m Bool
getTaskCompleted :: o -> m Bool
getTaskCompleted obj :: o
obj = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ o -> String -> IO Bool
forall a. GObject a => a -> String -> IO Bool
getObjectPropertyBool o
obj "completed"

#if ENABLE_OVERLOADING
data TaskCompletedPropertyInfo
instance AttrInfo TaskCompletedPropertyInfo where
    type AttrAllowedOps TaskCompletedPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint TaskCompletedPropertyInfo = (~) ()
    type AttrBaseTypeConstraint TaskCompletedPropertyInfo = IsTask
    type AttrGetType TaskCompletedPropertyInfo = Bool
    type AttrLabel TaskCompletedPropertyInfo = "completed"
    type AttrOrigin TaskCompletedPropertyInfo = Task
    attrGet _ = getTaskCompleted
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined
#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList Task
type instance O.AttributeList Task = TaskAttributeList
type TaskAttributeList = ('[ '("completed", TaskCompletedPropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
taskCompleted :: AttrLabelProxy "completed"
taskCompleted = AttrLabelProxy

#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Task = TaskSignalList
type TaskSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Task::new
-- method type : Constructor
-- Args : [Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GObject that owns\n  this task, or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional #GCancellable object, %NULL to ignore.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback.", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to @callback.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Task"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_task_new" g_task_new :: 
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- callback_data : TBasicType TPtr
    IO (Ptr Task)

{- |
Creates a 'GI.Gio.Objects.Task.Task' acting on /@sourceObject@/, which will eventually be
used to invoke /@callback@/ in the current
[thread-default main context][g-main-context-push-thread-default].

Call this in the \"start\" method of your asynchronous method, and
pass the 'GI.Gio.Objects.Task.Task' around throughout the asynchronous operation. You
can use 'GI.Gio.Objects.Task.taskSetTaskData' to attach task-specific data to the
object, which you can retrieve later via 'GI.Gio.Objects.Task.taskGetTaskData'.

By default, if /@cancellable@/ is cancelled, then the return value of
the task will always be 'GI.Gio.Enums.IOErrorEnumCancelled', even if the task had
already completed before the cancellation. This allows for
simplified handling in cases where cancellation may imply that
other objects that the task depends on have been destroyed. If you
do not want this behavior, you can use
'GI.Gio.Objects.Task.taskSetCheckCancellable' to change it.

/Since: 2.36/
-}
taskNew ::
    (B.CallStack.HasCallStack, MonadIO m, GObject.Object.IsObject a, Gio.Cancellable.IsCancellable b) =>
    Maybe (a)
    {- ^ /@sourceObject@/: the 'GI.GObject.Objects.Object.Object' that owns
  this task, or 'Nothing'. -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback'. -}
    -> m Task
    {- ^ __Returns:__ a 'GI.Gio.Objects.Task.Task'. -}
taskNew :: Maybe a -> Maybe b -> Maybe AsyncReadyCallback -> m Task
taskNew sourceObject :: Maybe a
sourceObject cancellable :: Maybe b
cancellable callback :: Maybe AsyncReadyCallback
callback = IO Task -> m Task
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Task -> m Task) -> IO Task -> m Task
forall a b. (a -> b) -> a -> b
$ do
    Ptr Object
maybeSourceObject <- case Maybe a
sourceObject of
        Nothing -> Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
forall a. Ptr a
nullPtr
        Just jSourceObject :: a
jSourceObject -> do
            Ptr Object
jSourceObject' <- a -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jSourceObject
            Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
jSourceObject'
    Ptr Cancellable
maybeCancellable <- case Maybe b
cancellable of
        Nothing -> Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
forall a. Ptr a
nullPtr
        Just jCancellable :: b
jCancellable -> do
            Ptr Cancellable
jCancellable' <- b -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jCancellable
            Ptr Cancellable -> IO (Ptr Cancellable)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Cancellable
jCancellable'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    let callbackData :: Ptr a
callbackData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Task
result <- Ptr Object
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO (Ptr Task)
g_task_new Ptr Object
maybeSourceObject Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
callbackData
    Text -> Ptr Task -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "taskNew" Ptr Task
result
    Task
result' <- ((ManagedPtr Task -> Task) -> Ptr Task -> IO Task
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Task -> Task
Task) Ptr Task
result
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
sourceObject a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
cancellable b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Task -> IO Task
forall (m :: * -> *) a. Monad m => a -> m a
return Task
result'

#if ENABLE_OVERLOADING
#endif

-- method Task::get_cancellable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Cancellable"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_cancellable" g_task_get_cancellable :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO (Ptr Gio.Cancellable.Cancellable)

{- |
Gets /@task@/\'s 'GI.Gio.Objects.Cancellable.Cancellable'

/Since: 2.36/
-}
taskGetCancellable ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m Gio.Cancellable.Cancellable
    {- ^ __Returns:__ /@task@/\'s 'GI.Gio.Objects.Cancellable.Cancellable' -}
taskGetCancellable :: a -> m Cancellable
taskGetCancellable task :: a
task = IO Cancellable -> m Cancellable
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Cancellable -> m Cancellable)
-> IO Cancellable -> m Cancellable
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr Cancellable
result <- Ptr Task -> IO (Ptr Cancellable)
g_task_get_cancellable Ptr Task
task'
    Text -> Ptr Cancellable -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "taskGetCancellable" Ptr Cancellable
result
    Cancellable
result' <- ((ManagedPtr Cancellable -> Cancellable)
-> Ptr Cancellable -> IO Cancellable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Cancellable -> Cancellable
Gio.Cancellable.Cancellable) Ptr Cancellable
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Cancellable -> IO Cancellable
forall (m :: * -> *) a. Monad m => a -> m a
return Cancellable
result'

#if ENABLE_OVERLOADING
data TaskGetCancellableMethodInfo
instance (signature ~ (m Gio.Cancellable.Cancellable), MonadIO m, IsTask a) => O.MethodInfo TaskGetCancellableMethodInfo a signature where
    overloadedMethod _ = taskGetCancellable

#endif

-- method Task::get_check_cancellable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_check_cancellable" g_task_get_check_cancellable :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CInt

{- |
Gets /@task@/\'s check-cancellable flag. See
'GI.Gio.Objects.Task.taskSetCheckCancellable' for more details.

/Since: 2.36/
-}
taskGetCheckCancellable ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> m Bool
taskGetCheckCancellable :: a -> m Bool
taskGetCheckCancellable task :: a
task = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CInt
result <- Ptr Task -> IO CInt
g_task_get_check_cancellable Ptr Task
task'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskGetCheckCancellableMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskGetCheckCancellableMethodInfo a signature where
    overloadedMethod _ = taskGetCheckCancellable

#endif

-- method Task::get_completed
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_completed" g_task_get_completed :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CInt

{- |
Gets the value of 'GI.Gio.Objects.Task.Task':@/completed/@. This changes from 'False' to 'True' after
the task’s callback is invoked, and will return 'False' if called from inside
the callback.

/Since: 2.44/
-}
taskGetCompleted ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the task has completed, 'False' otherwise. -}
taskGetCompleted :: a -> m Bool
taskGetCompleted task :: a
task = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CInt
result <- Ptr Task -> IO CInt
g_task_get_completed Ptr Task
task'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskGetCompletedMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskGetCompletedMethodInfo a signature where
    overloadedMethod _ = taskGetCompleted

#endif

-- method Task::get_context
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GLib", name = "MainContext"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_context" g_task_get_context :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO (Ptr GLib.MainContext.MainContext)

{- |
Gets the 'GI.GLib.Structs.MainContext.MainContext' that /@task@/ will return its result in (that
is, the context that was the
[thread-default main context][g-main-context-push-thread-default]
at the point when /@task@/ was created).

This will always return a non-'Nothing' value, even if the task\'s
context is the default 'GI.GLib.Structs.MainContext.MainContext'.

/Since: 2.36/
-}
taskGetContext ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m GLib.MainContext.MainContext
    {- ^ __Returns:__ /@task@/\'s 'GI.GLib.Structs.MainContext.MainContext' -}
taskGetContext :: a -> m MainContext
taskGetContext task :: a
task = IO MainContext -> m MainContext
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MainContext -> m MainContext)
-> IO MainContext -> m MainContext
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr MainContext
result <- Ptr Task -> IO (Ptr MainContext)
g_task_get_context Ptr Task
task'
    Text -> Ptr MainContext -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "taskGetContext" Ptr MainContext
result
    MainContext
result' <- ((ManagedPtr MainContext -> MainContext)
-> Ptr MainContext -> IO MainContext
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr MainContext -> MainContext
GLib.MainContext.MainContext) Ptr MainContext
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    MainContext -> IO MainContext
forall (m :: * -> *) a. Monad m => a -> m a
return MainContext
result'

#if ENABLE_OVERLOADING
data TaskGetContextMethodInfo
instance (signature ~ (m GLib.MainContext.MainContext), MonadIO m, IsTask a) => O.MethodInfo TaskGetContextMethodInfo a signature where
    overloadedMethod _ = taskGetContext

#endif

-- method Task::get_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_name" g_task_get_name :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CString

{- |
Gets /@task@/’s name. See 'GI.Gio.Objects.Task.taskSetName'.

/Since: 2.60/
-}
taskGetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ /@task@/’s name, or 'Nothing' -}
taskGetName :: a -> m (Maybe Text)
taskGetName task :: a
task = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CString
result <- Ptr Task -> IO CString
g_task_get_name Ptr Task
task'
    Maybe Text
maybeResult <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull CString
result ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \result' :: CString
result' -> do
        Text
result'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result'
        Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult

#if ENABLE_OVERLOADING
data TaskGetNameMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsTask a) => O.MethodInfo TaskGetNameMethodInfo a signature where
    overloadedMethod _ = taskGetName

#endif

-- method Task::get_priority
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_priority" g_task_get_priority :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO Int32

{- |
Gets /@task@/\'s priority

/Since: 2.36/
-}
taskGetPriority ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m Int32
    {- ^ __Returns:__ /@task@/\'s priority -}
taskGetPriority :: a -> m Int32
taskGetPriority task :: a
task = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Int32
result <- Ptr Task -> IO Int32
g_task_get_priority Ptr Task
task'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result

#if ENABLE_OVERLOADING
data TaskGetPriorityMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsTask a) => O.MethodInfo TaskGetPriorityMethodInfo a signature where
    overloadedMethod _ = taskGetPriority

#endif

-- method Task::get_return_on_cancel
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_return_on_cancel" g_task_get_return_on_cancel :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CInt

{- |
Gets /@task@/\'s return-on-cancel flag. See
'GI.Gio.Objects.Task.taskSetReturnOnCancel' for more details.

/Since: 2.36/
-}
taskGetReturnOnCancel ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> m Bool
taskGetReturnOnCancel :: a -> m Bool
taskGetReturnOnCancel task :: a
task = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CInt
result <- Ptr Task -> IO CInt
g_task_get_return_on_cancel Ptr Task
task'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskGetReturnOnCancelMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskGetReturnOnCancelMethodInfo a signature where
    overloadedMethod _ = taskGetReturnOnCancel

#endif

-- method Task::get_source_object
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GObject", name = "Object"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_source_object" g_task_get_source_object :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO (Ptr GObject.Object.Object)

{- |
Gets the source object from /@task@/. Like
'GI.Gio.Interfaces.AsyncResult.asyncResultGetSourceObject', but does not ref the object.

/Since: 2.36/
-}
taskGetSourceObject ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (Maybe GObject.Object.Object)
    {- ^ __Returns:__ /@task@/\'s source object, or 'Nothing' -}
taskGetSourceObject :: a -> m (Maybe Object)
taskGetSourceObject task :: a
task = IO (Maybe Object) -> m (Maybe Object)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Object) -> m (Maybe Object))
-> IO (Maybe Object) -> m (Maybe Object)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr Object
result <- Ptr Task -> IO (Ptr Object)
g_task_get_source_object Ptr Task
task'
    Maybe Object
maybeResult <- Ptr Object -> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Object
result ((Ptr Object -> IO Object) -> IO (Maybe Object))
-> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. (a -> b) -> a -> b
$ \result' :: Ptr Object
result' -> do
        Object
result'' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result'
        Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result''
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Maybe Object -> IO (Maybe Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Object
maybeResult

#if ENABLE_OVERLOADING
data TaskGetSourceObjectMethodInfo
instance (signature ~ (m (Maybe GObject.Object.Object)), MonadIO m, IsTask a) => O.MethodInfo TaskGetSourceObjectMethodInfo a signature where
    overloadedMethod _ = taskGetSourceObject

#endif

-- method Task::get_source_tag
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_source_tag" g_task_get_source_tag :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO (Ptr ())

{- |
Gets /@task@/\'s source tag. See 'GI.Gio.Objects.Task.taskSetSourceTag'.

/Since: 2.36/
-}
taskGetSourceTag ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (Ptr ())
    {- ^ __Returns:__ /@task@/\'s source tag -}
taskGetSourceTag :: a -> m (Ptr ())
taskGetSourceTag task :: a
task = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr ()
result <- Ptr Task -> IO (Ptr ())
g_task_get_source_tag Ptr Task
task'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result

#if ENABLE_OVERLOADING
data TaskGetSourceTagMethodInfo
instance (signature ~ (m (Ptr ())), MonadIO m, IsTask a) => O.MethodInfo TaskGetSourceTagMethodInfo a signature where
    overloadedMethod _ = taskGetSourceTag

#endif

-- method Task::get_task_data
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_get_task_data" g_task_get_task_data :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO (Ptr ())

{- |
Gets /@task@/\'s @task_data@.

/Since: 2.36/
-}
taskGetTaskData ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (Ptr ())
    {- ^ __Returns:__ /@task@/\'s @task_data@. -}
taskGetTaskData :: a -> m (Ptr ())
taskGetTaskData task :: a
task = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr ()
result <- Ptr Task -> IO (Ptr ())
g_task_get_task_data Ptr Task
task'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result

#if ENABLE_OVERLOADING
data TaskGetTaskDataMethodInfo
instance (signature ~ (m (Ptr ())), MonadIO m, IsTask a) => O.MethodInfo TaskGetTaskDataMethodInfo a signature where
    overloadedMethod _ = taskGetTaskData

#endif

-- method Task::had_error
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_had_error" g_task_had_error :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CInt

{- |
Tests if /@task@/ resulted in an error.

/Since: 2.36/
-}
taskHadError ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the task resulted in an error, 'False' otherwise. -}
taskHadError :: a -> m Bool
taskHadError task :: a
task = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CInt
result <- Ptr Task -> IO CInt
g_task_had_error Ptr Task
task'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskHadErrorMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskHadErrorMethodInfo a signature where
    overloadedMethod _ = taskHadError

#endif

-- method Task::propagate_boolean
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_task_propagate_boolean" g_task_propagate_boolean :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Gets the result of /@task@/ as a 'Bool'.

If the task resulted in an error, or was cancelled, then this will
instead return 'False' and set /@error@/.

Since this method transfers ownership of the return value (or
error) to the caller, you may only call it once.

/Since: 2.36/
-}
taskPropagateBoolean ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
taskPropagateBoolean :: a -> m ()
taskPropagateBoolean task :: a
task = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Task -> Ptr (Ptr GError) -> IO CInt
g_task_propagate_boolean Ptr Task
task'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data TaskPropagateBooleanMethodInfo
instance (signature ~ (m ()), MonadIO m, IsTask a) => O.MethodInfo TaskPropagateBooleanMethodInfo a signature where
    overloadedMethod _ = taskPropagateBoolean

#endif

-- method Task::propagate_int
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt64)
-- throws : True
-- Skip return : False

foreign import ccall "g_task_propagate_int" g_task_propagate_int :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr (Ptr GError) ->                     -- error
    IO Int64

{- |
Gets the result of /@task@/ as an integer (@/gssize/@).

If the task resulted in an error, or was cancelled, then this will
instead return -1 and set /@error@/.

Since this method transfers ownership of the return value (or
error) to the caller, you may only call it once.

/Since: 2.36/
-}
taskPropagateInt ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> m Int64
    {- ^ __Returns:__ the task result, or -1 on error /(Can throw 'Data.GI.Base.GError.GError')/ -}
taskPropagateInt :: a -> m Int64
taskPropagateInt task :: a
task = IO Int64 -> m Int64
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int64 -> m Int64) -> IO Int64 -> m Int64
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    IO Int64 -> IO () -> IO Int64
forall a b. IO a -> IO b -> IO a
onException (do
        Int64
result <- (Ptr (Ptr GError) -> IO Int64) -> IO Int64
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO Int64) -> IO Int64)
-> (Ptr (Ptr GError) -> IO Int64) -> IO Int64
forall a b. (a -> b) -> a -> b
$ Ptr Task -> Ptr (Ptr GError) -> IO Int64
g_task_propagate_int Ptr Task
task'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
        Int64 -> IO Int64
forall (m :: * -> *) a. Monad m => a -> m a
return Int64
result
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data TaskPropagateIntMethodInfo
instance (signature ~ (m Int64), MonadIO m, IsTask a) => O.MethodInfo TaskPropagateIntMethodInfo a signature where
    overloadedMethod _ = taskPropagateInt

#endif

-- method Task::propagate_pointer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TPtr)
-- throws : True
-- Skip return : False

foreign import ccall "g_task_propagate_pointer" g_task_propagate_pointer :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr ())

{- |
Gets the result of /@task@/ as a pointer, and transfers ownership
of that value to the caller.

If the task resulted in an error, or was cancelled, then this will
instead return 'Nothing' and set /@error@/.

Since this method transfers ownership of the return value (or
error) to the caller, you may only call it once.

/Since: 2.36/
-}
taskPropagatePointer ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (Ptr ())
    {- ^ __Returns:__ the task result, or 'Nothing' on error /(Can throw 'Data.GI.Base.GError.GError')/ -}
taskPropagatePointer :: a -> m (Ptr ())
taskPropagatePointer task :: a
task = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    IO (Ptr ()) -> IO () -> IO (Ptr ())
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr ()
result <- (Ptr (Ptr GError) -> IO (Ptr ())) -> IO (Ptr ())
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr ())) -> IO (Ptr ()))
-> (Ptr (Ptr GError) -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ Ptr Task -> Ptr (Ptr GError) -> IO (Ptr ())
g_task_propagate_pointer Ptr Task
task'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
        Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if ENABLE_OVERLOADING
data TaskPropagatePointerMethodInfo
instance (signature ~ (m (Ptr ())), MonadIO m, IsTask a) => O.MethodInfo TaskPropagatePointerMethodInfo a signature where
    overloadedMethod _ = taskPropagatePointer

#endif

-- method Task::propagate_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TInterface (Name {namespace = "GObject", name = "Value"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "return location for the #GValue", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = True, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_task_propagate_value" g_task_propagate_value :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr GValue ->                           -- value : TInterface (Name {namespace = "GObject", name = "Value"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Gets the result of /@task@/ as a 'GI.GObject.Structs.Value.Value', and transfers ownership of
that value to the caller. As with 'GI.Gio.Objects.Task.taskReturnValue', this is
a generic low-level method; 'GI.Gio.Objects.Task.taskPropagatePointer' and the like
will usually be more useful for C code.

If the task resulted in an error, or was cancelled, then this will
instead set /@error@/ and return 'False'.

Since this method transfers ownership of the return value (or
error) to the caller, you may only call it once.

/Since: 2.64/
-}
taskPropagateValue ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m (GValue)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
taskPropagateValue :: a -> m GValue
taskPropagateValue task :: a
task = IO GValue -> m GValue
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO GValue -> m GValue) -> IO GValue -> m GValue
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr GValue
value <- Int -> IO (Ptr GValue)
forall a. BoxedObject a => Int -> IO (Ptr a)
callocBoxedBytes 24 :: IO (Ptr GValue)
    IO GValue -> IO () -> IO GValue
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Task -> Ptr GValue -> Ptr (Ptr GError) -> IO CInt
g_task_propagate_value Ptr Task
task' Ptr GValue
value
        GValue
value' <- ((ManagedPtr GValue -> GValue) -> Ptr GValue -> IO GValue
forall a.
(HasCallStack, BoxedObject a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr GValue -> GValue
GValue) Ptr GValue
value
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
        GValue -> IO GValue
forall (m :: * -> *) a. Monad m => a -> m a
return GValue
value'
     ) (do
        Ptr GValue -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr GValue
value
     )

#if ENABLE_OVERLOADING
data TaskPropagateValueMethodInfo
instance (signature ~ (m (GValue)), MonadIO m, IsTask a) => O.MethodInfo TaskPropagateValueMethodInfo a signature where
    overloadedMethod _ = taskPropagateValue

#endif

-- method Task::return_boolean
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #gboolean result of a task function.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_boolean" g_task_return_boolean :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    CInt ->                                 -- result : TBasicType TBoolean
    IO ()

{- |
Sets /@task@/\'s result to /@result@/ and completes the task (see
'GI.Gio.Objects.Task.taskReturnPointer' for more discussion of exactly what this
means).

/Since: 2.36/
-}
taskReturnBoolean ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> Bool
    {- ^ /@result@/: the 'Bool' result of a task function. -}
    -> m ()
taskReturnBoolean :: a -> Bool -> m ()
taskReturnBoolean task :: a
task result_ :: Bool
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    let result_' :: CInt
result_' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
result_
    Ptr Task -> CInt -> IO ()
g_task_return_boolean Ptr Task
task' CInt
result_'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskReturnBooleanMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskReturnBooleanMethodInfo a signature where
    overloadedMethod _ = taskReturnBoolean

#endif

-- method Task::return_error
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "error", argType = TError, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GError result of a task function.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_error" g_task_return_error :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr GError ->                           -- error : TError
    IO ()

{- |
Sets /@task@/\'s result to /@error@/ (which /@task@/ assumes ownership of)
and completes the task (see 'GI.Gio.Objects.Task.taskReturnPointer' for more
discussion of exactly what this means).

Note that since the task takes ownership of /@error@/, and since the
task may be completed before returning from 'GI.Gio.Objects.Task.taskReturnError',
you cannot assume that /@error@/ is still valid after calling this.
Call 'GI.GLib.Structs.Error.errorCopy' on the error if you need to keep a local copy
as well.

See also @/g_task_return_new_error()/@.

/Since: 2.36/
-}
taskReturnError ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> GError
    {- ^ /@error@/: the 'GError' result of a task function. -}
    -> m ()
taskReturnError :: a -> GError -> m ()
taskReturnError task :: a
task error_ :: GError
error_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr GError
error_' <- GError -> IO (Ptr GError)
forall a. (HasCallStack, BoxedObject a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed GError
error_
    Ptr Task -> Ptr GError -> IO ()
g_task_return_error Ptr Task
task' Ptr GError
error_'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    GError -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GError
error_
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskReturnErrorMethodInfo
instance (signature ~ (GError -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskReturnErrorMethodInfo a signature where
    overloadedMethod _ = taskReturnError

#endif

-- method Task::return_error_if_cancelled
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_error_if_cancelled" g_task_return_error_if_cancelled :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    IO CInt

{- |
Checks if /@task@/\'s 'GI.Gio.Objects.Cancellable.Cancellable' has been cancelled, and if so, sets
/@task@/\'s error accordingly and completes the task (see
'GI.Gio.Objects.Task.taskReturnPointer' for more discussion of exactly what this
means).

/Since: 2.36/
-}
taskReturnErrorIfCancelled ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@task@/ has been cancelled, 'False' if not -}
taskReturnErrorIfCancelled :: a -> m Bool
taskReturnErrorIfCancelled task :: a
task = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CInt
result <- Ptr Task -> IO CInt
g_task_return_error_if_cancelled Ptr Task
task'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskReturnErrorIfCancelledMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskReturnErrorIfCancelledMethodInfo a signature where
    overloadedMethod _ = taskReturnErrorIfCancelled

#endif

-- method Task::return_int
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TBasicType TInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the integer (#gssize) result of a task function.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_int" g_task_return_int :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Int64 ->                                -- result : TBasicType TInt64
    IO ()

{- |
Sets /@task@/\'s result to /@result@/ and completes the task (see
'GI.Gio.Objects.Task.taskReturnPointer' for more discussion of exactly what this
means).

/Since: 2.36/
-}
taskReturnInt ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task'. -}
    -> Int64
    {- ^ /@result@/: the integer (@/gssize/@) result of a task function. -}
    -> m ()
taskReturnInt :: a -> Int64 -> m ()
taskReturnInt task :: a
task result_ :: Int64
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr Task -> Int64 -> IO ()
g_task_return_int Ptr Task
task' Int64
result_
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskReturnIntMethodInfo
instance (signature ~ (Int64 -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskReturnIntMethodInfo a signature where
    overloadedMethod _ = taskReturnInt

#endif

-- method Task::return_pointer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the pointer result of a task\n    function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "result_destroy", argType = TInterface (Name {namespace = "GLib", name = "DestroyNotify"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GDestroyNotify function.", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_pointer" g_task_return_pointer :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr () ->                               -- result : TBasicType TPtr
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- result_destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO ()

{- |
Sets /@task@/\'s result to /@result@/ and completes the task. If /@result@/
is not 'Nothing', then /@resultDestroy@/ will be used to free /@result@/ if
the caller does not take ownership of it with
'GI.Gio.Objects.Task.taskPropagatePointer'.

\"Completes the task\" means that for an ordinary asynchronous task
it will either invoke the task\'s callback, or else queue that
callback to be invoked in the proper 'GI.GLib.Structs.MainContext.MainContext', or in the next
iteration of the current 'GI.GLib.Structs.MainContext.MainContext'. For a task run via
'GI.Gio.Objects.Task.taskRunInThread' or 'GI.Gio.Objects.Task.taskRunInThreadSync', calling this
method will save /@result@/ to be returned to the caller later, but
the task will not actually be completed until the 'GI.Gio.Callbacks.TaskThreadFunc'
exits.

Note that since the task may be completed before returning from
'GI.Gio.Objects.Task.taskReturnPointer', you cannot assume that /@result@/ is still
valid after calling this, unless you are still holding another
reference on it.

/Since: 2.36/
-}
taskReturnPointer ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> Ptr ()
    {- ^ /@result@/: the pointer result of a task
    function -}
    -> Maybe (GLib.Callbacks.DestroyNotify)
    {- ^ /@resultDestroy@/: a 'GI.GLib.Callbacks.DestroyNotify' function. -}
    -> m ()
taskReturnPointer :: a -> Ptr () -> Maybe DestroyNotify -> m ()
taskReturnPointer task :: a
task result_ :: Ptr ()
result_ resultDestroy :: Maybe DestroyNotify
resultDestroy = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    FunPtr DestroyNotify
maybeResultDestroy <- case Maybe DestroyNotify
resultDestroy of
        Nothing -> FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr DestroyNotify
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jResultDestroy :: DestroyNotify
jResultDestroy -> do
            Ptr (FunPtr DestroyNotify)
ptrresultDestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
            FunPtr DestroyNotify
jResultDestroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrresultDestroy) DestroyNotify
jResultDestroy)
            Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrresultDestroy FunPtr DestroyNotify
jResultDestroy'
            FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr DestroyNotify
jResultDestroy'
    Ptr Task -> Ptr () -> FunPtr DestroyNotify -> IO ()
g_task_return_pointer Ptr Task
task' Ptr ()
result_ FunPtr DestroyNotify
maybeResultDestroy
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskReturnPointerMethodInfo
instance (signature ~ (Ptr () -> Maybe (GLib.Callbacks.DestroyNotify) -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskReturnPointerMethodInfo a signature where
    overloadedMethod _ = taskReturnPointer

#endif

-- method Task::return_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "GObject", name = "Value"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GValue result of\n                                     a task function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_return_value" g_task_return_value :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr GValue ->                           -- result : TInterface (Name {namespace = "GObject", name = "Value"})
    IO ()

{- |
Sets /@task@/\'s result to /@result@/ (by copying it) and completes the task.

If /@result@/ is 'Nothing' then a 'GI.GObject.Structs.Value.Value' of type @/G_TYPE_POINTER/@
with a value of 'Nothing' will be used for the result.

This is a very generic low-level method intended primarily for use
by language bindings; for C code, 'GI.Gio.Objects.Task.taskReturnPointer' and the
like will normally be much easier to use.

/Since: 2.64/
-}
taskReturnValue ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> Maybe (GValue)
    {- ^ /@result@/: the 'GI.GObject.Structs.Value.Value' result of
                                     a task function -}
    -> m ()
taskReturnValue :: a -> Maybe GValue -> m ()
taskReturnValue task :: a
task result_ :: Maybe GValue
result_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr GValue
maybeResult_ <- case Maybe GValue
result_ of
        Nothing -> Ptr GValue -> IO (Ptr GValue)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr GValue
forall a. Ptr a
nullPtr
        Just jResult_ :: GValue
jResult_ -> do
            Ptr GValue
jResult_' <- GValue -> IO (Ptr GValue)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr GValue
jResult_
            Ptr GValue -> IO (Ptr GValue)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr GValue
jResult_'
    Ptr Task -> Ptr GValue -> IO ()
g_task_return_value Ptr Task
task' Ptr GValue
maybeResult_
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Maybe GValue -> (GValue -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe GValue
result_ GValue -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskReturnValueMethodInfo
instance (signature ~ (Maybe (GValue) -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskReturnValueMethodInfo a signature where
    overloadedMethod _ = taskReturnValue

#endif

-- method Task::run_in_thread
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "task_func", argType = TInterface (Name {namespace = "Gio", name = "TaskThreadFunc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTaskThreadFunc", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_run_in_thread" g_task_run_in_thread :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    FunPtr Gio.Callbacks.C_TaskThreadFunc -> -- task_func : TInterface (Name {namespace = "Gio", name = "TaskThreadFunc"})
    IO ()

{- |
Runs /@taskFunc@/ in another thread. When /@taskFunc@/ returns, /@task@/\'s
'GI.Gio.Callbacks.AsyncReadyCallback' will be invoked in /@task@/\'s 'GI.GLib.Structs.MainContext.MainContext'.

This takes a ref on /@task@/ until the task completes.

See 'GI.Gio.Callbacks.TaskThreadFunc' for more details about how /@taskFunc@/ is handled.

Although GLib currently rate-limits the tasks queued via
'GI.Gio.Objects.Task.taskRunInThread', you should not assume that it will always
do this. If you have a very large number of tasks to run, but don\'t
want them to all run at once, you should only queue a limited
number of them at a time.

/Since: 2.36/
-}
taskRunInThread ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> Gio.Callbacks.TaskThreadFunc
    {- ^ /@taskFunc@/: a 'GI.Gio.Callbacks.TaskThreadFunc' -}
    -> m ()
taskRunInThread :: a -> TaskThreadFunc -> m ()
taskRunInThread task :: a
task taskFunc :: TaskThreadFunc
taskFunc = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc <- IO (Ptr (FunPtr C_TaskThreadFunc))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_TaskThreadFunc))
    FunPtr C_TaskThreadFunc
taskFunc' <- C_TaskThreadFunc -> IO (FunPtr C_TaskThreadFunc)
Gio.Callbacks.mk_TaskThreadFunc (Maybe (Ptr (FunPtr C_TaskThreadFunc))
-> TaskThreadFunc -> C_TaskThreadFunc
Gio.Callbacks.wrap_TaskThreadFunc (Ptr (FunPtr C_TaskThreadFunc)
-> Maybe (Ptr (FunPtr C_TaskThreadFunc))
forall a. a -> Maybe a
Just Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc) TaskThreadFunc
taskFunc)
    Ptr (FunPtr C_TaskThreadFunc) -> FunPtr C_TaskThreadFunc -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc FunPtr C_TaskThreadFunc
taskFunc'
    Ptr Task -> FunPtr C_TaskThreadFunc -> IO ()
g_task_run_in_thread Ptr Task
task' FunPtr C_TaskThreadFunc
taskFunc'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskRunInThreadMethodInfo
instance (signature ~ (Gio.Callbacks.TaskThreadFunc -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskRunInThreadMethodInfo a signature where
    overloadedMethod _ = taskRunInThread

#endif

-- method Task::run_in_thread_sync
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "task_func", argType = TInterface (Name {namespace = "Gio", name = "TaskThreadFunc"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTaskThreadFunc", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_run_in_thread_sync" g_task_run_in_thread_sync :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    FunPtr Gio.Callbacks.C_TaskThreadFunc -> -- task_func : TInterface (Name {namespace = "Gio", name = "TaskThreadFunc"})
    IO ()

{- |
Runs /@taskFunc@/ in another thread, and waits for it to return or be
cancelled. You can use 'GI.Gio.Objects.Task.taskPropagatePointer', etc, afterward
to get the result of /@taskFunc@/.

See 'GI.Gio.Callbacks.TaskThreadFunc' for more details about how /@taskFunc@/ is handled.

Normally this is used with tasks created with a 'Nothing'
@callback@, but note that even if the task does
have a callback, it will not be invoked when /@taskFunc@/ returns.
'GI.Gio.Objects.Task.Task':@/completed/@ will be set to 'True' just before this function returns.

Although GLib currently rate-limits the tasks queued via
'GI.Gio.Objects.Task.taskRunInThreadSync', you should not assume that it will
always do this. If you have a very large number of tasks to run,
but don\'t want them to all run at once, you should only queue a
limited number of them at a time.

/Since: 2.36/
-}
taskRunInThreadSync ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> Gio.Callbacks.TaskThreadFunc
    {- ^ /@taskFunc@/: a 'GI.Gio.Callbacks.TaskThreadFunc' -}
    -> m ()
taskRunInThreadSync :: a -> TaskThreadFunc -> m ()
taskRunInThreadSync task :: a
task taskFunc :: TaskThreadFunc
taskFunc = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc <- IO (Ptr (FunPtr C_TaskThreadFunc))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_TaskThreadFunc))
    FunPtr C_TaskThreadFunc
taskFunc' <- C_TaskThreadFunc -> IO (FunPtr C_TaskThreadFunc)
Gio.Callbacks.mk_TaskThreadFunc (Maybe (Ptr (FunPtr C_TaskThreadFunc))
-> TaskThreadFunc -> C_TaskThreadFunc
Gio.Callbacks.wrap_TaskThreadFunc (Ptr (FunPtr C_TaskThreadFunc)
-> Maybe (Ptr (FunPtr C_TaskThreadFunc))
forall a. a -> Maybe a
Just Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc) TaskThreadFunc
taskFunc)
    Ptr (FunPtr C_TaskThreadFunc) -> FunPtr C_TaskThreadFunc -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_TaskThreadFunc)
ptrtaskFunc FunPtr C_TaskThreadFunc
taskFunc'
    Ptr Task -> FunPtr C_TaskThreadFunc -> IO ()
g_task_run_in_thread_sync Ptr Task
task' FunPtr C_TaskThreadFunc
taskFunc'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskRunInThreadSyncMethodInfo
instance (signature ~ (Gio.Callbacks.TaskThreadFunc -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskRunInThreadSyncMethodInfo a signature where
    overloadedMethod _ = taskRunInThreadSync

#endif

-- method Task::set_check_cancellable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "check_cancellable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether #GTask will check the state of\n  its #GCancellable for you.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_check_cancellable" g_task_set_check_cancellable :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    CInt ->                                 -- check_cancellable : TBasicType TBoolean
    IO ()

{- |
Sets or clears /@task@/\'s check-cancellable flag. If this is 'True'
(the default), then 'GI.Gio.Objects.Task.taskPropagatePointer', etc, and
'GI.Gio.Objects.Task.taskHadError' will check the task\'s 'GI.Gio.Objects.Cancellable.Cancellable' first, and
if it has been cancelled, then they will consider the task to have
returned an \"Operation was cancelled\" error
('GI.Gio.Enums.IOErrorEnumCancelled'), regardless of any other error or return
value the task may have had.

If /@checkCancellable@/ is 'False', then the 'GI.Gio.Objects.Task.Task' will not check the
cancellable itself, and it is up to /@task@/\'s owner to do this (eg,
via 'GI.Gio.Objects.Task.taskReturnErrorIfCancelled').

If you are using 'GI.Gio.Objects.Task.taskSetReturnOnCancel' as well, then
you must leave check-cancellable set 'True'.

/Since: 2.36/
-}
taskSetCheckCancellable ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> Bool
    {- ^ /@checkCancellable@/: whether 'GI.Gio.Objects.Task.Task' will check the state of
  its 'GI.Gio.Objects.Cancellable.Cancellable' for you. -}
    -> m ()
taskSetCheckCancellable :: a -> Bool -> m ()
taskSetCheckCancellable task :: a
task checkCancellable :: Bool
checkCancellable = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    let checkCancellable' :: CInt
checkCancellable' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
checkCancellable
    Ptr Task -> CInt -> IO ()
g_task_set_check_cancellable Ptr Task
task' CInt
checkCancellable'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskSetCheckCancellableMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskSetCheckCancellableMethodInfo a signature where
    overloadedMethod _ = taskSetCheckCancellable

#endif

-- method Task::set_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a human readable name for the task, or %NULL to unset it", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_name" g_task_set_name :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    CString ->                              -- name : TBasicType TUTF8
    IO ()

{- |
Sets /@task@/’s name, used in debugging and profiling. The name defaults to
'Nothing'.

The task name should describe in a human readable way what the task does.
For example, ‘Open file’ or ‘Connect to network host’. It is used to set the
name of the 'GI.GLib.Structs.Source.Source' used for idle completion of the task.

This function may only be called before the /@task@/ is first used in a thread
other than the one it was constructed in.

/Since: 2.60/
-}
taskSetName ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: a 'GI.Gio.Objects.Task.Task' -}
    -> Maybe (T.Text)
    {- ^ /@name@/: a human readable name for the task, or 'Nothing' to unset it -}
    -> m ()
taskSetName :: a -> Maybe Text -> m ()
taskSetName task :: a
task name :: Maybe Text
name = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    CString
maybeName <- case Maybe Text
name of
        Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
        Just jName :: Text
jName -> do
            CString
jName' <- Text -> IO CString
textToCString Text
jName
            CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
jName'
    Ptr Task -> CString -> IO ()
g_task_set_name Ptr Task
task' CString
maybeName
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeName
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskSetNameMethodInfo
instance (signature ~ (Maybe (T.Text) -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskSetNameMethodInfo a signature where
    overloadedMethod _ = taskSetName

#endif

-- method Task::set_priority
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "priority", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the [priority][io-priority] of the request", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_priority" g_task_set_priority :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Int32 ->                                -- priority : TBasicType TInt
    IO ()

{- |
Sets /@task@/\'s priority. If you do not call this, it will default to
'GI.GLib.Constants.PRIORITY_DEFAULT'.

This will affect the priority of @/GSources/@ created with
@/g_task_attach_source()/@ and the scheduling of tasks run in threads,
and can also be explicitly retrieved later via
'GI.Gio.Objects.Task.taskGetPriority'.

/Since: 2.36/
-}
taskSetPriority ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> Int32
    {- ^ /@priority@/: the [priority][io-priority] of the request -}
    -> m ()
taskSetPriority :: a -> Int32 -> m ()
taskSetPriority task :: a
task priority :: Int32
priority = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr Task -> Int32 -> IO ()
g_task_set_priority Ptr Task
task' Int32
priority
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskSetPriorityMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskSetPriorityMethodInfo a signature where
    overloadedMethod _ = taskSetPriority

#endif

-- method Task::set_return_on_cancel
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "return_on_cancel", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether the task returns automatically when\n  it is cancelled.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_return_on_cancel" g_task_set_return_on_cancel :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    CInt ->                                 -- return_on_cancel : TBasicType TBoolean
    IO CInt

{- |
Sets or clears /@task@/\'s return-on-cancel flag. This is only
meaningful for tasks run via 'GI.Gio.Objects.Task.taskRunInThread' or
'GI.Gio.Objects.Task.taskRunInThreadSync'.

If /@returnOnCancel@/ is 'True', then cancelling /@task@/\'s
'GI.Gio.Objects.Cancellable.Cancellable' will immediately cause it to return, as though the
task\'s 'GI.Gio.Callbacks.TaskThreadFunc' had called
'GI.Gio.Objects.Task.taskReturnErrorIfCancelled' and then returned.

This allows you to create a cancellable wrapper around an
uninterruptable function. The 'GI.Gio.Callbacks.TaskThreadFunc' just needs to be
careful that it does not modify any externally-visible state after
it has been cancelled. To do that, the thread should call
'GI.Gio.Objects.Task.taskSetReturnOnCancel' again to (atomically) set
return-on-cancel 'False' before making externally-visible changes;
if the task gets cancelled before the return-on-cancel flag could
be changed, 'GI.Gio.Objects.Task.taskSetReturnOnCancel' will indicate this by
returning 'False'.

You can disable and re-enable this flag multiple times if you wish.
If the task\'s 'GI.Gio.Objects.Cancellable.Cancellable' is cancelled while return-on-cancel is
'False', then calling 'GI.Gio.Objects.Task.taskSetReturnOnCancel' to set it 'True'
again will cause the task to be cancelled at that point.

If the task\'s 'GI.Gio.Objects.Cancellable.Cancellable' is already cancelled before you call
'GI.Gio.Objects.Task.taskRunInThread'\/'GI.Gio.Objects.Task.taskRunInThreadSync', then the
'GI.Gio.Callbacks.TaskThreadFunc' will still be run (for consistency), but the task
will also be completed right away.

/Since: 2.36/
-}
taskSetReturnOnCancel ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> Bool
    {- ^ /@returnOnCancel@/: whether the task returns automatically when
  it is cancelled. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@task@/\'s return-on-cancel flag was changed to
  match /@returnOnCancel@/. 'False' if /@task@/ has already been
  cancelled. -}
taskSetReturnOnCancel :: a -> Bool -> m Bool
taskSetReturnOnCancel task :: a
task returnOnCancel :: Bool
returnOnCancel = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    let returnOnCancel' :: CInt
returnOnCancel' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
returnOnCancel
    CInt
result <- Ptr Task -> CInt -> IO CInt
g_task_set_return_on_cancel Ptr Task
task' CInt
returnOnCancel'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
data TaskSetReturnOnCancelMethodInfo
instance (signature ~ (Bool -> m Bool), MonadIO m, IsTask a) => O.MethodInfo TaskSetReturnOnCancelMethodInfo a signature where
    overloadedMethod _ = taskSetReturnOnCancel

#endif

-- method Task::set_source_tag
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_tag", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "an opaque pointer indicating the source of this task", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_source_tag" g_task_set_source_tag :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr () ->                               -- source_tag : TBasicType TPtr
    IO ()

{- |
Sets /@task@/\'s source tag. You can use this to tag a task return
value with a particular pointer (usually a pointer to the function
doing the tagging) and then later check it using
'GI.Gio.Objects.Task.taskGetSourceTag' (or 'GI.Gio.Interfaces.AsyncResult.asyncResultIsTagged') in the
task\'s \"finish\" function, to figure out if the response came from a
particular place.

/Since: 2.36/
-}
taskSetSourceTag ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> Ptr ()
    {- ^ /@sourceTag@/: an opaque pointer indicating the source of this task -}
    -> m ()
taskSetSourceTag :: a -> Ptr () -> m ()
taskSetSourceTag task :: a
task sourceTag :: Ptr ()
sourceTag = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    Ptr Task -> DestroyNotify
g_task_set_source_tag Ptr Task
task' Ptr ()
sourceTag
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskSetSourceTagMethodInfo
instance (signature ~ (Ptr () -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskSetSourceTagMethodInfo a signature where
    overloadedMethod _ = taskSetSourceTag

#endif

-- method Task::set_task_data
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "task", argType = TInterface (Name {namespace = "Gio", name = "Task"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the #GTask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "task_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "task-specific data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "task_data_destroy", argType = TInterface (Name {namespace = "GLib", name = "DestroyNotify"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "#GDestroyNotify for @task_data", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_set_task_data" g_task_set_task_data :: 
    Ptr Task ->                             -- task : TInterface (Name {namespace = "Gio", name = "Task"})
    Ptr () ->                               -- task_data : TBasicType TPtr
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- task_data_destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO ()

{- |
Sets /@task@/\'s task data (freeing the existing task data, if any).

/Since: 2.36/
-}
taskSetTaskData ::
    (B.CallStack.HasCallStack, MonadIO m, IsTask a) =>
    a
    {- ^ /@task@/: the 'GI.Gio.Objects.Task.Task' -}
    -> Ptr ()
    {- ^ /@taskData@/: task-specific data -}
    -> Maybe (GLib.Callbacks.DestroyNotify)
    {- ^ /@taskDataDestroy@/: 'GI.GLib.Callbacks.DestroyNotify' for /@taskData@/ -}
    -> m ()
taskSetTaskData :: a -> Ptr () -> Maybe DestroyNotify -> m ()
taskSetTaskData task :: a
task taskData :: Ptr ()
taskData taskDataDestroy :: Maybe DestroyNotify
taskDataDestroy = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Task
task' <- a -> IO (Ptr Task)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
task
    FunPtr DestroyNotify
maybeTaskDataDestroy <- case Maybe DestroyNotify
taskDataDestroy of
        Nothing -> FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr DestroyNotify
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jTaskDataDestroy :: DestroyNotify
jTaskDataDestroy -> do
            Ptr (FunPtr DestroyNotify)
ptrtaskDataDestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
            FunPtr DestroyNotify
jTaskDataDestroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrtaskDataDestroy) DestroyNotify
jTaskDataDestroy)
            Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrtaskDataDestroy FunPtr DestroyNotify
jTaskDataDestroy'
            FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr DestroyNotify
jTaskDataDestroy'
    Ptr Task -> Ptr () -> FunPtr DestroyNotify -> IO ()
g_task_set_task_data Ptr Task
task' Ptr ()
taskData FunPtr DestroyNotify
maybeTaskDataDestroy
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
task
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
data TaskSetTaskDataMethodInfo
instance (signature ~ (Ptr () -> Maybe (GLib.Callbacks.DestroyNotify) -> m ()), MonadIO m, IsTask a) => O.MethodInfo TaskSetTaskDataMethodInfo a signature where
    overloadedMethod _ = taskSetTaskData

#endif

-- method Task::is_valid
-- method type : MemberFunction
-- Args : [Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GAsyncResult", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the source object\n  expected to be associated with the task", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "g_task_is_valid" g_task_is_valid :: 
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    IO CInt

{- |
Checks that /@result@/ is a 'GI.Gio.Objects.Task.Task', and that /@sourceObject@/ is its
source object (or that /@sourceObject@/ is 'Nothing' and /@result@/ has no
source object). This can be used in @/g_return_if_fail()/@ checks.

/Since: 2.36/
-}
taskIsValid ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.AsyncResult.IsAsyncResult a, GObject.Object.IsObject b) =>
    a
    {- ^ /@result@/: A 'GI.Gio.Interfaces.AsyncResult.AsyncResult' -}
    -> Maybe (b)
    {- ^ /@sourceObject@/: the source object
  expected to be associated with the task -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@result@/ and /@sourceObject@/ are valid, 'False'
if not -}
taskIsValid :: a -> Maybe b -> m Bool
taskIsValid result_ :: a
result_ sourceObject :: Maybe b
sourceObject = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    Ptr AsyncResult
result_' <- a -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
result_
    Ptr Object
maybeSourceObject <- case Maybe b
sourceObject of
        Nothing -> Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
forall a. Ptr a
nullPtr
        Just jSourceObject :: b
jSourceObject -> do
            Ptr Object
jSourceObject' <- b -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jSourceObject
            Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
jSourceObject'
    CInt
result <- Ptr AsyncResult -> Ptr Object -> IO CInt
g_task_is_valid Ptr AsyncResult
result_' Ptr Object
maybeSourceObject
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= 0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
result_
    Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
sourceObject b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'

#if ENABLE_OVERLOADING
#endif

-- method Task::report_error
-- method type : MemberFunction
-- Args : [Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the #GObject that owns\n  this task, or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback.", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 2, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "user data passed to @callback.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_tag", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "an opaque pointer indicating the source of this task", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "error", argType = TError, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "error to report", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_task_report_error" g_task_report_error :: 
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- callback_data : TBasicType TPtr
    Ptr () ->                               -- source_tag : TBasicType TPtr
    Ptr GError ->                           -- error : TError
    IO ()

{- |
Creates a 'GI.Gio.Objects.Task.Task' and then immediately calls 'GI.Gio.Objects.Task.taskReturnError'
on it. Use this in the wrapper function of an asynchronous method
when you want to avoid even calling the virtual method. You can
then use 'GI.Gio.Interfaces.AsyncResult.asyncResultIsTagged' in the finish method wrapper to
check if the result there is tagged as having been created by the
wrapper method, and deal with it appropriately if so.

See also @/g_task_report_new_error()/@.

/Since: 2.36/
-}
taskReportError ::
    (B.CallStack.HasCallStack, MonadIO m, GObject.Object.IsObject a) =>
    Maybe (a)
    {- ^ /@sourceObject@/: the 'GI.GObject.Objects.Object.Object' that owns
  this task, or 'Nothing'. -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback'. -}
    -> Ptr ()
    {- ^ /@sourceTag@/: an opaque pointer indicating the source of this task -}
    -> GError
    {- ^ /@error@/: error to report -}
    -> m ()
taskReportError :: Maybe a -> Maybe AsyncReadyCallback -> Ptr () -> GError -> m ()
taskReportError sourceObject :: Maybe a
sourceObject callback :: Maybe AsyncReadyCallback
callback sourceTag :: Ptr ()
sourceTag error_ :: GError
error_ = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Object
maybeSourceObject <- case Maybe a
sourceObject of
        Nothing -> Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
forall a. Ptr a
nullPtr
        Just jSourceObject :: a
jSourceObject -> do
            Ptr Object
jSourceObject' <- a -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jSourceObject
            Ptr Object -> IO (Ptr Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Object
jSourceObject'
    FunPtr C_AsyncReadyCallback
maybeCallback <- case Maybe AsyncReadyCallback
callback of
        Nothing -> FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr C_AsyncReadyCallback
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just jCallback :: AsyncReadyCallback
jCallback -> do
            Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback <- IO (Ptr (FunPtr C_AsyncReadyCallback))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
            FunPtr C_AsyncReadyCallback
jCallback' <- C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
Gio.Callbacks.mk_AsyncReadyCallback (Maybe (Ptr (FunPtr C_AsyncReadyCallback))
-> AsyncReadyCallback_WithClosures -> C_AsyncReadyCallback
Gio.Callbacks.wrap_AsyncReadyCallback (Ptr (FunPtr C_AsyncReadyCallback)
-> Maybe (Ptr (FunPtr C_AsyncReadyCallback))
forall a. a -> Maybe a
Just Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback) (AsyncReadyCallback -> AsyncReadyCallback_WithClosures
Gio.Callbacks.drop_closures_AsyncReadyCallback AsyncReadyCallback
jCallback))
            Ptr (FunPtr C_AsyncReadyCallback)
-> FunPtr C_AsyncReadyCallback -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr C_AsyncReadyCallback)
ptrcallback FunPtr C_AsyncReadyCallback
jCallback'
            FunPtr C_AsyncReadyCallback -> IO (FunPtr C_AsyncReadyCallback)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr C_AsyncReadyCallback
jCallback'
    Ptr GError
error_' <- GError -> IO (Ptr GError)
forall a. (HasCallStack, BoxedObject a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed GError
error_
    let callbackData :: Ptr a
callbackData = Ptr a
forall a. Ptr a
nullPtr
    Ptr Object
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> Ptr ()
-> Ptr GError
-> IO ()
g_task_report_error Ptr Object
maybeSourceObject FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
callbackData Ptr ()
sourceTag Ptr GError
error_'
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
sourceObject a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    GError -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GError
error_
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if ENABLE_OVERLOADING
#endif