{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.Gio.Interfaces.FileDescriptorBased.FileDescriptorBased' is implemented by streams (implementations of
-- t'GI.Gio.Objects.InputStream.InputStream' or t'GI.Gio.Objects.OutputStream.OutputStream') that are based on file descriptors.
-- 
-- Note that @\<gio\/gfiledescriptorbased.h>@ belongs to the UNIX-specific
-- GIO interfaces, thus you have to use the @gio-unix-2.0.pc@ pkg-config
-- file when using it.
-- 
-- /Since: 2.24/

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

module GI.Gio.Interfaces.FileDescriptorBased
    ( 

-- * Exported types
    FileDescriptorBased(..)                 ,
    IsFileDescriptorBased                   ,
    toFileDescriptorBased                   ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveFileDescriptorBasedMethod        ,
#endif


-- ** getFd #method:getFd#

#if defined(ENABLE_OVERLOADING)
    FileDescriptorBasedGetFdMethodInfo      ,
#endif
    fileDescriptorBasedGetFd                ,




    ) 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.BasicTypes as B.Types
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 Control.Monad.IO.Class as MIO
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

-- interface FileDescriptorBased 
-- | Memory-managed wrapper type.
newtype FileDescriptorBased = FileDescriptorBased (SP.ManagedPtr FileDescriptorBased)
    deriving (FileDescriptorBased -> FileDescriptorBased -> Bool
(FileDescriptorBased -> FileDescriptorBased -> Bool)
-> (FileDescriptorBased -> FileDescriptorBased -> Bool)
-> Eq FileDescriptorBased
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileDescriptorBased -> FileDescriptorBased -> Bool
$c/= :: FileDescriptorBased -> FileDescriptorBased -> Bool
== :: FileDescriptorBased -> FileDescriptorBased -> Bool
$c== :: FileDescriptorBased -> FileDescriptorBased -> Bool
Eq)

instance SP.ManagedPtrNewtype FileDescriptorBased where
    toManagedPtr :: FileDescriptorBased -> ManagedPtr FileDescriptorBased
toManagedPtr (FileDescriptorBased ManagedPtr FileDescriptorBased
p) = ManagedPtr FileDescriptorBased
p

foreign import ccall "g_file_descriptor_based_get_type"
    c_g_file_descriptor_based_get_type :: IO B.Types.GType

instance B.Types.TypedObject FileDescriptorBased where
    glibType :: IO GType
glibType = IO GType
c_g_file_descriptor_based_get_type

instance B.Types.GObject FileDescriptorBased

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

-- | Type class for types which can be safely cast to `FileDescriptorBased`, for instance with `toFileDescriptorBased`.
class (SP.GObject o, O.IsDescendantOf FileDescriptorBased o) => IsFileDescriptorBased o
instance (SP.GObject o, O.IsDescendantOf FileDescriptorBased o) => IsFileDescriptorBased o

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

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

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

#if defined(ENABLE_OVERLOADING)
#endif

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

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

#endif

-- method FileDescriptorBased::get_fd
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "fd_based"
--           , argType =
--               TInterface
--                 Name { namespace = "Gio" , name = "FileDescriptorBased" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GFileDescriptorBased."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "g_file_descriptor_based_get_fd" g_file_descriptor_based_get_fd :: 
    Ptr FileDescriptorBased ->              -- fd_based : TInterface (Name {namespace = "Gio", name = "FileDescriptorBased"})
    IO Int32

-- | Gets the underlying file descriptor.
-- 
-- /Since: 2.24/
fileDescriptorBasedGetFd ::
    (B.CallStack.HasCallStack, MonadIO m, IsFileDescriptorBased a) =>
    a
    -- ^ /@fdBased@/: a t'GI.Gio.Interfaces.FileDescriptorBased.FileDescriptorBased'.
    -> m Int32
    -- ^ __Returns:__ The file descriptor
fileDescriptorBasedGetFd :: a -> m Int32
fileDescriptorBasedGetFd a
fdBased = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    Ptr FileDescriptorBased
fdBased' <- a -> IO (Ptr FileDescriptorBased)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
fdBased
    Int32
result <- Ptr FileDescriptorBased -> IO Int32
g_file_descriptor_based_get_fd Ptr FileDescriptorBased
fdBased'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
fdBased
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result

#if defined(ENABLE_OVERLOADING)
data FileDescriptorBasedGetFdMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsFileDescriptorBased a) => O.MethodInfo FileDescriptorBasedGetFdMethodInfo a signature where
    overloadedMethod = fileDescriptorBasedGetFd

#endif

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

#endif