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

This interface abstracts handling of property sets for elements with
children. Imagine elements such as mixers or polyphonic generators. They all
have multiple 'GI.Gst.Objects.Pad.Pad' or some kind of voice objects. Another use case are
container elements like 'GI.Gst.Objects.Bin.Bin'.
The element implementing the interface acts as a parent for those child
objects.

By implementing this interface the child properties can be accessed from the
parent element by using @/gst_child_proxy_get()/@ and @/gst_child_proxy_set()/@.

Property names are written as \"child-name::property-name\". The whole naming
scheme is recursive. Thus \"child1::child2::property\" is valid too, if
\"child1\" and \"child2\" implement the 'GI.Gst.Interfaces.ChildProxy.ChildProxy' interface.
-}

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

module GI.Gst.Interfaces.ChildProxy
    (

-- * Exported types
    ChildProxy(..)                          ,
    noChildProxy                            ,
    IsChildProxy                            ,
    toChildProxy                            ,


 -- * Methods
-- ** childAdded #method:childAdded#

#if ENABLE_OVERLOADING
    ChildProxyChildAddedMethodInfo          ,
#endif
    childProxyChildAdded                    ,


-- ** childRemoved #method:childRemoved#

#if ENABLE_OVERLOADING
    ChildProxyChildRemovedMethodInfo        ,
#endif
    childProxyChildRemoved                  ,


-- ** getChildByIndex #method:getChildByIndex#

#if ENABLE_OVERLOADING
    ChildProxyGetChildByIndexMethodInfo     ,
#endif
    childProxyGetChildByIndex               ,


-- ** getChildByName #method:getChildByName#

#if ENABLE_OVERLOADING
    ChildProxyGetChildByNameMethodInfo      ,
#endif
    childProxyGetChildByName                ,


-- ** getChildrenCount #method:getChildrenCount#

#if ENABLE_OVERLOADING
    ChildProxyGetChildrenCountMethodInfo    ,
#endif
    childProxyGetChildrenCount              ,


-- ** getProperty #method:getProperty#

#if ENABLE_OVERLOADING
    ChildProxyGetPropertyMethodInfo         ,
#endif
    childProxyGetProperty                   ,


-- ** lookup #method:lookup#

#if ENABLE_OVERLOADING
    ChildProxyLookupMethodInfo              ,
#endif
    childProxyLookup                        ,


-- ** setProperty #method:setProperty#

#if ENABLE_OVERLOADING
    ChildProxySetPropertyMethodInfo         ,
#endif
    childProxySetProperty                   ,




 -- * Signals
-- ** childAdded #signal:childAdded#

    C_ChildProxyChildAddedCallback          ,
    ChildProxyChildAddedCallback            ,
#if ENABLE_OVERLOADING
    ChildProxyChildAddedSignalInfo          ,
#endif
    afterChildProxyChildAdded               ,
    genClosure_ChildProxyChildAdded         ,
    mk_ChildProxyChildAddedCallback         ,
    noChildProxyChildAddedCallback          ,
    onChildProxyChildAdded                  ,
    wrap_ChildProxyChildAddedCallback       ,


-- ** childRemoved #signal:childRemoved#

    C_ChildProxyChildRemovedCallback        ,
    ChildProxyChildRemovedCallback          ,
#if ENABLE_OVERLOADING
    ChildProxyChildRemovedSignalInfo        ,
#endif
    afterChildProxyChildRemoved             ,
    genClosure_ChildProxyChildRemoved       ,
    mk_ChildProxyChildRemovedCallback       ,
    noChildProxyChildRemovedCallback        ,
    onChildProxyChildRemoved                ,
    wrap_ChildProxyChildRemovedCallback     ,




    ) 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.GObject.Objects.Object as GObject.Object

-- interface ChildProxy 
-- | Memory-managed wrapper type.
newtype ChildProxy = ChildProxy (ManagedPtr ChildProxy)
-- | A convenience alias for `Nothing` :: `Maybe` `ChildProxy`.
noChildProxy :: Maybe ChildProxy
noChildProxy = Nothing

