moncalls.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. {$IFDEF FPC}
  51. {$PACKRECORDS 1}
  52. {$ENDIF FPC}
  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; cdecl;
  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; cdecl;
  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; cdecl;
  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. cdecl;
  181. {Move a filtered data record from the monitor's private data area into the
  182. monitor's output buffer.}
  183. {OutBuf - monitor output buffer, DataBuf - monitor's private data area
  184. containing a filtered data record of length ByteCount, this filtered data
  185. record is moved into the monitor's output buffer by this call, ByteCount - size
  186. of the data record.}
  187. {Possible return codes:
  188. 0 No_Error
  189. 8 Error_Not_Enough_Memory
  190. 379 Error_Mon_Invalid_Parms
  191. 384 Error_Mon_Data_Too_Large}
  192. {Remarks:
  193. * For a detailed description of the use of this call see the chapter
  194. "Character Device Monitors" in the IBM Operating System/2 Version 1.2 I/O
  195. Subsystems And Device Support Volume 1.}
  196. function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word; cdecl;
  197. {***************************************************************************}
  198. implementation
  199. {***************************************************************************}
  200. function DosMonClose(MonHandle:word):word; cdecl;
  201. external 'EMXWRAP' index 403;
  202. {external 'MONCALLS' index 3;}
  203. function DosMonOpen(DevName:PChar;var MonHandle:word):word; cdecl;
  204. external 'EMXWRAP' index 404;
  205. {external 'MONCALLS' index 4;}
  206. function DosMonOpen(DevName:string;var MonHandle:word):word;
  207. var
  208. i : byte;
  209. begin
  210. if DevName[0]=#255 then
  211. begin
  212. I:=byte(DevName[0]);
  213. Move(DevName[1],DevName[0],255);
  214. DevName[255]:=#0;
  215. DosMonOpen:=DosMonOpen(@DevName,MonHandle);
  216. end else
  217. begin
  218. DevName[Succ(byte(DevName[0]))]:=#0;
  219. DosMonOpen:=DosMonOpen(@DevName[1],MonHandle);
  220. end;
  221. end;
  222. function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
  223. var ByteCount:word):word; cdecl;
  224. external 'EMXWRAP' index 402;
  225. {external 'MONCALLS' index 2;}
  226. function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
  227. cdecl;
  228. external 'EMXWRAP' index 405;
  229. {external 'MONCALLS' index 5;}
  230. function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word; cdecl;
  231. external 'EMXWRAP' index 401;
  232. {external 'MONCALLS' index 1;}
  233. end.
  234. {
  235. $Log$
  236. Revision 1.3 2003-11-05 09:14:00 yuri
  237. * exec fix
  238. * unused units removed
  239. Revision 1.2 2002/09/07 16:01:24 peter
  240. * old logs removed and tabs fixed
  241. }