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

'GI.Gst.Structs.ReferenceTimestampMeta.ReferenceTimestampMeta' can be used to attach alternative timestamps and
possibly durations to a 'GI.Gst.Structs.Buffer.Buffer'. These are generally not according to
the pipeline clock and could be e.g. the NTP timestamp when the media was
captured.

The reference is stored as a 'GI.Gst.Structs.Caps.Caps' in /@reference@/. Examples of valid
references would be \"timestamp\/x-drivername-stream\" for timestamps that are locally
generated by some driver named \"drivername\" when generating the stream,
e.g. based on a frame counter, or \"timestamp\/x-ntp, host=pool.ntp.org,
port=123\" for timestamps based on a specific NTP server.

/Since: 1.14/
-}

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

module GI.Gst.Structs.ReferenceTimestampMeta
    (

-- * Exported types
    ReferenceTimestampMeta(..)              ,
    newZeroReferenceTimestampMeta           ,
    noReferenceTimestampMeta                ,


 -- * Methods
-- ** getInfo #method:getInfo#

    referenceTimestampMetaGetInfo           ,




 -- * Properties
-- ** duration #attr:duration#
{- | duration, or 'GI.Gst.Constants.CLOCK_TIME_NONE'
-}
    getReferenceTimestampMetaDuration       ,
#if ENABLE_OVERLOADING
    referenceTimestampMeta_duration         ,
#endif
    setReferenceTimestampMetaDuration       ,


-- ** parent #attr:parent#
{- | the parent 'GI.Gst.Structs.Meta.Meta' structure
-}
    getReferenceTimestampMetaParent         ,
#if ENABLE_OVERLOADING
    referenceTimestampMeta_parent           ,
#endif


-- ** reference #attr:reference#
{- | identifier for the timestamp reference.
-}
    clearReferenceTimestampMetaReference    ,
    getReferenceTimestampMetaReference      ,
#if ENABLE_OVERLOADING
    referenceTimestampMeta_reference        ,
#endif
    setReferenceTimestampMetaReference      ,


-- ** timestamp #attr:timestamp#
{- | timestamp
-}
    getReferenceTimestampMetaTimestamp      ,
#if ENABLE_OVERLOADING
    referenceTimestampMeta_timestamp        ,
#endif
    setReferenceTimestampMetaTimestamp      ,




    ) 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 {-# SOURCE #-} qualified GI.Gst.Structs.Caps as Gst.Caps
import {-# SOURCE #-} qualified GI.Gst.Structs.Meta as Gst.Meta
import {-# SOURCE #-} qualified GI.Gst.Structs.MetaInfo as Gst.MetaInfo

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `ReferenceTimestampMeta`.
noReferenceTimestampMeta :: Maybe ReferenceTimestampMeta
noReferenceTimestampMeta = Nothing

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

@
'Data.GI.Base.Attributes.get' referenceTimestampMeta #parent
@
-}
getReferenceTimestampMetaParent :: MonadIO m => ReferenceTimestampMeta -> m Gst.Meta.Meta
getReferenceTimestampMetaParent s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 0 :: (Ptr Gst.Meta.Meta)
    val' <- (newPtr Gst.Meta.Meta) val
    return val'

#if ENABLE_OVERLOADING
data ReferenceTimestampMetaParentFieldInfo
instance AttrInfo ReferenceTimestampMetaParentFieldInfo where
    type AttrAllowedOps ReferenceTimestampMetaParentFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint ReferenceTimestampMetaParentFieldInfo = (~) (Ptr Gst.Meta.Meta)
    type AttrBaseTypeConstraint ReferenceTimestampMetaParentFieldInfo = (~) ReferenceTimestampMeta
    type AttrGetType ReferenceTimestampMetaParentFieldInfo = Gst.Meta.Meta
    type AttrLabel ReferenceTimestampMetaParentFieldInfo = "parent"
    type AttrOrigin ReferenceTimestampMetaParentFieldInfo = ReferenceTimestampMeta
    attrGet _ = getReferenceTimestampMetaParent
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

referenceTimestampMeta_parent :: AttrLabelProxy "parent"
referenceTimestampMeta_parent = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' referenceTimestampMeta #reference
@
-}
getReferenceTimestampMetaReference :: MonadIO m => ReferenceTimestampMeta -> m (Maybe Gst.Caps.Caps)
getReferenceTimestampMetaReference s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO (Ptr Gst.Caps.Caps)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newBoxed Gst.Caps.Caps) val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' referenceTimestampMeta [ #reference 'Data.GI.Base.Attributes.:=' value ]
@
-}
setReferenceTimestampMetaReference :: MonadIO m => ReferenceTimestampMeta -> Ptr Gst.Caps.Caps -> m ()
setReferenceTimestampMetaReference s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Ptr Gst.Caps.Caps)

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

@
'Data.GI.Base.Attributes.clear' #reference
@
-}
clearReferenceTimestampMetaReference :: MonadIO m => ReferenceTimestampMeta -> m ()
clearReferenceTimestampMetaReference s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: Ptr Gst.Caps.Caps)