-- signal ChildProxy::child-added
{- |
Will be emitted after the /@object@/ was added to the /@childProxy@/.
-}
type ChildProxyChildAddedCallback =
    GObject.Object.Object
    {- ^ /@object@/: the 'GI.GObject.Objects.Object.Object' that was added -}
    -> T.Text
    {- ^ /@name@/: the name of the new child -}
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ChildProxyChildAddedCallback`@.
noChildProxyChildAddedCallback :: Maybe ChildProxyChildAddedCallback
noChildProxyChildAddedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_ChildProxyChildAddedCallback =
    Ptr () ->                               -- object
    Ptr GObject.Object.Object ->
    CString ->
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_ChildProxyChildAddedCallback`.
foreign import ccall "wrapper"
    mk_ChildProxyChildAddedCallback :: C_ChildProxyChildAddedCallback -> IO (FunPtr C_ChildProxyChildAddedCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_ChildProxyChildAdded :: MonadIO m => ChildProxyChildAddedCallback -> m (GClosure C_ChildProxyChildAddedCallback)
genClosure_ChildProxyChildAdded cb = liftIO $ do
    let cb' = wrap_ChildProxyChildAddedCallback cb
    mk_ChildProxyChildAddedCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `ChildProxyChildAddedCallback` into a `C_ChildProxyChildAddedCallback`.
wrap_ChildProxyChildAddedCallback ::
    ChildProxyChildAddedCallback ->
    C_ChildProxyChildAddedCallback
wrap_ChildProxyChildAddedCallback _cb _ object name _ = do
    object' <- (newObject GObject.Object.Object) object
    name' <- cstringToText name
    _cb  object' name'


{- |
Connect a signal handler for the “@child-added@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' childProxy #childAdded callback
@
-}
onChildProxyChildAdded :: (IsChildProxy a, MonadIO m) => a -> ChildProxyChildAddedCallback -> m SignalHandlerId
onChildProxyChildAdded obj cb = liftIO $ do
    let cb' = wrap_ChildProxyChildAddedCallback cb
    cb'' <- mk_ChildProxyChildAddedCallback cb'
    connectSignalFunPtr obj "child-added" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@child-added@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' childProxy #childAdded callback
@
-}
afterChildProxyChildAdded :: (IsChildProxy a, MonadIO m) => a -> ChildProxyChildAddedCallback -> m SignalHandlerId
afterChildProxyChildAdded obj cb = liftIO $ do
    let cb' = wrap_ChildProxyChildAddedCallback cb
    cb'' <- mk_ChildProxyChildAddedCallback cb'
    connectSignalFunPtr obj "child-added" cb'' SignalConnectAfter


-- signal ChildProxy::child-removed
{- |
Will be emitted after the /@object@/ was removed from the /@childProxy@/.
-}
type ChildProxyChildRemovedCallback =
    GObject.Object.Object
    {- ^ /@object@/: the 'GI.GObject.Objects.Object.Object' that was removed -}
    -> T.Text
    {- ^ /@name@/: the name of the old child -}
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ChildProxyChildRemovedCallback`@.
noChildProxyChildRemovedCallback :: Maybe ChildProxyChildRemovedCallback
noChildProxyChildRemovedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_ChildProxyChildRemovedCallback =
    Ptr () ->                               -- object
    Ptr GObject.Object.Object ->
    CString ->
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_ChildProxyChildRemovedCallback`.
foreign import ccall "wrapper"
    mk_ChildProxyChildRemovedCallback :: C_ChildProxyChildRemovedCallback -> IO (FunPtr C_ChildProxyChildRemovedCallback)

-- | Wrap the callback into a `GClosure`.
genClosure_ChildProxyChildRemoved :: MonadIO m => ChildProxyChildRemovedCallback -> m (GClosure C_ChildProxyChildRemovedCallback)
genClosure_ChildProxyChildRemoved cb = liftIO $ do
    let cb' = wrap_ChildProxyChildRemovedCallback cb
    mk_ChildProxyChildRemovedCallback cb' >>= B.GClosure.newGClosure


