{-# 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
-- \<https:\/\/en.wikipedia.org\/wiki\/Futures_and_promises>.
-- 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'. The exact value returned is defined by the API
-- contract of the producer and 'P.Nothing' may be a valid reply.
-- '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
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [expire]("GI.Gst.Structs.Promise#g:method:expire"), [interrupt]("GI.Gst.Structs.Promise#g:method:interrupt"), [reply]("GI.Gst.Structs.Promise#g:method:reply"), [wait]("GI.Gst.Structs.Promise#g:method:wait").
-- 
-- ==== Getters
-- [getReply]("GI.Gst.Structs.Promise#g:method:getReply").
-- 
-- ==== Setters
-- /None/.

#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.GArray as B.GArray
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 GHC.Records as R

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'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe Promise) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_gst_promise_get_type
    gvalueSet_ :: Ptr GValue -> Maybe Promise -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Promise
P.Nothing = Ptr GValue -> Ptr Promise -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv (Ptr Promise
forall a. Ptr a
FP.nullPtr :: FP.Ptr Promise)
    gvalueSet_ Ptr GValue
gv (P.Just Promise
obj) = Promise -> (Ptr Promise -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Promise
obj (Ptr GValue -> Ptr Promise -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe Promise)
gvalueGet_ Ptr GValue
gv = do
        Ptr Promise
ptr <- Ptr GValue -> IO (Ptr Promise)
forall b. Ptr GValue -> IO (Ptr b)
B.GValue.get_boxed Ptr GValue
gv :: IO (Ptr Promise)
        if Ptr Promise
ptr Ptr Promise -> Ptr Promise -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr Promise
forall a. Ptr a
FP.nullPtr
        then Promise -> Maybe Promise
forall a. a -> Maybe a
P.Just (Promise -> Maybe Promise) -> IO Promise -> IO (Maybe Promise)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (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
        else Maybe Promise -> IO (Maybe Promise)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Promise
forall a. Maybe a
P.Nothing
        
    

-- | Construct a `Promise` struct initialized to zero.
newZeroPromise :: MonadIO m => m Promise
newZeroPromise :: forall (m :: * -> *). MonadIO m => 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 :: forall (m :: * -> *).
MonadIO m =>
(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 :: forall (m :: * -> *). MonadIO m => 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 :: forall (m :: * -> *). (HasCallStack, MonadIO m) => 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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
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 ())
SP.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 :: forall (m :: * -> *). (HasCallStack, MonadIO m) => 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.OverloadedMethod PromiseExpireMethodInfo Promise signature where
    overloadedMethod = promiseExpire

instance O.OverloadedMethodInfo PromiseExpireMethodInfo Promise where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gst.Structs.Promise.promiseExpire",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gst-1.0.24/docs/GI-Gst-Structs-Promise.html#v: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 (Maybe Gst.Structure.Structure)
    -- ^ __Returns:__ The reply set on /@promise@/
promiseGetReply :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Promise -> m (Maybe Structure)
promiseGetReply Promise
promise = IO (Maybe Structure) -> m (Maybe Structure)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Structure) -> m (Maybe Structure))
-> IO (Maybe Structure) -> m (Maybe 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'
    Maybe Structure
maybeResult <- Ptr Structure
-> (Ptr Structure -> IO Structure) -> IO (Maybe Structure)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Structure
result ((Ptr Structure -> IO Structure) -> IO (Maybe Structure))
-> (Ptr Structure -> IO Structure) -> IO (Maybe Structure)
forall a b. (a -> b) -> a -> b
$ \Ptr Structure
result' -> do
        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'
        Structure -> IO Structure
forall (m :: * -> *) a. Monad m => a -> m a
return Structure
result''
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    Maybe Structure -> IO (Maybe Structure)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Structure
maybeResult

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

instance O.OverloadedMethodInfo PromiseGetReplyMethodInfo Promise where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gst.Structs.Promise.promiseGetReply",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gst-1.0.24/docs/GI-Gst-Structs-Promise.html#v: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 :: forall (m :: * -> *). (HasCallStack, MonadIO m) => 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.OverloadedMethod PromiseInterruptMethodInfo Promise signature where
    overloadedMethod = promiseInterrupt

instance O.OverloadedMethodInfo PromiseInterruptMethodInfo Promise where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gst.Structs.Promise.promiseInterrupt",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gst-1.0.24/docs/GI-Gst-Structs-Promise.html#v: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 = True
--           , 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'
    -> Maybe (Gst.Structure.Structure)
    -- ^ /@s@/: a t'GI.Gst.Structs.Structure.Structure' with the the reply contents
    -> m ()
promiseReply :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Promise -> Maybe Structure -> m ()
promiseReply Promise
promise Maybe 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
maybeS <- case Maybe Structure
s of
        Maybe Structure
Nothing -> Ptr Structure -> IO (Ptr Structure)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Structure
forall a. Ptr a
nullPtr
        Just Structure
jS -> do
            Ptr Structure
jS' <- Structure -> IO (Ptr Structure)
forall a. (HasCallStack, GBoxed a) => a -> IO (Ptr a)
B.ManagedPtr.disownBoxed Structure
jS
            Ptr Structure -> IO (Ptr Structure)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Structure
jS'
    Ptr Promise -> Ptr Structure -> IO ()
gst_promise_reply Ptr Promise
promise' Ptr Structure
maybeS
    PromiseChangeFunc
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Promise
promise
    Maybe Structure -> (Structure -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Structure
s Structure -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

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

instance O.OverloadedMethodInfo PromiseReplyMethodInfo Promise where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gst.Structs.Promise.promiseReply",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gst-1.0.24/docs/GI-Gst-Structs-Promise.html#v: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 :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
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.OverloadedMethod PromiseWaitMethodInfo Promise signature where
    overloadedMethod = promiseWait

instance O.OverloadedMethodInfo PromiseWaitMethodInfo Promise where
    overloadedMethodInfo = O.MethodInfo {
        O.overloadedMethodName = "GI.Gst.Structs.Promise.promiseWait",
        O.overloadedMethodURL = "https://hackage.haskell.org/package/gi-gst-1.0.24/docs/GI-Gst-Structs-Promise.html#v: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.OverloadedMethod 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

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolvePromiseMethod t Promise, O.OverloadedMethod info Promise p, R.HasField t Promise p) => R.HasField t Promise p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolvePromiseMethod t Promise, O.OverloadedMethodInfo info Promise) => OL.IsLabel t (O.MethodProxy info Promise) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif