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

module GI.Gio.Interfaces.AsyncResult
    ( 

-- * Exported types
    AsyncResult(..)                         ,
    noAsyncResult                           ,
    AsyncResultK                            ,
    toAsyncResult                           ,


 -- * Methods
-- ** asyncResultGetSourceObject
    asyncResultGetSourceObject              ,


-- ** asyncResultGetUserData
    asyncResultGetUserData                  ,


-- ** asyncResultIsTagged
    asyncResultIsTagged                     ,


-- ** asyncResultLegacyPropagateError
    asyncResultLegacyPropagateError         ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gio.Types
import GI.Gio.Callbacks
import qualified GI.GObject as GObject

-- interface AsyncResult 

newtype AsyncResult = AsyncResult (ForeignPtr AsyncResult)
noAsyncResult :: Maybe AsyncResult
noAsyncResult = Nothing

type instance AttributeList AsyncResult = AsyncResultAttributeList
type AsyncResultAttributeList = ('[ ] :: [(Symbol, *)])

type instance SignalList AsyncResult = AsyncResultSignalList
type AsyncResultSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "g_async_result_get_type"
    c_g_async_result_get_type :: IO GType

type instance ParentTypes AsyncResult = AsyncResultParentTypes
type AsyncResultParentTypes = '[GObject.Object]

instance GObject AsyncResult where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_async_result_get_type
    

class GObject o => AsyncResultK o
instance (GObject o, IsDescendantOf AsyncResult o) => AsyncResultK o

toAsyncResult :: AsyncResultK o => o -> IO AsyncResult
toAsyncResult = unsafeCastTo AsyncResult

-- method AsyncResult::get_source_object
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "GObject" "Object"
-- throws : False
-- Skip return : False

foreign import ccall "g_async_result_get_source_object" g_async_result_get_source_object :: 
    Ptr AsyncResult ->                      -- _obj : TInterface "Gio" "AsyncResult"
    IO (Ptr GObject.Object)


asyncResultGetSourceObject ::
    (MonadIO m, AsyncResultK a) =>
    a ->                                    -- _obj
    m GObject.Object
asyncResultGetSourceObject _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_async_result_get_source_object _obj'
    checkUnexpectedReturnNULL "g_async_result_get_source_object" result
    result' <- (wrapObject GObject.Object) result
    touchManagedPtr _obj
    return result'

-- method AsyncResult::get_user_data
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_async_result_get_user_data" g_async_result_get_user_data :: 
    Ptr AsyncResult ->                      -- _obj : TInterface "Gio" "AsyncResult"
    IO ()


asyncResultGetUserData ::
    (MonadIO m, AsyncResultK a) =>
    a ->                                    -- _obj
    m ()
asyncResultGetUserData _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    g_async_result_get_user_data _obj'
    touchManagedPtr _obj
    return ()

-- method AsyncResult::is_tagged
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "source_tag", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "source_tag", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "g_async_result_is_tagged" g_async_result_is_tagged :: 
    Ptr AsyncResult ->                      -- _obj : TInterface "Gio" "AsyncResult"
    Ptr () ->                               -- source_tag : TBasicType TVoid
    IO CInt


asyncResultIsTagged ::
    (MonadIO m, AsyncResultK a) =>
    a ->                                    -- _obj
    Ptr () ->                               -- source_tag
    m Bool
asyncResultIsTagged _obj source_tag = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_async_result_is_tagged _obj' source_tag
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

-- method AsyncResult::legacy_propagate_error
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : True
-- Skip return : False

foreign import ccall "g_async_result_legacy_propagate_error" g_async_result_legacy_propagate_error :: 
    Ptr AsyncResult ->                      -- _obj : TInterface "Gio" "AsyncResult"
    Ptr (Ptr GError) ->                     -- error
    IO CInt


asyncResultLegacyPropagateError ::
    (MonadIO m, AsyncResultK a) =>
    a ->                                    -- _obj
    m ()
asyncResultLegacyPropagateError _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    onException (do
        _ <- propagateGError $ g_async_result_legacy_propagate_error _obj'
        touchManagedPtr _obj
        return ()
     ) (do
        return ()
     )