{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The t'GI.Gst.Structs.Promise.Promise' object implements the container for values that may
-- be available later. i.e. a Future or a Promise in
-- \<ulink url=\"https:\/\/en.wikipedia.org\/wiki\/Futures_and_promises\">https:\/\/en.wikipedia.org\/wiki\/Futures_and_promises\<\/ulink>
-- As with all Future\/Promise-like functionality, there is the concept of the
-- producer of the value and the consumer of the value.
-- 
-- A t'GI.Gst.Structs.Promise.Promise' is created with 'GI.Gst.Structs.Promise.promiseNew' by the consumer and passed
-- to the producer to avoid thread safety issues with the change callback.
-- A t'GI.Gst.Structs.Promise.Promise' can be replied to with a value (or an error) by the producer
-- with 'GI.Gst.Structs.Promise.promiseReply'. 'GI.Gst.Structs.Promise.promiseInterrupt' is for the consumer to
-- indicate to the producer that the value is not needed anymore and producing
-- that value can stop.  The /@gSTPROMISERESULTEXPIRED@/ state set by a call
-- to 'GI.Gst.Structs.Promise.promiseExpire' indicates to the consumer that a value will never
-- be produced and is intended to be called by a third party that implements
-- some notion of message handling such as t'GI.Gst.Objects.Bus.Bus'.
-- A callback can also be installed at t'GI.Gst.Structs.Promise.Promise' creation for
-- result changes with 'GI.Gst.Structs.Promise.promiseNewWithChangeFunc'.
-- The change callback can be used to chain @/GstPromises/@\'s together as in the
-- following example.
-- 
-- === /C code/
-- >
-- >const GstStructure *reply;
-- >GstPromise *p;
-- >if (gst_promise_wait (promise) != GST_PROMISE_RESULT_REPLIED)
-- >  return; // interrupted or expired value
-- >reply = gst_promise_get_reply (promise);
-- >if (error in reply)
-- >  return; // propagate error
-- >p = gst_promise_new_with_change_func (another_promise_change_func, user_data, notify);
-- >pass p to promise-using API
-- 
-- 
-- Each t'GI.Gst.Structs.Promise.Promise' starts out with a t'GI.Gst.Enums.PromiseResult' of
-- 'GI.Gst.Enums.PromiseResultPending' and only ever transitions once
-- into one of the other t'GI.Gst.Enums.PromiseResult'\'s.
-- 
-- In order to support multi-threaded code, 'GI.Gst.Structs.Promise.promiseReply',
-- 'GI.Gst.Structs.Promise.promiseInterrupt' and 'GI.Gst.Structs.Promise.promiseExpire' may all be from
-- different threads with some restrictions and the final result of the promise
-- is whichever call is made first.  There are two restrictions on ordering:
-- 
-- 1. That 'GI.Gst.Structs.Promise.promiseReply' and 'GI.Gst.Structs.Promise.promiseInterrupt' cannot be called
-- after 'GI.Gst.Structs.Promise.promiseExpire'
-- 2. That 'GI.Gst.Structs.Promise.promiseReply' and 'GI.Gst.Structs.Promise.promiseInterrupt'
-- cannot be called twice.
-- 
-- The change function set with 'GI.Gst.Structs.Promise.promiseNewWithChangeFunc' is
-- called directly from either the 'GI.Gst.Structs.Promise.promiseReply',
-- 'GI.Gst.Structs.Promise.promiseInterrupt' or 'GI.Gst.Structs.Promise.promiseExpire' and can be called
-- from an arbitrary thread.  t'GI.Gst.Structs.Promise.Promise' using APIs can restrict this to
-- a single thread or a subset of threads but that is entirely up to the API
-- that uses t'GI.Gst.Structs.Promise.Promise'.
-- 
-- /Since: 1.14/

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

module GI.Gst.Structs.Promise
    ( 

-- * Exported types
    Promise(..)                             ,
    newZeroPromise                          ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolvePromiseMethod                    ,
#endif


-- ** expire #method:expire#

#if defined(ENABLE_OVERLOADING)
    PromiseExpireMethodInfo                 ,
#endif
    promiseExpire                           ,


-- ** getReply #method:getReply#

#if defined(ENABLE_OVERLOADING)
    PromiseGetReplyMethodInfo               ,
#endif
    promiseGetReply                         ,


-- ** interrupt #method:interrupt#

#if defined(ENABLE_OVERLOADING)
    PromiseInterruptMethodInfo              ,
#endif
    promiseInterrupt                        ,


-- ** new #method:new#

    promiseNew                              ,


-- ** newWithChangeFunc #method:newWithChangeFunc#

    promiseNewWithChangeFunc                ,


-- ** reply #method:reply#

#if defined(ENABLE_OVERLOADING)
    PromiseReplyMethodInfo                  ,
#endif
    promiseReply                            ,


-- ** wait #method:wait#

#if defined(ENABLE_OVERLOADING)
    PromiseWaitMethodInfo                   ,
#endif
    promiseWait                             ,




 -- * Properties
-- ** parent #attr:parent#
-- | parent t'GI.Gst.Structs.MiniObject.MiniObject'

    getPromiseParent                        ,
#if defined(ENABLE_OVERLOADING)
    promise_parent                          ,
#endif




    ) 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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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.GLib.Callbacks as GLib.Callbacks
import qualified GI.Gst.Callbacks as Gst.Callbacks
import {-# SOURCE #-} qualified GI.Gst.Enums as Gst.Enums
import {-# SOURCE #-} qualified GI.Gst.Structs.MiniObject as Gst.MiniObject
import {-# SOURCE #-} qualified GI.Gst.Structs.Structure as Gst.Structure

-- | Memory-managed wrapper type.
newtype Promise = Promise (SP.ManagedPtr Promise)
    deriving (Promise -> Promise -> Bool
(Promise -> Promise -> Bool)
-> (Promise -> Promise -> Bool) -> Eq Promise
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Promise -> Promise -> Bool
$c/= :: Promise -> Promise -> Bool
== :: Promise -> Promise -> Bool
$c== :: Promise -> Promise -> Bool
Eq)

instance SP.ManagedPtrNewtype Promise where
    toManagedPtr :: Promise -> ManagedPtr Promise
toManagedPtr (Promise ManagedPtr Promise
p) = ManagedPtr Promise
p

foreign import ccall "gst_promise_get_type" c_gst_promise_get_type :: 
    IO GType

type instance O.ParentTypes Promise = '[]
instance O.HasParentTypes Promise

instance B.Types.TypedObject Promise where
    glibType :: IO GType
glibType = IO GType
c_gst_promise_get_type

instance B.Types.GBoxed Promise

-- | Convert 'Promise' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue Promise where
    toGValue :: Promise -> IO GValue
toGValue Promise
o = do
        GType
gtype <- IO GType
c_gst_promise_get_type
        Promise -> (Ptr Promise -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Promise
o (GType
-> (GValue -> Ptr Promise -> IO ()) -> Ptr Promise -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr Promise -> IO ()
forall a. GValue -> Ptr a -> IO ()
B.GValue.set_boxed)
        
    fromGValue :: GValue -> IO Promise
fromGValue GValue
gv = do
        Ptr Promise
ptr <- GValue -> IO (Ptr Promise)
forall b. GValue -> IO (Ptr b)
B.GValue.get_boxed GValue
gv :: IO (Ptr Promise)
        (ManagedPtr Promise -> Promise) -> Ptr Promise -> IO Promise
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Promise -> Promise
Promise Ptr Promise
ptr
        
    

-- | Construct a `Promise` struct initialized to zero.
newZeroPromise :: MonadIO m => m Promise
newZeroPromise :: m Promise
newZeroPromise = IO Promise -> m Promise
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Promise -> m Promise) -> IO Promise -> m Promise
forall a b. (a -> b) -> a -> b
$ Int -> IO (Ptr Promise)
forall a. GBoxed a => Int -> IO (Ptr a)
callocBoxedBytes Int
64 IO (Ptr Promise) -> (Ptr Promise -> IO Promise) -> IO Promise
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr Promise -> Promise) -> Ptr Promise -> IO Promise
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Promise -> Promise
Promise

instance tag ~ 'AttrSet => Constructible Promise tag where
    new :: (ManagedPtr Promise -> Promise)
-> [AttrOp Promise tag] -> m Promise
new ManagedPtr Promise -> Promise
_ [AttrOp Promise tag]
attrs = do
        Promise
o <- m Promise
forall (m :: * -> *). MonadIO m => m Promise
newZeroPromise
        Promise -> [AttrOp Promise 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set Promise
o [AttrOp Promise tag]
[AttrOp Promise 'AttrSet]
attrs
        Promise -> m Promise
forall (m :: * -> *) a. Monad m => a -> m a
return Promise
o


-- | 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' promise #parent
-- @
getPromiseParent :: MonadIO m => Promise -> m Gst.MiniObject.MiniObject
getPromiseParent :: Promise -> m MiniObject
getPromiseParent Promise
s = IO MiniObject -> m MiniObject
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MiniObject -> m MiniObject) -> IO MiniObject -> m MiniObject
forall a b. (a -> b) -> a -> b
$ Promise -> (Ptr Promise -> IO MiniObject) -> IO MiniObject
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Promise
s ((Ptr Promise -> IO MiniObject) -> IO MiniObject)
-> (Ptr Promise -> IO MiniObject) -> IO MiniObject
forall a b. (a -> b) -> a -> b
$ \Ptr Promise
ptr -> do
    let val :: Ptr MiniObject
val = Ptr Promise
ptr Ptr Promise -> Int -> Ptr MiniObject
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0 :: (Ptr Gst.MiniObject.MiniObject)
    MiniObject
val' <- ((ManagedPtr MiniObject -> MiniObject)
-> Ptr MiniObject -> IO MiniObject
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newPtr ManagedPtr MiniObject -> MiniObject
Gst.MiniObject.MiniObject) Ptr MiniObject
val
    MiniObject -> IO MiniObject
forall (m :: * -> *) a. Monad m => a -> m a
return MiniObject
val'

#if defined(ENABLE_OVERLOADING)
data PromiseParentFieldInfo
instance AttrInfo PromiseParentFieldInfo where
    type AttrBaseTypeConstraint PromiseParentFieldInfo = (~) Promise
    type AttrAllowedOps PromiseParentFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint PromiseParentFieldInfo = (~) (Ptr Gst.MiniObject.MiniObject)
    type AttrTransferTypeConstraint PromiseParentFieldInfo = (~)(Ptr Gst.MiniObject.MiniObject)
    type AttrTransferType PromiseParentFieldInfo = (Ptr Gst.MiniObject.MiniObject)
    type AttrGetType PromiseParentFieldInfo = Gst.MiniObject.MiniObject
    type AttrLabel PromiseParentFieldInfo = "parent"
    type AttrOrigin PromiseParentFieldInfo = Promise
    attrGet = getPromiseParent
    attrSet = undefined
    attrConstruct = undefined
    attrClear = undefined
    attrTransfer = undefined

promise_parent :: AttrLabelProxy "parent"
promise_parent = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Promise
type instance O.AttributeList Promise = PromiseAttributeList
type PromiseAttributeList = ('[ '("parent", PromiseParentFieldInfo)] :: [(Symbol, *)])
#endif

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

foreign import ccall "gst_promise_new" gst_promise_new :: 
    IO (Ptr Promise)

-- | /No description available in the introspection data./
-- 
-- /Since: 1.14/
promiseNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m Promise
    -- ^ __Returns:__ a new t'GI.Gst.Structs.Promise.Promise'
promiseNew :: m Promise
promiseNew  = IO Promise -> m Promise
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Promise -> m Promise) -> IO Promise -> m Promise
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
result <- IO (Ptr Promise)
gst_promise_new
    Text -> Ptr Promise -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"promiseNew" Ptr Promise
result
    Promise
result' <- ((ManagedPtr Promise -> Promise) -> Ptr Promise -> IO Promise
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Promise -> Promise
Promise) Ptr Promise
result
    Promise -> IO Promise
