1 | /* $Id: HandleManager.h,v 1.3 1999-06-10 19:11:30 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
5 | * Win32 Unified Handle Manager for OS/2
|
---|
6 | * 1998/02/11 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
7 | *
|
---|
8 | * @(#) HandleManager.Cpp 1.0.0 1998/02/11 PH start
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef _HANDLEMANAGER_H_
|
---|
12 | #define _HANDLEMANAGER_H_
|
---|
13 |
|
---|
14 |
|
---|
15 | /*****************************************************************************
|
---|
16 | * Remark *
|
---|
17 | *****************************************************************************
|
---|
18 |
|
---|
19 | 1998/02/11 PH The interface to the handle manager is twofold:
|
---|
20 | a) HMxxx routines to be called from the "top" from the
|
---|
21 | KERNEL32 stubs
|
---|
22 | b) the HMDeviceHandler class is actually a workaround for
|
---|
23 | the device driver that would handle the requests on Win32.
|
---|
24 | To implement a new pseudo-device, one has create a new
|
---|
25 | HMDeviceHandler class and link it into the table in the
|
---|
26 | HANDLEMANAGER.CPP file.
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | /*****************************************************************************
|
---|
31 | * Includes *
|
---|
32 | *****************************************************************************/
|
---|
33 |
|
---|
34 | #ifdef _OS2WIN_H
|
---|
35 | #include <winos2def.h>
|
---|
36 | #else
|
---|
37 | typedef struct {
|
---|
38 | DWORD Internal;
|
---|
39 | DWORD InternalHigh;
|
---|
40 | DWORD Offset;
|
---|
41 | DWORD OffsetHigh;
|
---|
42 | HANDLE hEvent;
|
---|
43 | } OVERLAPPED, *POVERLAPPED, *LPOVERLAPPED;
|
---|
44 | #endif
|
---|
45 |
|
---|
46 |
|
---|
47 | /*****************************************************************************
|
---|
48 | * Defines & Macros *
|
---|
49 | *****************************************************************************/
|
---|
50 |
|
---|
51 | /* all handles to our special pseudo-devices are ORed with this define */
|
---|
52 | /* this allows us to determine quickly how to where to route requests to. */
|
---|
53 | #define HM_HANDLE_ID 0xDEAD0000
|
---|
54 | #define HM_HANDLE_MASK 0x0000FFFF
|
---|
55 |
|
---|
56 |
|
---|
57 | #define IS_HM_HANDLE(hHandle) ( (hHandle & ~HM_HANDLE_MASK) == HM_HANDLE_ID )
|
---|
58 |
|
---|
59 |
|
---|
60 | /* 1998/02/12 PH Correction of os2win.h */
|
---|
61 | #undef FILE_TYPE_UNKNOWN
|
---|
62 | #define FILE_TYPE_UNKNOWN 0x0000
|
---|
63 |
|
---|
64 | #undef FILE_TYPE_DISK
|
---|
65 | #define FILE_TYPE_DISK 0x0001
|
---|
66 |
|
---|
67 | #undef FILE_TYPE_CHAR
|
---|
68 | #define FILE_TYPE_CHAR 0x0002
|
---|
69 |
|
---|
70 | #undef FILE_TYPE_PIPE
|
---|
71 | #define FILE_TYPE_PIPE 0x0003
|
---|
72 |
|
---|
73 | #undef FILE_TYPE_REMOTE
|
---|
74 | #define FILE_TYPE_REMOTE 0x8000
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | /*****************************************************************************
|
---|
79 | * Structures *
|
---|
80 | *****************************************************************************/
|
---|
81 |
|
---|
82 | typedef struct _HMHANDLEDATA
|
---|
83 | {
|
---|
84 | HANDLE hHandle; /* a copy of the handle */
|
---|
85 |
|
---|
86 | DWORD dwType; /* handle type identifier */
|
---|
87 |
|
---|
88 | DWORD dwAccess; /* access mode of the handle */
|
---|
89 | DWORD dwShare; /* share mode of the handle */
|
---|
90 | DWORD dwCreation; /* dwCreationDisposition */
|
---|
91 | DWORD dwFlags; /* flags and attributes */
|
---|
92 |
|
---|
93 | LPVOID lpHandlerData; /* for private use of the device handler */
|
---|
94 | } HMHANDLEDATA, *PHMHANDLEDATA;
|
---|
95 |
|
---|
96 |
|
---|
97 | #ifdef __cplusplus
|
---|
98 | class HMDeviceHandler
|
---|
99 | {
|
---|
100 | /***************************************************************************
|
---|
101 | * The following methods are called by the handle manager request router. *
|
---|
102 | * They are exact replacements for the corresponding Win32 calls. *
|
---|
103 | ***************************************************************************/
|
---|
104 |
|
---|
105 | public:
|
---|
106 | LPCSTR lpHMDeviceName; /* a reference to the device name */
|
---|
107 |
|
---|
108 | HMDeviceHandler(LPCSTR lpDeviceName); /* constructor with device name */
|
---|
109 |
|
---|
110 |
|
---|
111 | /***********************************
|
---|
112 | * handle generic standard methods *
|
---|
113 | ***********************************/
|
---|
114 |
|
---|
115 | /* this is a special internal method to handle non-standard requests */
|
---|
116 | /* such as GetConsoleMode() for console devices */
|
---|
117 | virtual DWORD _DeviceRequest (PHMHANDLEDATA pHMHandleData,
|
---|
118 | ULONG ulRequestCode,
|
---|
119 | ULONG arg1,
|
---|
120 | ULONG arg2,
|
---|
121 | ULONG arg3,
|
---|
122 | ULONG arg4);
|
---|
123 |
|
---|
124 | /* this is a handler method for calls to CreateFile() */
|
---|
125 | virtual DWORD CreateFile (LPCSTR lpFileName,
|
---|
126 | PHMHANDLEDATA pHMHandleData,
|
---|
127 | PVOID lpSecurityAttributes,
|
---|
128 | PHMHANDLEDATA pHMHandleDataTemplate);
|
---|
129 |
|
---|
130 | /* this is a handler method for calls to CloseHandle() */
|
---|
131 | virtual DWORD CloseHandle(PHMHANDLEDATA pHMHandleData);
|
---|
132 |
|
---|
133 | /* this is a handler method for calls to ReadFile() */
|
---|
134 | virtual DWORD ReadFile (PHMHANDLEDATA pHMHandleData,
|
---|
135 | LPCVOID lpBuffer,
|
---|
136 | DWORD nNumberOfBytesToRead,
|
---|
137 | LPDWORD lpNumberOfBytesRead,
|
---|
138 | LPOVERLAPPED lpOverlapped);
|
---|
139 |
|
---|
140 | /* this is a handler method for calls to WriteFile() */
|
---|
141 | virtual DWORD WriteFile (PHMHANDLEDATA pHMHandleData,
|
---|
142 | LPCVOID lpBuffer,
|
---|
143 | DWORD nNumberOfBytesToWrite,
|
---|
144 | LPDWORD lpNumberOfBytesWritten,
|
---|
145 | LPOVERLAPPED lpOverlapped);
|
---|
146 |
|
---|
147 | /* this is a handler method for calls to GetFileType() */
|
---|
148 | virtual DWORD GetFileType (PHMHANDLEDATA pHMHandleData);
|
---|
149 | };
|
---|
150 |
|
---|
151 | #endif
|
---|
152 |
|
---|
153 |
|
---|
154 | /*****************************************************************************
|
---|
155 | * Prototypes *
|
---|
156 | *****************************************************************************/
|
---|
157 |
|
---|
158 | DWORD HMInitialize(void); /* initialize the HandleManager */
|
---|
159 |
|
---|
160 | DWORD HMTerminate(void); /* terminate the HandleManager */
|
---|
161 |
|
---|
162 |
|
---|
163 | #ifdef __cplusplus
|
---|
164 | /* register a new device with the handle manager */
|
---|
165 | DWORD HMDeviceRegister(PSZ pszDeviceName, HMDeviceHandler *pDeviceHandler);
|
---|
166 | #endif
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 | /* handle manager version of GetStdHandle, Open32 can't really help us here */
|
---|
171 | HANDLE HMGetStdHandle(DWORD nStdHandle);
|
---|
172 |
|
---|
173 | /* handle manager version of GetStdHandle, Open32 can't really help us here */
|
---|
174 | BOOL HMSetStdHandle(DWORD nStdHandle,
|
---|
175 | HANDLE hHandle);
|
---|
176 |
|
---|
177 | /* this is a handler method for calls to CreateFile() */
|
---|
178 | HANDLE HMCreateFile (LPCSTR lpFileName,
|
---|
179 | DWORD dwDesiredAccess,
|
---|
180 | DWORD dwShareMode,
|
---|
181 | PVOID lpSecurityAttributes,
|
---|
182 | DWORD dwCreationDisposition,
|
---|
183 | DWORD dwFlagsAndAttributes,
|
---|
184 | HANDLE hTemplateFile);
|
---|
185 |
|
---|
186 | /* this is a handler method for calls to CloseHandle() */
|
---|
187 | BOOL HMCloseHandle(HANDLE hObject);
|
---|
188 |
|
---|
189 | /* this is a handler method for calls to ReadFile() */
|
---|
190 | BOOL HMReadFile (HANDLE hFile,
|
---|
191 | LPCVOID lpBuffer,
|
---|
192 | DWORD nNumberOfBytesToRead,
|
---|
193 | LPDWORD lpNumberOfBytesRead,
|
---|
194 | LPOVERLAPPED lpOverlapped);
|
---|
195 |
|
---|
196 | /* this is a handler method for calls to WriteFile() */
|
---|
197 | BOOL HMWriteFile (HANDLE hFile,
|
---|
198 | LPCVOID lpBuffer,
|
---|
199 | DWORD nNumberOfBytesToWrite,
|
---|
200 | LPDWORD lpNumberOfBytesWritten,
|
---|
201 | LPOVERLAPPED lpOverlapped);
|
---|
202 |
|
---|
203 | /* this is a handler method for calls to GetFileType() */
|
---|
204 | DWORD HMGetFileType(HANDLE hFile);
|
---|
205 |
|
---|
206 | /* this is for special non-standard device I/O */
|
---|
207 | DWORD HMDeviceRequest (HANDLE hFile,
|
---|
208 | ULONG ulRequestCode,
|
---|
209 | ULONG arg1,
|
---|
210 | ULONG arg2,
|
---|
211 | ULONG arg3,
|
---|
212 | ULONG arg4);
|
---|
213 |
|
---|
214 |
|
---|
215 | /*****************************************************************************/
|
---|
216 | /* handle translation buffer management */
|
---|
217 | /* */
|
---|
218 | /* Since some Win32 applications rely (!) on 16-bit handles, we've got to do */
|
---|
219 | /* 32-bit to 16-bit and vs vsa translation here. */
|
---|
220 | /* Filehandle-based functions should be routed via the handlemanager instead */
|
---|
221 | /* of going to Open32 directly. */
|
---|
222 | /*****************************************************************************/
|
---|
223 |
|
---|
224 | DWORD HMHandleAllocate (PULONG phHandle16,
|
---|
225 | ULONG hHandle32);
|
---|
226 |
|
---|
227 | DWORD HMHandleFree (ULONG hHandle16);
|
---|
228 |
|
---|
229 | DWORD HMHandleValidate (ULONG hHandle16);
|
---|
230 |
|
---|
231 | DWORD HMHandleTranslateToWin (ULONG hHandle32,
|
---|
232 | PULONG phHandle16);
|
---|
233 |
|
---|
234 | DWORD HMHandleTranslateToOS2 (ULONG hHandle16,
|
---|
235 | PULONG hHandle32);
|
---|
236 |
|
---|
237 | DWORD HMHandleTranslateToOS2i(ULONG hHandle16);
|
---|
238 |
|
---|
239 |
|
---|
240 | /*****************************************************************************
|
---|
241 | * Forwarders *
|
---|
242 | *****************************************************************************/
|
---|
243 |
|
---|
244 |
|
---|
245 | #endif /* _HANDLEMANAGER_H_ */
|
---|