{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

The @GSourceCallbackFuncs@ struct contains
functions for managing callback objects.
-}

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

module GI.GLib.Structs.SourceCallbackFuncs
    (

-- * Exported types
    SourceCallbackFuncs(..)                 ,
    newZeroSourceCallbackFuncs              ,
    noSourceCallbackFuncs                   ,


 -- * Properties
-- ** ref #attr:ref#
{- | /No description available in the introspection data./
-}
    clearSourceCallbackFuncsRef             ,
    getSourceCallbackFuncsRef               ,
    setSourceCallbackFuncsRef               ,
#if ENABLE_OVERLOADING
    sourceCallbackFuncs_ref                 ,
#endif


-- ** unref #attr:unref#
{- | /No description available in the introspection data./
-}
    clearSourceCallbackFuncsUnref           ,
    getSourceCallbackFuncsUnref             ,
    setSourceCallbackFuncsUnref             ,
#if ENABLE_OVERLOADING
    sourceCallbackFuncs_unref               ,
#endif




    ) 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.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.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.GLib.Callbacks as GLib.Callbacks

-- | Memory-managed wrapper type.
newtype SourceCallbackFuncs = SourceCallbackFuncs (ManagedPtr SourceCallbackFuncs)
instance WrappedPtr SourceCallbackFuncs where
    wrappedPtrCalloc = callocBytes 24
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 24 >=> wrapPtr SourceCallbackFuncs)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `SourceCallbackFuncs` struct initialized to zero.
newZeroSourceCallbackFuncs :: MonadIO m => m SourceCallbackFuncs
newZeroSourceCallbackFuncs = liftIO $ wrappedPtrCalloc >>= wrapPtr SourceCallbackFuncs

instance tag ~ 'AttrSet => Constructible SourceCallbackFuncs tag where
    new _ attrs = do
        o <- newZeroSourceCallbackFuncs
        GI.Attributes.set o attrs
        return o


-- | A convenience alias for `Nothing` :: `Maybe` `SourceCallbackFuncs`.
noSourceCallbackFuncs :: Maybe SourceCallbackFuncs
noSourceCallbackFuncs = Nothing

{- |
Get the value of the “@ref@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' sourceCallbackFuncs #ref
@
-}
getSourceCallbackFuncsRef :: MonadIO m => SourceCallbackFuncs -> m (Maybe GLib.Callbacks.SourceCallbackFuncsRefFieldCallback)
getSourceCallbackFuncsRef s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO (FunPtr GLib.Callbacks.C_SourceCallbackFuncsRefFieldCallback)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = GLib.Callbacks.dynamic_SourceCallbackFuncsRefFieldCallback val'
        return val''
    return result

{- |
Set the value of the “@ref@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' sourceCallbackFuncs [ #ref 'Data.GI.Base.Attributes.:=' value ]
@
-}
setSourceCallbackFuncsRef :: MonadIO m => SourceCallbackFuncs -> FunPtr GLib.Callbacks.C_SourceCallbackFuncsRefFieldCallback -> m ()
setSourceCallbackFuncsRef s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: FunPtr GLib.Callbacks.C_SourceCallbackFuncsRefFieldCallback)

{- |
Set the value of the “@ref@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #ref
@
-}
clearSourceCallbackFuncsRef :: MonadIO m => SourceCallbackFuncs -> m ()
clearSourceCallbackFuncsRef s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullFunPtr :: FunPtr GLib.Callbacks.C_SourceCallbackFuncsRefFieldCallback)

