moncalls.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. {Set tabsize to 4.}
  2. {****************************************************************************
  3. MONCALLS interface unit
  4. FPK-Pascal Runtime Library for OS/2
  5. Copyright (c) 1993,94 by Florian Kl„mpfl
  6. Copyright (c) 1997 by Dani‰l Mantione
  7. Copyright (c) 1998 by Tomas Hajny
  8. The FPK-Pascal runtime library is distributed under the Library GNU Public
  9. License v2. So is this unit. The Library GNU Public License requires you to
  10. distribute the source code of this unit with any product that uses it.
  11. Because the EMX library isn't under the LGPL, we grant you an exception to
  12. this, and that is, when you compile a program with the FPK Pascal compiler,
  13. you do not need to ship source code with that program, AS LONG AS YOU ARE
  14. USING UNMODIFIED CODE! If you modify this code, you MUST change the next
  15. line:
  16. <This is an official, unmodified FPK Pascal source code file.>
  17. Send us your modified files, we can work together if you want!
  18. FPK-Pascal is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. Library GNU General Public License for more details.
  22. You should have received a copy of the Library GNU General Public License
  23. along with FPK-Pascal; see the file COPYING.LIB. If not, write to
  24. the Free Software Foundation, 59 Temple Place - Suite 330,
  25. Boston, MA 02111-1307, USA.
  26. ****************************************************************************}
  27. unit MonCalls;
  28. { Interface library to MONCALLS.DLL (through EMXWRAP.DLL)
  29. Please, note, that monitors are supported for OS/2 v2.1 and above only
  30. (not for v2.0) and that they cannot be used in PM applications.
  31. Changelog:
  32. People:
  33. TH - Tomas Hajny
  34. Date: Description of change: Changed by:
  35. - First released version 1.0 TH
  36. Coding style:
  37. I have tried to use the same coding style as Dani‰l Mantione in unit
  38. DOSCALLS, although I can't say I would write it the same way otherwise
  39. (I would write much more spaces myself, at least). Try to use it as well,
  40. please. Original note by Dani‰l Mantione follows:
  41. It may be well possible that coding style feels a bit strange to you.
  42. Nevertheless I friendly ask you to try to make your changes not look all
  43. to different. To make life easier, set your IDE to use tab characters,
  44. turn optimal fill, autoindent and backspace unindents on and set a
  45. tabsize of 4.}
  46. {***************************************************************************}
  47. interface
  48. {***************************************************************************}
  49. uses strings;
  50. {$ifdef FPK}
  51. {$packrecords 1}
  52. {$endif FPK}
  53. const
  54. {return codes / error constants (those marked with * shouldn't occur)}
  55. NO_ERROR = 0;
  56. ERROR_NOT_ENOUGH_MEMORY = 8;
  57. ERROR_OPEN_FAILED = 110;
  58. ERROR_MONITORS_NOT_SUPPORTED = 165;
  59. ERROR_MON_INVALID_PARMS = 379;
  60. ERROR_MON_INVALID_DEVNAME = 380;
  61. ERROR_MON_INVALID_HANDLE = 381;
  62. ERROR_MON_BUFFER_TOO_SMALL = 382;
  63. ERROR_MON_BUFFER_EMPTY = 383;
  64. ERROR_MON_DATA_TOO_LARGE = 384;
  65. ERROR_MON_BAD_BUFFER = 730; {*}
  66. ERROR_MON_CHAIN_HANDLE = 32784; {*}
  67. ERROR_MON_NOT_REGISTERED = 32785; {*}
  68. {WaitFlag}
  69. IO_WAIT =0; {The monitor thread that issues DosMonRead wishes to block}
  70. {until a data record is available in its input buffer.}
  71. IO_NOWAIT =1; {The monitor thread that issues DosMonRead does not wish}
  72. {to block when its input buffer is empty.}
  73. {Terminate character device monitoring. All monitor buffers associated with
  74. this process are flushed and closed.}
  75. {MonHandle - device handle returned from a previous DosMonOpen call.}
  76. {Possible return codes:
  77. 0 NO_ERROR
  78. 381 ERROR_MON_INVALID_HANDLE}
  79. {Remarks:
  80. * A single process may register one or more monitors with a character device
  81. using the same device handle returned from a previous DosMonOpen call.
  82. When DosMonClose is issued for a specific, opened device handle, all
  83. monitors for the current process registered with this handle terminate.
  84. * When DosMonClose is issued, the monitor loses access to the device data
  85. stream. Before issuing DosMonClose, monitor threads calling DosMonRead and
  86. DosMonWrite should be terminated. After DosMonClose has been called,
  87. DosMonRead calls return an ERROR_MON_BUFFER_EMPTY return code and
  88. DosMonWrite calls return an ERROR_NOT_ENOUGH_MEMORY return code.
  89. * Data area containing monitor buffers should not be freed until after
  90. DosMonClose is called. If data area containing monitor buffers is freed
  91. before DosMonClose is called, a GP fault occurs when DosMonClose is called
  92. and the process is terminated.
  93. * For a detailed description of this call see the chapter "Character Device
  94. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  95. Device Support Volume 1.}
  96. function DosMonClose(MonHandle:word):word;
  97. {Gain access to a character device data stream.}
  98. {DevName - device name, monitor handle returned in MonHandle.}
  99. {Possible return codes:
  100. 0 NO_ERROR
  101. 110 ERROR_OPEN_FAILED
  102. 379 ERROR_MON_INVALID_PARMS
  103. 380 ERROR_MON_INVALID_DEVNAME}
  104. {Remarks:
  105. * Only one DosMonOpen call is necessary per device per process. That is,
  106. several DosMonReg calls can be made using the same monitor handle to the
  107. same device. This allows monitors to be registered using different values
  108. for Index from the same process and going to the same device. When the
  109. DosMonClose is issued, all of the monitors registered on the handle are
  110. closed.
  111. * For a detailed description of this call see the chapter "Character Device
  112. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  113. Device Support Volume 1.}
  114. function DosMonOpen(DevName:PChar;var MonHandle:word):word;
  115. function DosMonOpen(DevName:string;var MonHandle:word):word;
  116. {Wait for a data record, move it from the input buffer of a registered
  117. character device monitor and place it in a private data area where the monitor
  118. can freely access it.}
  119. {InBuf - monitor input buffer, WaitFlag - see IO_WAIT and IO_NOWAIT constants,
  120. DataBuf - data area in the calling process address space that the data from the
  121. monitor's input buffer is read into, ByteCount - on input size of the DataBuf,
  122. on return number of bytes of data moved.}
  123. {Possible return codes:
  124. 0 NO_ERROR
  125. 379 ERROR_MON_INVALID_PARMS
  126. 382 ERROR_MON_BUFFER_TOO_SMALL
  127. 383 ERROR_MON_BUFFER_EMPTY}
  128. {Remarks:
  129. * For a detailed description of this call see the chapter "Character Device
  130. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  131. Device Support Volume 1.}
  132. function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
  133. var ByteCount:word):word;
  134. {Establish an input and output buffers to monitor an I/O stream for a character
  135. device.}
  136. {MonHandle - device handle returned from a previous DosMonOpen call, InBuf -
  137. monitor input buffer, the monitor dispatcher moves data records into this
  138. buffer from the device driver (if the monitor is the first one in the monitor
  139. chain) or from the previous monitor in the chain, monitor then takes data from
  140. this buffer for filtering by calling DosMonRead, OutBuf - monitor output
  141. buffer, monitor places filtered data into this buffer by calling DosMonWrite,
  142. the monitor dispatcher moves data records from this buffer to the device driver
  143. (if the monitor is the last one in the monitor chain) or to the next monitor in
  144. the chain, PosCode - used to specify placement of a monitor's buffers with the
  145. monitor chain (FIRST, LAST or DEFAULT) and whether one or two threads are
  146. created by the monitor dispatcher to handle data movement (see explanation
  147. bellow), Index - device specific value, for the keyboard it pertains to the
  148. session you wish to register a monitor on, for the printer it pertains to the
  149. data or code page monitor chain.}
  150. {Possible return codes:
  151. 0 NO_ERROR
  152. 8 ERROR_NOT_ENOUGH_MEMORY
  153. 165 ERROR_MONITORS_NOT_SUPPORTED
  154. 379 ERROR_MON_INVALID_PARMS
  155. 381 ERROR_MON_INVALID_HANDLE
  156. 382 ERROR_MON_BUFFER_TOO_SMALL}
  157. {Remarks:
  158. * PosCode meaning:
  159. 0 DEFAULT (no position preference) and one thread for data movement
  160. 1 FIRST (monitor placed at beginning of monitor chain) and one thread for
  161. data movement
  162. 2 LAST (monitor placed at the end of monitor chain) and one thread for
  163. data movement
  164. 3 DEFAULT with two threads for data movement
  165. 4 FIRST with two threads for data movement
  166. 5 LAST with two threads for data movement
  167. The first monitor in a monitor chain that registers as FIRST is placed at the
  168. head of the monitor chain. The next monitor that registers as FIRST follows
  169. the last monitor registered as FIRST, and so on. Similarly, the first monitor
  170. that registers as LAST is placed at the end of the monitor chain. The next
  171. monitor that registers as LAST is placed before the last monitor that
  172. registered as LAST, and so on. The first monitor that registers as DEFAULT is
  173. placed before the last monitor, if any, that registered as LAST. The next
  174. monitor that registers as DEFAULT is placed before the last monitor that
  175. registered as DEFAULT, and so on.
  176. * For a detailed description of this call see the chapter "Character Device
  177. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  178. Device Support Volume 1.}
  179. function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
  180. {Move a filtered data record from the monitor's private data area into the
  181. monitor's output buffer.}
  182. {OutBuf - monitor output buffer, DataBuf - monitor's private data area
  183. containing a filtered data record of length ByteCount, this filtered data
  184. record is moved into the monitor's output buffer by this call, ByteCount - size
  185. of the data record.}
  186. {Possible return codes:
  187. 0 NO_ERROR
  188. 8 ERROR_NOT_ENOUGH_MEMORY
  189. 379 ERROR_MON_INVALID_PARMS
  190. 384 ERROR_MON_DATA_TOO_LARGE}
  191. {Remarks:
  192. * For a detailed description of the use of this call see the chapter
  193. "Character Device Monitors" in the IBM Operating System/2 Version 1.2 I/O
  194. Subsystems And Device Support Volume 1.}
  195. function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word;
  196. {***************************************************************************}
  197. implementation
  198. {***************************************************************************}
  199. function DosMonClose(MonHandle:word):word;
  200. external 'EMXWRAP' index 403;
  201. {external 'MONCALLS' index 3;}
  202. function DosMonOpen(DevName:PChar;var MonHandle:word):word;
  203. external 'EMXWRAP' index 404;
  204. {external 'MONCALLS' index 4;}
  205. function DosMonOpen(DevName:string;var MonHandle:word):word;
  206. var
  207. i : byte;
  208. begin
  209. if DevName[0]=#255 then
  210. begin
  211. I:=byte(DevName[0]);
  212. Move(DevName[1],DevName[0],255);
  213. DevName[255]:=#0;
  214. DosMonOpen:=DosMonOpen(@DevName,MonHandle);
  215. end else
  216. begin
  217. DevName[Succ(byte(DevName[0]))]:=#0;
  218. DosMonOpen:=DosMonOpen(@DevName[1],MonHandle);
  219. end;
  220. end;
  221. function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
  222. var ByteCount:word):word;
  223. external 'EMXWRAP' index 402;
  224. {external 'MONCALLS' index 2;}
  225. function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
  226. external 'EMXWRAP' index 405;
  227. {external 'MONCALLS' index 5;}
  228. function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word;
  229. external 'EMXWRAP' index 401;
  230. {external 'MONCALLS' index 1;}
  231. end.
  232.