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

'GI.Gst.Structs.MiniObject.MiniObject' is a simple structure that can be used to implement refcounted
types.

Subclasses will include 'GI.Gst.Structs.MiniObject.MiniObject' as the first member in their structure
and then call @/gst_mini_object_init()/@ to initialize the 'GI.Gst.Structs.MiniObject.MiniObject' fields.

@/gst_mini_object_ref()/@ and @/gst_mini_object_unref()/@ increment and decrement the
refcount respectively. When the refcount of a mini-object reaches 0, the
dispose function is called first and when this returns 'True', the free
function of the miniobject is called.

A copy can be made with @/gst_mini_object_copy()/@.

'GI.Gst.Structs.MiniObject.miniObjectIsWritable' will return 'True' when the refcount of the
object is exactly 1 and there is no parent or a single parent exists and is
writable itself, meaning the current caller has the only reference to the
object. @/gst_mini_object_make_writable()/@ will return a writable version of
the object, which might be a new copy when the refcount was not 1.

Opaque data can be associated with a 'GI.Gst.Structs.MiniObject.MiniObject' with
'GI.Gst.Structs.MiniObject.miniObjectSetQdata' and 'GI.Gst.Structs.MiniObject.miniObjectGetQdata'. The data is
meant to be specific to the particular object and is not automatically copied
with @/gst_mini_object_copy()/@ or similar methods.

A weak reference can be added and remove with @/gst_mini_object_weak_ref()/@
and @/gst_mini_object_weak_unref()/@ respectively.
-}

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

module GI.Gst.Structs.MiniObject
    (

-- * Exported types
    MiniObject(..)                          ,
    newZeroMiniObject                       ,
    noMiniObject                            ,


 -- * Methods
-- ** addParent #method:addParent#

#if ENABLE_OVERLOADING
    MiniObjectAddParentMethodInfo           ,
#endif
    miniObjectAddParent                     ,


-- ** getQdata #method:getQdata#

#if ENABLE_OVERLOADING
    MiniObjectGetQdataMethodInfo            ,
#endif
    miniObjectGetQdata                      ,


-- ** isWritable #method:isWritable#

#if ENABLE_OVERLOADING
    MiniObjectIsWritableMethodInfo          ,
#endif
    miniObjectIsWritable                    ,


-- ** lock #method:lock#

#if ENABLE_OVERLOADING
    MiniObjectLockMethodInfo                ,
#endif
    miniObjectLock                          ,


-- ** removeParent #method:removeParent#

#if ENABLE_OVERLOADING
    MiniObjectRemoveParentMethodInfo        ,
#endif
    miniObjectRemoveParent                  ,


-- ** setQdata #method:setQdata#

#if ENABLE_OVERLOADING
    MiniObjectSetQdataMethodInfo            ,
#endif
    miniObjectSetQdata                      ,


-- ** stealQdata #method:stealQdata#

#if ENABLE_OVERLOADING
    MiniObjectStealQdataMethodInfo          ,
#endif
    miniObjectStealQdata                    ,


-- ** unlock #method:unlock#

#if ENABLE_OVERLOADING
    MiniObjectUnlockMethodInfo              ,
#endif
    miniObjectUnlock                        ,




 -- * Properties
-- ** dispose #attr:dispose#
{- | a dispose function
-}
    clearMiniObjectDispose                  ,
    getMiniObjectDispose                    ,
#if ENABLE_OVERLOADING
    miniObject_dispose                      ,
#endif
    setMiniObjectDispose                    ,


-- ** flags #attr:flags#
{- | extra flags.
-}
    getMiniObjectFlags                      ,
#if ENABLE_OVERLOADING
    miniObject_flags                        ,
#endif
    setMiniObjectFlags                      ,


-- ** free #attr:free#
{- | the free function
-}
    clearMiniObjectFree                     ,
    getMiniObjectFree                       ,
#if ENABLE_OVERLOADING
    miniObject_free                         ,
#endif
    setMiniObjectFree                       ,


-- ** lockstate #attr:lockstate#
{- | atomic state of the locks
-}
    getMiniObjectLockstate                  ,
#if ENABLE_OVERLOADING
    miniObject_lockstate                    ,
#endif
    setMiniObjectLockstate                  ,


-- ** refcount #attr:refcount#
{- | atomic refcount
-}
    getMiniObjectRefcount                   ,
#if ENABLE_OVERLOADING
    miniObject_refcount                     ,
#endif
    setMiniObjectRefcount                   ,


-- ** type #attr:type#
{- | the GType of the object
-}
    getMiniObjectType                       ,
#if ENABLE_OVERLOADING
    miniObject_type                         ,
#endif
    setMiniObjectType                       ,




    ) 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
