{- |
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.Objects.IOStream
    ( 

-- * Exported types
    IOStream(..)                            ,
    IOStreamK                               ,
    toIOStream                              ,
    noIOStream                              ,


 -- * Methods
-- ** iOStreamClearPending
    iOStreamClearPending                    ,


-- ** iOStreamClose
    iOStreamClose                           ,


-- ** iOStreamCloseAsync
    iOStreamCloseAsync                      ,


-- ** iOStreamCloseFinish
    iOStreamCloseFinish                     ,


-- ** iOStreamGetInputStream
    iOStreamGetInputStream                  ,


-- ** iOStreamGetOutputStream
    iOStreamGetOutputStream                 ,


-- ** iOStreamHasPending
    iOStreamHasPending                      ,


-- ** iOStreamIsClosed
    iOStreamIsClosed                        ,


-- ** iOStreamSetPending
    iOStreamSetPending                      ,


-- ** iOStreamSpliceAsync
    iOStreamSpliceAsync                     ,


-- ** iOStreamSpliceFinish
    iOStreamSpliceFinish                    ,




 -- * Properties
-- ** Closed
    IOStreamClosedPropertyInfo              ,
    getIOStreamClosed                       ,


-- ** InputStream
    IOStreamInputStreamPropertyInfo         ,
    getIOStreamInputStream                  ,


-- ** OutputStream
    IOStreamOutputStreamPropertyInfo        ,
    getIOStreamOutputStream                 ,




    ) 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

newtype IOStream = IOStream (ForeignPtr IOStream)
foreign import ccall "g_io_stream_get_type"
    c_g_io_stream_get_type :: IO GType

type instance ParentTypes IOStream = IOStreamParentTypes
type IOStreamParentTypes = '[GObject.Object]

instance GObject IOStream where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_io_stream_get_type
    

class GObject o => IOStreamK o
instance (GObject o, IsDescendantOf IOStream o) => IOStreamK o

toIOStream :: IOStreamK o => o -> IO IOStream
toIOStream = unsafeCastTo IOStream

noIOStream :: Maybe IOStream
noIOStream = Nothing

-- VVV Prop "closed"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable]

getIOStreamClosed :: (MonadIO m, IOStreamK o) => o -> m Bool
getIOStreamClosed obj = liftIO $ getObjectPropertyBool obj "closed"

data IOStreamClosedPropertyInfo
instance AttrInfo IOStreamClosedPropertyInfo where
    type AttrAllowedOps IOStreamClosedPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint IOStreamClosedPropertyInfo = (~) ()
    type AttrBaseTypeConstraint IOStreamClosedPropertyInfo = IOStreamK
    type AttrGetType IOStreamClosedPropertyInfo = Bool
    type AttrLabel IOStreamClosedPropertyInfo = "IOStream::closed"
    attrGet _ = getIOStreamClosed
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "input-stream"
   -- Type: TInterface "Gio" "InputStream"
   -- Flags: [PropertyReadable]

getIOStreamInputStream :: (MonadIO m, IOStreamK o) => o -> m InputStream
getIOStreamInputStream obj = liftIO $ getObjectPropertyObject obj "input-stream" InputStream

data IOStreamInputStreamPropertyInfo
instance AttrInfo IOStreamInputStreamPropertyInfo where
    type AttrAllowedOps IOStreamInputStreamPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint IOStreamInputStreamPropertyInfo = (~) ()
    type AttrBaseTypeConstraint IOStreamInputStreamPropertyInfo = IOStreamK
    type AttrGetType IOStreamInputStreamPropertyInfo = InputStream
    type AttrLabel IOStreamInputStreamPropertyInfo = "IOStream::input-stream"
    attrGet _ = getIOStreamInputStream
    attrSet _ = undefined
    attrConstruct _ = undefined

-- VVV Prop "output-stream"
   -- Type: TInterface "Gio" "OutputStream"
   -- Flags: [PropertyReadable]

getIOStreamOutputStream :: (MonadIO m, IOStreamK o) => o -> m OutputStream
getIOStreamOutputStream obj = liftIO $ getObjectPropertyObject obj "output-stream" OutputStream

