gi-glib-0.2.46.13: GI/GLib/Structs/Once.hs
{- |
Copyright : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
A #GOnce struct controls a one-time initialization function. Any
one-time initialization function must have its own unique #GOnce
struct.
-}
module GI.GLib.Structs.Once
(
-- * Exported types
Once(..) ,
newZeroOnce ,
noOnce ,
-- * Methods
-- ** onceInitEnter
onceInitEnter ,
-- ** onceInitLeave
onceInitLeave ,
-- * Properties
-- ** Retval
onceReadRetval ,
-- ** Status
onceReadStatus ,
) where
import Prelude ()
import Data.GI.Base.ShortPrelude
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import GI.GLib.Types
import GI.GLib.Callbacks
newtype Once = Once (ForeignPtr Once)
-- | Construct a `Once` struct initialized to zero.
newZeroOnce :: MonadIO m => m Once
newZeroOnce = liftIO $ callocBytes 16 >>= wrapPtr Once
noOnce :: Maybe Once
noOnce = Nothing
onceReadStatus :: Once -> IO OnceStatus
onceReadStatus s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO CUInt
let val' = (toEnum . fromIntegral) val
return val'
onceReadRetval :: Once -> IO (Ptr ())
onceReadRetval s = withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 8) :: IO (Ptr ())
return val
-- method Once::init_enter
-- method type : MemberFunction
-- Args : [Arg {argCName = "location", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False
foreign import ccall "g_once_init_enter" g_once_init_enter ::
Ptr () -> -- location : TBasicType TVoid
IO CInt
onceInitEnter ::
(MonadIO m) =>
Ptr () -- location
-> m Bool -- result
onceInitEnter location = liftIO $ do
result <- g_once_init_enter location
let result' = (/= 0) result
return result'
-- method Once::init_leave
-- method type : MemberFunction
-- Args : [Arg {argCName = "location", argType = TBasicType TVoid, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False
foreign import ccall "g_once_init_leave" g_once_init_leave ::
Ptr () -> -- location : TBasicType TVoid
Word64 -> -- result : TBasicType TUInt64
IO ()
onceInitLeave ::
(MonadIO m) =>
Ptr () -- location
-> Word64 -- result_
-> m () -- result
onceInitLeave location result_ = liftIO $ do
g_once_init_leave location result_
return ()
type family ResolveOnceMethod (t :: Symbol) (o :: *) :: * where
ResolveOnceMethod l o = MethodResolutionFailed l o
instance (info ~ ResolveOnceMethod t Once, MethodInfo info Once p) => IsLabelProxy t (Once -> p) where
fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)
#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveOnceMethod t Once, MethodInfo info Once p) => IsLabel t (Once -> p) where
fromLabel _ = overloadedMethod (MethodProxy :: MethodProxy info)
#endif