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

Opaque structure.
-}

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

module GI.Gst.Structs.ParseContext
    (

-- * Exported types
    ParseContext(..)                        ,
    noParseContext                          ,


 -- * Methods
-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    ParseContextCopyMethodInfo              ,
#endif
    parseContextCopy                        ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    ParseContextFreeMethodInfo              ,
#endif
    parseContextFree                        ,


-- ** getMissingElements #method:getMissingElements#

#if ENABLE_OVERLOADING
    ParseContextGetMissingElementsMethodInfo,
#endif
    parseContextGetMissingElements          ,


-- ** new #method:new#

    parseContextNew                         ,




    ) 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


-- | Memory-managed wrapper type.
newtype ParseContext = ParseContext (ManagedPtr ParseContext)
foreign import ccall "gst_parse_context_get_type" c_gst_parse_context_get_type ::
    IO GType

instance BoxedObject ParseContext where
    boxedType _ = c_gst_parse_context_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `ParseContext`.
noParseContext :: Maybe ParseContext
noParseContext = Nothing


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

-- method ParseContext::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "ParseContext"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_parse_context_new" gst_parse_context_new ::
    IO (Ptr ParseContext)

{- |
Allocates a parse context for use with 'GI.Gst.Functions.parseLaunchFull' or
'GI.Gst.Functions.parseLaunchvFull'.

Free-function: gst_parse_context_free
-}
parseContextNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m (Maybe ParseContext)
    {- ^ __Returns:__ a newly-allocated parse context. Free
    with 'GI.Gst.Structs.ParseContext.parseContextFree' when no longer needed. -}
parseContextNew  = liftIO $ do
    result <- gst_parse_context_new
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed ParseContext) result'
        return result''
    return maybeResult

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "gst_parse_context_copy" gst_parse_context_copy ::
    Ptr ParseContext ->                     -- context : TInterface (Name {namespace = "Gst", name = "ParseContext"})
    IO (Ptr ParseContext)

{- |
Copies the /@context@/.
-}
parseContextCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ParseContext
    {- ^ /@context@/: a 'GI.Gst.Structs.ParseContext.ParseContext' -}
    -> m (Maybe ParseContext)
    {- ^ __Returns:__ A copied 'GI.Gst.Structs.ParseContext.ParseContext' -}
parseContextCopy context = liftIO $ do
    context' <- unsafeManagedPtrGetPtr context
    result <- gst_parse_context_copy context'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed ParseContext) result'
        return result''
    touchManagedPtr context
    return maybeResult

#if ENABLE_OVERLOADING
data ParseContextCopyMethodInfo
instance (signature ~ (m (Maybe ParseContext)), MonadIO m) => O.MethodInfo ParseContextCopyMethodInfo ParseContext signature where
    overloadedMethod _ = parseContextCopy

#endif

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

foreign import ccall "gst_parse_context_free" gst_parse_context_free ::
    Ptr ParseContext ->                     -- context : TInterface (Name {namespace = "Gst", name = "ParseContext"})
    IO ()

{- |
Frees a parse context previously allocated with 'GI.Gst.Structs.ParseContext.parseContextNew'.
-}
parseContextFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ParseContext
    {- ^ /@context@/: a 'GI.Gst.Structs.ParseContext.ParseContext' -}
    -> m ()
parseContextFree context = liftIO $ do
    context' <- B.ManagedPtr.disownBoxed context
    gst_parse_context_free context'
    touchManagedPtr context
    return ()

#if ENABLE_OVERLOADING
data ParseContextFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo ParseContextFreeMethodInfo ParseContext signature where
    overloadedMethod _ = parseContextFree

#endif

-- method ParseContext::get_missing_elements
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gst", name = "ParseContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstParseContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TCArray True (-1) (-1) (TBasicType TUTF8))
-- throws : False
-- Skip return : False

foreign import ccall "gst_parse_context_get_missing_elements" gst_parse_context_get_missing_elements ::
    Ptr ParseContext ->                     -- context : TInterface (Name {namespace = "Gst", name = "ParseContext"})
    IO (Ptr CString)

{- |
Retrieve missing elements from a previous run of 'GI.Gst.Functions.parseLaunchFull'
or 'GI.Gst.Functions.parseLaunchvFull'. Will only return results if an error code
of 'GI.Gst.Enums.ParseErrorNoSuchElement' was returned.
-}
parseContextGetMissingElements ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ParseContext
    {- ^ /@context@/: a 'GI.Gst.Structs.ParseContext.ParseContext' -}
    -> m (Maybe [T.Text])
    {- ^ __Returns:__ a
    'Nothing'-terminated array of element factory name strings of missing
    elements. Free with 'GI.GLib.Functions.strfreev' when no longer needed. -}
parseContextGetMissingElements context = liftIO $ do
    context' <- unsafeManagedPtrGetPtr context
    result <- gst_parse_context_get_missing_elements context'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- unpackZeroTerminatedUTF8CArray result'
        mapZeroTerminatedCArray freeMem result'
        freeMem result'
        return result''
    touchManagedPtr context
    return maybeResult

#if ENABLE_OVERLOADING
data ParseContextGetMissingElementsMethodInfo
instance (signature ~ (m (Maybe [T.Text])), MonadIO m) => O.MethodInfo ParseContextGetMissingElementsMethodInfo ParseContext signature where
    overloadedMethod _ = parseContextGetMissingElements

#endif

#if ENABLE_OVERLOADING
type family ResolveParseContextMethod (t :: Symbol) (o :: *) :: * where
    ResolveParseContextMethod "copy" o = ParseContextCopyMethodInfo
    ResolveParseContextMethod "free" o = ParseContextFreeMethodInfo
    ResolveParseContextMethod "getMissingElements" o = ParseContextGetMissingElementsMethodInfo
    ResolveParseContextMethod l o = O.MethodResolutionFailed l o

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