{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Memory is usually created by allocators with a 'GI.Gst.Objects.Allocator.allocatorAlloc'
-- method call. When 'P.Nothing' is used as the allocator, the default allocator will
-- be used.
-- 
-- New allocators can be registered with 'GI.Gst.Objects.Allocator.allocatorRegister'.
-- Allocators are identified by name and can be retrieved with
-- 'GI.Gst.Objects.Allocator.allocatorFind'. 'GI.Gst.Objects.Allocator.allocatorSetDefault' can be used to change the
-- default allocator.
-- 
-- New memory can be created with 'GI.Gst.Structs.Memory.memoryNewWrapped' that wraps the memory
-- allocated elsewhere.

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

module GI.Gst.Objects.Allocator
    ( 

-- * Exported types
    Allocator(..)                           ,
    IsAllocator                             ,
    toAllocator                             ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveAllocatorMethod                  ,
#endif


-- ** alloc #method:alloc#

#if defined(ENABLE_OVERLOADING)
    AllocatorAllocMethodInfo                ,
#endif
    allocatorAlloc                          ,


-- ** find #method:find#

    allocatorFind                           ,


-- ** free #method:free#

#if defined(ENABLE_OVERLOADING)
    AllocatorFreeMethodInfo                 ,
#endif
    allocatorFree                           ,


-- ** register #method:register#

    allocatorRegister                       ,


-- ** setDefault #method:setDefault#

#if defined(ENABLE_OVERLOADING)
    AllocatorSetDefaultMethodInfo           ,
#endif
    allocatorSetDefault                     ,




    ) 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
import {-# SOURCE #-} qualified GI.Gst.Objects.Object as Gst.Object
import {-# SOURCE #-} qualified GI.Gst.Structs.AllocationParams as Gst.AllocationParams
import {-# SOURCE #-} qualified GI.Gst.Structs.Memory as Gst.Memory

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

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

foreign import ccall "gst_allocator_get_type"
    c_gst_allocator_get_type :: IO B.Types.GType

instance B.Types.TypedObject Allocator where
    glibType :: IO GType
glibType = IO GType
c_gst_allocator_get_type

instance B.Types.GObject Allocator

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

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

instance O.HasParentTypes Allocator
type instance O.ParentTypes Allocator = '[Gst.Object.Object, GObject.Object.Object]

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

#if defined(ENABLE_OVERLOADING)
type family ResolveAllocatorMethod (t :: Symbol) (o :: *) :: * where
    ResolveAllocatorMethod "addControlBinding" o = Gst.Object.ObjectAddControlBindingMethodInfo
    ResolveAllocatorMethod "alloc" o = AllocatorAllocMethodInfo
    ResolveAllocatorMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAllocatorMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAllocatorMethod "defaultError" o = Gst.Object.ObjectDefaultErrorMethodInfo
    ResolveAllocatorMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAllocatorMethod "free" o = AllocatorFreeMethodInfo
    ResolveAllocatorMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAllocatorMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAllocatorMethod "hasActiveControlBindings" o = Gst.Object.ObjectHasActiveControlBindingsMethodInfo
    ResolveAllocatorMethod "hasAncestor" o = Gst.Object.ObjectHasAncestorMethodInfo
    ResolveAllocatorMethod "hasAsAncestor" o = Gst.Object.ObjectHasAsAncestorMethodInfo
    ResolveAllocatorMethod "hasAsParent" o = Gst.Object.ObjectHasAsParentMethodInfo
    ResolveAllocatorMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAllocatorMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAllocatorMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAllocatorMethod "ref" o = Gst.Object.ObjectRefMethodInfo
    ResolveAllocatorMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAllocatorMethod "removeControlBinding" o = Gst.Object.ObjectRemoveControlBindingMethodInfo
    ResolveAllocatorMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAllocatorMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAllocatorMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAllocatorMethod "suggestNextSync" o = Gst.Object.ObjectSuggestNextSyncMethodInfo
    ResolveAllocatorMethod "syncValues" o = Gst.Object.ObjectSyncValuesMethodInfo
    ResolveAllocatorMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAllocatorMethod "unparent" o = Gst.Object.ObjectUnparentMethodInfo
    ResolveAllocatorMethod "unref" o = Gst.Object.ObjectUnrefMethodInfo
    ResolveAllocatorMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAllocatorMethod "getControlBinding" o = Gst.Object.ObjectGetControlBindingMethodInfo
    ResolveAllocatorMethod "getControlRate" o = Gst.Object.ObjectGetControlRateMethodInfo
    ResolveAllocatorMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAllocatorMethod "getGValueArray" o = Gst.Object.ObjectGetGValueArrayMethodInfo
    ResolveAllocatorMethod "getName" o = Gst.Object.ObjectGetNameMethodInfo
    ResolveAllocatorMethod "getParent" o = Gst.Object.ObjectGetParentMethodInfo
    ResolveAllocatorMethod "getPathString" o = Gst.Object.ObjectGetPathStringMethodInfo
    ResolveAllocatorMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAllocatorMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAllocatorMethod "getValue" o = Gst.Object.ObjectGetValueMethodInfo
    ResolveAllocatorMethod "setControlBindingDisabled" o = Gst.Object.ObjectSetControlBindingDisabledMethodInfo
    ResolveAllocatorMethod "setControlBindingsDisabled" o = Gst.Object.ObjectSetControlBindingsDisabledMethodInfo
    ResolveAllocatorMethod "setControlRate" o = Gst.Object.ObjectSetControlRateMethodInfo
    ResolveAllocatorMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAllocatorMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveAllocatorMethod "setDefault" o = AllocatorSetDefaultMethodInfo
    ResolveAllocatorMethod "setName" o = Gst.Object.ObjectSetNameMethodInfo
    ResolveAllocatorMethod "setParent" o = Gst.Object.ObjectSetParentMethodInfo
    ResolveAllocatorMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAllocatorMethod l o = O.MethodResolutionFailed l o

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Allocator
type instance O.AttributeList Allocator = AllocatorAttributeList
type AllocatorAttributeList = ('[ '("name", Gst.Object.ObjectNamePropertyInfo), '("parent", Gst.Object.ObjectParentPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList Allocator = AllocatorSignalList
type AllocatorSignalList = ('[ '("deepNotify", Gst.Object.ObjectDeepNotifySignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Allocator::alloc
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "allocator"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Allocator" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstAllocator to use"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "size"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "size of the visible memory area"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "params"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "AllocationParams" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "optional parameters"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gst" , name = "Memory" })
-- throws : False
-- Skip return : False

foreign import ccall "gst_allocator_alloc" gst_allocator_alloc :: 
    Ptr Allocator ->                        -- allocator : TInterface (Name {namespace = "Gst", name = "Allocator"})
    Word64 ->                               -- size : TBasicType TUInt64
    Ptr Gst.AllocationParams.AllocationParams -> -- params : TInterface (Name {namespace = "Gst", name = "AllocationParams"})
    IO (Ptr Gst.Memory.Memory)

-- | Use /@allocator@/ to allocate a new memory block with memory that is at least
-- /@size@/ big.
-- 
-- The optional /@params@/ can specify the prefix and padding for the memory. If
-- 'P.Nothing' is passed, no flags, no extra prefix\/padding and a default alignment is
-- used.
-- 
-- The prefix\/padding will be filled with 0 if flags contains
-- @/GST_MEMORY_FLAG_ZERO_PREFIXED/@ and @/GST_MEMORY_FLAG_ZERO_PADDED/@ respectively.
-- 
-- When /@allocator@/ is 'P.Nothing', the default allocator will be used.
-- 
-- The alignment in /@params@/ is given as a bitmask so that /@align@/ + 1 equals
-- the amount of bytes to align to. For example, to align to 8 bytes,
-- use an alignment of 7.
allocatorAlloc ::
    (B.CallStack.HasCallStack, MonadIO m, IsAllocator a) =>
    a
    -- ^ /@allocator@/: a t'GI.Gst.Objects.Allocator.Allocator' to use
    -> Word64
    -- ^ /@size@/: size of the visible memory area
    -> Maybe (Gst.AllocationParams.AllocationParams)
    -- ^ /@params@/: optional parameters
    -> m (Maybe Gst.Memory.Memory)
    -- ^ __Returns:__ a new t'GI.Gst.Structs.Memory.Memory'.
allocatorAlloc :: a -> Word64 -> Maybe AllocationParams -> m (Maybe Memory)
allocatorAlloc a
allocator Word64
size Maybe AllocationParams
params = IO (Maybe Memory) -> m (Maybe Memory)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Memory) -> m (Maybe Memory))
-> IO (Maybe Memory) -> m (Maybe Memory)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Allocator
allocator' <- a -> IO (Ptr Allocator)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
allocator
    Ptr AllocationParams
maybeParams <- case Maybe AllocationParams
params of
        Maybe AllocationParams
Nothing -> Ptr AllocationParams -> IO (Ptr AllocationParams)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr AllocationParams
forall a. Ptr a
nullPtr
        Just AllocationParams
jParams -> do
            Ptr AllocationParams
jParams' <- AllocationParams -> IO (Ptr AllocationParams)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr AllocationParams
jParams
            Ptr AllocationParams -> IO (Ptr AllocationParams)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr AllocationParams
jParams'
    Ptr Memory
result <- Ptr Allocator -> Word64 -> Ptr AllocationParams -> IO (Ptr Memory)
gst_allocator_alloc Ptr Allocator
allocator' Word64
size Ptr AllocationParams
maybeParams
    Maybe Memory
maybeResult <- Ptr Memory -> (Ptr Memory -> IO Memory) -> IO (Maybe Memory)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Memory
result ((Ptr Memory -> IO Memory) -> IO (Maybe Memory))
-> (Ptr Memory -> IO Memory) -> IO (Maybe Memory)
forall a b. (a -> b) -> a -> b
$ \Ptr Memory
result' -> do
        Memory
result'' <- ((ManagedPtr Memory -> Memory) -> Ptr Memory -> IO Memory
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Memory -> Memory
Gst.Memory.Memory) Ptr Memory
result'
        Memory -> IO Memory
forall (m :: * -> *) a. Monad m => a -> m a
return Memory
result''
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
allocator
    Maybe AllocationParams -> (AllocationParams -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe AllocationParams
params AllocationParams -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Maybe Memory -> IO (Maybe Memory)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Memory
maybeResult

#if defined(ENABLE_OVERLOADING)
data AllocatorAllocMethodInfo
instance (signature ~ (Word64 -> Maybe (Gst.AllocationParams.AllocationParams) -> m (Maybe Gst.Memory.Memory)), MonadIO m, IsAllocator a) => O.MethodInfo AllocatorAllocMethodInfo a signature where
    overloadedMethod = allocatorAlloc

#endif

-- method Allocator::free
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "allocator"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Allocator" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstAllocator to use"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "memory"
--           , argType = TInterface Name { namespace = "Gst" , name = "Memory" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the memory to free" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_allocator_free" gst_allocator_free :: 
    Ptr Allocator ->                        -- allocator : TInterface (Name {namespace = "Gst", name = "Allocator"})
    Ptr Gst.Memory.Memory ->                -- memory : TInterface (Name {namespace = "Gst", name = "Memory"})
    IO ()

-- | Free /@memory@/ that was previously allocated with 'GI.Gst.Objects.Allocator.allocatorAlloc'.
allocatorFree ::
    (B.CallStack.HasCallStack, MonadIO m, IsAllocator a) =>
    a
    -- ^ /@allocator@/: a t'GI.Gst.Objects.Allocator.Allocator' to use
    -> Gst.Memory.Memory
    -- ^ /@memory@/: the memory to free
    -> m ()
allocatorFree :: a -> Memory -> m ()
allocatorFree a
allocator Memory
memory = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Allocator
allocator' <- a -> IO (Ptr Allocator)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
allocator
    Ptr Memory
memory' <- Memory -> IO (Ptr Memory)
forall a. (HasCallStack, GBoxed a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed Memory
memory
    Ptr Allocator -> Ptr Memory -> IO ()
gst_allocator_free Ptr Allocator
allocator' Ptr Memory
memory'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
allocator
    Memory -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Memory
memory
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data AllocatorFreeMethodInfo
instance (signature ~ (Gst.Memory.Memory -> m ()), MonadIO m, IsAllocator a) => O.MethodInfo AllocatorFreeMethodInfo a signature where
    overloadedMethod = allocatorFree

#endif

-- method Allocator::set_default
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "allocator"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Allocator" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstAllocator" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_allocator_set_default" gst_allocator_set_default :: 
    Ptr Allocator ->                        -- allocator : TInterface (Name {namespace = "Gst", name = "Allocator"})
    IO ()

-- | Set the default allocator. This function takes ownership of /@allocator@/.
allocatorSetDefault ::
    (B.CallStack.HasCallStack, MonadIO m, IsAllocator a) =>
    a
    -- ^ /@allocator@/: a t'GI.Gst.Objects.Allocator.Allocator'
    -> m ()
allocatorSetDefault :: a -> m ()
allocatorSetDefault a
allocator = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Allocator
allocator' <- a -> IO (Ptr Allocator)
forall a b. (HasCallStack, GObject a) => a -> IO (Ptr b)
B.ManagedPtr.disownObject a
allocator
    Ptr Allocator -> IO ()
gst_allocator_set_default Ptr Allocator
allocator'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
allocator
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data AllocatorSetDefaultMethodInfo
instance (signature ~ (m ()), MonadIO m, IsAllocator a) => O.MethodInfo AllocatorSetDefaultMethodInfo a signature where
    overloadedMethod = allocatorSetDefault

#endif

-- method Allocator::find
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "name"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the name of the allocator"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gst" , name = "Allocator" })
-- throws : False
-- Skip return : False

foreign import ccall "gst_allocator_find" gst_allocator_find :: 
    CString ->                              -- name : TBasicType TUTF8
    IO (Ptr Allocator)

-- | Find a previously registered allocator with /@name@/. When /@name@/ is 'P.Nothing', the
-- default allocator will be returned.
allocatorFind ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe (T.Text)
    -- ^ /@name@/: the name of the allocator
    -> m (Maybe Allocator)
    -- ^ __Returns:__ a t'GI.Gst.Objects.Allocator.Allocator' or 'P.Nothing' when
    -- the allocator with /@name@/ was not registered. Use 'GI.Gst.Objects.Object.objectUnref'
    -- to release the allocator after usage.
allocatorFind :: Maybe Text -> m (Maybe Allocator)
allocatorFind Maybe Text
name = IO (Maybe Allocator) -> m (Maybe Allocator)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Allocator) -> m (Maybe Allocator))
-> IO (Maybe Allocator) -> m (Maybe Allocator)
forall a b. (a -> b) -> a -> b
$ do
    Ptr CChar
maybeName <- case Maybe Text
name of
        Maybe Text
Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just Text
jName -> do
            Ptr CChar
jName' <- Text -> IO (Ptr CChar)
textToCString Text
jName
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jName'
    Ptr Allocator
result <- Ptr CChar -> IO (Ptr Allocator)
gst_allocator_find Ptr CChar
maybeName
    Maybe Allocator
maybeResult <- Ptr Allocator
-> (Ptr Allocator -> IO Allocator) -> IO (Maybe Allocator)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Allocator
result ((Ptr Allocator -> IO Allocator) -> IO (Maybe Allocator))
-> (Ptr Allocator -> IO Allocator) -> IO (Maybe Allocator)
forall a b. (a -> b) -> a -> b
$ \Ptr Allocator
result' -> do
        Allocator
result'' <- ((ManagedPtr Allocator -> Allocator)
-> Ptr Allocator -> IO Allocator
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Allocator -> Allocator
Allocator) Ptr Allocator
result'
        Allocator -> IO Allocator
forall (m :: * -> *) a. Monad m => a -> m a
return Allocator
result''
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeName
    Maybe Allocator -> IO (Maybe Allocator)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Allocator
maybeResult

#if defined(ENABLE_OVERLOADING)
#endif

-- method Allocator::register
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "name"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the name of the allocator"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "allocator"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Allocator" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "#GstAllocator" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_allocator_register" gst_allocator_register :: 
    CString ->                              -- name : TBasicType TUTF8
    Ptr Allocator ->                        -- allocator : TInterface (Name {namespace = "Gst", name = "Allocator"})
    IO ()

-- | Registers the memory /@allocator@/ with /@name@/. This function takes ownership of
-- /@allocator@/.
allocatorRegister ::
    (B.CallStack.HasCallStack, MonadIO m, IsAllocator a) =>
    T.Text
    -- ^ /@name@/: the name of the allocator
    -> a
    -- ^ /@allocator@/: t'GI.Gst.Objects.Allocator.Allocator'
    -> m ()
allocatorRegister :: Text -> a -> m ()
allocatorRegister Text
name a
allocator = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr CChar
name' <- Text -> IO (Ptr CChar)
textToCString Text
name
    Ptr Allocator
allocator' <- a -> IO (Ptr Allocator)
forall a b. (HasCallStack, GObject a) => a -> IO (Ptr b)
B.ManagedPtr.disownObject a
allocator
    Ptr CChar -> Ptr Allocator -> IO ()
gst_allocator_register Ptr CChar
name' Ptr Allocator
allocator'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
allocator
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
name'
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
#endif