moncalls.pas 12 KB

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