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