StdReceiver.dcl 5.51 KB
Newer Older
Peter Achten's avatar
Peter Achten committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
definition module StdReceiver


//	********************************************************************************
//	Clean Standard Object I/O library, version 1.2
//	
//	StdReceiver specifies all receiver operations.
//	********************************************************************************


import	StdReceiverDef, StdMaybe
from	iostate	import	PSt, IOSt
from	id		import	RId, R2Id, RIdtoId, R2IdtoId, ==


//	Operations on the ReceiverDevice. 

//	Open uni- and bi-directional receivers:

class Receivers rdef where
21
22
	openReceiver   :: .ls !*(*rdef .ls (PSt .l)) !(PSt .l) -> (!ErrorReport,!PSt .l)
	getReceiverType::      *(*rdef .ls .pst)               -> ReceiverType
Peter Achten's avatar
Peter Achten committed
23
24
25
26
27
28
29
30
31
32
33
/*	openReceiver
		opens the given receiver if no receiver currently exists with the given 
		R(2)Id. The R(2)Id has to be used to send messages to this receiver. 
	getReceiverType
		returns the type of the receiver (see also getReceivers).
*/

instance Receivers (Receiver  msg)
instance Receivers (Receiver2 msg resp)


34
closeReceiver		:: !Id !(IOSt .l) -> IOSt .l
Peter Achten's avatar
Peter Achten committed
35
36
37
38
39
/*	closeReceiver closes the indicated uni- or bi-directional receiver.
	Invalid Ids have no effect.
*/


40
getReceivers		:: !(IOSt .l) -> (![(Id,ReceiverType)], !IOSt .l)
Peter Achten's avatar
Peter Achten committed
41
42
43
44
45
/*	getReceivers returns the Ids and ReceiverTypes of all currently open uni- or 
	bi-directional receivers of this interactive process.
*/


46
47
48
enableReceivers			:: ![Id] !(IOSt .l) ->                      IOSt .l
disableReceivers		:: ![Id] !(IOSt .l) ->                      IOSt .l
getReceiverSelectState	:: ! Id	 !(IOSt .l) -> (!Maybe SelectState,!IOSt .l)
Peter Achten's avatar
Peter Achten committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*	(en/dis)ableReceivers
		(en/dis)able the indicated uni- or bi-directional receivers. 
		Note that this implies that in case of synchronous message passing messages 
		can fail (see the comments of syncSend and syncSend2 below). Invalid Ids 
		have no effect. 
	getReceiverSelectState
		yields the current SelectState of the indicated receiver. In case the 
		receiver does not exist, Nothing is returned.
*/


//	Inter-process communication:

//	Message passing status report:
::	SendReport
	=	SendOk
	|	SendUnknownReceiver
	|	SendUnableReceiver
	|	SendDeadlock
Peter Achten's avatar
Peter Achten committed
68
	|	OtherSendReport !String
Peter Achten's avatar
Peter Achten committed
69
70
71
72

instance ==       SendReport
instance toString SendReport

73
asyncSend :: !(RId msg) msg !(PSt .l) -> (!SendReport, !PSt .l)
Peter Achten's avatar
Peter Achten committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*	asyncSend posts a message to the receiver indicated by the argument RId. In case
	the indicated receiver belongs to this process, the message is simply buffered. 
	asyncSend is asynchronous: the message will at some point be received by the 
	indicated receiver. 
	The SendReport can be one of the following alternatives:
	-	SendOk:	No exceptional situation has occurred. The message has been sent. 
				Note that even though the message has been sent, it cannot be 
				guaranteed that the message will actually be handled by the 
				indicated receiver because it might become closed, forever disabled,
				or flooded with synchronous messages.
	-	SendUnknownReceiver:
				The indicated receiver does not exist. 
	-	SendUnableReceiver:
				Does not occur: the message is always buffered, regardless whether 
				the indicated receiver is Able or Unable. Note that in case the 
				receiver never becomes Able, the message will not be handled.
	-	SendDeadlock:
				Does not occur.
*/

94
syncSend :: !(RId msg) msg !(PSt .l) -> (!SendReport, !PSt .l)
Peter Achten's avatar
Peter Achten committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*	syncSend posts a message to the receiver indicated by the argument RId. In case 
	the indicated receiver belongs to the current process, the corresponding 
	ReceiverFunction is applied directly to the message argument and current process
	state. 
	syncSend is synchronous: this interactive process blocks evaluation until the 
	indicated receiver has received the message. 
	The SendReport can be one of the following alternatives:
	-	SendOk:	No exceptional situation has occurred. The message has been sent and
				handled by the indicated receiver. 
	-	SendUnknownReceiver:
				The indicated receiver does not exist. 
	-	SendUnableReceiver:
				The receiver exists, but its ReceiverSelectState is Unable. 
				Message passing is halted. The message is not sent. 
	-	SendDeadlock:
				The receiver is involved in a synchronous, cyclic communication 
				with the current process. Blocking the current process would result 
				in a deadlock situation. Message passing is halted to circumvent the
				deadlock. The message is not sent.
*/

116
117
syncSend2 :: !(R2Id msg resp) msg  !(PSt .l)
	-> (!(!SendReport,!Maybe resp), !PSt .l)
Peter Achten's avatar
Peter Achten committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*	syncSend2 posts a message to the receiver indicated by the argument R2Id. In 
	case the indicated receiver belongs to the current process, the corresponding 
	Receiver2Function is applied directly to the message argument and current 
	process state. 
	syncSend2 is synchronous: this interactive process blocks until the indicated 
	receiver has received the message. 
	The SendReport can be one of the following alternatives:
	-	SendOk:	No exceptional situation has occurred. The message has been sent and
				handled by the indicated receiver. The response of the receiver is 
				returned as well as (Just response).
	-	SendUnknownReceiver:
				The indicated receiver does not exist. 
	-	SendUnableReceiver:
				The receiver exists, but its ReceiverSelect is Unable. 
				Message passing is halted. The message is not sent. 
	-	SendDeadlock:
				The receiver is involved in a synchronous, cyclic communication 
				with the current process. Blocking the current process would result 
				in a deadlock situation. Message passing is halted to circumvent the
				deadlock. The message is not sent.
	In all other cases than SendOk, the optional response is Nothing.
*/