Sync with trunk r62529.
[reactos.git] / dll / directx / wine / dplayx / lobbysp.c
1 /* This contains the implementation of the Lobby Service
2 * Providers interface required to communicate with Direct Play
3 *
4 * Copyright 2001 Peter Hunnisett
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "dplayx_global.h"
22
23 /* Prototypes */
24 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP );
25 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP );
26 static BOOL DPLSP_CreateDPLobbySP( void *lpSP, IDirectPlayImpl *dp );
27 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP );
28
29
30 /* Predefine the interface */
31 typedef struct IDPLobbySPImpl IDPLobbySPImpl;
32
33 typedef struct tagDPLobbySPIUnknownData
34 {
35 LONG ulObjRef;
36 CRITICAL_SECTION DPLSP_lock;
37 } DPLobbySPIUnknownData;
38
39 typedef struct tagDPLobbySPData
40 {
41 IDirectPlayImpl *dplay;
42 } DPLobbySPData;
43
44 #define DPLSP_IMPL_FIELDS \
45 LONG ulInterfaceRef; \
46 DPLobbySPIUnknownData* unk; \
47 DPLobbySPData* sp;
48
49 struct IDPLobbySPImpl
50 {
51 const IDPLobbySPVtbl *lpVtbl;
52 DPLSP_IMPL_FIELDS
53 };
54
55 /* Forward declaration of virtual tables */
56 static const IDPLobbySPVtbl dpLobbySPVT;
57
58 HRESULT DPLSP_CreateInterface( REFIID riid, void **ppvObj, IDirectPlayImpl *dp )
59 {
60 TRACE( " for %s\n", debugstr_guid( riid ) );
61
62 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
63 sizeof( IDPLobbySPImpl ) );
64
65 if( *ppvObj == NULL )
66 {
67 return DPERR_OUTOFMEMORY;
68 }
69
70 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
71 {
72 IDPLobbySPImpl *This = *ppvObj;
73 This->lpVtbl = &dpLobbySPVT;
74 }
75 else
76 {
77 /* Unsupported interface */
78 HeapFree( GetProcessHeap(), 0, *ppvObj );
79 *ppvObj = NULL;
80
81 return E_NOINTERFACE;
82 }
83
84 /* Initialize it */
85 if( DPLSP_CreateIUnknown( *ppvObj ) &&
86 DPLSP_CreateDPLobbySP( *ppvObj, dp )
87 )
88 {
89 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
90 return S_OK;
91 }
92
93 /* Initialize failed, destroy it */
94 DPLSP_DestroyDPLobbySP( *ppvObj );
95 DPLSP_DestroyIUnknown( *ppvObj );
96
97 HeapFree( GetProcessHeap(), 0, *ppvObj );
98 *ppvObj = NULL;
99
100 return DPERR_NOMEMORY;
101 }
102
103 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP )
104 {
105 IDPLobbySPImpl *This = lpSP;
106
107 This->unk = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->unk) ) );
108
109 if ( This->unk == NULL )
110 {
111 return FALSE;
112 }
113
114 InitializeCriticalSection( &This->unk->DPLSP_lock );
115 This->unk->DPLSP_lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDPLobbySPImpl*->DPLobbySPIUnknownData*->DPLSP_lock");
116
117 return TRUE;
118 }
119
120 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
121 {
122 IDPLobbySPImpl *This = lpSP;
123
124 This->unk->DPLSP_lock.DebugInfo->Spare[0] = 0;
125 DeleteCriticalSection( &This->unk->DPLSP_lock );
126 HeapFree( GetProcessHeap(), 0, This->unk );
127
128 return TRUE;
129 }
130
131 static BOOL DPLSP_CreateDPLobbySP( void *lpSP, IDirectPlayImpl *dp )
132 {
133 IDPLobbySPImpl *This = lpSP;
134
135 This->sp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->sp) ) );
136
137 if ( This->sp == NULL )
138 {
139 return FALSE;
140 }
141
142 This->sp->dplay = dp;
143
144 return TRUE;
145 }
146
147 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
148 {
149 IDPLobbySPImpl *This = lpSP;
150
151 HeapFree( GetProcessHeap(), 0, This->sp );
152
153 return TRUE;
154 }
155
156 static
157 HRESULT WINAPI DPLSP_QueryInterface
158 ( LPDPLOBBYSP iface,
159 REFIID riid,
160 LPVOID* ppvObj
161 )
162 {
163 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
164 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
165
166 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
167 sizeof( *This ) );
168
169 if( *ppvObj == NULL )
170 {
171 return DPERR_OUTOFMEMORY;
172 }
173
174 CopyMemory( *ppvObj, This, sizeof( *This ) );
175 (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0;
176
177 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
178 {
179 IDPLobbySPImpl *This = *ppvObj;
180 This->lpVtbl = &dpLobbySPVT;
181 }
182 else
183 {
184 /* Unsupported interface */
185 HeapFree( GetProcessHeap(), 0, *ppvObj );
186 *ppvObj = NULL;
187
188 return E_NOINTERFACE;
189 }
190
191 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
192
193 return S_OK;
194 }
195
196 static
197 ULONG WINAPI DPLSP_AddRef
198 ( LPDPLOBBYSP iface )
199 {
200 ULONG ulInterfaceRefCount, ulObjRefCount;
201 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
202
203 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
204 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
205
206 TRACE( "ref count incremented to %u:%u for %p\n",
207 ulInterfaceRefCount, ulObjRefCount, This );
208
209 return ulObjRefCount;
210 }
211
212 static
213 ULONG WINAPI DPLSP_Release
214 ( LPDPLOBBYSP iface )
215 {
216 ULONG ulInterfaceRefCount, ulObjRefCount;
217 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
218
219 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
220 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
221
222 TRACE( "ref count decremented to %u:%u for %p\n",
223 ulInterfaceRefCount, ulObjRefCount, This );
224
225 /* Deallocate if this is the last reference to the object */
226 if( ulObjRefCount == 0 )
227 {
228 DPLSP_DestroyDPLobbySP( This );
229 DPLSP_DestroyIUnknown( This );
230 }
231
232 if( ulInterfaceRefCount == 0 )
233 {
234 HeapFree( GetProcessHeap(), 0, This );
235 }
236
237 return ulInterfaceRefCount;
238 }
239
240 static
241 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
242 ( LPDPLOBBYSP iface,
243 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
244 )
245 {
246 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
247 FIXME( "(%p)->(%p):stub\n", This, argtg );
248 return DP_OK;
249 }
250
251 static
252 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
253 ( LPDPLOBBYSP iface,
254 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
255 )
256 {
257 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
258 FIXME( "(%p)->(%p):stub\n", This, arptg );
259 return DP_OK;
260 }
261
262 static
263 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
264 ( LPDPLOBBYSP iface,
265 LPSPDATA_CREATEREMOTEGROUP crg
266 )
267 {
268 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
269 FIXME( "(%p)->(%p):stub\n", This, crg );
270 return DP_OK;
271 }
272
273 static
274 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
275 ( LPDPLOBBYSP iface,
276 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
277 )
278 {
279 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
280 FIXME( "(%p)->(%p):stub\n", This, crgig );
281 return DP_OK;
282 }
283
284 static
285 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
286 ( LPDPLOBBYSP iface,
287 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
288 )
289 {
290 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
291 FIXME( "(%p)->(%p):stub\n", This, drgfg );
292 return DP_OK;
293 }
294
295 static
296 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
297 ( LPDPLOBBYSP iface,
298 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
299 )
300 {
301 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
302 FIXME( "(%p)->(%p):stub\n", This, drpfg );
303 return DP_OK;
304 }
305
306 static
307 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
308 ( LPDPLOBBYSP iface,
309 LPSPDATA_DESTROYREMOTEGROUP drg
310 )
311 {
312 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
313 FIXME( "(%p)->(%p):stub\n", This, drg );
314 return DP_OK;
315 }
316
317 static
318 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
319 ( LPDPLOBBYSP iface,
320 LPSPDATA_ENUMSESSIONSRESPONSE er
321 )
322 {
323 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
324 FIXME( "(%p)->(%p):stub\n", This, er );
325 return DP_OK;
326 }
327
328 static
329 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
330 ( LPDPLOBBYSP iface,
331 LPVOID* lplpData
332 )
333 {
334 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
335 FIXME( "(%p)->(%p):stub\n", This, lplpData );
336 return DP_OK;
337 }
338
339 static
340 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
341 ( LPDPLOBBYSP iface,
342 LPSPDATA_HANDLEMESSAGE hm
343 )
344 {
345 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
346 FIXME( "(%p)->(%p):stub\n", This, hm );
347 return DP_OK;
348 }
349
350 static
351 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
352 ( LPDPLOBBYSP iface,
353 LPSPDATA_CHATMESSAGE cm
354 )
355 {
356 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
357 FIXME( "(%p)->(%p):stub\n", This, cm );
358 return DP_OK;
359 }
360
361 static
362 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
363 ( LPDPLOBBYSP iface,
364 LPSPDATA_SETREMOTEGROUPNAME srgn
365 )
366 {
367 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
368 FIXME( "(%p)->(%p):stub\n", This, srgn );
369 return DP_OK;
370 }
371
372 static
373 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
374 ( LPDPLOBBYSP iface,
375 LPSPDATA_SETREMOTEPLAYERNAME srpn
376 )
377 {
378 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
379 FIXME( "(%p)->(%p):stub\n", This, srpn );
380 return DP_OK;
381 }
382
383 static
384 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
385 ( LPDPLOBBYSP iface,
386 LPSPDATA_SETSESSIONDESC ssd
387 )
388 {
389 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
390 FIXME( "(%p)->(%p):stub\n", This, ssd );
391 return DP_OK;
392 }
393
394 static
395 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
396 ( LPDPLOBBYSP iface,
397 LPVOID lpData
398 )
399 {
400 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
401 FIXME( "(%p)->(%p):stub\n", This, lpData );
402 return DP_OK;
403 }
404
405 static
406 HRESULT WINAPI IDPLobbySPImpl_StartSession
407 ( LPDPLOBBYSP iface,
408 LPSPDATA_STARTSESSIONCOMMAND ssc
409 )
410 {
411 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
412 FIXME( "(%p)->(%p):stub\n", This, ssc );
413 return DP_OK;
414 }
415
416
417 static const IDPLobbySPVtbl dpLobbySPVT =
418 {
419
420 DPLSP_QueryInterface,
421 DPLSP_AddRef,
422 DPLSP_Release,
423
424 IDPLobbySPImpl_AddGroupToGroup,
425 IDPLobbySPImpl_AddPlayerToGroup,
426 IDPLobbySPImpl_CreateGroup,
427 IDPLobbySPImpl_CreateGroupInGroup,
428 IDPLobbySPImpl_DeleteGroupFromGroup,
429 IDPLobbySPImpl_DeletePlayerFromGroup,
430 IDPLobbySPImpl_DestroyGroup,
431 IDPLobbySPImpl_EnumSessionsResponse,
432 IDPLobbySPImpl_GetSPDataPointer,
433 IDPLobbySPImpl_HandleMessage,
434 IDPLobbySPImpl_SendChatMessage,
435 IDPLobbySPImpl_SetGroupName,
436 IDPLobbySPImpl_SetPlayerName,
437 IDPLobbySPImpl_SetSessionDesc,
438 IDPLobbySPImpl_SetSPDataPointer,
439 IDPLobbySPImpl_StartSession
440
441 };