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

Element interface that allows setting of the TOC.

Elements that support some kind of chapters or editions (or tracks like in
the FLAC cue sheet) will implement this interface.

If you just want to retrieve the TOC in your application then all you
need to do is watch for TOC messages on your pipeline\'s bus (or you can
perform TOC query). This interface is only for setting TOC data, not for
extracting it. To set TOC from the application, find proper tocsetter element
and set TOC using 'GI.Gst.Interfaces.TocSetter.tocSetterSetToc'.

Elements implementing the 'GI.Gst.Interfaces.TocSetter.TocSetter' interface can extend existing TOC
by getting extend UID for that (you can use 'GI.Gst.Structs.Toc.tocFindEntry' to retrieve it)
with any TOC entries received from downstream.
-}

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

module GI.Gst.Interfaces.TocSetter
    (

-- * Exported types
    TocSetter(..)                           ,
    noTocSetter                             ,
    IsTocSetter                             ,
    toTocSetter                             ,


 -- * Methods
-- ** getToc #method:getToc#

#if ENABLE_OVERLOADING
    TocSetterGetTocMethodInfo               ,
#endif
    tocSetterGetToc                         ,


-- ** reset #method:reset#

#if ENABLE_OVERLOADING
    TocSetterResetMethodInfo                ,
#endif
    tocSetterReset                          ,


-- ** setToc #method:setToc#

#if ENABLE_OVERLOADING
    TocSetterSetTocMethodInfo               ,
#endif
    tocSetterSetToc                         ,




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

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

#if ENABLE_OVERLOADING
type instance O.SignalList TocSetter = TocSetterSignalList
type TocSetterSignalList = ('[ '("deepNotify", Gst.Object.ObjectDeepNotifySignalInfo), '("noMorePads", Gst.Element.ElementNoMorePadsSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo), '("padAdded", Gst.Element.ElementPadAddedSignalInfo), '("padRemoved", Gst.Element.ElementPadRemovedSignalInfo)] :: [(Symbol, *)])

#endif

foreign import ccall "gst_toc_setter_get_type"
    c_gst_toc_setter_get_type :: IO GType

instance GObject TocSetter where
    gobjectType = c_gst_toc_setter_get_type


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

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

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

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

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type family ResolveTocSetterMethod (t :: Symbol) (o :: *) :: * where
    ResolveTocSetterMethod "abortState" o = Gst.Element.ElementAbortStateMethodInfo
    ResolveTocSetterMethod "addControlBinding" o = Gst.Object.ObjectAddControlBindingMethodInfo
    ResolveTocSetterMethod "addPad" o = Gst.Element.ElementAddPadMethodInfo
    ResolveTocSetterMethod "addPropertyDeepNotifyWatch" o = Gst.Element.ElementAddPropertyDeepNotifyWatchMethodInfo
    ResolveTocSetterMethod "addPropertyNotifyWatch" o = Gst.Element.ElementAddPropertyNotifyWatchMethodInfo
    ResolveTocSetterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveTocSetterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveTocSetterMethod "callAsync" o = Gst.Element.ElementCallAsyncMethodInfo
    ResolveTocSetterMethod "changeState" o = Gst.Element.ElementChangeStateMethodInfo
    ResolveTocSetterMethod "continueState" o = Gst.Element.ElementContinueStateMethodInfo
    ResolveTocSetterMethod "createAllPads" o = Gst.Element.ElementCreateAllPadsMethodInfo
    ResolveTocSetterMethod "defaultError" o = Gst.Object.ObjectDefaultErrorMethodInfo
    ResolveTocSetterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveTocSetterMethod "foreachPad" o = Gst.Element.ElementForeachPadMethodInfo
    ResolveTocSetterMethod "foreachSinkPad" o = Gst.Element.ElementForeachSinkPadMethodInfo
    ResolveTocSetterMethod "foreachSrcPad" o = Gst.Element.ElementForeachSrcPadMethodInfo
    ResolveTocSetterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveTocSetterMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveTocSetterMethod "hasActiveControlBindings" o = Gst.Object.ObjectHasActiveControlBindingsMethodInfo
    ResolveTocSetterMethod "hasAncestor" o = Gst.Object.ObjectHasAncestorMethodInfo
    ResolveTocSetterMethod "hasAsAncestor" o = Gst.Object.ObjectHasAsAncestorMethodInfo
    ResolveTocSetterMethod "hasAsParent" o = Gst.Object.ObjectHasAsParentMethodInfo
    ResolveTocSetterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveTocSetterMethod "isLockedState" o = Gst.Element.ElementIsLockedStateMethodInfo
    ResolveTocSetterMethod "iteratePads" o = Gst.Element.ElementIteratePadsMethodInfo
    ResolveTocSetterMethod "iterateSinkPads" o = Gst.Element.ElementIterateSinkPadsMethodInfo
    ResolveTocSetterMethod "iterateSrcPads" o = Gst.Element.ElementIterateSrcPadsMethodInfo
    ResolveTocSetterMethod "link" o = Gst.Element.ElementLinkMethodInfo
    ResolveTocSetterMethod "linkFiltered" o = Gst.Element.ElementLinkFilteredMethodInfo
    ResolveTocSetterMethod "linkPads" o = Gst.Element.ElementLinkPadsMethodInfo
    ResolveTocSetterMethod "linkPadsFiltered" o = Gst.Element.ElementLinkPadsFilteredMethodInfo
    ResolveTocSetterMethod "linkPadsFull" o = Gst.Element.ElementLinkPadsFullMethodInfo
    ResolveTocSetterMethod "lostState" o = Gst.Element.ElementLostStateMethodInfo
    ResolveTocSetterMethod "messageFull" o = Gst.Element.ElementMessageFullMethodInfo
    ResolveTocSetterMethod "messageFullWithDetails" o = Gst.Element.ElementMessageFullWithDetailsMethodInfo
    ResolveTocSetterMethod "noMorePads" o = Gst.Element.ElementNoMorePadsMethodInfo
    ResolveTocSetterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveTocSetterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveTocSetterMethod "postMessage" o = Gst.Element.ElementPostMessageMethodInfo
    ResolveTocSetterMethod "provideClock" o = Gst.Element.ElementProvideClockMethodInfo
    ResolveTocSetterMethod "query" o = Gst.Element.ElementQueryMethodInfo
    ResolveTocSetterMethod "queryConvert" o = Gst.Element.ElementQueryConvertMethodInfo
    ResolveTocSetterMethod "queryDuration" o = Gst.Element.ElementQueryDurationMethodInfo
    ResolveTocSetterMethod "queryPosition" o = Gst.Element.ElementQueryPositionMethodInfo
    ResolveTocSetterMethod "ref" o = Gst.Object.ObjectRefMethodInfo
    ResolveTocSetterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveTocSetterMethod "releaseRequestPad" o = Gst.Element.ElementReleaseRequestPadMethodInfo
    ResolveTocSetterMethod "removeControlBinding" o = Gst.Object.ObjectRemoveControlBindingMethodInfo
    ResolveTocSetterMethod "removePad" o = Gst.Element.ElementRemovePadMethodInfo
    ResolveTocSetterMethod "removePropertyNotifyWatch" o = Gst.Element.ElementRemovePropertyNotifyWatchMethodInfo
    ResolveTocSetterMethod "requestPad" o = Gst.Element.ElementRequestPadMethodInfo
    ResolveTocSetterMethod "reset" o = TocSetterResetMethodInfo
    ResolveTocSetterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveTocSetterMethod "seek" o = Gst.Element.ElementSeekMethodInfo
    ResolveTocSetterMethod "seekSimple" o = Gst.Element.ElementSeekSimpleMethodInfo
    ResolveTocSetterMethod "sendEvent" o = Gst.Element.ElementSendEventMethodInfo
    ResolveTocSetterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveTocSetterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveTocSetterMethod "suggestNextSync" o = Gst.Object.ObjectSuggestNextSyncMethodInfo
    ResolveTocSetterMethod "syncStateWithParent" o = Gst.Element.ElementSyncStateWithParentMethodInfo
    ResolveTocSetterMethod "syncValues" o = Gst.Object.ObjectSyncValuesMethodInfo
    ResolveTocSetterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveTocSetterMethod "unlink" o = Gst.Element.ElementUnlinkMethodInfo
    ResolveTocSetterMethod "unlinkPads" o = Gst.Element.ElementUnlinkPadsMethodInfo
    ResolveTocSetterMethod "unparent" o = Gst.Object.ObjectUnparentMethodInfo
    ResolveTocSetterMethod "unref" o = Gst.Object.ObjectUnrefMethodInfo
    ResolveTocSetterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveTocSetterMethod "getBaseTime" o = Gst.Element.ElementGetBaseTimeMethodInfo
    ResolveTocSetterMethod "getBus" o = Gst.Element.ElementGetBusMethodInfo
    ResolveTocSetterMethod "getClock" o = Gst.Element.ElementGetClockMethodInfo
    ResolveTocSetterMethod "getCompatiblePad" o = Gst.Element.ElementGetCompatiblePadMethodInfo
    ResolveTocSetterMethod "getCompatiblePadTemplate" o = Gst.Element.ElementGetCompatiblePadTemplateMethodInfo
    ResolveTocSetterMethod "getContext" o = Gst.Element.ElementGetContextMethodInfo
    ResolveTocSetterMethod "getContextUnlocked" o = Gst.Element.ElementGetContextUnlockedMethodInfo
    ResolveTocSetterMethod "getContexts" o = Gst.Element.ElementGetContextsMethodInfo
    ResolveTocSetterMethod "getControlBinding" o = Gst.Object.ObjectGetControlBindingMethodInfo
    ResolveTocSetterMethod "getControlRate" o = Gst.Object.ObjectGetControlRateMethodInfo
    ResolveTocSetterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveTocSetterMethod "getFactory" o = Gst.Element.ElementGetFactoryMethodInfo
    ResolveTocSetterMethod "getGValueArray" o = Gst.Object.ObjectGetGValueArrayMethodInfo
    ResolveTocSetterMethod "getMetadata" o = Gst.Element.ElementGetMetadataMethodInfo
    ResolveTocSetterMethod "getName" o = Gst.Object.ObjectGetNameMethodInfo
    ResolveTocSetterMethod "getPadTemplate" o = Gst.Element.ElementGetPadTemplateMethodInfo
    ResolveTocSetterMethod "getPadTemplateList" o = Gst.Element.ElementGetPadTemplateListMethodInfo
    ResolveTocSetterMethod "getParent" o = Gst.Object.ObjectGetParentMethodInfo
    ResolveTocSetterMethod "getPathString" o = Gst.Object.ObjectGetPathStringMethodInfo
    ResolveTocSetterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveTocSetterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveTocSetterMethod "getRequestPad" o = Gst.Element.ElementGetRequestPadMethodInfo
    ResolveTocSetterMethod "getStartTime" o = Gst.Element.ElementGetStartTimeMethodInfo
    ResolveTocSetterMethod "getState" o = Gst.Element.ElementGetStateMethodInfo
    ResolveTocSetterMethod "getStaticPad" o = Gst.Element.ElementGetStaticPadMethodInfo
    ResolveTocSetterMethod "getToc" o = TocSetterGetTocMethodInfo
    ResolveTocSetterMethod "getValue" o = Gst.Object.ObjectGetValueMethodInfo
    ResolveTocSetterMethod "setBaseTime" o = Gst.Element.ElementSetBaseTimeMethodInfo
    ResolveTocSetterMethod "setBus" o = Gst.Element.ElementSetBusMethodInfo
    ResolveTocSetterMethod "setClock" o = Gst.Element.ElementSetClockMethodInfo
    ResolveTocSetterMethod "setContext" o = Gst.Element.ElementSetContextMethodInfo
    ResolveTocSetterMethod "setControlBindingDisabled" o = Gst.Object.ObjectSetControlBindingDisabledMethodInfo
    ResolveTocSetterMethod "setControlBindingsDisabled" o = Gst.Object.ObjectSetControlBindingsDisabledMethodInfo
    ResolveTocSetterMethod "setControlRate" o = Gst.Object.ObjectSetControlRateMethodInfo
    ResolveTocSetterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveTocSetterMethod "setLockedState" o = Gst.Element.ElementSetLockedStateMethodInfo
    ResolveTocSetterMethod "setName" o = Gst.Object.ObjectSetNameMethodInfo
    ResolveTocSetterMethod "setParent" o = Gst.Object.ObjectSetParentMethodInfo
    ResolveTocSetterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveTocSetterMethod "setStartTime" o = Gst.Element.ElementSetStartTimeMethodInfo
    ResolveTocSetterMethod "setState" o = Gst.Element.ElementSetStateMethodInfo
    ResolveTocSetterMethod "setToc" o = TocSetterSetTocMethodInfo
    ResolveTocSetterMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTocSetterMethod t TocSetter, O.MethodInfo info TocSetter p) => OL.IsLabel t (TocSetter -> 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 TocSetter::get_toc
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "setter", argType = TInterface (Name {namespace = "Gst", name = "TocSetter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstTocSetter.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Toc"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_toc_setter_get_toc" gst_toc_setter_get_toc ::
    Ptr TocSetter ->                        -- setter : TInterface (Name {namespace = "Gst", name = "TocSetter"})
    IO (Ptr Gst.Toc.Toc)

{- |
Return current TOC the setter uses. The TOC should not be
modified without making it writable first.
-}
tocSetterGetToc ::
    (B.CallStack.HasCallStack, MonadIO m, IsTocSetter a) =>
    a
    {- ^ /@setter@/: a 'GI.Gst.Interfaces.TocSetter.TocSetter'. -}
    -> m (Maybe Gst.Toc.Toc)
    {- ^ __Returns:__ TOC set, or 'Nothing'. Unref with
    @/gst_toc_unref()/@ when no longer needed -}
tocSetterGetToc setter = liftIO $ do
    setter' <- unsafeManagedPtrCastPtr setter
    result <- gst_toc_setter_get_toc setter'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Gst.Toc.Toc) result'
        return result''
    touchManagedPtr setter
    return maybeResult

#if ENABLE_OVERLOADING
data TocSetterGetTocMethodInfo
instance (signature ~ (m (Maybe Gst.Toc.Toc)), MonadIO m, IsTocSetter a) => O.MethodInfo TocSetterGetTocMethodInfo a signature where
    overloadedMethod _ = tocSetterGetToc

#endif

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

foreign import ccall "gst_toc_setter_reset" gst_toc_setter_reset ::
    Ptr TocSetter ->                        -- setter : TInterface (Name {namespace = "Gst", name = "TocSetter"})
    IO ()

{- |
Reset the internal TOC. Elements should call this from within the
state-change handler.
-}
tocSetterReset ::
    (B.CallStack.HasCallStack, MonadIO m, IsTocSetter a) =>
    a
    {- ^ /@setter@/: a 'GI.Gst.Interfaces.TocSetter.TocSetter'. -}
    -> m ()
tocSetterReset setter = liftIO $ do
    setter' <- unsafeManagedPtrCastPtr setter
    gst_toc_setter_reset setter'
    touchManagedPtr setter
    return ()

#if ENABLE_OVERLOADING
data TocSetterResetMethodInfo
instance (signature ~ (m ()), MonadIO m, IsTocSetter a) => O.MethodInfo TocSetterResetMethodInfo a signature where
    overloadedMethod _ = tocSetterReset

#endif

-- method TocSetter::set_toc
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "setter", argType = TInterface (Name {namespace = "Gst", name = "TocSetter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstTocSetter.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "toc", argType = TInterface (Name {namespace = "Gst", name = "Toc"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GstToc to set.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_toc_setter_set_toc" gst_toc_setter_set_toc ::
    Ptr TocSetter ->                        -- setter : TInterface (Name {namespace = "Gst", name = "TocSetter"})
    Ptr Gst.Toc.Toc ->                      -- toc : TInterface (Name {namespace = "Gst", name = "Toc"})
    IO ()

{- |
Set the given TOC on the setter. Previously set TOC will be
unreffed before setting a new one.
-}
tocSetterSetToc ::
    (B.CallStack.HasCallStack, MonadIO m, IsTocSetter a) =>
    a
    {- ^ /@setter@/: a 'GI.Gst.Interfaces.TocSetter.TocSetter'. -}
    -> Maybe (Gst.Toc.Toc)
    {- ^ /@toc@/: a 'GI.Gst.Structs.Toc.Toc' to set. -}
    -> m ()
tocSetterSetToc setter toc = liftIO $ do
    setter' <- unsafeManagedPtrCastPtr setter
    maybeToc <- case toc of
        Nothing -> return nullPtr
        Just jToc -> do
            jToc' <- unsafeManagedPtrGetPtr jToc
            return jToc'
    gst_toc_setter_set_toc setter' maybeToc
    touchManagedPtr setter
    whenJust toc touchManagedPtr
    return ()

#if ENABLE_OVERLOADING
data TocSetterSetTocMethodInfo
instance (signature ~ (Maybe (Gst.Toc.Toc) -> m ()), MonadIO m, IsTocSetter a) => O.MethodInfo TocSetterSetTocMethodInfo a signature where
    overloadedMethod _ = tocSetterSetToc

#endif