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