2 -----------------------------------------------------------------------------
4 -- Module : GHC.ConsoleHandler
5 -- Copyright : whatevah
6 -- License : see libraries/base/LICENSE
8 -- Maintainer : cvs-ghc@haskell.org
9 -- Stability : internal
10 -- Portability : non-portable (GHC extensions)
12 -- Installing Win32 console handlers.
14 -----------------------------------------------------------------------------
15 module GHC.ConsoleHandler
16 #ifndef mingw32_TARGET_OS
18 import Prelude -- necessary to get dependencies right
19 #else /* whole file */
29 import Prelude -- necessary to get dependencies right
37 | Catch (ConsoleEvent -> IO ())
43 -- these are sent to Services only.
47 installHandler :: Handler -> IO Handler
48 installHandler handler =
52 Default -> rts_installHandler STG_SIG_DFL p_sp
53 Ignore -> rts_installHandler STG_SIG_IGN p_sp
55 v <- newStablePtr (toHandler h)
57 rts_installHandler STG_SIG_HAN p_sp
59 STG_SIG_DFL -> return Default
60 STG_SIG_IGN -> return Ignore
63 oldh <- deRefStablePtr osptr
64 -- stable pointer is no longer in use, free it.
66 return (Catch (\ ev -> oldh (fromConsoleEvent ev)))
70 0 {- CTRL_C_EVENT-} -> Just ControlC
71 1 {- CTRL_BREAK_EVENT-} -> Just Break
72 2 {- CTRL_CLOSE_EVENT-} -> Just Close
73 5 {- CTRL_LOGOFF_EVENT-} -> Just Logoff
74 6 {- CTRL_SHUTDOWN_EVENT-} -> Just Shutdown
78 ControlC -> 0 {- CTRL_C_EVENT-}
79 Break -> 1 {- CTRL_BREAK_EVENT-}
80 Close -> 2 {- CTRL_CLOSE_EVENT-}
81 Logoff -> 5 {- CTRL_LOGOFF_EVENT-}
82 Shutdown -> 6 {- CTRL_SHUTDOWN_EVENT-}
84 toHandler hdlr ev = do
85 case toConsoleEvent ev of
87 Nothing -> return () -- silently ignore..
89 foreign import ccall unsafe "Signals.h stg_InstallConsoleEvent"
90 rts_installHandler :: CInt -> Ptr (StablePtr (CInt -> IO ())) -> IO CInt
91 #endif /* mingw32_TARGET_OS */