forall (m :: * -> *) a. Monad m => a -> m a
return Promise
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Promise::new_with_change_func
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "func"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "PromiseChangeFunc" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstPromiseChangeFunc to call"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeNotified
--           , argClosure = 1
--           , argDestroy = 2
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "argument to call @func with"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "notify"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "notification function that @user_data is no longer needed"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gst" , name = "Promise" })
-- throws : False
-- Skip return : False

foreign import ccall "gst_promise_new_with_change_func" gst_promise_new_with_change_func :: 
    FunPtr Gst.Callbacks.C_PromiseChangeFunc -> -- func : TInterface (Name {namespace = "Gst", name = "PromiseChangeFunc"})
    Ptr () ->                               -- user_data : TBasicType TPtr
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- notify : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO (Ptr Promise)

-- | /@func@/ will be called exactly once when transitioning out of
-- 'GI.Gst.Enums.PromiseResultPending' into any of the other t'GI.Gst.Enums.PromiseResult'
-- states.
-- 
-- /Since: 1.14/
promiseNewWithChangeFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Callbacks.PromiseChangeFunc
    -- ^ /@func@/: a t'GI.Gst.Callbacks.PromiseChangeFunc' to call
    -> m Promise
    -- ^ __Returns:__ a new t'GI.Gst.Structs.Promise.Promise'
