interrupt.icl 1.35 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1 2 3 4 5 6 7 8
implementation module interrupt

import StdList
import StdPSt, StdId, StdTimer, StdWindow

checkDialogExistence id io
	# (st,io)	= getDialogsStack io
	= (isMember id st,io)
9

Diederik van Arkel's avatar
Diederik van Arkel committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
StartIntr :: !(!Id,Id) .a (.Bool -> .(.a -> .(*(PSt .b) -> *(.a,*(PSt .b))))) !*(PSt .b) -> *(PSt .b)
StartIntr (dialogId,interruptId) ls callback ps
	# (exist,ps)	= accPIO (checkDialogExistence dialogId) ps
	| exist
		# (err,ps)	= openTimer ls timerdef ps
		| err <> NoError
			= ps
		= ps
	# (_,ps)	= openTimer ls timerdef` ps
	= ps
where
	timerdef		= Timer 0
						NilLS
						[ TimerId interruptId
						, TimerSelectState Able
						, TimerFunction (TriggerIntr dialogId interruptId)
						]
	timerdef`		= Timer 0
						NilLS
						[ TimerId interruptId
						, TimerSelectState Able
						, TimerFunction (TriggerNoIntr interruptId)
						]

	TriggerIntr dialogid interruptId noi (ls, ps)
		# (exist,ps)	= accPIO (checkDialogExistence dialogId) ps
		| exist
			# ps		= appPIO (disableTimer interruptId) ps
			= callback False ls ps
		# ps			= closeWindow dialogid ps
		= callback True ls ps
		
	TriggerNoIntr interruptId noi (ls,ps)
		= callback False ls ps

StopIntr :: !(.a,!Id) !*(PSt .b) -> *(PSt .b)
StopIntr (dialogId,interruptId) ps
	= appPIO (closeTimer interruptId) ps
	
ContIntr :: !(.a,!Id) !*(PSt .b) -> *(PSt .b)
ContIntr (dialogId,interruptId) ps
	= appPIO (enableTimer interruptId) ps