source: trunk/src/wsock32/new/relaywin.cpp@ 1930

Last change on this file since 1930 was 1930, checked in by phaller, 26 years ago

Fix: calling convention for PostMessageA

File size: 6.8 KB
Line 
1/* $Id: relaywin.cpp,v 1.2 1999-12-01 20:29:39 phaller Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 * Win32 SOCK32 for OS/2
8 *
9 * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
10 *
11 */
12
13/* Remark:
14 * - this is an object window that acts as "relay", this is
15 * it receives WSAAsyncSelect()'s messages and redirects
16 * them to the appropriate PostMessageA function of USER32.
17 */
18
19
20/*****************************************************************************
21 * Includes *
22 *****************************************************************************/
23
24/* object.c: the object window procedure on thread 2 */
25// os2 includes
26#define INCL_DOSPROCESS
27#define INCL_WIN
28#include <os2.h>
29// crt includes
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#include <odin.h>
35#include <odinwrap.h>
36#include <misc.h>
37
38#include "relaywin.h"
39
40ODINDEBUGCHANNEL(WSOCK32-RELAYWIN)
41
42
43/*****************************************************************************
44 * Structures *
45 *****************************************************************************/
46
47#define MAX_ASYNC_SOCKETS 64
48
49// static table for id / hwnd-msg translation
50static HWNDMSGPAIR arrHwndMsgPair[MAX_ASYNC_SOCKETS];
51static char* ODIN_WSOCK_RELAY_CLASS = "ODIN_WSOCK_RELAY";
52
53
54// prototype for PostMessageA
55//BOOL _Stdcall PostMessageA(HWND,UINT,WPARAM,LPARAM);
56BOOL __stdcall PostMessageA(HWND,UINT,ULONG,ULONG);
57
58
59/*****************************************************************************
60 * Name :
61 * Purpose :
62 * Parameters:
63 * Variables :
64 * Result :
65 * Remark :
66 * Status :
67 *
68 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
69 *****************************************************************************/
70
71ULONG RelayAlloc(HWND hwnd, ULONG ulMsg)
72{
73 ULONG ulCounter;
74
75 for (ulCounter = 0;
76 ulCounter < MAX_ASYNC_SOCKETS;
77 ulCounter++)
78 if ( (arrHwndMsgPair[ulCounter].hwnd == 0) || // slot free?
79 (arrHwndMsgPair[ulCounter].hwnd == hwnd) ) // same window?
80 {
81 // occupy slot
82 arrHwndMsgPair[ulCounter].hwnd = hwnd;
83 arrHwndMsgPair[ulCounter].ulMsg = ulMsg;
84 return ulCounter; // return "id"
85 }
86
87 return -1; // not found
88}
89
90
91/*****************************************************************************
92 * Name :
93 * Purpose :
94 * Parameters:
95 * Variables :
96 * Result :
97 * Remark :
98 * Status :
99 *
100 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
101 *****************************************************************************/
102
103ULONG RelayFree(ULONG ulID)
104{
105 if ( (ulID < 0) || // check range
106 (ulID >= MAX_ASYNC_SOCKETS) )
107 return -1; // error
108
109 arrHwndMsgPair[ulID].hwnd = 0; // mark free
110
111 return 0; // OK
112}
113
114
115/*****************************************************************************
116 * Name :
117 * Purpose :
118 * Parameters:
119 * Variables :
120 * Result :
121 * Remark :
122 * Status :
123 *
124 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
125 *****************************************************************************/
126
127ULONG RelayFreeByHwnd(HWND hwnd)
128{
129 ULONG ulCounter;
130
131 for (ulCounter = 0;
132 ulCounter < MAX_ASYNC_SOCKETS;
133 ulCounter++)
134 if ( arrHwndMsgPair[ulCounter].hwnd == hwnd ) // same window?
135 {
136 arrHwndMsgPair[ulCounter].hwnd = 0; // free slot
137 return 0; // OK
138 }
139
140 return -1; // not found
141}
142
143
144/*****************************************************************************
145 * Name :
146 * Purpose :
147 * Parameters:
148 * Variables :
149 * Result :
150 * Remark :
151 * Status :
152 *
153 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
154 *****************************************************************************/
155
156PHWNDMSGPAIR RelayQuery(ULONG ulID)
157{
158 if ( (ulID < 0) || // check range
159 (ulID >= MAX_ASYNC_SOCKETS) )
160 return NULL; // error
161
162 return (&arrHwndMsgPair[ulID]);
163}
164
165
166/*****************************************************************************
167 * Name :
168 * Purpose :
169 * Parameters:
170 * Variables :
171 * Result :
172 * Remark :
173 * Status :
174 *
175 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
176 *****************************************************************************/
177
178MRESULT RelayWindowProc(HWND hwnd,
179 ULONG ulMsg,
180 MPARAM mp1,
181 MPARAM mp2)
182{
183 PHWNDMSGPAIR pHM;
184
185 // termination flag handling?
186 // if (fTerminate)
187 // WinDefWindowProc()
188
189 //@@@PH: 1999/11/31 PROBLEM
190 // hwnd and ulMsg passed in have been converted by our USER32 code
191 // here, we ultimatively need to translate it back.
192 // under the debugger, things WORK now !:)
193
194 pHM = RelayQuery(ulMsg); // find registered message
195 if (pHM != NULL) // message pair found
196 {
197 PostMessageA(pHM->hwnd,
198 pHM->ulMsg,
199 (ULONG)mp1,
200 (ULONG)mp2);
201
202 // if socket close, free entry
203 //@@@PH
204
205 return FALSE; // OK, message sent
206 }
207
208 // default message processing
209 return WinDefWindowProc( hwnd, ulMsg, mp1, mp2 );
210}
211
212
213/*****************************************************************************
214 * Name :
215 * Purpose :
216 * Parameters:
217 * Variables :
218 * Result :
219 * Remark :
220 * Status :
221 *
222 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
223 *****************************************************************************/
224
225HWND RelayInitialize(HWND hwndPost)
226{
227 BOOL fSuccess;
228 HAB hab;
229 HWND hwnd;
230
231
232 // thread initialization
233 hab = WinQueryAnchorBlock(hwndPost);
234 if (hab == NULLHANDLE)
235 return NULLHANDLE;
236
237 // register relay window class
238 fSuccess = WinRegisterClass(hab,
239 ODIN_WSOCK_RELAY_CLASS,
240 (PFNWP)RelayWindowProc,
241 0,
242 0);
243 if (fSuccess == FALSE)
244 return NULLHANDLE;
245
246 hwnd = WinCreateWindow(HWND_OBJECT,
247 ODIN_WSOCK_RELAY_CLASS,
248 "ODIN WSock Relay",
249 0, 0, 0, 0, 0,
250 HWND_OBJECT,
251 HWND_BOTTOM,
252 0,
253 NULL,
254 NULL );
255
256 //WinDestroyWindow( pg->hwndObject );
257 return hwnd;
258}
259
260
261/*****************************************************************************
262 * Name :
263 * Purpose :
264 * Parameters:
265 * Variables :
266 * Result :
267 * Remark :
268 * Status :
269 *
270 * Author : Patrick Haller [Tue, 1999/11/30 23:00]
271 *****************************************************************************/
272
273BOOL RelayTerminate(HWND hwndRelay)
274{
275 return WinDestroyWindow(hwndRelay);
276}
277
Note: See TracBrowser for help on using the repository browser.