{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- This is the asynchronous version of t'GI.Gio.Interfaces.Initable.Initable'; it behaves the same
-- in all ways except that initialization is asynchronous. For more details
-- see the descriptions on t'GI.Gio.Interfaces.Initable.Initable'.
-- 
-- A class may implement both the t'GI.Gio.Interfaces.Initable.Initable' and t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable' interfaces.
-- 
-- Users of objects implementing this are not intended to use the interface
-- method directly; instead it will be used automatically in various ways.
-- For C applications you generally just call @/g_async_initable_new_async()/@
-- directly, or indirectly via a @/foo_thing_new_async()/@ wrapper. This will call
-- 'GI.Gio.Interfaces.AsyncInitable.asyncInitableInitAsync' under the cover, calling back with 'P.Nothing' and
-- a set @/GError/@ on failure.
-- 
-- A typical implementation might look something like this:
-- 
-- 
-- === /C code/
-- >
-- >enum {
-- >   NOT_INITIALIZED,
-- >   INITIALIZING,
-- >   INITIALIZED
-- >};
-- >
-- >static void
-- >_foo_ready_cb (Foo *self)
-- >{
-- >  GList *l;
-- >
-- >  self->priv->state = INITIALIZED;
-- >
-- >  for (l = self->priv->init_results; l != NULL; l = l->next)
-- >    {
-- >      GTask *task = l->data;
-- >
-- >      if (self->priv->success)
-- >        g_task_return_boolean (task, TRUE);
-- >      else
-- >        g_task_return_new_error (task, ...);
-- >      g_object_unref (task);
-- >    }
-- >
-- >  g_list_free (self->priv->init_results);
-- >  self->priv->init_results = NULL;
-- >}
-- >
-- >static void
-- >foo_init_async (GAsyncInitable       *initable,
-- >                int                   io_priority,
-- >                GCancellable         *cancellable,
-- >                GAsyncReadyCallback   callback,
-- >                gpointer              user_data)
-- >{
-- >  Foo *self = FOO (initable);
-- >  GTask *task;
-- >
-- >  task = g_task_new (initable, cancellable, callback, user_data);
-- >
-- >  switch (self->priv->state)
-- >    {
-- >      case NOT_INITIALIZED:
-- >        _foo_get_ready (self);
-- >        self->priv->init_results = g_list_append (self->priv->init_results,
-- >                                                  task);
-- >        self->priv->state = INITIALIZING;
-- >        break;
-- >      case INITIALIZING:
-- >        self->priv->init_results = g_list_append (self->priv->init_results,
-- >                                                  task);
-- >        break;
-- >      case INITIALIZED:
-- >        if (!self->priv->success)
-- >          g_task_return_new_error (task, ...);
-- >        else
-- >          g_task_return_boolean (task, TRUE);
-- >        g_object_unref (task);
-- >        break;
-- >    }
-- >}
-- >
-- >static gboolean
-- >foo_init_finish (GAsyncInitable       *initable,
-- >                 GAsyncResult         *result,
-- >                 GError              **error)
-- >{
-- >  g_return_val_if_fail (g_task_is_valid (result, initable), FALSE);
-- >
-- >  return g_task_propagate_boolean (G_TASK (result), error);
-- >}
-- >
-- >static void
-- >foo_async_initable_iface_init (gpointer g_iface,
-- >                               gpointer data)
-- >{
-- >  GAsyncInitableIface *iface = g_iface;
-- >
-- >  iface->init_async = foo_init_async;
-- >  iface->init_finish = foo_init_finish;
-- >}
-- 
-- 
-- /Since: 2.22/

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Gio.Interfaces.AsyncInitable
    ( 

-- * Exported types
    AsyncInitable(..)                       ,
    noAsyncInitable                         ,
    IsAsyncInitable                         ,
    toAsyncInitable                         ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveAsyncInitableMethod              ,
#endif


-- ** initAsync #method:initAsync#

#if defined(ENABLE_OVERLOADING)
    AsyncInitableInitAsyncMethodInfo        ,
#endif
    asyncInitableInitAsync                  ,


-- ** initFinish #method:initFinish#

#if defined(ENABLE_OVERLOADING)
    AsyncInitableInitFinishMethodInfo       ,
#endif
    asyncInitableInitFinish                 ,


-- ** newFinish #method:newFinish#

#if defined(ENABLE_OVERLOADING)
    AsyncInitableNewFinishMethodInfo        ,
#endif
    asyncInitableNewFinish                  ,


-- ** newvAsync #method:newvAsync#

    asyncInitableNewvAsync                  ,




    ) 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.GClosure as B.GClosure
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.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
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 GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.GObject.Structs.Parameter as GObject.Parameter
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

-- interface AsyncInitable 
-- | Memory-managed wrapper type.
newtype AsyncInitable = AsyncInitable (ManagedPtr AsyncInitable)
    deriving (AsyncInitable -> AsyncInitable -> Bool
(AsyncInitable -> AsyncInitable -> Bool)
-> (AsyncInitable -> AsyncInitable -> Bool) -> Eq AsyncInitable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AsyncInitable -> AsyncInitable -> Bool
$c/= :: AsyncInitable -> AsyncInitable -> Bool
== :: AsyncInitable -> AsyncInitable -> Bool
$c== :: AsyncInitable -> AsyncInitable -> Bool
Eq)
-- | A convenience alias for `Nothing` :: `Maybe` `AsyncInitable`.
noAsyncInitable :: Maybe AsyncInitable
noAsyncInitable :: Maybe AsyncInitable
noAsyncInitable = Maybe AsyncInitable
forall a. Maybe a
Nothing

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

#endif

foreign import ccall "g_async_initable_get_type"
    c_g_async_initable_get_type :: IO GType

instance GObject AsyncInitable where
    gobjectType :: IO GType
gobjectType = IO GType
c_g_async_initable_get_type
    

-- | Convert 'AsyncInitable' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue AsyncInitable where
    toGValue :: AsyncInitable -> IO GValue
toGValue o :: AsyncInitable
o = do
        GType
gtype <- IO GType
c_g_async_initable_get_type
        AsyncInitable -> (Ptr AsyncInitable -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr AsyncInitable
o (GType
-> (GValue -> Ptr AsyncInitable -> IO ())
-> Ptr AsyncInitable
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr AsyncInitable -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO AsyncInitable
fromGValue gv :: GValue
gv = do
        Ptr AsyncInitable
ptr <- GValue -> IO (Ptr AsyncInitable)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr AsyncInitable)
        (ManagedPtr AsyncInitable -> AsyncInitable)
-> Ptr AsyncInitable -> IO AsyncInitable
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr AsyncInitable -> AsyncInitable
AsyncInitable Ptr AsyncInitable
ptr
        
    

-- | Type class for types which can be safely cast to `AsyncInitable`, for instance with `toAsyncInitable`.
class (GObject o, O.IsDescendantOf AsyncInitable o) => IsAsyncInitable o
instance (GObject o, O.IsDescendantOf AsyncInitable o) => IsAsyncInitable o

instance O.HasParentTypes AsyncInitable
type instance O.ParentTypes AsyncInitable = '[GObject.Object.Object]

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

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList AsyncInitable
type instance O.AttributeList AsyncInitable = AsyncInitableAttributeList
type AsyncInitableAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveAsyncInitableMethod (t :: Symbol) (o :: *) :: * where
    ResolveAsyncInitableMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAsyncInitableMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAsyncInitableMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAsyncInitableMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAsyncInitableMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAsyncInitableMethod "initAsync" o = AsyncInitableInitAsyncMethodInfo
    ResolveAsyncInitableMethod "initFinish" o = AsyncInitableInitFinishMethodInfo
    ResolveAsyncInitableMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAsyncInitableMethod "newFinish" o = AsyncInitableNewFinishMethodInfo
    ResolveAsyncInitableMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAsyncInitableMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAsyncInitableMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAsyncInitableMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAsyncInitableMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAsyncInitableMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAsyncInitableMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAsyncInitableMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAsyncInitableMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAsyncInitableMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAsyncInitableMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAsyncInitableMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAsyncInitableMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAsyncInitableMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAsyncInitableMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveAsyncInitableMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAsyncInitableMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveAsyncInitableMethod t AsyncInitable, O.MethodInfo info AsyncInitable p) => OL.IsLabel t (AsyncInitable -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

-- method AsyncInitable::init_async
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "initable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncInitable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GAsyncInitable." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "io_priority"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the [I/O priority][io-priority] of the operation"
--                 , 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 to call when the request is satisfied"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 4
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the data to pass to callback 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_async_initable_init_async" g_async_initable_init_async :: 
    Ptr AsyncInitable ->                    -- initable : TInterface (Name {namespace = "Gio", name = "AsyncInitable"})
    Int32 ->                                -- io_priority : TBasicType TInt
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

-- | Starts asynchronous initialization of the object implementing the
-- interface. This must be done before any real use of the object after
-- initial construction. If the object also implements t'GI.Gio.Interfaces.Initable.Initable' you can
-- optionally call 'GI.Gio.Interfaces.Initable.initableInit' instead.
-- 
-- This method is intended for language bindings. If writing in C,
-- @/g_async_initable_new_async()/@ should typically be used instead.
-- 
-- When the initialization is finished, /@callback@/ will be called. You can
-- then call 'GI.Gio.Interfaces.AsyncInitable.asyncInitableInitFinish' to get the result of the
-- initialization.
-- 
-- Implementations may also support cancellation. If /@cancellable@/ is not
-- 'P.Nothing', then initialization can be cancelled by triggering the cancellable
-- object from another thread. If the operation was cancelled, the error
-- 'GI.Gio.Enums.IOErrorEnumCancelled' will be returned. If /@cancellable@/ is not 'P.Nothing', and
-- the object doesn\'t support cancellable initialization, the error
-- 'GI.Gio.Enums.IOErrorEnumNotSupported' will be returned.
-- 
-- As with t'GI.Gio.Interfaces.Initable.Initable', if the object is not initialized, or initialization
-- returns with an error, then all operations on the object except
-- 'GI.GObject.Objects.Object.objectRef' and 'GI.GObject.Objects.Object.objectUnref' are considered to be invalid, and
-- have undefined behaviour. They will often fail with @/g_critical()/@ or
-- @/g_warning()/@, but this must not be relied on.
-- 
-- Callers should not assume that a class which implements t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable' can
-- be initialized multiple times; for more information, see 'GI.Gio.Interfaces.Initable.initableInit'.
-- If a class explicitly supports being initialized multiple times,
-- implementation requires yielding all subsequent calls to @/init_async()/@ on the
-- results of the first call.
-- 
-- For classes that also support the t'GI.Gio.Interfaces.Initable.Initable' interface, the default
-- implementation of this method will run the 'GI.Gio.Interfaces.Initable.initableInit' function
-- in a thread, so if you want to support asynchronous initialization via
-- threads, just implement the t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable' interface without overriding
-- any interface methods.
-- 
-- /Since: 2.22/
asyncInitableInitAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsAsyncInitable a, Gio.Cancellable.IsCancellable b) =>
    a
    -- ^ /@initable@/: a t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable'.
    -> Int32
    -- ^ /@ioPriority@/: the [I\/O priority][io-priority] of the operation
    -> Maybe (b)
    -- ^ /@cancellable@/: optional t'GI.Gio.Objects.Cancellable.Cancellable' object, 'P.Nothing' to ignore.
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: a t'GI.Gio.Callbacks.AsyncReadyCallback' to call when the request is satisfied
    -> m ()
asyncInitableInitAsync :: a -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
asyncInitableInitAsync initable :: a
initable ioPriority :: Int32
ioPriority cancellable :: Maybe b
cancellable callback :: Maybe AsyncReadyCallback
callback = 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 AsyncInitable
initable' <- a -> IO (Ptr AsyncInitable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
initable
    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 userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    Ptr AsyncInitable
-> Int32
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_async_initable_init_async Ptr AsyncInitable
initable' Int32
ioPriority Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
initable
    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
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data AsyncInitableInitAsyncMethodInfo
instance (signature ~ (Int32 -> Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsAsyncInitable a, Gio.Cancellable.IsCancellable b) => O.MethodInfo AsyncInitableInitAsyncMethodInfo a signature where
    overloadedMethod = asyncInitableInitAsync

#endif

-- method AsyncInitable::init_finish
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "initable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncInitable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GAsyncInitable." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "res"
--           , 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
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_async_initable_init_finish" g_async_initable_init_finish :: 
    Ptr AsyncInitable ->                    -- initable : TInterface (Name {namespace = "Gio", name = "AsyncInitable"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- res : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Finishes asynchronous initialization and returns the result.
-- See 'GI.Gio.Interfaces.AsyncInitable.asyncInitableInitAsync'.
-- 
-- /Since: 2.22/
asyncInitableInitFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsAsyncInitable a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    -- ^ /@initable@/: a t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable'.
    -> b
    -- ^ /@res@/: a t'GI.Gio.Interfaces.AsyncResult.AsyncResult'.
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
asyncInitableInitFinish :: a -> b -> m ()
asyncInitableInitFinish initable :: a
initable res :: b
res = 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 AsyncInitable
initable' <- a -> IO (Ptr AsyncInitable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
initable
    Ptr AsyncResult
res' <- b -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
res
    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 AsyncInitable -> Ptr AsyncResult -> Ptr (Ptr GError) -> IO CInt
g_async_initable_init_finish Ptr AsyncInitable
initable' Ptr AsyncResult
res'
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
initable
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
res
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data AsyncInitableInitFinishMethodInfo
instance (signature ~ (b -> m ()), MonadIO m, IsAsyncInitable a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo AsyncInitableInitFinishMethodInfo a signature where
    overloadedMethod = asyncInitableInitFinish

#endif

-- method AsyncInitable::new_finish
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "initable"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncInitable" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the #GAsyncInitable from the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "res"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "AsyncResult" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the #GAsyncResult from the callback"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "GObject" , name = "Object" })
-- throws : True
-- Skip return : False

foreign import ccall "g_async_initable_new_finish" g_async_initable_new_finish :: 
    Ptr AsyncInitable ->                    -- initable : TInterface (Name {namespace = "Gio", name = "AsyncInitable"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- res : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GObject.Object.Object)

-- | Finishes the async construction for the various g_async_initable_new
-- calls, returning the created object or 'P.Nothing' on error.
-- 
-- /Since: 2.22/
asyncInitableNewFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsAsyncInitable a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    -- ^ /@initable@/: the t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable' from the callback
    -> b
    -- ^ /@res@/: the t'GI.Gio.Interfaces.AsyncResult.AsyncResult' from the callback
    -> m GObject.Object.Object
    -- ^ __Returns:__ a newly created t'GI.GObject.Objects.Object.Object',
    --      or 'P.Nothing' on error. Free with 'GI.GObject.Objects.Object.objectUnref'. /(Can throw 'Data.GI.Base.GError.GError')/
asyncInitableNewFinish :: a -> b -> m Object
asyncInitableNewFinish initable :: a
initable res :: b
res = IO Object -> m Object
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Object -> m Object) -> IO Object -> m Object
forall a b. (a -> b) -> a -> b
$ do
    Ptr AsyncInitable
initable' <- a -> IO (Ptr AsyncInitable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
initable
    Ptr AsyncResult
res' <- b -> IO (Ptr AsyncResult)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
res
    IO Object -> IO () -> IO Object
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Object
result <- (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object))
-> (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a b. (a -> b) -> a -> b
$ Ptr AsyncInitable
-> Ptr AsyncResult -> Ptr (Ptr GError) -> IO (Ptr Object)
g_async_initable_new_finish Ptr AsyncInitable
initable' Ptr AsyncResult
res'
        Text -> Ptr Object -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL "asyncInitableNewFinish" Ptr Object
result
        Object
result' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
initable
        b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
res
        Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result'
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data AsyncInitableNewFinishMethodInfo
instance (signature ~ (b -> m GObject.Object.Object), MonadIO m, IsAsyncInitable a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo AsyncInitableNewFinishMethodInfo a signature where
    overloadedMethod = asyncInitableNewFinish

#endif

-- method AsyncInitable::newv_async
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "object_type"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GType supporting #GAsyncInitable."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "n_parameters"
--           , argType = TBasicType TUInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the number of parameters in @parameters"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "parameters"
--           , argType =
--               TInterface Name { namespace = "GObject" , name = "Parameter" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the parameters to use to construct the object"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "io_priority"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the [I/O priority][io-priority] of the operation"
--                 , 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 to call when the initialization is\n    finished"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = 6
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the data to pass to callback 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_async_initable_newv_async" g_async_initable_newv_async :: 
    CGType ->                               -- object_type : TBasicType TGType
    Word32 ->                               -- n_parameters : TBasicType TUInt
    Ptr GObject.Parameter.Parameter ->      -- parameters : TInterface (Name {namespace = "GObject", name = "Parameter"})
    Int32 ->                                -- io_priority : TBasicType TInt
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    IO ()

{-# DEPRECATED asyncInitableNewvAsync ["(Since version 2.54)","Use @/g_object_new_with_properties()/@ and","'GI.Gio.Interfaces.AsyncInitable.asyncInitableInitAsync' instead. See t'GI.GObject.Structs.Parameter.Parameter' for more information."] #-}
-- | Helper function for constructing t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable' object. This is
-- similar to 'GI.GObject.Objects.Object.objectNewv' but also initializes the object asynchronously.
-- 
-- When the initialization is finished, /@callback@/ will be called. You can
-- then call 'GI.Gio.Interfaces.AsyncInitable.asyncInitableNewFinish' to get the new object and check
-- for any errors.
-- 
-- /Since: 2.22/
asyncInitableNewvAsync ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.Cancellable.IsCancellable a) =>
    GType
    -- ^ /@objectType@/: a t'GType' supporting t'GI.Gio.Interfaces.AsyncInitable.AsyncInitable'.
    -> Word32
    -- ^ /@nParameters@/: the number of parameters in /@parameters@/
    -> GObject.Parameter.Parameter
    -- ^ /@parameters@/: the parameters to use to construct the object
    -> Int32
    -- ^ /@ioPriority@/: the [I\/O priority][io-priority] of the operation
    -> Maybe (a)
    -- ^ /@cancellable@/: optional t'GI.Gio.Objects.Cancellable.Cancellable' object, 'P.Nothing' to ignore.
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    -- ^ /@callback@/: a t'GI.Gio.Callbacks.AsyncReadyCallback' to call when the initialization is
    --     finished
    -> m ()
asyncInitableNewvAsync :: GType
-> Word32
-> Parameter
-> Int32
-> Maybe a
-> Maybe AsyncReadyCallback
-> m ()
asyncInitableNewvAsync objectType :: GType
objectType nParameters :: Word32
nParameters parameters :: Parameter
parameters ioPriority :: Int32
ioPriority cancellable :: Maybe a
cancellable callback :: Maybe AsyncReadyCallback
callback = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    let objectType' :: CGType
objectType' = GType -> CGType
gtypeToCGType GType
objectType
    Ptr Parameter
parameters' <- Parameter -> IO (Ptr Parameter)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Parameter
parameters
    Ptr Cancellable
maybeCancellable <- case Maybe a
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 :: a
jCancellable -> do
            Ptr Cancellable
jCancellable' <- a -> IO (Ptr Cancellable)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
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 userData :: Ptr a
userData = Ptr a
forall a. Ptr a
nullPtr
    CGType
-> Word32
-> Ptr Parameter
-> Int32
-> Ptr Cancellable
-> FunPtr C_AsyncReadyCallback
-> Ptr ()
-> IO ()
g_async_initable_newv_async CGType
objectType' Word32
nParameters Ptr Parameter
parameters' Int32
ioPriority Ptr Cancellable
maybeCancellable FunPtr C_AsyncReadyCallback
maybeCallback Ptr ()
forall a. Ptr a
userData
    Parameter -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Parameter
parameters
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
cancellable a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
#endif