import qualified GI.Gst.Callbacks as Gst.Callbacks
import {-# SOURCE #-} qualified GI.Gst.Flags as Gst.Flags

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `MiniObject`.
noMiniObject :: Maybe MiniObject
noMiniObject = Nothing

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

@
'Data.GI.Base.Attributes.get' miniObject #type
@
-}
getMiniObjectType :: MonadIO m => MiniObject -> m GType
getMiniObjectType s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CGType
    let val' = GType val
    return val'

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

@
'Data.GI.Base.Attributes.set' miniObject [ #type 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectType :: MonadIO m => MiniObject -> GType -> m ()
setMiniObjectType s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = gtypeToCGType val
    poke (ptr `plusPtr` 0) (val' :: CGType)

#if ENABLE_OVERLOADING
data MiniObjectTypeFieldInfo
instance AttrInfo MiniObjectTypeFieldInfo where
    type AttrAllowedOps MiniObjectTypeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint MiniObjectTypeFieldInfo = (~) GType
    type AttrBaseTypeConstraint MiniObjectTypeFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectTypeFieldInfo = GType
    type AttrLabel MiniObjectTypeFieldInfo = "type"
    type AttrOrigin MiniObjectTypeFieldInfo = MiniObject
    attrGet _ = getMiniObjectType
    attrSet _ = setMiniObjectType
    attrConstruct = undefined
    attrClear _ = undefined

miniObject_type :: AttrLabelProxy "type"
miniObject_type = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' miniObject #refcount
@
-}
getMiniObjectRefcount :: MonadIO m => MiniObject -> m Int32
getMiniObjectRefcount s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' miniObject [ #refcount 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectRefcount :: MonadIO m => MiniObject -> Int32 -> m ()
setMiniObjectRefcount s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if ENABLE_OVERLOADING
data MiniObjectRefcountFieldInfo
instance AttrInfo MiniObjectRefcountFieldInfo where
    type AttrAllowedOps MiniObjectRefcountFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint MiniObjectRefcountFieldInfo = (~) Int32
    type AttrBaseTypeConstraint MiniObjectRefcountFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectRefcountFieldInfo = Int32
    type AttrLabel MiniObjectRefcountFieldInfo = "refcount"
    type AttrOrigin MiniObjectRefcountFieldInfo = MiniObject
    attrGet _ = getMiniObjectRefcount
    attrSet _ = setMiniObjectRefcount
    attrConstruct = undefined
    attrClear _ = undefined

miniObject_refcount :: AttrLabelProxy "refcount"
miniObject_refcount = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' miniObject #lockstate
@
-}
getMiniObjectLockstate :: MonadIO m => MiniObject -> m Int32
getMiniObjectLockstate s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' miniObject [ #lockstate 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectLockstate :: MonadIO m => MiniObject -> Int32 -> m ()
setMiniObjectLockstate s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Int32)

#if ENABLE_OVERLOADING
data MiniObjectLockstateFieldInfo
instance AttrInfo MiniObjectLockstateFieldInfo where
    type AttrAllowedOps MiniObjectLockstateFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint MiniObjectLockstateFieldInfo = (~) Int32
    type AttrBaseTypeConstraint MiniObjectLockstateFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectLockstateFieldInfo = Int32
    type AttrLabel MiniObjectLockstateFieldInfo = "lockstate"
    type AttrOrigin MiniObjectLockstateFieldInfo = MiniObject
    attrGet _ = getMiniObjectLockstate
    attrSet _ = setMiniObjectLockstate
    attrConstruct = undefined
    attrClear _ = undefined

miniObject_lockstate :: AttrLabelProxy "lockstate"
miniObject_lockstate = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' miniObject #flags
@
-}
getMiniObjectFlags :: MonadIO m => MiniObject -> m Word32
getMiniObjectFlags s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO Word32
    return val

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

