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

Opaque structure.
-}

module GI.Gst.Structs.ParseContext
    ( 

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


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ParseContextCopyMethodInfo              ,
#endif
    parseContextCopy                        ,


-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    ParseContextFreeMethodInfo              ,
#endif
    parseContextFree                        ,


-- ** getMissingElements #method:getMissingElements#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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


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

noParseContext :: Maybe ParseContext
noParseContext = Nothing


#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 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
    checkUnexpectedReturnNULL "parseContextNew" result
    result' <- (wrapBoxed ParseContext) result
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#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 ParseContext
    {- ^ __Returns:__ A copied 'GI.Gst.Structs.ParseContext.ParseContext' -}
parseContextCopy context = liftIO $ do
    context' <- unsafeManagedPtrGetPtr context
    result <- gst_parse_context_copy context'
    checkUnexpectedReturnNULL "parseContextCopy" result
    result' <- (wrapBoxed ParseContext) result
    touchManagedPtr context
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data ParseContextCopyMethodInfo
instance (signature ~ (m 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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 [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'
    checkUnexpectedReturnNULL "parseContextGetMissingElements" result
    result' <- unpackZeroTerminatedUTF8CArray result
    mapZeroTerminatedCArray freeMem result
    freeMem result
    touchManagedPtr context
    return result'

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

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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) => O.IsLabelProxy t (ParseContext -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveParseContextMethod t ParseContext, O.MethodInfo info ParseContext p) => O.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

#endif