#if ENABLE_OVERLOADING
data SourceCallbackFuncsRefFieldInfo
instance AttrInfo SourceCallbackFuncsRefFieldInfo where
    type AttrAllowedOps SourceCallbackFuncsRefFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint SourceCallbackFuncsRefFieldInfo = (~) (FunPtr GLib.Callbacks.C_SourceCallbackFuncsRefFieldCallback)
    type AttrBaseTypeConstraint SourceCallbackFuncsRefFieldInfo = (~) SourceCallbackFuncs
    type AttrGetType SourceCallbackFuncsRefFieldInfo = Maybe GLib.Callbacks.SourceCallbackFuncsRefFieldCallback
    type AttrLabel SourceCallbackFuncsRefFieldInfo = "ref"
    type AttrOrigin SourceCallbackFuncsRefFieldInfo = SourceCallbackFuncs
    attrGet _ = getSourceCallbackFuncsRef
    attrSet _ = setSourceCallbackFuncsRef
    attrConstruct = undefined
    attrClear _ = clearSourceCallbackFuncsRef

sourceCallbackFuncs_ref :: AttrLabelProxy "ref"
sourceCallbackFuncs_ref = AttrLabelProxy

#endif


{- |
Get the value of the “@unref@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' sourceCallbackFuncs #unref
@
-}
getSourceCallbackFuncsUnref :: MonadIO m => SourceCallbackFuncs -> m (Maybe GLib.Callbacks.SourceCallbackFuncsUnrefFieldCallback)
getSourceCallbackFuncsUnref s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO (FunPtr GLib.Callbacks.C_SourceCallbackFuncsUnrefFieldCallback)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = GLib.Callbacks.dynamic_SourceCallbackFuncsUnrefFieldCallback val'
        return val''
    return result

{- |
Set the value of the “@unref@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' sourceCallbackFuncs [ #unref 'Data.GI.Base.Attributes.:=' value ]
@
-}
setSourceCallbackFuncsUnref :: MonadIO m => SourceCallbackFuncs -> FunPtr GLib.Callbacks.C_SourceCallbackFuncsUnrefFieldCallback -> m ()
setSourceCallbackFuncsUnref s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: FunPtr GLib.Callbacks.C_SourceCallbackFuncsUnrefFieldCallback)

{- |
Set the value of the “@unref@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #unref
@
-}
clearSourceCallbackFuncsUnref :: MonadIO m => SourceCallbackFuncs -> m ()
clearSourceCallbackFuncsUnref s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullFunPtr :: FunPtr GLib.Callbacks.C_SourceCallbackFuncsUnrefFieldCallback)

#if ENABLE_OVERLOADING
data SourceCallbackFuncsUnrefFieldInfo
instance AttrInfo SourceCallbackFuncsUnrefFieldInfo where
    type AttrAllowedOps SourceCallbackFuncsUnrefFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint SourceCallbackFuncsUnrefFieldInfo = (~) (FunPtr GLib.Callbacks.C_SourceCallbackFuncsUnrefFieldCallback)
    type AttrBaseTypeConstraint SourceCallbackFuncsUnrefFieldInfo = (~) SourceCallbackFuncs
    type AttrGetType SourceCallbackFuncsUnrefFieldInfo = Maybe GLib.Callbacks.SourceCallbackFuncsUnrefFieldCallback
    type AttrLabel SourceCallbackFuncsUnrefFieldInfo = "unref"
    type AttrOrigin SourceCallbackFuncsUnrefFieldInfo = SourceCallbackFuncs
    attrGet _ = getSourceCallbackFuncsUnref
    attrSet _ = setSourceCallbackFuncsUnref
    attrConstruct = undefined
    attrClear _ = clearSourceCallbackFuncsUnref

sourceCallbackFuncs_unref :: AttrLabelProxy "unref"
sourceCallbackFuncs_unref = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList SourceCallbackFuncs
type instance O.AttributeList SourceCallbackFuncs = SourceCallbackFuncsAttributeList
type SourceCallbackFuncsAttributeList = ('[ '("ref", SourceCallbackFuncsRefFieldInfo), '("unref", SourceCallbackFuncsUnrefFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveSourceCallbackFuncsMethod (t :: Symbol) (o :: *) :: * where
    ResolveSourceCallbackFuncsMethod l o = O.MethodResolutionFailed l o

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

#endif