promiseNewWithChangeFunc :: PromiseChangeFunc -> m Promise
promiseNewWithChangeFunc PromiseChangeFunc
func = IO Promise -> m Promise
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Promise -> m Promise) -> IO Promise -> m Promise
forall a b. (a -> b) -> a -> b
$ do
    FunPtr C_PromiseChangeFunc
func' <- C_PromiseChangeFunc -> IO (FunPtr C_PromiseChangeFunc)
Gst.Callbacks.mk_PromiseChangeFunc (Maybe (Ptr (FunPtr C_PromiseChangeFunc))
-> PromiseChangeFunc_WithClosures -> C_PromiseChangeFunc
Gst.Callbacks.wrap_PromiseChangeFunc Maybe (Ptr (FunPtr C_PromiseChangeFunc))
forall a. Maybe a
Nothing (PromiseChangeFunc -> PromiseChangeFunc_WithClosures
Gst.Callbacks.drop_closures_PromiseChangeFunc PromiseChangeFunc
func))
    let userData :: Ptr ()
userData = FunPtr C_PromiseChangeFunc -> Ptr ()
forall a b. FunPtr a -> Ptr b
castFunPtrToPtr FunPtr C_PromiseChangeFunc
func'
    let notify :: FunPtr (Ptr a -> IO ())
