scheduler.dcl 6.5 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
4
5
6
7
definition module scheduler


//	Clean Object I/O library, version 1.2

//	Process creation, termination, and handling functions.

8
import	StdString
Peter Achten's avatar
Peter Achten committed
9
10
import	deviceevents, StdMaybe
from	id				import Id
11
from	iostate			import PSt, IOSt, RR, CProcesses, CProcess
Peter Achten's avatar
Peter Achten committed
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
from	receivertable	import ReceiverTable, ReceiverTableEntry, RecLoc
from	device			import Device
from	processstack	import ProcessStack, ProcessShowState, ShowFlag, ProcessKind, InteractiveProcess, VirtualProcess
from	systemid		import SystemId
from	StdIOCommon		import SelectState, Able, Unable, IdFun,
								ProcessAttribute, ProcessWindowPos,
									ItemPos, ItemLoc, Fix, LeftTop, RightTop, LeftBottom, RightBottom, 
										Left, Center, Right, LeftOf, RightTo, Above, Below, 
										LeftOfPrev, RightToPrev, AbovePrev, BelowPrev, 
									ItemOffset, 
								ProcessWindowSize, ProcessWindowResize, ProcessWindowResizeFunction,
								ProcessActivate, ProcessDeactivate, ProcessClose, ProcessNoWindowMenu,
								Vector2, Point2, Size
from	osevent			import OSEvents, OSEvent, CrossCallInfo
from	ostoolbox		import OSToolbox
from	ostime			import OSTime
from	StdProcessDef	import ProcessInit, DocumentInterface, NDI, SDI, MDI


::	*Environs
	=	{	envsEvents		:: !*OSEvents
		,	envsWorld		:: !*World
		}
::	*Context
	=	{	cEnvs			:: !*Environs			// The global environments
37
38
39
40
41
42
43
44
45
		,	cProcessStack	:: !ProcessStack		// The global process stack
		,	cMaxIONr		:: !SystemId			// The global maximum system number
		,	cProcesses		:: !*CProcesses			// All processes
		,	cModalProcess	:: !Maybe SystemId		// The SystemId of the interactive process that has a modal window
		,	cReceiverTable	:: !ReceiverTable		// The global receiver-process table
		,	cTimerTable		:: !TimerTable			// The table of all currently active timers
		,	cIdTable		:: !IdTable				// The table of all bound Ids
		,	cOSTime			:: !OSTime				// The current OSTime
		,	cIdSeed			:: !Int					// The global id generating number (actually the World)
Peter Achten's avatar
Peter Achten committed
46
47
48
		,	cOSToolbox		:: !*OSToolbox			// The toolbox environment
		}

49
initContext		:: !(ProcessInit (PSt .l)) !String !.l !DocumentInterface !ProcessKind !*World -> (!Context,!*OSToolbox)
Peter Achten's avatar
Peter Achten committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*	Generate an initial Context, given the initial actions, state, and (document/process)kind of an interactive
	process, and World.