@
'Data.GI.Base.Attributes.set' miniObject [ #flags 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectFlags :: MonadIO m => MiniObject -> Word32 -> m ()
setMiniObjectFlags s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Word32)

#if ENABLE_OVERLOADING
data MiniObjectFlagsFieldInfo
instance AttrInfo MiniObjectFlagsFieldInfo where
    type AttrAllowedOps MiniObjectFlagsFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint MiniObjectFlagsFieldInfo = (~) Word32
    type AttrBaseTypeConstraint MiniObjectFlagsFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectFlagsFieldInfo = Word32
    type AttrLabel MiniObjectFlagsFieldInfo = "flags"
    type AttrOrigin MiniObjectFlagsFieldInfo = MiniObject
    attrGet _ = getMiniObjectFlags
    attrSet _ = setMiniObjectFlags
    attrConstruct = undefined
    attrClear _ = undefined

miniObject_flags :: AttrLabelProxy "flags"
miniObject_flags = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' miniObject #dispose
@
-}
getMiniObjectDispose :: MonadIO m => MiniObject -> m (Maybe Gst.Callbacks.MiniObjectDisposeFunction)
getMiniObjectDispose s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO (FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = Gst.Callbacks.dynamic_MiniObjectDisposeFunction val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' miniObject [ #dispose 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectDispose :: MonadIO m => MiniObject -> FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction -> m ()
setMiniObjectDispose s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (val :: FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction)

{- |
Set the value of the “@dispose@” 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' #dispose
@
-}
clearMiniObjectDispose :: MonadIO m => MiniObject -> m ()
clearMiniObjectDispose s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (FP.nullFunPtr :: FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction)

#if ENABLE_OVERLOADING
data MiniObjectDisposeFieldInfo
instance AttrInfo MiniObjectDisposeFieldInfo where
    type AttrAllowedOps MiniObjectDisposeFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint MiniObjectDisposeFieldInfo = (~) (FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction)
    type AttrBaseTypeConstraint MiniObjectDisposeFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectDisposeFieldInfo = Maybe Gst.Callbacks.MiniObjectDisposeFunction
    type AttrLabel MiniObjectDisposeFieldInfo = "dispose"
    type AttrOrigin MiniObjectDisposeFieldInfo = MiniObject
    attrGet _ = getMiniObjectDispose
    attrSet _ = setMiniObjectDispose
    attrConstruct = undefined
    attrClear _ = clearMiniObjectDispose

miniObject_dispose :: AttrLabelProxy "dispose"
miniObject_dispose = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' miniObject #free
@
-}
getMiniObjectFree :: MonadIO m => MiniObject -> m (Maybe Gst.Callbacks.MiniObjectFreeFunction)
getMiniObjectFree s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 40) :: IO (FunPtr Gst.Callbacks.C_MiniObjectFreeFunction)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = Gst.Callbacks.dynamic_MiniObjectFreeFunction val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' miniObject [ #free 'Data.GI.Base.Attributes.:=' value ]
@
-}
setMiniObjectFree :: MonadIO m => MiniObject -> FunPtr Gst.Callbacks.C_MiniObjectFreeFunction -> m ()
setMiniObjectFree s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 40) (val :: FunPtr Gst.Callbacks.C_MiniObjectFreeFunction)

{- |
Set the value of the “@free@” 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' #free
@
-}
clearMiniObjectFree :: MonadIO m => MiniObject -> m ()
clearMiniObjectFree s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 40) (FP.nullFunPtr :: FunPtr Gst.Callbacks.C_MiniObjectFreeFunction)

#if ENABLE_OVERLOADING
data MiniObjectFreeFieldInfo
instance AttrInfo MiniObjectFreeFieldInfo where
    type AttrAllowedOps MiniObjectFreeFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint MiniObjectFreeFieldInfo = (~) (FunPtr Gst.Callbacks.C_MiniObjectFreeFunction)
    type AttrBaseTypeConstraint MiniObjectFreeFieldInfo = (~) MiniObject
    type AttrGetType MiniObjectFreeFieldInfo = Maybe Gst.Callbacks.MiniObjectFreeFunction
    type AttrLabel MiniObjectFreeFieldInfo = "free"
    type AttrOrigin MiniObjectFreeFieldInfo = MiniObject
    attrGet _ = getMiniObjectFree
    attrSet _ = setMiniObjectFree
    attrConstruct = undefined
    attrClear _ = clearMiniObjectFree

miniObject_free :: AttrLabelProxy "free"
miniObject_free = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList MiniObject
type instance O.AttributeList MiniObject = MiniObjectAttributeList
type MiniObjectAttributeList = ('[ '("type", MiniObjectTypeFieldInfo), '("refcount", MiniObjectRefcountFieldInfo), '("lockstate", MiniObjectLockstateFieldInfo), '("flags", MiniObjectFlagsFieldInfo), '("dispose", MiniObjectDisposeFieldInfo), '("free", MiniObjectFreeFieldInfo)] :: [(Symbol, *)])
#endif

-- method MiniObject::add_parent
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstMiniObject", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a parent #GstMiniObject", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_add_parent" gst_mini_object_add_parent ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    Ptr MiniObject ->                       -- parent : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    IO ()

{- |
This adds /@parent@/ as a parent for /@object@/. Having one ore more parents affects the
writability of /@object@/: if a /@parent@/ is not writable, /@object@/ is also not
writable, regardless of its refcount. /@object@/ is only writable if all
the parents are writable and its own refcount is exactly 1.

Note: This function does not take ownership of /@parent@/ and also does not
take an additional reference. It is the responsibility of the caller to
remove the parent again at a later time.

/Since: 1.16/
-}
miniObjectAddParent ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: a 'GI.Gst.Structs.MiniObject.MiniObject' -}
    -> MiniObject
    {- ^ /@parent@/: a parent 'GI.Gst.Structs.MiniObject.MiniObject' -}
    -> m ()
miniObjectAddParent object parent = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    parent' <- unsafeManagedPtrGetPtr parent
    gst_mini_object_add_parent object' parent'
    touchManagedPtr object
    touchManagedPtr parent
    return ()

#if ENABLE_OVERLOADING
data MiniObjectAddParentMethodInfo
instance (signature ~ (MiniObject -> m ()), MonadIO m) => O.MethodInfo MiniObjectAddParentMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectAddParent

#endif

-- method MiniObject::get_qdata
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The GstMiniObject to get a stored user data pointer from", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "quark", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GQuark, naming the user data pointer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_get_qdata" gst_mini_object_get_qdata ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    Word32 ->                               -- quark : TBasicType TUInt32
    IO (Ptr ())

{- |
This function gets back user data pointers stored via
'GI.Gst.Structs.MiniObject.miniObjectSetQdata'.
-}
miniObjectGetQdata ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: The GstMiniObject to get a stored user data pointer from -}
    -> Word32
    {- ^ /@quark@/: A @/GQuark/@, naming the user data pointer -}
    -> m (Ptr ())
    {- ^ __Returns:__ The user data pointer set, or
'Nothing' -}
miniObjectGetQdata object quark = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    result <- gst_mini_object_get_qdata object' quark
    touchManagedPtr object
    return result

#if ENABLE_OVERLOADING
data MiniObjectGetQdataMethodInfo
instance (signature ~ (Word32 -> m (Ptr ())), MonadIO m) => O.MethodInfo MiniObjectGetQdataMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectGetQdata

#endif

-- method MiniObject::is_writable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mini_object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the mini-object to check", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_is_writable" gst_mini_object_is_writable ::
    Ptr MiniObject ->                       -- mini_object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    IO CInt

{- |
If /@miniObject@/ has the LOCKABLE flag set, check if the current EXCLUSIVE
lock on /@object@/ is the only one, this means that changes to the object will
not be visible to any other object.

If the LOCKABLE flag is not set, check if the refcount of /@miniObject@/ is
exactly 1, meaning that no other reference exists to the object and that the
object is therefore writable.

Modification of a mini-object should only be done after verifying that it
is writable.
-}
miniObjectIsWritable ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@miniObject@/: the mini-object to check -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the object is writable. -}
miniObjectIsWritable miniObject = liftIO $ do
    miniObject' <- unsafeManagedPtrGetPtr miniObject
    result <- gst_mini_object_is_writable miniObject'
    let result' = (/= 0) result
    touchManagedPtr miniObject
    return result'

