mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-10-31 14:31:38 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			273 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			273 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
| {Set tabsize to 4.}
 | ||
| {****************************************************************************
 | ||
| 
 | ||
|                            MONCALLS interface unit
 | ||
|                      FPK-Pascal Runtime Library for OS/2
 | ||
|                    Copyright (c) 1993,94 by Florian Kl„mpfl
 | ||
|                     Copyright (c) 1997 by Dani‰l Mantione
 | ||
|                       Copyright (c) 1998 by Tomas Hajny
 | ||
| 
 | ||
|  The FPK-Pascal runtime library is distributed under the Library GNU Public
 | ||
|  License v2. So is this unit. The Library GNU Public License requires you to
 | ||
|  distribute the source code of this unit with any product that uses it.
 | ||
|  Because the EMX library isn't under the LGPL, we grant you an exception to
 | ||
|  this, and that is, when you compile a program with the FPK Pascal compiler,
 | ||
|  you do not need to ship source code with that program, AS LONG AS YOU ARE
 | ||
|  USING UNMODIFIED CODE! If you modify this code, you MUST change the next
 | ||
|  line:
 | ||
| 
 | ||
|  <This is an official, unmodified FPK Pascal source code file.>
 | ||
| 
 | ||
|  Send us your modified files, we can work together if you want!
 | ||
| 
 | ||
|  FPK-Pascal is distributed in the hope that it will be useful,
 | ||
|  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | ||
|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | ||
|  Library GNU General Public License for more details.
 | ||
| 
 | ||
|  You should have received a copy of the Library GNU General Public License
 | ||
|  along with FPK-Pascal; see the file COPYING.LIB.  If not, write to
 | ||
|  the Free Software Foundation, 59 Temple Place - Suite 330,
 | ||
|  Boston, MA 02111-1307, USA.
 | ||
| 
 | ||
| ****************************************************************************}
 | ||
| 
 | ||
| unit MonCalls;
 | ||
| 
 | ||
| { Interface library to MONCALLS.DLL (through EMXWRAP.DLL)
 | ||
| 
 | ||
| Please, note, that monitors are supported for OS/2 v2.1 and above only
 | ||
| (not for v2.0) and that they cannot be used in PM applications.
 | ||
| 
 | ||
| Changelog:
 | ||
| 
 | ||
|     People:
 | ||
| 
 | ||
|         TH - Tomas Hajny
 | ||
| 
 | ||
|     Date:           Description of change:              Changed by:
 | ||
| 
 | ||
|      -              First released version 1.0          TH
 | ||
| 
 | ||
| Coding style:
 | ||
| 
 | ||
|     I have tried to use the same coding style as Dani‰l Mantione in unit
 | ||
|     DOSCALLS, although I can't say I would write it the same way otherwise
 | ||
|     (I would write much more spaces myself, at least). Try to use it as well,
 | ||
|     please. Original note by Dani‰l Mantione follows:
 | ||
| 
 | ||
| 
 | ||
|     It may be well possible that coding style feels a bit strange to you.
 | ||
|     Nevertheless I friendly ask you to try to make your changes not look all
 | ||
|     to different. To make life easier, set your IDE to use tab characters,
 | ||
|     turn optimal fill, autoindent and backspace unindents on and set a
 | ||
|     tabsize of 4.}
 | ||
| 
 | ||
| {***************************************************************************}
 | ||
| interface
 | ||
| {***************************************************************************}
 | ||
| 
 | ||
| uses    strings;
 | ||
| 
 | ||
| {$ifdef FPK}
 | ||
|     {$packrecords 1}
 | ||
| {$endif FPK}
 | ||
| 
 | ||
| const
 | ||
