Update of /cvsroot/htoolkit/port/src/Port
In directory sc8-pr-cvs1:/tmp/cvs-serv1886
Added Files:
Timer.hs
Log Message:
import
--- NEW FILE: Timer.hs ---
{-# OPTIONS -fglasgow-exts -#include Types.h -#include Timer.h #-}
-----------------------------------------------------------------------------------------
{-| Module : Handlers
Copyright : (c) Krasimir Angelov 2003
License : BSD-style
Maintainer : ka2...@ya...
Stability : provisional
Portability : portable
Timers
-}
-----------------------------------------------------------------------------------------
module Graphics.UI.Port.Timer
( createTimer, destroyTimer
, getAllTimerHandles, destroyAllTimers
) where
import Prelude hiding (lookup)
import Graphics.UI.Port.Types
import Graphics.UI.Port.PtrMap
import Graphics.UI.Port.Handlers(registerTimer, unregisterTimer, getAllTimerHandles)
import System.IO.Unsafe( unsafePerformIO )
import Control.Concurrent.MVar
-- | Create a timer with a handler that is called on a specified milli-second interval.
createTimer :: Int -> IO () -> IO TimerHandle
createTimer msecs handler = do
htimer <- osCreateTimer msecs
registerTimer htimer handler
return htimer
foreign import ccall osCreateTimer :: Int -> IO TimerHandle
-- | Destroy a timer and automatically unregister its event handler.
destroyTimer :: TimerHandle -> IO ()
destroyTimer htimer = do
unregisterTimer htimer
osDestroyTimer htimer
foreign import ccall osDestroyTimer :: TimerHandle -> IO ()
-- Destroy all timers (called by quit).
destroyAllTimers :: IO ()
destroyAllTimers = getAllTimerHandles >>= mapM_ osDestroyTimer
|