-- | Wrap a `ChildProxyChildRemovedCallback` into a `C_ChildProxyChildRemovedCallback`.
wrap_ChildProxyChildRemovedCallback ::
    ChildProxyChildRemovedCallback ->
    C_ChildProxyChildRemovedCallback
wrap_ChildProxyChildRemovedCallback _cb _ object name _ = do
    object' <- (newObject GObject.Object.Object) object
    name' <- cstringToText name
    _cb  object' name'


{- |
Connect a signal handler for the “@child-removed@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' childProxy #childRemoved callback
@
-}
onChildProxyChildRemoved :: (IsChildProxy a, MonadIO m) => a -> ChildProxyChildRemovedCallback -> m SignalHandlerId
onChildProxyChildRemoved obj cb = liftIO $ do
    let cb' = wrap_ChildProxyChildRemovedCallback cb
    cb'' <- mk_ChildProxyChildRemovedCallback cb'
    connectSignalFunPtr obj "child-removed" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@child-removed@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' childProxy #childRemoved callback
@
-}
afterChildProxyChildRemoved :: (IsChildProxy a, MonadIO m) => a -> ChildProxyChildRemovedCallback -> m SignalHandlerId
afterChildProxyChildRemoved obj cb = liftIO $ do
    let cb' = wrap_ChildProxyChildRemovedCallback cb
    cb'' <- mk_ChildProxyChildRemovedCallback cb'
    connectSignalFunPtr obj "child-removed" cb'' SignalConnectAfter


#if ENABLE_OVERLOADING
data ChildProxyChildAddedSignalInfo
instance SignalInfo ChildProxyChildAddedSignalInfo where
    type HaskellCallbackType ChildProxyChildAddedSignalInfo = ChildProxyChildAddedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_ChildProxyChildAddedCallback cb
        cb'' <- mk_ChildProxyChildAddedCallback cb'
        connectSignalFunPtr obj "child-added" cb'' connectMode

data ChildProxyChildRemovedSignalInfo
instance SignalInfo ChildProxyChildRemovedSignalInfo where
    type HaskellCallbackType ChildProxyChildRemovedSignalInfo = ChildProxyChildRemovedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_ChildProxyChildRemovedCallback cb
        cb'' <- mk_ChildProxyChildRemovedCallback cb'
        connectSignalFunPtr obj "child-removed" cb'' connectMode

type instance O.SignalList ChildProxy = ChildProxySignalList
type ChildProxySignalList = ('[ '("childAdded", ChildProxyChildAddedSignalInfo), '("childRemoved", ChildProxyChildRemovedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "gst_child_proxy_get_type"
    c_gst_child_proxy_get_type :: IO GType

instance GObject ChildProxy where
    gobjectType = c_gst_child_proxy_get_type


-- | Type class for types which can be safely cast to `ChildProxy`, for instance with `toChildProxy`.
class (GObject o, O.IsDescendantOf ChildProxy o) => IsChildProxy o
instance (GObject o, O.IsDescendantOf ChildProxy o) => IsChildProxy o

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

-- | Cast to `ChildProxy`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toChildProxy :: (MonadIO m, IsChildProxy o) => o -> m ChildProxy
toChildProxy = liftIO . unsafeCastTo ChildProxy

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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type family ResolveChildProxyMethod (t :: Symbol) (o :: *) :: * where
    ResolveChildProxyMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveChildProxyMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveChildProxyMethod "childAdded" o = ChildProxyChildAddedMethodInfo
    ResolveChildProxyMethod "childRemoved" o = ChildProxyChildRemovedMethodInfo
    ResolveChildProxyMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveChildProxyMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveChildProxyMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveChildProxyMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveChildProxyMethod "lookup" o = ChildProxyLookupMethodInfo
    ResolveChildProxyMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveChildProxyMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveChildProxyMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveChildProxyMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveChildProxyMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveChildProxyMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveChildProxyMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveChildProxyMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveChildProxyMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveChildProxyMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveChildProxyMethod "getChildByIndex" o = ChildProxyGetChildByIndexMethodInfo
    ResolveChildProxyMethod "getChildByName" o = ChildProxyGetChildByNameMethodInfo
    ResolveChildProxyMethod "getChildrenCount" o = ChildProxyGetChildrenCountMethodInfo
    ResolveChildProxyMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveChildProxyMethod "getProperty" o = ChildProxyGetPropertyMethodInfo
    ResolveChildProxyMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveChildProxyMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveChildProxyMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveChildProxyMethod "setProperty" o = ChildProxySetPropertyMethodInfo
    ResolveChildProxyMethod l o = O.MethodResolutionFailed l o

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

-- method ChildProxy::child_added
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the parent object", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "child", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the newly added child", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the new child", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_child_added" gst_child_proxy_child_added ::
    Ptr ChildProxy ->                       -- parent : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    Ptr GObject.Object.Object ->            -- child : TInterface (Name {namespace = "GObject", name = "Object"})
    CString ->                              -- name : TBasicType TUTF8
    IO ()

{- |
Emits the \"child-added\" signal.
-}
childProxyChildAdded ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a, GObject.Object.IsObject b) =>
    a
    {- ^ /@parent@/: the parent object -}
    -> b
    {- ^ /@child@/: the newly added child -}
    -> T.Text
    {- ^ /@name@/: the name of the new child -}
    -> m ()