notify = FunPtr (Ptr a -> IO ())
forall a. FunPtr (Ptr a -> IO ())
safeFreeFunPtrPtr
    Ptr Promise
result <- FunPtr C_PromiseChangeFunc
-> Ptr () -> FunPtr C_DestroyNotify -> IO (Ptr Promise)
gst_promise_new_with_change_func FunPtr C_PromiseChangeFunc
func' Ptr ()
userData FunPtr C_DestroyNotify
forall a. FunPtr (Ptr a -> IO ())
notify
    Text -> Ptr Promise -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"promiseNewWithChangeFunc" Ptr Promise
result
    Promise
result' <- ((ManagedPtr Promise -> Promise) -> Ptr Promise -> IO Promise
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Promise -> Promise
Promise) Ptr Promise
result
    Promise -> IO Promise
forall (m :: * -> *) a. Monad m => a -> m a
return Promise
result'

#if defined(ENABLE_OVERLOADING)
#endif

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

foreign import ccall "gst_promise_expire" gst_promise_expire :: 
    Ptr Promise ->                          -- promise : TInterface (Name {namespace = "Gst", name = "Promise"})
    IO ()

-- | Expire a /@promise@/.  This will wake up any waiters with
-- 'GI.Gst.Enums.PromiseResultExpired'.  Called by a message loop when the parent
-- message is handled and\/or destroyed (possibly unanswered).
-- 
-- /Since: 1.14/
promiseExpire ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Promise
    -- ^ /@promise@/: a t'GI.Gst.Structs.Promise.Promise'
    -> m ()