*/
initContext`	:: !*World -> (!Context,!*OSToolbox)

handleEvents	:: !Context !*OSToolbox -> (!Context,!*OSToolbox)
/*	Consecutively handle events until termination of all interactive processes.
*/

CondHandleEvents :: !(St Context Bool) !*OSToolbox !Context -> (!*OSToolbox,!Context)
/*	CondHandleEvents consecutively handles events while condition holds.
*/

handleContextOSEvent :: !OSEvent !Context -> (![Int],!Context)
/*	Handle one OSEvent. Context MUST not be a final context, otherwise a runtime error occurs!
*/

closeContext	:: !Context !*OSToolbox -> *World
/*	Retrieve the final World value from the Context. Context MUST be a final context, otherwise a runtime error occurs!
*/


72
handleOneEventForDevices :: !SchedulerEvent !(PSt .l) -> (!Bool,!SchedulerEvent,!PSt .l)
Peter Achten's avatar
Peter Achten committed
73
74
75
76
77
78
/*	Apply the given event to all devices in the current interactive process.
	The Boolean result indicates whether one of the devices actually handled the event.
	The DeviceEvent result may contain a response of type [o], or an error indication.
*/


79
addVirtualProcess		:: !(ProcessInit (PSt .l)) String .l !(PSt .l`) -> PSt .l`
Peter Achten's avatar
Peter Achten committed
80
81
82
83
84
85
86
87
88
89
/*	AddVirtualProcess adds a process to the process administration as a virtual process.
	For virtual processes no initial devices are created. If the initial actions of the
	virtual process attempt to create a device instance this results in a runtime error.
	Virtual processes always share the GUI of their parent process. Termination is
	detected and handled by the system.
*/

ShareGUI			:==	True
NotShareGUI			:==	False

90
91
addInteractiveProcess	:: ![ProcessAttribute (PSt .l)] !(ProcessInit (PSt .l)) String .l 
							!Bool !DocumentInterface !(PSt .l`) -> PSt .l`
Peter Achten's avatar
Peter Achten committed
92
93
94
95
96
97
98
99
/*	AddInteractiveProcess adds a process to the process administration as an interactive process.
	For interactive processes initial devices are created. 
	The Boolean argument determines whether the process shares (ShareGUI) or not shares 
	(NotShareGUI) the GUI of the current process. If it does, then the current process
	becomes the parent process of the new process, and the new process its child.
*/


100
quitProcess			:: !(PSt .l) -> PSt .l
Peter Achten's avatar
Peter Achten committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*	QuitProcess removes all abstract devices that are held in the interactive process
	and takes care that all processes that share its GUI are also terminated recursively.
	The resulting IOSt is a terminal value and will be removed from the process administration.
*/


//	Context-switching operations:

::	SwitchError
	=	SwitchToYourself
	|	SwitchToDoesNotExist
	|	SwitchToReceiverDoesNotExist
	|	SwitchReceiverUnable
	|	SwitchEndsUpInDeadlock

116
cswitchProcess :: !SystemId !SchedulerEvent !(PSt .l) -> (!Maybe SwitchError, ![SemiDynamic], !PSt .l)
Peter Achten's avatar
Peter Achten committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*	cswitchProcess processId msgEvent pstate switches to PSt identified by processId, lets that process 
	handle the msgEvent, and switches back to pstate.
	Nothing SwitchError is returned if no exceptions were detected. 
	Exceptions are:
	-	SwitchToYourself:				processId is the current PSt. 
	-	SwitchToDoesNotExist:			no current process can be identified by processId. 
	-	SwitchToReceiverDoesNotExist:	process  exists, but receiver doesn't.
	-	SwitchReceiverUnable:			receiver exists, but is not Able.
	-	SwitchEndsUpInDeadlock:			if this process would block for the process with 
										id processId to get unblocked, a deadlock would occur.
	In all exceptional cases the PSt remains unchanged.
	Observe that in case Nothing is returned, the ps PSt component may have changed value.
*/

131
accContext :: !.(St Context .x) !(PSt .l) -> (!.x, !PSt .l)
Peter Achten's avatar
Peter Achten committed
132
133
134
135
136
137
138
139
140
141
142
143
144
/*	accContext applies the Context access function to the switched out process state (which creates a
	Context value), and switches back to the process state. The Context access function must not
	remove the argument process, otherwise a run-time error will occur!
*/


//	Function threading operations:

::	Result r
	:==	(	!Bool			//	object is found
		,	!Maybe r		//	optional access information
		)

145
accessLocals :: !(St CProcess (Result r)) !*CProcesses -> (!Result r,!*CProcesses)
Peter Achten's avatar
Peter Achten committed
146
/*	Let f::(IOSt .l .p) -> (Result r,IOSt .l .p) be an IOSt access function. 
147
	To thread f through *CProcesses until fst(fst(f io)), define gLocals as follows:
Peter Achten's avatar
Peter Achten committed
148
	
149
		gLocals :: *CProcesses -> (Result r, *CProcesses)
Peter Achten's avatar
Peter Achten committed
150
151
152
153
		gLocals locals = accessLocals f` locals
		where	f` localIO	= (r,{localIO & localIOSt=ioState})
				where	(r,ioState)	= f localIO.localIOSt
*/