moncalls.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. {Set tabsize to 4.}
  2. {****************************************************************************
  3. MONCALLS interface unit
  4. Free Pascal Runtime Library for OS/2
  5. Copyright (c) 1999-2000 by Florian Kl„mpfl
  6. Copyright (c) 1999-2000 by Daniel Mantione
  7. Copyright (c) 1999-2000 by Tomas Hajny
  8. The Free 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 Free 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 Free Pascal source code file.>
  17. Send us your modified files, we can work together if you want!
  18. Free 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 Free 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 Daniel 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 Daniel 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. {$IFDEF FPC}
  50. {$PACKRECORDS 1}
  51. {$ENDIF FPC}
  52. const
  53. {return codes / error constants (those marked with * shouldn't occur)}
  54. No_Error = 0;
  55. Error_Not_Enough_Memory = 8;
  56. Error_Open_Failed = 110;
  57. Error_Monitors_Not_Supported = 165;
  58. Error_Mon_Invalid_Parms = 379;
  59. Error_Mon_Invalid_DevName = 380;
  60. Error_Mon_Invalid_Handle = 381;
  61. Error_Mon_Buffer_Too_Small = 382;
  62. Error_Mon_Buffer_Empty = 383;
  63. Error_Mon_Data_Too_Large = 384;
  64. Error_Mon_Bad_Buffer = 730; {*}
  65. Error_Mon_Chain_Handle = 32784; {*}
  66. Error_Mon_Not_Registered = 32785; {*}
  67. {WaitFlag}
  68. IO_Wait =0; {The monitor thread that issues DosMonRead wishes to block}
  69. {until a data record is available in its input buffer.}
  70. IO_NoWait =1; {The monitor thread that issues DosMonRead does not wish}
  71. {to block when its input buffer is empty.}
  72. {Terminate character device monitoring. All monitor buffers associated with
  73. this process are flushed and closed.}
  74. {MonHandle - device handle returned from a previous DosMonOpen call.}
  75. {Possible return codes:
  76. 0 No_Error
  77. 381 Error_Mon_Invalid_Handle}
  78. {Remarks:
  79. * A single process may register one or more monitors with a character device
  80. using the same device handle returned from a previous DosMonOpen call.
  81. When DosMonClose is issued for a specific, opened device handle, all
  82. monitors for the current process registered with this handle terminate.
  83. * When DosMonClose is issued, the monitor loses access to the device data
  84. stream. Before issuing DosMonClose, monitor threads calling DosMonRead and
  85. DosMonWrite should be terminated. After DosMonClose has been called,
  86. DosMonRead calls return an ERROR_MON_BUFFER_EMPTY return code and
  87. DosMonWrite calls return an ERROR_NOT_ENOUGH_MEMORY return code.
  88. * Data area containing monitor buffers should not be freed until after
  89. DosMonClose is called. If data area containing monitor buffers is freed
  90. before DosMonClose is called, a GP fault occurs when DosMonClose is called
  91. and the process is terminated.
  92. * For a detailed description of this call see the chapter "Character Device
  93. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  94. Device Support Volume 1.}
  95. function DosMonClose(MonHandle:word):word; cdecl;
  96. {Gain access to a character device data stream.}
  97. {DevName - device name, monitor handle returned in MonHandle.}
  98. {Possible return codes:
  99. 0 No_Error
  100. 110 Error_Open_Failed
  101. 379 Error_Mon_Invalid_Parms
  102. 380 Error_Mon_Invalid_DevName}
  103. {Remarks:
  104. * Only one DosMonOpen call is necessary per device per process. That is,
  105. several DosMonReg calls can be made using the same monitor handle to the
  106. same device. This allows monitors to be registered using different values
  107. for Index from the same process and going to the same device. When the
  108. DosMonClose is issued, all of the monitors registered on the handle are
  109. closed.
  110. * For a detailed description of this call see the chapter "Character Device
  111. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  112. Device Support Volume 1.}
  113. function DosMonOpen(DevName:PChar;var MonHandle:word):word; cdecl;
  114. function DosMonOpen(DevName:string;var MonHandle:word):word;
  115. {Wait for a data record, move it from the input buffer of a registered
  116. character device monitor and place it in a private data area where the monitor
  117. can freely access it.}
  118. {InBuf - monitor input buffer, WaitFlag - see IO_WAIT and IO_NOWAIT constants,
  119. DataBuf - data area in the calling process address space that the data from the
  120. monitor's input buffer is read into, ByteCount - on input size of the DataBuf,
  121. on return number of bytes of data moved.}
  122. {Possible return codes:
  123. 0 No_Error
  124. 379 Error_Mon_Invalid_Parms
  125. 382 Error_Mon_Buffer_Too_Small
  126. 383 Error_Mon_Buffer_Empty}
  127. {Remarks:
  128. * For a detailed description of this call see the chapter "Character Device
  129. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  130. Device Support Volume 1.}
  131. function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
  132. var ByteCount:word):word; cdecl;
  133. {Establish an input and output buffers to monitor an I/O stream for a character
  134. device.}
  135. {MonHandle - device handle returned from a previous DosMonOpen call, InBuf -
  136. monitor input buffer, the monitor dispatcher moves data records into this
  137. buffer from the device driver (if the monitor is the first one in the monitor
  138. chain) or from the previous monitor in the chain, monitor then takes data from
  139. this buffer for filtering by calling DosMonRead, OutBuf - monitor output
  140. buffer, monitor places filtered data into this buffer by calling DosMonWrite,
  141. the monitor dispatcher moves data records from this buffer to the device driver
  142. (if the monitor is the last one in the monitor chain) or to the next monitor in
  143. the chain, PosCode - used to specify placement of a monitor's buffers with the
  144. monitor chain (FIRST, LAST or DEFAULT) and whether one or two threads are
  145. created by the monitor dispatcher to handle data movement (see explanation
  146. bellow), Index - device specific value, for the keyboard it pertains to the
  147. session you wish to register a monitor on, for the printer it pertains to the
  148. data or code page monitor chain.}
  149. {Possible return codes:
  150. 0 No_Error
  151. 8 Error_Not_Enough_Memory
  152. 165 Error_Monitors_Not_Supported
  153. 379 Error_Mon_Invalid_Parms
  154. 381 Error_Mon_Invalid_Handle
  155. 382 Error_Mon_Buffer_Too_Small}
  156. {Remarks:
  157. * PosCode meaning:
  158. 0 DEFAULT (no position preference) and one thread for data movement
  159. 1 FIRST (monitor placed at beginning of monitor chain) and one thread for
  160. data movement
  161. 2 LAST (monitor placed at the end of monitor chain) and one thread for
  162. data movement
  163. 3 DEFAULT with two threads for data movement
  164. 4 FIRST with two threads for data movement
  165. 5 LAST with two threads for data movement
  166. The first monitor in a monitor chain that registers as FIRST is placed at the
  167. head of the monitor chain. The next monitor that registers as FIRST follows
  168. the last monitor registered as FIRST, and so on. Similarly, the first monitor
  169. that registers as LAST is placed at the end of the monitor chain. The next
  170. monitor that registers as LAST is placed before the last monitor that
  171. registered as LAST, and so on. The first monitor that registers as DEFAULT is
  172. placed before the last monitor, if any, that registered as LAST. The next
  173. monitor that registers as DEFAULT is placed before the last monitor that
  174. registered as DEFAULT, and so on.
  175. * For a detailed description of this call see the chapter "Character Device
  176. Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
  177. Device Support Volume 1.}
  178. function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
  179. cdecl;
  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; cdecl;
  196. {***************************************************************************}
  197. implementation
  198. {***************************************************************************}
  199. function DosMonClose(MonHandle:word):word; cdecl;
  200. external 'EMXWRAP' index 403;
  201. {external 'MONCALLS' index 3;}
  202. function DosMonOpen(DevName:PChar;var MonHandle:word):word; cdecl;
  203. external 'EMXWRAP' index 404;
  204. {external 'MONCALLS' index 4;}
  205. function DosMonOpen(DevName:string;var MonHandle:word):word;
  206. begin
  207. if DevName[0]=#255 then
  208. begin
  209. Move(DevName[1],DevName[0],255);
  210. DevName[255]:=#0;
  211. DosMonOpen:=DosMonOpen(@DevName,MonHandle);
  212. end else
  213. begin
  214. DevName[Succ(byte(DevName[0]))]:=#0;
  215. DosMonOpen:=DosMonOpen(@DevName[1],MonHandle);
  216. end;
  217. end;
  218. function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
  219. var ByteCount:word):word; cdecl;
  220. external 'EMXWRAP' index 402;
  221. {external 'MONCALLS' index 2;}
  222. function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
  223. cdecl;
  224. external 'EMXWRAP' index 405;
  225. {external 'MONCALLS' index 5;}
  226. function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word; cdecl;
  227. external 'EMXWRAP' index 401;
  228. {external 'MONCALLS' index 1;}
  229. end.