promiseExpire :: Promise -> m ()
promiseExpire Promise
promise = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
promise' <- Promise -> IO (Ptr Promise)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Promise
promise
    Ptr Promise -> IO ()
gst_promise_expire Ptr Promise
promise'
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data PromiseExpireMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo PromiseExpireMethodInfo Promise signature where
    overloadedMethod = promiseExpire

#endif

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

foreign import ccall "gst_promise_get_reply" gst_promise_get_reply :: 
    Ptr Promise ->                          -- promise : TInterface (Name {namespace = "Gst", name = "Promise"})
    IO (Ptr Gst.Structure.Structure)

-- | Retrieve the reply set on /@promise@/.  /@promise@/ must be in
-- 'GI.Gst.Enums.PromiseResultReplied' and the returned structure is owned by /@promise@/
-- 
-- /Since: 1.14/
promiseGetReply ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Promise
    -- ^ /@promise@/: a t'GI.Gst.Structs.Promise.Promise'
    -> m Gst.Structure.Structure
    -- ^ __Returns:__ The reply set on /@promise@/
promiseGetReply :: Promise -> m Structure
promiseGetReply Promise
promise = IO Structure -> m Structure
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Structure -> m Structure) -> IO Structure -> m Structure
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
promise' <- Promise -> IO (Ptr Promise)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Promise
promise
    Ptr Structure
result <- Ptr Promise -> IO (Ptr Structure)
gst_promise_get_reply Ptr Promise
promise'
    Text -> Ptr Structure -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"promiseGetReply" Ptr Structure
result
    Structure
result' <- ((ManagedPtr Structure -> Structure)
-> Ptr Structure -> IO Structure
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Structure -> Structure
Gst.Structure.Structure) Ptr Structure
result
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    Structure -> IO Structure
forall (m :: * -> *) a. Monad m => a -> m a
return Structure
result'

#if defined(ENABLE_OVERLOADING)
data PromiseGetReplyMethodInfo
instance (signature ~ (m Gst.Structure.Structure), MonadIO m) => O.MethodInfo PromiseGetReplyMethodInfo Promise signature where
    overloadedMethod = promiseGetReply

#endif

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

foreign import ccall "gst_promise_interrupt" gst_promise_interrupt :: 
    Ptr Promise ->                          -- promise : TInterface (Name {namespace = "Gst", name = "Promise"})
    IO ()

-- | Interrupt waiting for a /@promise@/.  This will wake up any waiters with
-- 'GI.Gst.Enums.PromiseResultInterrupted'.  Called when the consumer does not want
-- the value produced anymore.
-- 
-- /Since: 1.14/
promiseInterrupt ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Promise
    -- ^ /@promise@/: a t'GI.Gst.Structs.Promise.Promise'
    -> m ()
promiseInterrupt :: Promise -> m ()
promiseInterrupt Promise
promise = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
promise' <- Promise -> IO (Ptr Promise)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Promise
promise
    Ptr Promise -> IO ()
gst_promise_interrupt Ptr Promise
promise'
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data PromiseInterruptMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo PromiseInterruptMethodInfo Promise signature where
    overloadedMethod = promiseInterrupt

#endif