data IOStreamOutputStreamPropertyInfo
instance AttrInfo IOStreamOutputStreamPropertyInfo where
    type AttrAllowedOps IOStreamOutputStreamPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint IOStreamOutputStreamPropertyInfo = (~) ()
    type AttrBaseTypeConstraint IOStreamOutputStreamPropertyInfo = IOStreamK
    type AttrGetType IOStreamOutputStreamPropertyInfo = OutputStream
    type AttrLabel IOStreamOutputStreamPropertyInfo = "IOStream::output-stream"
    attrGet _ = getIOStreamOutputStream
    attrSet _ = undefined
    attrConstruct _ = undefined

type instance AttributeList IOStream = IOStreamAttributeList
type IOStreamAttributeList = ('[ '("closed", IOStreamClosedPropertyInfo), '("input-stream", IOStreamInputStreamPropertyInfo), '("output-stream", IOStreamOutputStreamPropertyInfo)] :: [(Symbol, *)])

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

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

foreign import ccall "g_io_stream_clear_pending" g_io_stream_clear_pending :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    IO ()


iOStreamClearPending ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m ()
iOStreamClearPending _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    g_io_stream_clear_pending _obj'
    touchManagedPtr _obj
    return ()

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

foreign import ccall "g_io_stream_close" g_io_stream_close :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    Ptr Cancellable ->                      -- cancellable : TInterface "Gio" "Cancellable"
    Ptr (Ptr GError) ->                     -- error
    IO CInt


iOStreamClose ::
    (MonadIO m, IOStreamK a, CancellableK b) =>
    a ->                                    -- _obj
    Maybe (b) ->                            -- cancellable
    m ()
iOStreamClose _obj cancellable = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        _ <- propagateGError $ g_io_stream_close _obj' maybeCancellable
        touchManagedPtr _obj
        whenJust cancellable touchManagedPtr
        return ()
     ) (do
        return ()
     )

-- method IOStream::close_async
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 4, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_io_stream_close_async" g_io_stream_close_async :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    Int32 ->                                -- io_priority : TBasicType TInt32
    Ptr Cancellable ->                      -- cancellable : TInterface "Gio" "Cancellable"
    FunPtr AsyncReadyCallbackC ->           -- callback : TInterface "Gio" "AsyncReadyCallback"
    Ptr () ->                               -- user_data : TBasicType TVoid
    IO ()


iOStreamCloseAsync ::
    (MonadIO m, IOStreamK a, CancellableK b) =>
    a ->                                    -- _obj
    Int32 ->                                -- io_priority
    Maybe (b) ->                            -- cancellable
    Maybe (AsyncReadyCallback) ->           -- callback
    m ()
iOStreamCloseAsync _obj io_priority cancellable callback = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr AsyncReadyCallbackC))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- mkAsyncReadyCallback (asyncReadyCallbackWrapper (Just ptrcallback) jCallback)
            poke ptrcallback jCallback'
            return jCallback'
    let user_data = nullPtr
    g_io_stream_close_async _obj' io_priority maybeCancellable maybeCallback user_data
    touchManagedPtr _obj
    whenJust cancellable touchManagedPtr
    return ()

-- method IOStream::close_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "result", 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_io_stream_close_finish" g_io_stream_close_finish :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    Ptr AsyncResult ->                      -- result : TInterface "Gio" "AsyncResult"
    Ptr (Ptr GError) ->                     -- error
    IO CInt


iOStreamCloseFinish ::
    (MonadIO m, IOStreamK a, AsyncResultK b) =>
    a ->                                    -- _obj
    b ->                                    -- result
    m ()
iOStreamCloseFinish _obj result_ = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let result_' = unsafeManagedPtrCastPtr result_
    onException (do
        _ <- propagateGError $ g_io_stream_close_finish _obj' result_'
        touchManagedPtr _obj
        touchManagedPtr result_
        return ()
     ) (do
        return ()
     )

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

foreign import ccall "g_io_stream_get_input_stream" g_io_stream_get_input_stream :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    IO (Ptr InputStream)


iOStreamGetInputStream ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m InputStream
iOStreamGetInputStream _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_io_stream_get_input_stream _obj'
    checkUnexpectedReturnNULL "g_io_stream_get_input_stream" result
    result' <- (newObject InputStream) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_io_stream_get_output_stream" g_io_stream_get_output_stream :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    IO (Ptr OutputStream)


iOStreamGetOutputStream ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m OutputStream
iOStreamGetOutputStream _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_io_stream_get_output_stream _obj'
    checkUnexpectedReturnNULL "g_io_stream_get_output_stream" result
    result' <- (newObject OutputStream) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_io_stream_has_pending" g_io_stream_has_pending :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    IO CInt


iOStreamHasPending ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m Bool
iOStreamHasPending _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_io_stream_has_pending _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

foreign import ccall "g_io_stream_is_closed" g_io_stream_is_closed :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    IO CInt


iOStreamIsClosed ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m Bool
iOStreamIsClosed _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_io_stream_is_closed _obj'
    let result' = (/= 0) result
    touchManagedPtr _obj
    return result'

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

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


iOStreamSetPending ::
    (MonadIO m, IOStreamK a) =>
    a ->                                    -- _obj
    m ()
iOStreamSetPending _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    onException (do
        _ <- propagateGError $ g_io_stream_set_pending _obj'
        touchManagedPtr _obj
        return ()
     ) (do
        return ()
     )

-- method IOStream::splice_async
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "stream2", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TInterface "Gio" "IOStreamSpliceFlags", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 6, argDestroy = -1, transfer = TransferNothing},Arg {argName = "user_data", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "stream2", argType = TInterface "Gio" "IOStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TInterface "Gio" "IOStreamSpliceFlags", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "io_priority", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "cancellable", argType = TInterface "Gio" "Cancellable", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "callback", argType = TInterface "Gio" "AsyncReadyCallback", direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeAsync, argClosure = 6, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_io_stream_splice_async" g_io_stream_splice_async :: 
    Ptr IOStream ->                         -- _obj : TInterface "Gio" "IOStream"
    Ptr IOStream ->                         -- stream2 : TInterface "Gio" "IOStream"
    CUInt ->                                -- flags : TInterface "Gio" "IOStreamSpliceFlags"
    Int32 ->                                -- io_priority : TBasicType TInt32
    Ptr Cancellable ->                      -- cancellable : TInterface "Gio" "Cancellable"
    FunPtr AsyncReadyCallbackC ->           -- callback : TInterface "Gio" "AsyncReadyCallback"
    Ptr () ->                               -- user_data : TBasicType TVoid
    IO ()


iOStreamSpliceAsync ::
    (MonadIO m, IOStreamK a, IOStreamK b, CancellableK c) =>
    a ->                                    -- _obj
    b ->                                    -- stream2
    [IOStreamSpliceFlags] ->                -- flags
    Int32 ->                                -- io_priority
    Maybe (c) ->                            -- cancellable
    Maybe (AsyncReadyCallback) ->           -- callback
    m ()
iOStreamSpliceAsync _obj stream2 flags io_priority cancellable callback = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let stream2' = unsafeManagedPtrCastPtr stream2
    let flags' = gflagsToWord flags
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            let jCancellable' = unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr AsyncReadyCallbackC))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            jCallback' <- mkAsyncReadyCallback (asyncReadyCallbackWrapper (Just ptrcallback) jCallback)
            poke ptrcallback jCallback'
            return jCallback'
    let user_data = nullPtr
    g_io_stream_splice_async _obj' stream2' flags' io_priority maybeCancellable maybeCallback user_data
    touchManagedPtr _obj
    touchManagedPtr stream2
    whenJust cancellable touchManagedPtr
    return ()

-- method IOStream::splice_finish
-- method type : MemberFunction
-- Args : [Arg {argName = "result", argType = TInterface "Gio" "AsyncResult", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "result", 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_io_stream_splice_finish" g_io_stream_splice_finish :: 
    Ptr AsyncResult ->                      -- result : TInterface "Gio" "AsyncResult"
    Ptr (Ptr GError) ->                     -- error
    IO CInt


iOStreamSpliceFinish ::
    (MonadIO m, AsyncResultK a) =>
    a ->                                    -- result
    m ()
iOStreamSpliceFinish result_ = liftIO $ do
    let result_' = unsafeManagedPtrCastPtr result_
    onException (do
        _ <- propagateGError $ g_io_stream_splice_finish result_'
        touchManagedPtr result_
        return ()
     ) (do
        return ()
     )