{- |
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.UnixFDList
    ( 

-- * Exported types
    UnixFDList(..)                          ,
    UnixFDListK                             ,
    toUnixFDList                            ,
    noUnixFDList                            ,


 -- * Methods
-- ** unixFDListAppend
    unixFDListAppend                        ,


-- ** unixFDListGet
    unixFDListGet                           ,


-- ** unixFDListGetLength
    unixFDListGetLength                     ,


-- ** unixFDListNew
    unixFDListNew                           ,


-- ** unixFDListNewFromArray
    unixFDListNewFromArray                  ,


-- ** unixFDListPeekFds
    unixFDListPeekFds                       ,


-- ** unixFDListStealFds
    unixFDListStealFds                      ,




    ) 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 UnixFDList = UnixFDList (ForeignPtr UnixFDList)
foreign import ccall "g_unix_fd_list_get_type"
    c_g_unix_fd_list_get_type :: IO GType

type instance ParentTypes UnixFDList = UnixFDListParentTypes
type UnixFDListParentTypes = '[GObject.Object]

instance GObject UnixFDList where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_unix_fd_list_get_type
    

class GObject o => UnixFDListK o
instance (GObject o, IsDescendantOf UnixFDList o) => UnixFDListK o

toUnixFDList :: UnixFDListK o => o -> IO UnixFDList
toUnixFDList = unsafeCastTo UnixFDList

noUnixFDList :: Maybe UnixFDList
noUnixFDList = Nothing

type instance AttributeList UnixFDList = UnixFDListAttributeList
type UnixFDListAttributeList = ('[ ] :: [(Symbol, *)])

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

-- method UnixFDList::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- hInArgs : []
-- returnType : TInterface "Gio" "UnixFDList"
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_fd_list_new" g_unix_fd_list_new :: 
    IO (Ptr UnixFDList)


unixFDListNew ::
    (MonadIO m) =>
    m UnixFDList
unixFDListNew  = liftIO $ do
    result <- g_unix_fd_list_new
    checkUnexpectedReturnNULL "g_unix_fd_list_new" result
    result' <- (wrapObject UnixFDList) result
    return result'

-- method UnixFDList::new_from_array
-- method type : Constructor
-- Args : [Arg {argName = "fds", argType = TCArray False (-1) 1 (TBasicType TInt32), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "n_fds", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : [Arg {argName = "n_fds", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- hInArgs : [Arg {argName = "fds", argType = TCArray False (-1) 1 (TBasicType TInt32), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "UnixFDList"
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_fd_list_new_from_array" g_unix_fd_list_new_from_array :: 
    Ptr Int32 ->                            -- fds : TCArray False (-1) 1 (TBasicType TInt32)
    Int32 ->                                -- n_fds : TBasicType TInt32
    IO (Ptr UnixFDList)


unixFDListNewFromArray ::
    (MonadIO m) =>
    [Int32] ->                              -- fds
    m UnixFDList
unixFDListNewFromArray fds = liftIO $ do
    let n_fds = fromIntegral $ length fds
    fds' <- packStorableArray fds
    result <- g_unix_fd_list_new_from_array fds' n_fds
    checkUnexpectedReturnNULL "g_unix_fd_list_new_from_array" result
    result' <- (wrapObject UnixFDList) result
    freeMem fds'
    return result'

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

foreign import ccall "g_unix_fd_list_append" g_unix_fd_list_append :: 
    Ptr UnixFDList ->                       -- _obj : TInterface "Gio" "UnixFDList"
    Int32 ->                                -- fd : TBasicType TInt32
    Ptr (Ptr GError) ->                     -- error
    IO Int32


unixFDListAppend ::
    (MonadIO m, UnixFDListK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- fd
    m Int32
unixFDListAppend _obj fd = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    onException (do
        result <- propagateGError $ g_unix_fd_list_append _obj' fd
        touchManagedPtr _obj
        return result
     ) (do
        return ()
     )

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

foreign import ccall "g_unix_fd_list_get" g_unix_fd_list_get :: 
    Ptr UnixFDList ->                       -- _obj : TInterface "Gio" "UnixFDList"
    Int32 ->                                -- index_ : TBasicType TInt32
    Ptr (Ptr GError) ->                     -- error
    IO Int32


unixFDListGet ::
    (MonadIO m, UnixFDListK a) =>
    a ->                                    -- _obj
    Int32 ->                                -- index_
    m Int32
unixFDListGet _obj index_ = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    onException (do
        result <- propagateGError $ g_unix_fd_list_get _obj' index_
        touchManagedPtr _obj
        return result
     ) (do
        return ()
     )

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

foreign import ccall "g_unix_fd_list_get_length" g_unix_fd_list_get_length :: 
    Ptr UnixFDList ->                       -- _obj : TInterface "Gio" "UnixFDList"
    IO Int32


unixFDListGetLength ::
    (MonadIO m, UnixFDListK a) =>
    a ->                                    -- _obj
    m Int32
unixFDListGetLength _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_unix_fd_list_get_length _obj'
    touchManagedPtr _obj
    return result

-- method UnixFDList::peek_fds
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixFDList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : [Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixFDList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TCArray False (-1) 1 (TBasicType TInt32)
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_fd_list_peek_fds" g_unix_fd_list_peek_fds :: 
    Ptr UnixFDList ->                       -- _obj : TInterface "Gio" "UnixFDList"
    Ptr Int32 ->                            -- length : TBasicType TInt32
    IO (Ptr Int32)


unixFDListPeekFds ::
    (MonadIO m, UnixFDListK a) =>
    a ->                                    -- _obj
    m [Int32]
unixFDListPeekFds _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    length_ <- allocMem :: IO (Ptr Int32)
    result <- g_unix_fd_list_peek_fds _obj' length_
    length_' <- peek length_
    checkUnexpectedReturnNULL "g_unix_fd_list_peek_fds" result
    result' <- (unpackStorableArrayWithLength length_') result
    touchManagedPtr _obj
    freeMem length_
    return result'

-- method UnixFDList::steal_fds
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixFDList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : [Arg {argName = "length", argType = TBasicType TInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixFDList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TCArray False (-1) 1 (TBasicType TInt32)
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_fd_list_steal_fds" g_unix_fd_list_steal_fds :: 
    Ptr UnixFDList ->                       -- _obj : TInterface "Gio" "UnixFDList"
    Ptr Int32 ->                            -- length : TBasicType TInt32
    IO (Ptr Int32)


unixFDListStealFds ::
    (MonadIO m, UnixFDListK a) =>
    a ->                                    -- _obj
    m [Int32]
unixFDListStealFds _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    length_ <- allocMem :: IO (Ptr Int32)
    result <- g_unix_fd_list_steal_fds _obj' length_
    length_' <- peek length_
    checkUnexpectedReturnNULL "g_unix_fd_list_steal_fds" result
    result' <- (unpackStorableArrayWithLength length_') result
    freeMem result
    touchManagedPtr _obj
    freeMem length_
    return result'