UtilInterrupt.icl 1.75 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1 2 3 4 5 6 7 8 9 10 11 12 13
implementation module UtilInterrupt

import StdClass,StdBool,StdInt, StdList
import StdTimer, StdWindow
import IdeState

// Convert to message passing...?
// Zero timers really aren't nice. Should be a separate thread.

getDialogExistence id io
	# (st,io)	= getDialogsStack io
	= (isMember id st, io)

14
:: Callback l :== Bool (*PSt l) -> *PSt l
Diederik van Arkel's avatar
Diederik van Arkel committed
15

16
StartIntr :: !(!Id,!Id) !(Callback General) !*(PSt General) -> *(PSt General)
Diederik van Arkel's avatar
Diederik van Arkel committed
17 18 19 20 21 22 23 24 25
StartIntr (dialogId,interruptId) callback ps
	# ps		= setCallback callback ps
	# (exists,ps)	= accPIO (getDialogExistence dialogId) ps
	| exists
		# (_,ps)	= openTimer 0 timerdef ps
		= callback False ps
	# (_,ps)	= openTimer 0 timerdef` ps
	= callback False ps
where
26
	timerdef		= Timer 0
Diederik van Arkel's avatar
Diederik van Arkel committed
27 28 29 30 31
						NilLS
						[ TimerId interruptId
						, TimerSelectState Unable
						, TimerFunction (TriggerIntr dialogId interruptId)
						]
32
	timerdef`		= Timer 0
Diederik van Arkel's avatar
Diederik van Arkel committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
						NilLS
						[ TimerId interruptId
						, TimerSelectState Unable
						, TimerFunction (TriggerNoIntr interruptId)
						]

TriggerIntr dialogId interruptId noi (ls, ps)
	# (callback,ps) = getCallback ps
	# (exists,ps)	= accPIO (getDialogExistence dialogId) ps
	| exists
		# ps		= appPIO (disableTimer interruptId) ps
		= (ls,callback False ps)
	# ps			= closeWindow dialogId ps
	# ps			= appPIO (closeTimer interruptId) ps
	= (ls,callback True  ps)
	
TriggerNoIntr interruptId noi (ls,ps)
	# (callback,ps) = getCallback ps
	# ps			= appPIO (disableTimer interruptId) ps
	= (ls,callback False ps)

54
StopIntr :: !(!Id,!Id) !*(PSt .l) -> *(PSt .l)
Diederik van Arkel's avatar
Diederik van Arkel committed
55 56 57
StopIntr (dialogId,interruptId) ps
	= appPIO (closeTimer interruptId) ps
	
58
ContIntr :: !(!Id,!Id) !(Callback General) !*(PSt General) -> *(PSt General)
Diederik van Arkel's avatar
Diederik van Arkel committed
59 60 61
ContIntr (dialogId,interruptId) callback ps
	# ps			= setCallback callback ps
	= appPIO (enableTimer interruptId) ps