-- method Promise::reply
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "promise"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Promise" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstPromise" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "s"
--           , argType =
--               TInterface Name { namespace = "Gst" , name = "Structure" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GstStructure with the the reply contents"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_promise_reply" gst_promise_reply :: 
    Ptr Promise ->                          -- promise : TInterface (Name {namespace = "Gst", name = "Promise"})
    Ptr Gst.Structure.Structure ->          -- s : TInterface (Name {namespace = "Gst", name = "Structure"})
    IO ()

-- | Set a reply on /@promise@/.  This will wake up any waiters with
-- 'GI.Gst.Enums.PromiseResultReplied'.  Called by the producer of the value to
-- indicate success (or failure).
-- 
-- If /@promise@/ has already been interrupted by the consumer, then this reply
-- is not visible to the consumer.
-- 
-- /Since: 1.14/
promiseReply ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Promise
    -- ^ /@promise@/: a t'GI.Gst.Structs.Promise.Promise'
    -> Gst.Structure.Structure
    -- ^ /@s@/: a t'GI.Gst.Structs.Structure.Structure' with the the reply contents
    -> m ()
promiseReply :: Promise -> Structure -> m ()
promiseReply Promise
promise Structure
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
promise' <- Promise -> IO (Ptr Promise)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Promise
promise
    Ptr Structure
s' <- Structure -> IO (Ptr Structure)
forall a. (HasCallStack, GBoxed a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed Structure
s
    Ptr Promise -> Ptr Structure -> IO ()
gst_promise_reply Ptr Promise
promise' Ptr Structure
s'
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    Structure -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Structure
s
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data PromiseReplyMethodInfo
instance (signature ~ (Gst.Structure.Structure -> m ()), MonadIO m) => O.MethodInfo PromiseReplyMethodInfo Promise signature where
    overloadedMethod = promiseReply

#endif

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

foreign import ccall "gst_promise_wait" gst_promise_wait :: 
    Ptr Promise ->                          -- promise : TInterface (Name {namespace = "Gst", name = "Promise"})
    IO CUInt

-- | Wait for /@promise@/ to move out of the 'GI.Gst.Enums.PromiseResultPending' state.
-- If /@promise@/ is not in 'GI.Gst.Enums.PromiseResultPending' then it will return
-- immediately with the current result.
-- 
-- /Since: 1.14/
promiseWait ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Promise
    -- ^ /@promise@/: a t'GI.Gst.Structs.Promise.Promise'
    -> m Gst.Enums.PromiseResult
    -- ^ __Returns:__ the result of the promise
promiseWait :: Promise -> m PromiseResult
promiseWait Promise
promise = IO PromiseResult -> m PromiseResult
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PromiseResult -> m PromiseResult)
-> IO PromiseResult -> m PromiseResult
forall a b. (a -> b) -> a -> b
$ do
    Ptr Promise
promise' <- Promise -> IO (Ptr Promise)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Promise
promise
    CUInt
result <- Ptr Promise -> IO CUInt
gst_promise_wait Ptr Promise
promise'
    let result' :: PromiseResult
result' = (Int -> PromiseResult
forall a. Enum a => Int -> a
toEnum (Int -> PromiseResult) -> (CUInt -> Int) -> CUInt -> PromiseResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
result
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    PromiseResult -> IO PromiseResult
forall (m :: * -> *) a. Monad m => a -> m a
return PromiseResult
result'

#if defined(ENABLE_OVERLOADING)
data PromiseWaitMethodInfo
instance (signature ~ (m Gst.Enums.PromiseResult), MonadIO m) => O.MethodInfo PromiseWaitMethodInfo Promise signature where
    overloadedMethod = promiseWait

#endif

#if defined(ENABLE_OVERLOADING)
type family ResolvePromiseMethod (t :: Symbol) (o :: *) :: * where
    ResolvePromiseMethod "expire" o = PromiseExpireMethodInfo
    ResolvePromiseMethod "interrupt" o = PromiseInterruptMethodInfo
    ResolvePromiseMethod "reply" o = PromiseReplyMethodInfo
    ResolvePromiseMethod "wait" o = PromiseWaitMethodInfo
    ResolvePromiseMethod "getReply" o = PromiseGetReplyMethodInfo
    ResolvePromiseMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePromiseMethod t Promise, O.MethodInfo info Promise p) => OL.IsLabel t (Promise -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif