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

'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, 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.
-}

module GI.Gst.Structs.MiniObject
    ( 

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


 -- * Methods
-- ** getQdata #method:getQdata#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectGetQdataMethodInfo            ,
#endif
    miniObjectGetQdata                      ,


-- ** isWritable #method:isWritable#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectIsWritableMethodInfo          ,
#endif
    miniObjectIsWritable                    ,


-- ** lock #method:lock#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectLockMethodInfo                ,
#endif
    miniObjectLock                          ,


-- ** setQdata #method:setQdata#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectSetQdataMethodInfo            ,
#endif
    miniObjectSetQdata                      ,


-- ** stealQdata #method:stealQdata#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectStealQdataMethodInfo          ,
#endif
    miniObjectStealQdata                    ,


-- ** unlock #method:unlock#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    MiniObjectUnlockMethodInfo              ,
#endif
    miniObjectUnlock                        ,




 -- * Properties
-- ** dispose #attr:dispose#
    clearMiniObjectDispose                  ,
    getMiniObjectDispose                    ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    miniObject_dispose                      ,
#endif
    setMiniObjectDispose                    ,


-- ** flags #attr:flags#
    getMiniObjectFlags                      ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    miniObject_flags                        ,
#endif
    setMiniObjectFlags                      ,


-- ** free #attr:free#
    clearMiniObjectFree                     ,
    getMiniObjectFree                       ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    miniObject_free                         ,
#endif
    setMiniObjectFree                       ,


-- ** lockstate #attr:lockstate#
    getMiniObjectLockstate                  ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    miniObject_lockstate                    ,
#endif
    setMiniObjectLockstate                  ,


-- ** refcount #attr:refcount#
    getMiniObjectRefcount                   ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    miniObject_refcount                     ,
#endif
    setMiniObjectRefcount                   ,


-- ** type #attr:type#
    getMiniObjectType                       ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.Gst.Callbacks as Gst.Callbacks
import {-# SOURCE #-} qualified GI.Gst.Flags as Gst.Flags

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


noMiniObject :: Maybe MiniObject
noMiniObject = Nothing

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'

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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


getMiniObjectRefcount :: MonadIO m => MiniObject -> m Int32
getMiniObjectRefcount s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

setMiniObjectRefcount :: MonadIO m => MiniObject -> Int32 -> m ()
setMiniObjectRefcount s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


getMiniObjectLockstate :: MonadIO m => MiniObject -> m Int32
getMiniObjectLockstate s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Int32
    return val

setMiniObjectLockstate :: MonadIO m => MiniObject -> Int32 -> m ()
setMiniObjectLockstate s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


getMiniObjectFlags :: MonadIO m => MiniObject -> m Word32
getMiniObjectFlags s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO Word32
    return val

setMiniObjectFlags :: MonadIO m => MiniObject -> Word32 -> m ()
setMiniObjectFlags s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Word32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


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

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)

clearMiniObjectDispose :: MonadIO m => MiniObject -> m ()
clearMiniObjectDispose s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (FP.nullFunPtr :: FunPtr Gst.Callbacks.C_MiniObjectDisposeFunction)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


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

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)

clearMiniObjectFree :: MonadIO m => MiniObject -> m ()
clearMiniObjectFree s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 40) (FP.nullFunPtr :: FunPtr Gst.Callbacks.C_MiniObjectFreeFunction)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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::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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data MiniObjectLockMethodInfo
instance (signature ~ ([Gst.Flags.LockFlags] -> m Bool), MonadIO m) => O.MethodInfo MiniObjectLockMethodInfo MiniObject signature where
    overloadedMethod _ = miniObjectLock

#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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveMiniObjectMethod (t :: Symbol) (o :: *) :: * where
    ResolveMiniObjectMethod "isWritable" o = MiniObjectIsWritableMethodInfo
    ResolveMiniObjectMethod "lock" o = MiniObjectLockMethodInfo
    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) => O.IsLabelProxy t (MiniObject -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveMiniObjectMethod t MiniObject, O.MethodInfo info MiniObject p) => O.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

#endif