childProxyChildAdded parent child name = liftIO $ do
    parent' <- unsafeManagedPtrCastPtr parent
    child' <- unsafeManagedPtrCastPtr child
    name' <- textToCString name
    gst_child_proxy_child_added parent' child' name'
    touchManagedPtr parent
    touchManagedPtr child
    freeMem name'
    return ()

#if ENABLE_OVERLOADING
data ChildProxyChildAddedMethodInfo
instance (signature ~ (b -> T.Text -> m ()), MonadIO m, IsChildProxy a, GObject.Object.IsObject b) => O.MethodInfo ChildProxyChildAddedMethodInfo a signature where
    overloadedMethod _ = childProxyChildAdded

#endif

-- method ChildProxy::child_removed
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the parent object", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "child", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the removed child", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the old child", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_child_removed" gst_child_proxy_child_removed ::
    Ptr ChildProxy ->                       -- parent : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    Ptr GObject.Object.Object ->            -- child : TInterface (Name {namespace = "GObject", name = "Object"})
    CString ->                              -- name : TBasicType TUTF8
    IO ()

{- |
Emits the \"child-removed\" signal.
-}
childProxyChildRemoved ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a, GObject.Object.IsObject b) =>
    a
    {- ^ /@parent@/: the parent object -}
    -> b
    {- ^ /@child@/: the removed child -}
    -> T.Text
    {- ^ /@name@/: the name of the old child -}
    -> m ()
childProxyChildRemoved parent child name = liftIO $ do
    parent' <- unsafeManagedPtrCastPtr parent
    child' <- unsafeManagedPtrCastPtr child
    name' <- textToCString name
    gst_child_proxy_child_removed parent' child' name'
    touchManagedPtr parent
    touchManagedPtr child
    freeMem name'
    return ()

#if ENABLE_OVERLOADING
data ChildProxyChildRemovedMethodInfo
instance (signature ~ (b -> T.Text -> m ()), MonadIO m, IsChildProxy a, GObject.Object.IsObject b) => O.MethodInfo ChildProxyChildRemovedMethodInfo a signature where
    overloadedMethod _ = childProxyChildRemoved

#endif

-- method ChildProxy::get_child_by_index
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the parent object to get the child from", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "index", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the child's position in the child list", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GObject", name = "Object"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_get_child_by_index" gst_child_proxy_get_child_by_index ::
    Ptr ChildProxy ->                       -- parent : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    Word32 ->                               -- index : TBasicType TUInt
    IO (Ptr GObject.Object.Object)

{- |
Fetches a child by its number.
-}
childProxyGetChildByIndex ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@parent@/: the parent object to get the child from -}
    -> Word32
    {- ^ /@index@/: the child\'s position in the child list -}
    -> m (Maybe GObject.Object.Object)
    {- ^ __Returns:__ the child object or 'Nothing' if
    not found (index too high). Unref after usage.

MT safe. -}
childProxyGetChildByIndex parent index = liftIO $ do
    parent' <- unsafeManagedPtrCastPtr parent
    result <- gst_child_proxy_get_child_by_index parent' index
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject GObject.Object.Object) result'
        return result''
    touchManagedPtr parent
    return maybeResult

