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

-- * Exported types
    UnixInputStream(..)                     ,
    UnixInputStreamK                        ,
    toUnixInputStream                       ,
    noUnixInputStream                       ,


 -- * Methods
-- ** unixInputStreamGetCloseFd
    unixInputStreamGetCloseFd               ,


-- ** unixInputStreamGetFd
    unixInputStreamGetFd                    ,


-- ** unixInputStreamNew
    unixInputStreamNew                      ,


-- ** unixInputStreamSetCloseFd
    unixInputStreamSetCloseFd               ,




 -- * Properties
-- ** CloseFd
    UnixInputStreamCloseFdPropertyInfo      ,
    constructUnixInputStreamCloseFd         ,
    getUnixInputStreamCloseFd               ,
    setUnixInputStreamCloseFd               ,


-- ** Fd
    UnixInputStreamFdPropertyInfo           ,
    constructUnixInputStreamFd              ,
    getUnixInputStreamFd                    ,




    ) 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 UnixInputStream = UnixInputStream (ForeignPtr UnixInputStream)
foreign import ccall "g_unix_input_stream_get_type"
    c_g_unix_input_stream_get_type :: IO GType

type instance ParentTypes UnixInputStream = UnixInputStreamParentTypes
type UnixInputStreamParentTypes = '[InputStream, GObject.Object, FileDescriptorBased, PollableInputStream]

instance GObject UnixInputStream where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_g_unix_input_stream_get_type
    

class GObject o => UnixInputStreamK o
instance (GObject o, IsDescendantOf UnixInputStream o) => UnixInputStreamK o

toUnixInputStream :: UnixInputStreamK o => o -> IO UnixInputStream
toUnixInputStream = unsafeCastTo UnixInputStream

noUnixInputStream :: Maybe UnixInputStream
noUnixInputStream = Nothing

-- VVV Prop "close-fd"
   -- Type: TBasicType TBoolean
   -- Flags: [PropertyReadable,PropertyWritable]

getUnixInputStreamCloseFd :: (MonadIO m, UnixInputStreamK o) => o -> m Bool
getUnixInputStreamCloseFd obj = liftIO $ getObjectPropertyBool obj "close-fd"

setUnixInputStreamCloseFd :: (MonadIO m, UnixInputStreamK o) => o -> Bool -> m ()
setUnixInputStreamCloseFd obj val = liftIO $ setObjectPropertyBool obj "close-fd" val

constructUnixInputStreamCloseFd :: Bool -> IO ([Char], GValue)
constructUnixInputStreamCloseFd val = constructObjectPropertyBool "close-fd" val

data UnixInputStreamCloseFdPropertyInfo
instance AttrInfo UnixInputStreamCloseFdPropertyInfo where
    type AttrAllowedOps UnixInputStreamCloseFdPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint UnixInputStreamCloseFdPropertyInfo = (~) Bool
    type AttrBaseTypeConstraint UnixInputStreamCloseFdPropertyInfo = UnixInputStreamK
    type AttrGetType UnixInputStreamCloseFdPropertyInfo = Bool
    type AttrLabel UnixInputStreamCloseFdPropertyInfo = "UnixInputStream::close-fd"
    attrGet _ = getUnixInputStreamCloseFd
    attrSet _ = setUnixInputStreamCloseFd
    attrConstruct _ = constructUnixInputStreamCloseFd

-- VVV Prop "fd"
   -- Type: TBasicType TInt32
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]

getUnixInputStreamFd :: (MonadIO m, UnixInputStreamK o) => o -> m Int32
getUnixInputStreamFd obj = liftIO $ getObjectPropertyCInt obj "fd"

constructUnixInputStreamFd :: Int32 -> IO ([Char], GValue)
constructUnixInputStreamFd val = constructObjectPropertyCInt "fd" val

data UnixInputStreamFdPropertyInfo
instance AttrInfo UnixInputStreamFdPropertyInfo where
    type AttrAllowedOps UnixInputStreamFdPropertyInfo = '[ 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint UnixInputStreamFdPropertyInfo = (~) Int32
    type AttrBaseTypeConstraint UnixInputStreamFdPropertyInfo = UnixInputStreamK
    type AttrGetType UnixInputStreamFdPropertyInfo = Int32
    type AttrLabel UnixInputStreamFdPropertyInfo = "UnixInputStream::fd"
    attrGet _ = getUnixInputStreamFd
    attrSet _ = undefined
    attrConstruct _ = constructUnixInputStreamFd

type instance AttributeList UnixInputStream = UnixInputStreamAttributeList
type UnixInputStreamAttributeList = ('[ '("close-fd", UnixInputStreamCloseFdPropertyInfo), '("fd", UnixInputStreamFdPropertyInfo)] :: [(Symbol, *)])

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

-- method UnixInputStream::new
-- method type : Constructor
-- Args : [Arg {argName = "fd", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "close_fd", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "fd", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "close_fd", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gio" "UnixInputStream"
-- throws : False
-- Skip return : False

foreign import ccall "g_unix_input_stream_new" g_unix_input_stream_new :: 
    Int32 ->                                -- fd : TBasicType TInt32
    CInt ->                                 -- close_fd : TBasicType TBoolean
    IO (Ptr UnixInputStream)


unixInputStreamNew ::
    (MonadIO m) =>
    Int32 ->                                -- fd
    Bool ->                                 -- close_fd
    m UnixInputStream
unixInputStreamNew fd close_fd = liftIO $ do
    let close_fd' = (fromIntegral . fromEnum) close_fd
    result <- g_unix_input_stream_new fd close_fd'
    checkUnexpectedReturnNULL "g_unix_input_stream_new" result
    result' <- (wrapObject UnixInputStream) result
    return result'

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

foreign import ccall "g_unix_input_stream_get_close_fd" g_unix_input_stream_get_close_fd :: 
    Ptr UnixInputStream ->                  -- _obj : TInterface "Gio" "UnixInputStream"
    IO CInt


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

-- method UnixInputStream::get_fd
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixInputStream", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gio" "UnixInputStream", 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_input_stream_get_fd" g_unix_input_stream_get_fd :: 
    Ptr UnixInputStream ->                  -- _obj : TInterface "Gio" "UnixInputStream"
    IO Int32


unixInputStreamGetFd ::
    (MonadIO m, UnixInputStreamK a) =>
    a ->                                    -- _obj
    m Int32
unixInputStreamGetFd _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    result <- g_unix_input_stream_get_fd _obj'
    touchManagedPtr _obj
    return result

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

foreign import ccall "g_unix_input_stream_set_close_fd" g_unix_input_stream_set_close_fd :: 
    Ptr UnixInputStream ->                  -- _obj : TInterface "Gio" "UnixInputStream"
    CInt ->                                 -- close_fd : TBasicType TBoolean
    IO ()


unixInputStreamSetCloseFd ::
    (MonadIO m, UnixInputStreamK a) =>
    a ->                                    -- _obj
    Bool ->                                 -- close_fd
    m ()
unixInputStreamSetCloseFd _obj close_fd = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let close_fd' = (fromIntegral . fromEnum) close_fd
    g_unix_input_stream_set_close_fd _obj' close_fd'
    touchManagedPtr _obj
    return ()