IOLINK.DEF 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. DEFINITION MODULE IOLink;
  2. (* Types and procedures giving the standard implementation of channels: *)
  3. FROM IOConsts IMPORT ReadResults;
  4. FROM ChanConsts IMPORT FlagSet;
  5. FROM SYSTEM IMPORT ADDRESS;
  6. TYPE
  7. ChanId; (* values of this type are used to identify channels *)
  8. (* Devices need to identify themselves in order to allow a check to be made
  9. that device-dependent operations are applied only for channels opened to
  10. that device: *)
  11. TYPE
  12. DeviceId; (* values of this type are used to identify new device
  13. modules and are normally obtained by them during their
  14. intialization *)
  15. PROCEDURE AllocateDeviceId (VAR did : DeviceId);
  16. (* Allocates a unique value of type DeviceId and assigns this value to
  17. the parameter did *)
  18. (* a new device module open procedure obtains a channel by calling MakeChan *)
  19. PROCEDURE MakeChan ( did : DeviceId;
  20. VAR cid : ChanId);
  21. (* Attempts to make a new channel for the device module identified by did.
  22. If no more channels can be made, the identity of the bad channel is
  23. assigned to cid. Otherwise, the identity ofa new channel is assigned to
  24. cid. *)
  25. (* If a channel is allocated but the call of the device module open
  26. procedure is not successful, and on a successful call of a device module
  27. close procedure, the device module unmakes the channel and returns the
  28. value identifying the bad channel to its client: *)
  29. PROCEDURE UnMakeChan ( did : DeviceId;
  30. VAR cid : ChanId);
  31. (* If the device module identified by the parameter did is not the module that
  32. made the channel identified by the parameter cid, the exception wrongDevice
  33. is raised.
  34. Otherwise, the channel is deallocated and the value identifying the bad
  35. channel is assigned to cid. *)
  36. PROCEDURE GetStdChanId ( stdCode : INTEGER) : ChanId;
  37. (* If stdCode corresponds to one of the standard channels, then
  38. returns the ChanId of that channel.
  39. Otherwise, the ChanId of the Bad Channel is returned. *)
  40. (* If the call of the device module open procedure is successful, the
  41. device module obtains a pointer to a device table for the channel, which
  42. will have been initialized by MakeChan. It then changes the fields of the
  43. device table to install its own values for the device data, supported
  44. operations, and flags, and returns to its client the identity of the
  45. channel. *)
  46. TYPE
  47. DeviceTablePtr = POINTER TO DeviceTable;
  48. (* Values of this type are used to refer to device tables *)
  49. (* Device modules supply procedures of the following types: *)
  50. TYPE
  51. LookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR ReadResults);
  52. SkipProc = PROCEDURE (DeviceTablePtr);
  53. SkipLookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR ReadResults);
  54. TextReadProc = PROCEDURE (DeviceTablePtr, ADDRESS, CARDINAL, VAR CARDINAL);
  55. TextWriteProc = PROCEDURE (DeviceTablePtr, ADDRESS, CARDINAL);
  56. WriteLnProc = PROCEDURE (DeviceTablePtr);
  57. RawReadProc = PROCEDURE (DeviceTablePtr, ADDRESS, CARDINAL, VAR CARDINAL);
  58. RawWriteProc = PROCEDURE (DeviceTablePtr, ADDRESS, CARDINAL);
  59. GetNameProc = PROCEDURE (DeviceTablePtr, VAR ARRAY OF CHAR);
  60. ResetProc = PROCEDURE (DeviceTablePtr);
  61. FlushProc = PROCEDURE (DeviceTablePtr);
  62. FreeProc = PROCEDURE (DeviceTablePtr);
  63. (* Carry out the operations involved in closing the corresponding
  64. channel, including flushing buffers, but do not unmake the channel.
  65. This procedure is called for each open channel at program
  66. termination. *)
  67. (* When a device procedure detects a device error, it raises the exception
  68. softDeviceError or hardDeviceError. If these exceptions are handled, the
  69. following procedure may be used to discover an implementation-defined error
  70. number for the channel. *)
  71. TYPE
  72. DeviceErrNum = INTEGER;
  73. PROCEDURE DeviceError (cid : ChanId) : DeviceErrNum;
  74. (* If a device error exception has been raised, returns the error
  75. number stored by the device module. *)
  76. TYPE
  77. DeviceData = ADDRESS;
  78. DeviceTable = RECORD
  79. cd : DeviceData;
  80. (* the value NIL *)
  81. did : DeviceId;
  82. (* the value given in the call MakeChan *)
  83. cid : ChanId;
  84. (* the identity of the channel *)
  85. result : ReadResults;
  86. (* the value notKnown *)
  87. errNum : DeviceErrNum;
  88. (* undefined *)
  89. flags : FlagSet;
  90. (* FlagSet{} *)
  91. doLook : LookProc;
  92. (* raise exception notAvailable *)
  93. doSkip : SkipProc;
  94. (* raise exception notAvailable *)
  95. doSkipLook : SkipLookProc;
  96. (* raise exception notAvailable *)
  97. doTextRead : TextReadProc;
  98. (* raise exception notAvailable *)
  99. doTextWrite : TextWriteProc;
  100. (* raise exception notAvailable *)
  101. doLnWrite : WriteLnProc;
  102. (* raise exception notAvailable *)
  103. doRawRead : RawReadProc;
  104. (* raise exception notAvailable *)
  105. doRawWrite : RawWriteProc;
  106. (* raise exception notAvailable *)
  107. doGetName : GetNameProc;
  108. (* return the empty string *)
  109. doReset : ResetProc;
  110. (* do nothing *)
  111. doFlush : FlushProc;
  112. (* do nothing *)
  113. doFree : FreeProc;
  114. (* do nothing *)
  115. END;
  116. (* The pointer to the device table for a channel is obtained using the
  117. following procedure: *)
  118. PROCEDURE DeviceTablePtrValue (cid : ChanId) : DeviceTablePtr;
  119. (* If the device module identified by the parameter did is not the module
  120. that made the channel identified by the parameter cid, the exception
  121. wrongDevice is raised.
  122. Otherwise, a pointer to the device table for the channel is returned. *)
  123. PROCEDURE AddDeviceTable (dtp : DeviceTablePtr);
  124. (* Includes dtp in record of open channels *)
  125. (* A device module can ask if it opened a given channel. It does this
  126. to implement a corresponding enquiry function that is exported from the
  127. device module: *)
  128. PROCEDURE IsDevice (cid : ChanId;
  129. did : DeviceId) : BOOLEAN;
  130. (* Tests if the device module identified by the parameter did is the
  131. module that made the channel identified by the parameter cid. *)
  132. (* The following exceptions are defined for this module and its clients *)
  133. TYPE
  134. ChanExceptions = (
  135. ChanNoException,
  136. (* there is no exception in this context *)
  137. notChanException,
  138. (* there is an exception in this context, but from another source *)
  139. wrongDevice,
  140. (* device specific operations on wrong device *)
  141. notAvailable,
  142. (* operations attempted that is not available on that channel *)
  143. skipAtEnd,
  144. (* attempt to skip data from a stream that has ended *)
  145. softDeviceError,
  146. (* device specific recoverable error *)
  147. hardDeviceError,
  148. (* device specific non-recoverable error *)
  149. textParseError,
  150. (* input data does not correspond to a character or line mark
  151. - optional detection *)
  152. notAChannel
  153. (* given value does not identify a channel - optional detection *)
  154. );
  155. (* Client modules may raise exceptions: *)
  156. TYPE
  157. DevExceptionRange = [wrongDevice .. notAChannel];
  158. PROCEDURE RAISEdevException (cid : ChanId;
  159. did : DeviceId;
  160. x : DevExceptionRange;
  161. s : ARRAY OF CHAR);
  162. (* If the device module identified by the parameter did is not the module
  163. that made the channel identified by the parameter cid, the exception
  164. wrongDevice is raised. Otherwise the given exception is raised and the
  165. string value of the parameter s is included in the exception message. *)
  166. PROCEDURE IOException () : ChanExceptions;
  167. (* If the current coroutine is in the exceptional execution state because of
  168. the raising of an exception from ChanExceptions, returns the corresponding
  169. enumeration value, and otherwise raises an exception.
  170. *)
  171. END IOLink.