| 1 |
(* Library module defined by the International Standard |
| 2 |
Information technology - programming languages |
| 3 |
BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. |
| 4 |
|
| 5 |
Copyright ISO/IEC (International Organization for Standardization |
| 6 |
and International Electrotechnical Commission) 1996-2021. |
| 7 |
|
| 8 |
It may be freely copied for the purpose of implementation (see page |
| 9 |
707 of the Information technology - Programming languages Part 1: |
| 10 |
Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) |
| 11 |
|
| 12 |
DEFINITION MODULE IOLink; |
| 13 |
|
| 14 |
(* Types and procedures for the standard implementation of channels *) |
| 15 |
|
| 16 |
IMPORT IOChan, IOConsts, ChanConsts, SYSTEM; |
| 17 |
|
| 18 |
TYPE |
| 19 |
DeviceId; |
| 20 |
(* Values of this type are used to identify new device modules, |
| 21 |
and are normally obtained by them during their initialization. |
| 22 |
*) |
| 23 |
|
| 24 |
PROCEDURE AllocateDeviceId (VAR did: DeviceId); |
| 25 |
(* Allocates a unique value of type DeviceId, and assigns this |
| 26 |
value to did. *) |
| 27 |
|
| 28 |
PROCEDURE MakeChan (did: DeviceId; VAR cid: IOChan.ChanId); |
| 29 |
(* Attempts to make a new channel for the device module identified |
| 30 |
by did. If no more channels can be made, the identity of |
| 31 |
the invalid channel is assigned to cid. Otherwise, the identity |
| 32 |
of a new channel is assigned to cid. |
| 33 |
*) |
| 34 |
|
| 35 |
PROCEDURE UnMakeChan (did: DeviceId; VAR cid: IOChan.ChanId); |
| 36 |
(* If the device module identified by did is not the module that |
| 37 |
made the channel identified by cid, the exception wrongDevice is |
| 38 |
raised; otherwise the channel is deallocated, and the value |
| 39 |
identifying the invalid channel is assigned to cid. |
| 40 |
*) |
| 41 |
|
| 42 |
TYPE |
| 43 |
DeviceTablePtr = POINTER TO DeviceTable; |
| 44 |
(* Values of this type are used to refer to device tables *) |
| 45 |
|
| 46 |
TYPE |
| 47 |
LookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ; |
| 48 |
SkipProc = PROCEDURE (DeviceTablePtr) ; |
| 49 |
SkipLookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ; |
| 50 |
WriteLnProc = PROCEDURE (DeviceTablePtr) ; |
| 51 |
TextReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ; |
| 52 |
TextWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ; |
| 53 |
RawReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ; |
| 54 |
RawWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ; |
| 55 |
GetNameProc = PROCEDURE (DeviceTablePtr, VAR ARRAY OF CHAR) ; |
| 56 |
ResetProc = PROCEDURE (DeviceTablePtr) ; |
| 57 |
FlushProc = PROCEDURE (DeviceTablePtr) ; |
| 58 |
FreeProc = PROCEDURE (DeviceTablePtr) ; |
| 59 |
(* Carry out the operations involved in closing the corresponding |
| 60 |
channel, including flushing buffers, but do not unmake the |
| 61 |
channel. |
| 62 |
*) |
| 63 |
|
| 64 |
|
| 65 |
TYPE |
| 66 |
DeviceData = SYSTEM.ADDRESS; |
| 67 |
|
| 68 |
DeviceTable = |
| 69 |
RECORD (* Initialized by MakeChan to: *) |
| 70 |
cd: DeviceData; (* the value NIL *) |
| 71 |
did: DeviceId; (* the value given in the call of MakeChan *) |
| 72 |
cid: IOChan.ChanId; (* the identity of the channel *) |
| 73 |
result: IOConsts.ReadResults;(* the value notKnown *) |
| 74 |
errNum: IOChan.DeviceErrNum; (* undefined *) |
| 75 |
flags: ChanConsts.FlagSet; (* ChanConsts.FlagSet{} *) |
| 76 |
doLook: LookProc; (* raise exception notAvailable *) |
| 77 |
doSkip: SkipProc; (* raise exception notAvailable *) |
| 78 |
doSkipLook: SkipLookProc; (* raise exception notAvailable *) |
| 79 |
doLnWrite: WriteLnProc; (* raise exception notAvailable *) |
| 80 |
doTextRead: TextReadProc; (* raise exception notAvailable *) |
| 81 |
doTextWrite: TextWriteProc; (* raise exception notAvailable *) |
| 82 |
doRawRead: RawReadProc; (* raise exception notAvailable *) |
| 83 |
doRawWrite: RawWriteProc; (* raise exception notAvailable *) |
| 84 |
doGetName: GetNameProc; (* return the empty string *) |
| 85 |
doReset: ResetProc; (* do nothing *) |
| 86 |
doFlush: FlushProc; (* do nothing *) |
| 87 |
doFree: FreeProc; (* do nothing *) |
| 88 |
END; |
| 89 |
|
| 90 |
|
| 91 |
(* The pointer to the device table for a channel is obtained using the |
| 92 |
following procedure: *) |
| 93 |
|
| 94 |
(* |
| 95 |
If the device module identified by did is not the module that made |
| 96 |
the channel identified by cid, the exception wrongDevice is raised. |
| 97 |
*) |
| 98 |
|
| 99 |
PROCEDURE DeviceTablePtrValue (cid: IOChan.ChanId; did: DeviceId): DeviceTablePtr; |
| 100 |
|
| 101 |
|
| 102 |
(* |
| 103 |
Tests if the device module identified by did is the module |
| 104 |
that made the channel identified by cid. |
| 105 |
*) |
| 106 |
|
| 107 |
PROCEDURE IsDevice (cid: IOChan.ChanId; did: DeviceId) : BOOLEAN; |
| 108 |
|
| 109 |
|
| 110 |
TYPE |
| 111 |
DevExceptionRange = IOChan.ChanExceptions; |
| 112 |
|
| 113 |
(* |
| 114 |
ISO standard states defines |
| 115 |
|
| 116 |
DevExceptionRange = [IOChan.notAvailable .. IOChan.textParseError]; |
| 117 |
|
| 118 |
however this must be a bug as other modules need to raise |
| 119 |
IOChan.wrongDevice exceptions. |
| 120 |
*) |
| 121 |
|
| 122 |
PROCEDURE RAISEdevException (cid: IOChan.ChanId; did: DeviceId; |
| 123 |
x: DevExceptionRange; s: ARRAY OF CHAR) <* noreturn *> ; |
| 124 |
|
| 125 |
(* If the device module identified by did is not the module that made the channel |
| 126 |
identified by cid, the exception wrongDevice is raised; otherwise the given exception |
| 127 |
is raised, and the string value in s is included in the exception message. |
| 128 |
*) |
| 129 |
|
| 130 |
PROCEDURE IsIOException () : BOOLEAN; |
| 131 |
(* Returns TRUE if the current coroutine is in the exceptional execution state |
| 132 |
because of the raising af an exception from ChanExceptions; |
| 133 |
otherwise FALSE. |
| 134 |
*) |
| 135 |
|
| 136 |
PROCEDURE IOException () : IOChan.ChanExceptions; |
| 137 |
(* If the current coroutine is in the exceptional execution state because of the |
| 138 |
raising af an exception from ChanExceptions, returns the corresponding |
| 139 |
enumeration value, and otherwise raises an exception. |
| 140 |
*) |
| 141 |
|
| 142 |
END IOLink. |