{- |
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 datatype that records a start time.
-}

module GI.GLib.Structs.Timer
    ( 

-- * Exported types
    Timer(..)                               ,
    noTimer                                 ,


 -- * Methods
-- ** timerContinue
    timerContinue                           ,


-- ** timerDestroy
    timerDestroy                            ,


-- ** timerElapsed
    timerElapsed                            ,


-- ** timerReset
    timerReset                              ,


-- ** timerStart
    timerStart                              ,


-- ** timerStop
    timerStop                               ,




    ) 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 Timer = Timer (ForeignPtr Timer)
noTimer :: Maybe Timer
noTimer = Nothing

-- method Timer::continue
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_continue" g_timer_continue :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    IO ()


timerContinue ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    m ()
timerContinue _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_timer_continue _obj'
    touchManagedPtr _obj
    return ()

-- method Timer::destroy
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_destroy" g_timer_destroy :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    IO ()


timerDestroy ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    m ()
timerDestroy _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_timer_destroy _obj'
    touchManagedPtr _obj
    return ()

-- method Timer::elapsed
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "microseconds", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "microseconds", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TDouble
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_elapsed" g_timer_elapsed :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    Word64 ->                               -- microseconds : TBasicType TUInt64
    IO CDouble


timerElapsed ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    Word64 ->                               -- microseconds
    m Double
timerElapsed _obj microseconds = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- g_timer_elapsed _obj' microseconds
    let result' = realToFrac result
    touchManagedPtr _obj
    return result'

-- method Timer::reset
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_reset" g_timer_reset :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    IO ()


timerReset ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    m ()
timerReset _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_timer_reset _obj'
    touchManagedPtr _obj
    return ()

-- method Timer::start
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_start" g_timer_start :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    IO ()


timerStart ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    m ()
timerStart _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_timer_start _obj'
    touchManagedPtr _obj
    return ()

-- method Timer::stop
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "GLib" "Timer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "g_timer_stop" g_timer_stop :: 
    Ptr Timer ->                            -- _obj : TInterface "GLib" "Timer"
    IO ()


timerStop ::
    (MonadIO m) =>
    Timer ->                                -- _obj
    m ()
timerStop _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    g_timer_stop _obj'
    touchManagedPtr _obj
    return ()