| {return codes / error constants (those marked with * shouldn't occur)}
 | ||
|     NO_ERROR                        =     0;
 | ||
|     ERROR_NOT_ENOUGH_MEMORY         =     8;
 | ||
|     ERROR_OPEN_FAILED               =   110;
 | ||
|     ERROR_MONITORS_NOT_SUPPORTED    =   165;
 | ||
|     ERROR_MON_INVALID_PARMS         =   379;
 | ||
|     ERROR_MON_INVALID_DEVNAME       =   380;
 | ||
|     ERROR_MON_INVALID_HANDLE        =   381;
 | ||
|     ERROR_MON_BUFFER_TOO_SMALL      =   382;
 | ||
|     ERROR_MON_BUFFER_EMPTY          =   383;
 | ||
|     ERROR_MON_DATA_TOO_LARGE        =   384;
 | ||
|     ERROR_MON_BAD_BUFFER            =   730; {*}
 | ||
|     ERROR_MON_CHAIN_HANDLE          = 32784; {*}
 | ||
|     ERROR_MON_NOT_REGISTERED        = 32785; {*}
 | ||
| 
 | ||
| {WaitFlag}
 | ||
|     IO_WAIT     =0; {The monitor thread that issues DosMonRead wishes to block}
 | ||
|                     {until a data record is available in its input buffer.}
 | ||
|     IO_NOWAIT   =1; {The monitor thread that issues DosMonRead does not wish}
 | ||
|                     {to block when its input buffer is empty.}
 | ||
| 
 | ||
| 
 | ||
| {Terminate character device monitoring.  All monitor buffers associated with
 | ||
| this process are flushed and closed.}
 | ||
| {MonHandle - device handle returned from a previous DosMonOpen call.}
 | ||
| {Possible return codes:
 | ||
|     0         NO_ERROR
 | ||
|     381       ERROR_MON_INVALID_HANDLE}
 | ||
| {Remarks:
 | ||
| * A single process may register one or more monitors with a character device
 | ||
|   using the same device handle returned from a previous DosMonOpen call.
 | ||
|   When DosMonClose is issued for a specific, opened device handle, all
 | ||
|   monitors for the current process registered with this handle terminate.
 | ||
| * When DosMonClose is issued, the monitor loses access to the device data
 | ||
|   stream. Before issuing DosMonClose, monitor threads calling DosMonRead and
 | ||
|   DosMonWrite should be terminated. After DosMonClose has been called,
 | ||
|   DosMonRead calls return an ERROR_MON_BUFFER_EMPTY return code and
 | ||
|   DosMonWrite calls return an ERROR_NOT_ENOUGH_MEMORY return code.
 | ||
| * Data area containing monitor buffers should not be freed until after
 | ||
|   DosMonClose is called. If data area containing monitor buffers is freed
 | ||
|   before DosMonClose is called, a GP fault occurs when DosMonClose is called
 | ||
|   and the process is terminated.
 | ||
| * For a detailed description of this call see the chapter "Character Device
 | ||
|   Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
 | ||
|   Device Support Volume 1.}
 | ||
| function DosMonClose(MonHandle:word):word;
 | ||
| 
 | ||
| {Gain access to a character device data stream.}
 | ||
| {DevName - device name, monitor handle returned in MonHandle.}
 | ||
| {Possible return codes:
 | ||
|     0         NO_ERROR
 | ||
|     110       ERROR_OPEN_FAILED
 | ||
|     379       ERROR_MON_INVALID_PARMS
 | ||
|     380       ERROR_MON_INVALID_DEVNAME}
 | ||
| {Remarks:
 | ||
| * Only one DosMonOpen call is necessary per device per process. That is,
 | ||
|   several DosMonReg calls can be made using the same monitor handle to the
 | ||
|   same device. This allows monitors to be registered using different values
 | ||
|   for Index from the same process and going to the same device. When the
 | ||
|   DosMonClose is issued, all of the monitors registered on the handle are
 | ||
|   closed.
 | ||
| * For a detailed description of this call see the chapter "Character Device
 | ||
|   Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
 | ||
|   Device Support Volume 1.}
 | ||
| function DosMonOpen(DevName:PChar;var MonHandle:word):word;
 | ||
| function DosMonOpen(DevName:string;var MonHandle:word):word;
 | ||
| 
 | ||
| {Wait for a data record, move it from the input buffer of a registered
 | ||
| character device monitor and place it in a private data area where the monitor
 | ||
| can freely access it.}
 | ||
| {InBuf - monitor input buffer, WaitFlag - see IO_WAIT and IO_NOWAIT constants,
 | ||
| DataBuf - data area in the calling process address space that the data from the
 | ||
| monitor's input buffer is read into, ByteCount - on input size of the DataBuf,
 | ||
| on return number of bytes of data moved.}
 | ||
| {Possible return codes:
 | ||
|     0         NO_ERROR
 | ||
|     379       ERROR_MON_INVALID_PARMS
 | ||
|     382       ERROR_MON_BUFFER_TOO_SMALL
 | ||
|     383       ERROR_MON_BUFFER_EMPTY}
 | ||
| {Remarks:
 | ||
| * For a detailed description of this call see the chapter "Character Device
 | ||
|   Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
 | ||
|   Device Support Volume 1.}
 | ||
| function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
 | ||
|                                                       var ByteCount:word):word;
 | ||
| 
 | ||
| {Establish an input and output buffers to monitor an I/O stream for a character
 | ||
| device.}
 | ||
| {MonHandle - device handle returned from a previous DosMonOpen call, InBuf -
 | ||
| monitor input buffer, the monitor dispatcher moves data records into this
 | ||
| buffer from the device driver (if the monitor is the first one in the monitor
 | ||
| chain) or from the previous monitor in the chain, monitor then takes data from
 | ||
| this buffer for filtering by calling DosMonRead, OutBuf - monitor output
 | ||
| buffer, monitor places filtered data into this buffer by calling DosMonWrite,
 | ||
| the monitor dispatcher moves data records from this buffer to the device driver
 | ||
| (if the monitor is the last one in the monitor chain) or to the next monitor in
 | ||
| the chain, PosCode - used to specify placement of a monitor's buffers with the
 | ||
| monitor chain (FIRST, LAST or DEFAULT) and whether one or two threads are
 | ||
| created by the monitor dispatcher to handle data movement (see explanation
 | ||
| bellow), Index - device specific value, for the keyboard it pertains to the
 | ||
| session you wish to register a monitor on, for the printer it pertains to the
 | ||
| data or code page monitor chain.}
 | ||
| {Possible return codes:
 | ||
|     0         NO_ERROR
 | ||
|     8         ERROR_NOT_ENOUGH_MEMORY
 | ||
|     165       ERROR_MONITORS_NOT_SUPPORTED
 | ||
|     379       ERROR_MON_INVALID_PARMS
 | ||
|     381       ERROR_MON_INVALID_HANDLE
 | ||
|     382       ERROR_MON_BUFFER_TOO_SMALL}
 | ||
| {Remarks:
 | ||
| * PosCode meaning:
 | ||
|     0   DEFAULT (no position preference) and one thread for data movement
 | ||
|     1   FIRST (monitor placed at beginning of monitor chain) and one thread for
 | ||
|         data movement
 | ||
|     2   LAST (monitor placed at the end of monitor chain) and one thread for
 | ||
|         data movement
 | ||
|     3   DEFAULT with two threads for data movement
 | ||
|     4   FIRST with two threads for data movement
 | ||
|     5   LAST with two threads for data movement
 | ||
|   The first monitor in a monitor chain that registers as FIRST is placed at the
 | ||
|   head of the monitor chain. The next monitor that registers as FIRST follows
 | ||
|   the last monitor registered as FIRST, and so on. Similarly, the first monitor
 | ||
|   that registers as LAST is placed at the end of the monitor chain. The next
 | ||
|   monitor that registers as LAST is placed before the last monitor that
 | ||
|   registered as LAST, and so on. The first monitor that registers as DEFAULT is
 | ||
|   placed before the last monitor, if any, that registered as LAST. The next
 | ||
|   monitor that registers as DEFAULT is placed before the last monitor that
 | ||
|   registered as DEFAULT, and so on.
 | ||
| * For a detailed description of this call see the chapter "Character Device
 | ||
|   Monitors" in the IBM Operating System/2 Version 1.2 I/O Subsystems And
 | ||
|   Device Support Volume 1.}
 | ||
| function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
 | ||
| 
 | ||
| {Move a filtered data record from the monitor's private data area into the
 | ||
| monitor's output buffer.}
 | ||
| {OutBuf - monitor output buffer, DataBuf - monitor's private data area
 | ||
| containing a filtered data record of length ByteCount, this filtered data
 | ||
| record is moved into the monitor's output buffer by this call, ByteCount - size
 | ||
| of the data record.}
 | ||
| {Possible return codes:
 | ||
|     0         NO_ERROR
 | ||
|     8         ERROR_NOT_ENOUGH_MEMORY
 | ||
|     379       ERROR_MON_INVALID_PARMS
 | ||
|     384       ERROR_MON_DATA_TOO_LARGE}
 | ||
| {Remarks:
 | ||
| * For a detailed description of the use of this call see the chapter
 | ||
|   "Character Device Monitors" in the IBM Operating System/2 Version 1.2 I/O
 | ||
|   Subsystems And Device Support Volume 1.}
 | ||
| function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word;
 | ||
| 
 | ||
| 
 | ||
| {***************************************************************************}
 | ||
| implementation
 | ||
| {***************************************************************************}
 | ||
| 
 | ||
| 
 | ||
| function DosMonClose(MonHandle:word):word;
 | ||
| external 'EMXWRAP' index 403;
 | ||
| {external 'MONCALLS' index 3;}
 | ||
| 
 | ||
| function DosMonOpen(DevName:PChar;var MonHandle:word):word;
 | ||
| external 'EMXWRAP' index 404;
 | ||
| {external 'MONCALLS' index 4;}
 | ||
| 
 | ||
| function DosMonOpen(DevName:string;var MonHandle:word):word;
 | ||
| var
 | ||
|   i : byte;
 | ||
| begin
 | ||
|     if DevName[0]=#255 then
 | ||
|     begin
 | ||
|         I:=byte(DevName[0]);
 | ||
|         Move(DevName[1],DevName[0],255);
 | ||
|         DevName[255]:=#0;
 | ||
|         DosMonOpen:=DosMonOpen(@DevName,MonHandle);
 | ||
|     end else
 | ||
|     begin
 | ||
|         DevName[Succ(byte(DevName[0]))]:=#0;
 | ||
|         DosMonOpen:=DosMonOpen(@DevName[1],MonHandle);
 | ||
|     end;
 | ||
| end;
 | ||
| 
 | ||
| function DosMonRead(var InBuf;WaitFlag:word;var DataBuf;
 | ||
|                                                       var ByteCount:word):word;
 | ||
| external 'EMXWRAP' index 402;
 | ||
| {external 'MONCALLS' index 2;}
 | ||
| 
 | ||
| function DosMonReg(MonHandle:word;var InBuf,OutBuf;PosCode,Index:word):word;
 | ||
| external 'EMXWRAP' index 405;
 | ||
| {external 'MONCALLS' index 5;}
 | ||
| 
 | ||
| function DosMonWrite(var OutBuf,DataBuf;ByteCount:word):word;
 | ||
| external 'EMXWRAP' index 401;
 | ||
| {external 'MONCALLS' index 1;}
 | ||
| 
 | ||
| 
 | ||
| end.
 | ||
|  | 