#if ENABLE_OVERLOADING
data MiniObjectIsWritableMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo MiniObjectIsWritableMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectIsWritable

#endif

-- method MiniObject::lock
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the mini-object to lock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TInterface (Name {namespace = "Gst", name = "LockFlags"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GstLockFlags", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_lock" gst_mini_object_lock ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gst", name = "LockFlags"})
    IO CInt

{- |
Lock the mini-object with the specified access mode in /@flags@/.
-}
miniObjectLock ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: the mini-object to lock -}
    -> [Gst.Flags.LockFlags]
    {- ^ /@flags@/: 'GI.Gst.Flags.LockFlags' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@object@/ could be locked. -}
miniObjectLock object flags = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    let flags' = gflagsToWord flags
    result <- gst_mini_object_lock object' flags'
    let result' = (/= 0) result
    touchManagedPtr object
    return result'

#if ENABLE_OVERLOADING
data MiniObjectLockMethodInfo
instance (signature ~ ([Gst.Flags.LockFlags] -> m Bool), MonadIO m) => O.MethodInfo MiniObjectLockMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectLock

#endif

-- method MiniObject::remove_parent
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstMiniObject", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a parent #GstMiniObject", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_remove_parent" gst_mini_object_remove_parent ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    Ptr MiniObject ->                       -- parent : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    IO ()

{- |
This removes /@parent@/ as a parent for /@object@/. See
'GI.Gst.Structs.MiniObject.miniObjectAddParent'.

/Since: 1.16/
-}
miniObjectRemoveParent ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: a 'GI.Gst.Structs.MiniObject.MiniObject' -}
    -> MiniObject
    {- ^ /@parent@/: a parent 'GI.Gst.Structs.MiniObject.MiniObject' -}
    -> m ()
miniObjectRemoveParent object parent = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    parent' <- unsafeManagedPtrGetPtr parent
    gst_mini_object_remove_parent object' parent'
    touchManagedPtr object
    touchManagedPtr parent
    return ()

#if ENABLE_OVERLOADING
data MiniObjectRemoveParentMethodInfo
instance (signature ~ (MiniObject -> m ()), MonadIO m) => O.MethodInfo MiniObjectRemoveParentMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectRemoveParent

#endif

-- method MiniObject::set_qdata
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstMiniObject", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "quark", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GQuark, naming the user data pointer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "An opaque user data pointer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "destroy", argType = TInterface (Name {namespace = "GLib", name = "DestroyNotify"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Function to invoke with @data as argument, when @data\n          needs to be freed", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_set_qdata" gst_mini_object_set_qdata ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    Word32 ->                               -- quark : TBasicType TUInt32
    Ptr () ->                               -- data : TBasicType TPtr
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO ()

{- |
This sets an opaque, named pointer on a miniobject.
The name is specified through a @/GQuark/@ (retrieved e.g. via
'GI.GLib.Functions.quarkFromStaticString'), and the pointer
can be gotten back from the /@object@/ with 'GI.Gst.Structs.MiniObject.miniObjectGetQdata'
until the /@object@/ is disposed.
Setting a previously set user data pointer, overrides (frees)
the old pointer set, using 'Nothing' as pointer essentially
removes the data stored.

/@destroy@/ may be specified which is called with /@data@/ as argument
when the /@object@/ is disposed, or the data is being overwritten by
a call to 'GI.Gst.Structs.MiniObject.miniObjectSetQdata' with the same /@quark@/.
-}
miniObjectSetQdata ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: a 'GI.Gst.Structs.MiniObject.MiniObject' -}
    -> Word32
    {- ^ /@quark@/: A @/GQuark/@, naming the user data pointer -}
    -> Ptr ()
    {- ^ /@data@/: An opaque user data pointer -}
    -> GLib.Callbacks.DestroyNotify
    {- ^ /@destroy@/: Function to invoke with /@data@/ as argument, when /@data@/
          needs to be freed -}
    -> m ()
miniObjectSetQdata object quark data_ destroy = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    ptrdestroy <- callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
    destroy' <- GLib.Callbacks.mk_DestroyNotify (GLib.Callbacks.wrap_DestroyNotify (Just ptrdestroy) destroy)
    poke ptrdestroy destroy'
    gst_mini_object_set_qdata object' quark data_ destroy'
    touchManagedPtr object
    return ()

#if ENABLE_OVERLOADING
data MiniObjectSetQdataMethodInfo
instance (signature ~ (Word32 -> Ptr () -> GLib.Callbacks.DestroyNotify -> m ()), MonadIO m) => O.MethodInfo MiniObjectSetQdataMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectSetQdata

#endif

-- method MiniObject::steal_qdata
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The GstMiniObject to get a stored user data pointer from", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "quark", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GQuark, naming the user data pointer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_steal_qdata" gst_mini_object_steal_qdata ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    Word32 ->                               -- quark : TBasicType TUInt32
    IO (Ptr ())

{- |
This function gets back user data pointers stored via 'GI.Gst.Structs.MiniObject.miniObjectSetQdata'
and removes the data from /@object@/ without invoking its @/destroy()/@ function (if
any was set).
-}
miniObjectStealQdata ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: The GstMiniObject to get a stored user data pointer from -}
    -> Word32
    {- ^ /@quark@/: A @/GQuark/@, naming the user data pointer -}
    -> m (Ptr ())
    {- ^ __Returns:__ The user data pointer set, or
'Nothing' -}
miniObjectStealQdata object quark = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    result <- gst_mini_object_steal_qdata object' quark
    touchManagedPtr object
    return result