#if ENABLE_OVERLOADING
data ReferenceTimestampMetaReferenceFieldInfo
instance AttrInfo ReferenceTimestampMetaReferenceFieldInfo where
    type AttrAllowedOps ReferenceTimestampMetaReferenceFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint ReferenceTimestampMetaReferenceFieldInfo = (~) (Ptr Gst.Caps.Caps)
    type AttrBaseTypeConstraint ReferenceTimestampMetaReferenceFieldInfo = (~) ReferenceTimestampMeta
    type AttrGetType ReferenceTimestampMetaReferenceFieldInfo = Maybe Gst.Caps.Caps
    type AttrLabel ReferenceTimestampMetaReferenceFieldInfo = "reference"
    type AttrOrigin ReferenceTimestampMetaReferenceFieldInfo = ReferenceTimestampMeta
    attrGet _ = getReferenceTimestampMetaReference
    attrSet _ = setReferenceTimestampMetaReference
    attrConstruct = undefined
    attrClear _ = clearReferenceTimestampMetaReference

referenceTimestampMeta_reference :: AttrLabelProxy "reference"
referenceTimestampMeta_reference = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' referenceTimestampMeta #timestamp
@
-}
getReferenceTimestampMetaTimestamp :: MonadIO m => ReferenceTimestampMeta -> m Word64
getReferenceTimestampMetaTimestamp s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO Word64
    return val

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

@
'Data.GI.Base.Attributes.set' referenceTimestampMeta [ #timestamp 'Data.GI.Base.Attributes.:=' value ]
@
-}
setReferenceTimestampMetaTimestamp :: MonadIO m => ReferenceTimestampMeta -> Word64 -> m ()
setReferenceTimestampMetaTimestamp s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: Word64)

#if ENABLE_OVERLOADING
data ReferenceTimestampMetaTimestampFieldInfo
instance AttrInfo ReferenceTimestampMetaTimestampFieldInfo where
    type AttrAllowedOps ReferenceTimestampMetaTimestampFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ReferenceTimestampMetaTimestampFieldInfo = (~) Word64
    type AttrBaseTypeConstraint ReferenceTimestampMetaTimestampFieldInfo = (~) ReferenceTimestampMeta
    type AttrGetType ReferenceTimestampMetaTimestampFieldInfo = Word64
    type AttrLabel ReferenceTimestampMetaTimestampFieldInfo = "timestamp"
    type AttrOrigin ReferenceTimestampMetaTimestampFieldInfo = ReferenceTimestampMeta
    attrGet _ = getReferenceTimestampMetaTimestamp
    attrSet _ = setReferenceTimestampMetaTimestamp
    attrConstruct = undefined
    attrClear _ = undefined

referenceTimestampMeta_timestamp :: AttrLabelProxy "timestamp"
referenceTimestampMeta_timestamp = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' referenceTimestampMeta #duration
@
-}
getReferenceTimestampMetaDuration :: MonadIO m => ReferenceTimestampMeta -> m Word64
getReferenceTimestampMetaDuration s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO Word64
    return val

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

@
'Data.GI.Base.Attributes.set' referenceTimestampMeta [ #duration 'Data.GI.Base.Attributes.:=' value ]
@
-}
setReferenceTimestampMetaDuration :: MonadIO m => ReferenceTimestampMeta -> Word64 -> m ()
setReferenceTimestampMetaDuration s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (val :: Word64)

#if ENABLE_OVERLOADING
data ReferenceTimestampMetaDurationFieldInfo
instance AttrInfo ReferenceTimestampMetaDurationFieldInfo where
    type AttrAllowedOps ReferenceTimestampMetaDurationFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint ReferenceTimestampMetaDurationFieldInfo = (~) Word64
    type AttrBaseTypeConstraint ReferenceTimestampMetaDurationFieldInfo = (~) ReferenceTimestampMeta
    type AttrGetType ReferenceTimestampMetaDurationFieldInfo = Word64
    type AttrLabel ReferenceTimestampMetaDurationFieldInfo = "duration"
    type AttrOrigin ReferenceTimestampMetaDurationFieldInfo = ReferenceTimestampMeta
    attrGet _ = getReferenceTimestampMetaDuration
    attrSet _ = setReferenceTimestampMetaDuration
    attrConstruct = undefined
    attrClear _ = undefined

referenceTimestampMeta_duration :: AttrLabelProxy "duration"
referenceTimestampMeta_duration = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList ReferenceTimestampMeta
type instance O.AttributeList ReferenceTimestampMeta = ReferenceTimestampMetaAttributeList
type ReferenceTimestampMetaAttributeList = ('[ '("parent", ReferenceTimestampMetaParentFieldInfo), '("reference", ReferenceTimestampMetaReferenceFieldInfo), '("timestamp", ReferenceTimestampMetaTimestampFieldInfo), '("duration", ReferenceTimestampMetaDurationFieldInfo)] :: [(Symbol, *)])
#endif

-- method ReferenceTimestampMeta::get_info
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "MetaInfo"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_reference_timestamp_meta_get_info" gst_reference_timestamp_meta_get_info ::
    IO (Ptr Gst.MetaInfo.MetaInfo)

{- |
Get the global 'GI.Gst.Structs.MetaInfo.MetaInfo' describing  the 'GI.Gst.Structs.ReferenceTimestampMeta.ReferenceTimestampMeta' meta.

/Since: 1.14/
-}
referenceTimestampMetaGetInfo ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Gst.MetaInfo.MetaInfo
    {- ^ __Returns:__ The 'GI.Gst.Structs.MetaInfo.MetaInfo' -}
referenceTimestampMetaGetInfo  = liftIO $ do
    result <- gst_reference_timestamp_meta_get_info
    checkUnexpectedReturnNULL "referenceTimestampMetaGetInfo" result
    result' <- (newPtr Gst.MetaInfo.MetaInfo) result
    return result'

#if ENABLE_OVERLOADING
#endif

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

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