#if ENABLE_OVERLOADING
data ChildProxyGetChildByIndexMethodInfo
instance (signature ~ (Word32 -> m (Maybe GObject.Object.Object)), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxyGetChildByIndexMethodInfo a signature where
    overloadedMethod _ = childProxyGetChildByIndex

#endif

-- method ChildProxy::get_child_by_name
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "parent", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the parent object to get the child from", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the child's name", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GObject", name = "Object"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_get_child_by_name" gst_child_proxy_get_child_by_name ::
    Ptr ChildProxy ->                       -- parent : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    CString ->                              -- name : TBasicType TUTF8
    IO (Ptr GObject.Object.Object)

{- |
Looks up a child element by the given name.

This virtual method has a default implementation that uses 'GI.Gst.Objects.Object.Object'
together with 'GI.Gst.Objects.Object.objectGetName'. If the interface is to be used with
@/GObjects/@, this methods needs to be overridden.
-}
childProxyGetChildByName ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@parent@/: the parent object to get the child from -}
    -> T.Text
    {- ^ /@name@/: the child\'s name -}
    -> m (Maybe GObject.Object.Object)
    {- ^ __Returns:__ the child object or 'Nothing' if
    not found. Unref after usage.

MT safe. -}
childProxyGetChildByName parent name = liftIO $ do
    parent' <- unsafeManagedPtrCastPtr parent
    name' <- textToCString name
    result <- gst_child_proxy_get_child_by_name parent' name'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject GObject.Object.Object) result'
        return result''
    touchManagedPtr parent
    freeMem name'
    return maybeResult

#if ENABLE_OVERLOADING
data ChildProxyGetChildByNameMethodInfo
instance (signature ~ (T.Text -> m (Maybe GObject.Object.Object)), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxyGetChildByNameMethodInfo a signature where
    overloadedMethod _ = childProxyGetChildByName

#endif

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

foreign import ccall "gst_child_proxy_get_children_count" gst_child_proxy_get_children_count ::
    Ptr ChildProxy ->                       -- parent : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    IO Word32

{- |
Gets the number of child objects this parent contains.
-}
childProxyGetChildrenCount ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@parent@/: the parent object -}
    -> m Word32
    {- ^ __Returns:__ the number of child objects

MT safe. -}
childProxyGetChildrenCount parent = liftIO $ do
    parent' <- unsafeManagedPtrCastPtr parent
    result <- gst_child_proxy_get_children_count parent'
    touchManagedPtr parent
    return result