#if ENABLE_OVERLOADING
data MiniObjectStealQdataMethodInfo
instance (signature ~ (Word32 -> m (Ptr ())), MonadIO m) => O.MethodInfo MiniObjectStealQdataMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectStealQdata

#endif

-- method MiniObject::unlock
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "MiniObject"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the mini-object to unlock", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TInterface (Name {namespace = "Gst", name = "LockFlags"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "#GstLockFlags", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_mini_object_unlock" gst_mini_object_unlock ::
    Ptr MiniObject ->                       -- object : TInterface (Name {namespace = "Gst", name = "MiniObject"})
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gst", name = "LockFlags"})
    IO ()

{- |
Unlock the mini-object with the specified access mode in /@flags@/.
-}
miniObjectUnlock ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    MiniObject
    {- ^ /@object@/: the mini-object to unlock -}
    -> [Gst.Flags.LockFlags]
    {- ^ /@flags@/: 'GI.Gst.Flags.LockFlags' -}
    -> m ()
miniObjectUnlock object flags = liftIO $ do
    object' <- unsafeManagedPtrGetPtr object
    let flags' = gflagsToWord flags
    gst_mini_object_unlock object' flags'
    touchManagedPtr object
    return ()

#if ENABLE_OVERLOADING
data MiniObjectUnlockMethodInfo
instance (signature ~ ([Gst.Flags.LockFlags] -> m ()), MonadIO m) => O.MethodInfo MiniObjectUnlockMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectUnlock

#endif

-- XXX Could not generate method MiniObject::replace
-- Error was : Not implemented: "Nullable inout structs not supported"
#if ENABLE_OVERLOADING
type family ResolveMiniObjectMethod (t :: Symbol) (o :: *) :: * where
    ResolveMiniObjectMethod "addParent" o = MiniObjectAddParentMethodInfo
    ResolveMiniObjectMethod "isWritable" o = MiniObjectIsWritableMethodInfo
    ResolveMiniObjectMethod "lock" o = MiniObjectLockMethodInfo
    ResolveMiniObjectMethod "removeParent" o = MiniObjectRemoveParentMethodInfo
    ResolveMiniObjectMethod "stealQdata" o = MiniObjectStealQdataMethodInfo
    ResolveMiniObjectMethod "unlock" o = MiniObjectUnlockMethodInfo
    ResolveMiniObjectMethod "getQdata" o = MiniObjectGetQdataMethodInfo
    ResolveMiniObjectMethod "setQdata" o = MiniObjectSetQdataMethodInfo
    ResolveMiniObjectMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMiniObjectMethod t MiniObject, O.MethodInfo info MiniObject p) => OL.IsLabel t (MiniObject -> 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