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 #else /* whole file */
34 | Catch (ConsoleEvent -> IO ())
40 -- these are sent to Services only.
44 installHandler :: Handler -> IO Handler
45 installHandler handler =
49 Default -> rts_installHandler STG_SIG_DFL p_sp
50 Ignore -> rts_installHandler STG_SIG_IGN p_sp
52 v <- newStablePtr (toHandler h)
54 rts_installHandler STG_SIG_HAN p_sp
56 STG_SIG_DFL -> return Default
57 STG_SIG_IGN -> return Ignore
60 oldh <- deRefStablePtr osptr
61 -- stable pointer is no longer in use, free it.
63 return (Catch (\ ev -> oldh (fromConsoleEvent ev)))
67 0 {- CTRL_C_EVENT-} -> Just ControlC
68 1 {- CTRL_BREAK_EVENT-} -> Just Break
69 2 {- CTRL_CLOSE_EVENT-} -> Just Close
70 5 {- CTRL_LOGOFF_EVENT-} -> Just Logoff
71 6 {- CTRL_SHUTDOWN_EVENT-} -> Just Shutdown
75 ControlC -> 0 {- CTRL_C_EVENT-}
76 Break -> 1 {- CTRL_BREAK_EVENT-}
77 Close -> 2 {- CTRL_CLOSE_EVENT-}
78 Logoff -> 5 {- CTRL_LOGOFF_EVENT-}
79 Shutdown -> 6 {- CTRL_SHUTDOWN_EVENT-}
81 toHandler hdlr ev = do
82 case toConsoleEvent ev of
84 Nothing -> return () -- silently ignore..
86 foreign import ccall unsafe "Signals.h stg_InstallConsoleEvent"
87 rts_installHandler :: CInt -> Ptr (StablePtr (CInt -> IO ())) -> IO CInt
88 #endif /* mingw32_TARGET_OS */