#if ENABLE_OVERLOADING
data ChildProxyGetChildrenCountMethodInfo
instance (signature ~ (m Word32), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxyGetChildrenCountMethodInfo a signature where
    overloadedMethod _ = childProxyGetChildrenCount

#endif

-- method ChildProxy::get_property
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "object to query", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "name of the property", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TInterface (Name {namespace = "GObject", name = "Value"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GValue that should take the result.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = True, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_get_property" gst_child_proxy_get_property ::
    Ptr ChildProxy ->                       -- object : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    CString ->                              -- name : TBasicType TUTF8
    Ptr GValue ->                           -- value : TInterface (Name {namespace = "GObject", name = "Value"})
    IO ()

{- |
Gets a single property using the GstChildProxy mechanism.
You are responsible for freeing it by calling 'GI.GObject.Structs.Value.valueUnset'
-}
childProxyGetProperty ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@object@/: object to query -}
    -> T.Text
    {- ^ /@name@/: name of the property -}
    -> m (GValue)
childProxyGetProperty object name = liftIO $ do
    object' <- unsafeManagedPtrCastPtr object
    name' <- textToCString name
    value <- callocBoxedBytes 24 :: IO (Ptr GValue)
    gst_child_proxy_get_property object' name' value
    value' <- (wrapBoxed GValue) value
    touchManagedPtr object
    freeMem name'
    return value'

#if ENABLE_OVERLOADING
data ChildProxyGetPropertyMethodInfo
instance (signature ~ (T.Text -> m (GValue)), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxyGetPropertyMethodInfo a signature where
    overloadedMethod _ = childProxyGetProperty

#endif

-- method ChildProxy::lookup
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "child proxy object to lookup the property in", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "name of the property to look up", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "target", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to a #GObject that\n    takes the real object to set property on", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "pspec", argType = TParamSpec, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "pointer to take the #GParamSpec\n    describing the property", 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_child_proxy_lookup" gst_child_proxy_lookup ::
    Ptr ChildProxy ->                       -- object : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    CString ->                              -- name : TBasicType TUTF8
    Ptr (Ptr GObject.Object.Object) ->      -- target : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GParamSpec) ->                 -- pspec : TParamSpec
    IO CInt

{- |
Looks up which object and 'GI.GObject.Objects.ParamSpec.ParamSpec' would be effected by the given /@name@/.

MT safe.
-}
childProxyLookup ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@object@/: child proxy object to lookup the property in -}
    -> T.Text
    {- ^ /@name@/: name of the property to look up -}
    -> m ((Bool, GObject.Object.Object, GParamSpec))
    {- ^ __Returns:__ 'True' if /@target@/ and /@pspec@/ could be found. 'False' otherwise. In that
case the values for /@pspec@/ and /@target@/ are not modified. Unref /@target@/ after
usage. For plain GObjects /@target@/ is the same as /@object@/. -}
childProxyLookup object name = liftIO $ do
    object' <- unsafeManagedPtrCastPtr object
    name' <- textToCString name
    target <- allocMem :: IO (Ptr (Ptr GObject.Object.Object))
    pspec <- allocMem :: IO (Ptr (Ptr GParamSpec))
    result <- gst_child_proxy_lookup object' name' target pspec
    let result' = (/= 0) result
    target' <- peek target
    target'' <- (wrapObject GObject.Object.Object) target'
    pspec' <- peek pspec
    pspec'' <- B.GParamSpec.newGParamSpecFromPtr pspec'
    touchManagedPtr object
    freeMem name'
    freeMem target
    freeMem pspec
    return (result', target'', pspec'')

#if ENABLE_OVERLOADING
data ChildProxyLookupMethodInfo
instance (signature ~ (T.Text -> m ((Bool, GObject.Object.Object, GParamSpec))), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxyLookupMethodInfo a signature where
    overloadedMethod _ = childProxyLookup

#endif

-- method ChildProxy::set_property
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "object", argType = TInterface (Name {namespace = "Gst", name = "ChildProxy"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the parent object", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "name of the property to set", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TInterface (Name {namespace = "GObject", name = "Value"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "new #GValue for the property", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_child_proxy_set_property" gst_child_proxy_set_property ::
    Ptr ChildProxy ->                       -- object : TInterface (Name {namespace = "Gst", name = "ChildProxy"})
    CString ->                              -- name : TBasicType TUTF8
    Ptr GValue ->                           -- value : TInterface (Name {namespace = "GObject", name = "Value"})
    IO ()

{- |
Sets a single property using the GstChildProxy mechanism.
-}
childProxySetProperty ::
    (B.CallStack.HasCallStack, MonadIO m, IsChildProxy a) =>
    a
    {- ^ /@object@/: the parent object -}
    -> T.Text
    {- ^ /@name@/: name of the property to set -}
    -> GValue
    {- ^ /@value@/: new 'GI.GObject.Structs.Value.Value' for the property -}
    -> m ()
childProxySetProperty object name value = liftIO $ do
    object' <- unsafeManagedPtrCastPtr object
    name' <- textToCString name
    value' <- unsafeManagedPtrGetPtr value
    gst_child_proxy_set_property object' name' value'
    touchManagedPtr object
    touchManagedPtr value
    freeMem name'
    return ()

#if ENABLE_OVERLOADING
data ChildProxySetPropertyMethodInfo
instance (signature ~ (T.Text -> GValue -> m ()), MonadIO m, IsChildProxy a) => O.MethodInfo ChildProxySetPropertyMethodInfo a signature where
    overloadedMethod _ = childProxySetProperty

#endif