wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / dplayx / lobbysp.c
blob830ad32855fc42933e703ab7d6d4138486ed96af
1 /* This contains the implementation of the Lobby Service
2 * Providers interface required to communicate with Direct Play
4 * Copyright 2001 Peter Hunnisett
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.
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.
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
21 #include "winerror.h"
22 #include "wine/debug.h"
24 #include "lobbysp.h"
25 #include "dplay_global.h"
26 #include "dpinit.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
30 /* Prototypes */
31 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP );
32 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP );
33 static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp );
34 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP );
37 /* Predefine the interface */
38 typedef struct IDPLobbySPImpl IDPLobbySPImpl;
40 typedef struct tagDPLobbySPIUnknownData
42 LONG ulObjRef;
43 CRITICAL_SECTION DPLSP_lock;
44 } DPLobbySPIUnknownData;
46 typedef struct tagDPLobbySPData
48 IDirectPlay2Impl* dplay;
49 } DPLobbySPData;
51 #define DPLSP_IMPL_FIELDS \
52 LONG ulInterfaceRef; \
53 DPLobbySPIUnknownData* unk; \
54 DPLobbySPData* sp;
56 struct IDPLobbySPImpl
58 const IDPLobbySPVtbl *lpVtbl;
59 DPLSP_IMPL_FIELDS
62 /* Forward declaration of virtual tables */
63 static const IDPLobbySPVtbl dpLobbySPVT;
65 HRESULT DPLSP_CreateInterface( REFIID riid, LPVOID* ppvObj, IDirectPlay2Impl* dp )
67 TRACE( " for %s\n", debugstr_guid( riid ) );
69 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
70 sizeof( IDPLobbySPImpl ) );
72 if( *ppvObj == NULL )
74 return DPERR_OUTOFMEMORY;
77 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
79 IDPLobbySPImpl *This = (IDPLobbySPImpl *)*ppvObj;
80 This->lpVtbl = &dpLobbySPVT;
82 else
84 /* Unsupported interface */
85 HeapFree( GetProcessHeap(), 0, *ppvObj );
86 *ppvObj = NULL;
88 return E_NOINTERFACE;
91 /* Initialize it */
92 if( DPLSP_CreateIUnknown( *ppvObj ) &&
93 DPLSP_CreateDPLobbySP( *ppvObj, dp )
96 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
97 return S_OK;
100 /* Initialize failed, destroy it */
101 DPLSP_DestroyDPLobbySP( *ppvObj );
102 DPLSP_DestroyIUnknown( *ppvObj );
104 HeapFree( GetProcessHeap(), 0, *ppvObj );
105 *ppvObj = NULL;
107 return DPERR_NOMEMORY;
110 static BOOL DPLSP_CreateIUnknown( LPVOID lpSP )
112 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
114 This->unk = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->unk) ) );
116 if ( This->unk == NULL )
118 return FALSE;
121 InitializeCriticalSection( &This->unk->DPLSP_lock );
123 return TRUE;
126 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
128 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
130 DeleteCriticalSection( &This->unk->DPLSP_lock );
131 HeapFree( GetProcessHeap(), 0, This->unk );
133 return TRUE;
136 static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp )
138 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
140 This->sp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->sp) ) );
142 if ( This->sp == NULL )
144 return FALSE;
147 This->sp->dplay = dp;
149 /* Normally we should be keeping a reference, but since only the dplay
150 * interface that created us can destroy us, we do not keep a reference
151 * to it (ie we'd be stuck with always having one reference to the dplay
152 * object, and hence us, around).
153 * NOTE: The dp object does reference count us.
155 * FIXME: This is a kludge to get around a problem where a queryinterface
156 * is used to get a new interface and then is closed. We will then
157 * reference garbage. However, with this we will never deallocate
158 * the interface we store. The correct fix is to require all
159 * DP internal interfaces to use the This->dp2 interface which
160 * should be changed to This->dp
162 IDirectPlayX_AddRef( (LPDIRECTPLAY2)dp );
165 return TRUE;
168 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
170 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
172 HeapFree( GetProcessHeap(), 0, This->sp );
174 return TRUE;
177 static
178 HRESULT WINAPI DPLSP_QueryInterface
179 ( LPDPLOBBYSP iface,
180 REFIID riid,
181 LPVOID* ppvObj
184 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
185 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
187 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
188 sizeof( *This ) );
190 if( *ppvObj == NULL )
192 return DPERR_OUTOFMEMORY;
195 CopyMemory( *ppvObj, This, sizeof( *This ) );
196 (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0;
198 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
200 IDPLobbySPImpl *This = (IDPLobbySPImpl *)*ppvObj;
201 This->lpVtbl = &dpLobbySPVT;
203 else
205 /* Unsupported interface */
206 HeapFree( GetProcessHeap(), 0, *ppvObj );
207 *ppvObj = NULL;
209 return E_NOINTERFACE;
212 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
214 return S_OK;
217 static
218 ULONG WINAPI DPLSP_AddRef
219 ( LPDPLOBBYSP iface )
221 ULONG ulInterfaceRefCount, ulObjRefCount;
222 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
224 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
225 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
227 TRACE( "ref count incremented to %lu:%lu for %p\n",
228 ulInterfaceRefCount, ulObjRefCount, This );
230 return ulObjRefCount;
233 static
234 ULONG WINAPI DPLSP_Release
235 ( LPDPLOBBYSP iface )
237 ULONG ulInterfaceRefCount, ulObjRefCount;
238 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
240 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
241 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
243 TRACE( "ref count decremented to %lu:%lu for %p\n",
244 ulInterfaceRefCount, ulObjRefCount, This );
246 /* Deallocate if this is the last reference to the object */
247 if( ulObjRefCount == 0 )
249 DPLSP_DestroyDPLobbySP( This );
250 DPLSP_DestroyIUnknown( This );
253 if( ulInterfaceRefCount == 0 )
255 HeapFree( GetProcessHeap(), 0, This );
258 return ulInterfaceRefCount;
261 static
262 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
263 ( LPDPLOBBYSP iface,
264 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
267 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
268 FIXME( "(%p)->(%p):stub\n", This, argtg );
269 return DP_OK;
272 static
273 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
274 ( LPDPLOBBYSP iface,
275 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
278 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
279 FIXME( "(%p)->(%p):stub\n", This, arptg );
280 return DP_OK;
283 static
284 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
285 ( LPDPLOBBYSP iface,
286 LPSPDATA_CREATEREMOTEGROUP crg
289 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
290 FIXME( "(%p)->(%p):stub\n", This, crg );
291 return DP_OK;
294 static
295 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
296 ( LPDPLOBBYSP iface,
297 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
300 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
301 FIXME( "(%p)->(%p):stub\n", This, crgig );
302 return DP_OK;
305 static
306 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
307 ( LPDPLOBBYSP iface,
308 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
311 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
312 FIXME( "(%p)->(%p):stub\n", This, drgfg );
313 return DP_OK;
316 static
317 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
318 ( LPDPLOBBYSP iface,
319 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
322 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
323 FIXME( "(%p)->(%p):stub\n", This, drpfg );
324 return DP_OK;
327 static
328 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
329 ( LPDPLOBBYSP iface,
330 LPSPDATA_DESTROYREMOTEGROUP drg
333 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
334 FIXME( "(%p)->(%p):stub\n", This, drg );
335 return DP_OK;
338 static
339 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
340 ( LPDPLOBBYSP iface,
341 LPSPDATA_ENUMSESSIONSRESPONSE er
344 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
345 FIXME( "(%p)->(%p):stub\n", This, er );
346 return DP_OK;
349 static
350 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
351 ( LPDPLOBBYSP iface,
352 LPVOID* lplpData
355 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
356 FIXME( "(%p)->(%p):stub\n", This, lplpData );
357 return DP_OK;
360 static
361 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
362 ( LPDPLOBBYSP iface,
363 LPSPDATA_HANDLEMESSAGE hm
366 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
367 FIXME( "(%p)->(%p):stub\n", This, hm );
368 return DP_OK;
371 static
372 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
373 ( LPDPLOBBYSP iface,
374 LPSPDATA_CHATMESSAGE cm
377 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
378 FIXME( "(%p)->(%p):stub\n", This, cm );
379 return DP_OK;
382 static
383 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
384 ( LPDPLOBBYSP iface,
385 LPSPDATA_SETREMOTEGROUPNAME srgn
388 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
389 FIXME( "(%p)->(%p):stub\n", This, srgn );
390 return DP_OK;
393 static
394 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
395 ( LPDPLOBBYSP iface,
396 LPSPDATA_SETREMOTEPLAYERNAME srpn
399 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
400 FIXME( "(%p)->(%p):stub\n", This, srpn );
401 return DP_OK;
404 static
405 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
406 ( LPDPLOBBYSP iface,
407 LPSPDATA_SETSESSIONDESC ssd
410 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
411 FIXME( "(%p)->(%p):stub\n", This, ssd );
412 return DP_OK;
415 static
416 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
417 ( LPDPLOBBYSP iface,
418 LPVOID lpData
421 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
422 FIXME( "(%p)->(%p):stub\n", This, lpData );
423 return DP_OK;
426 static
427 HRESULT WINAPI IDPLobbySPImpl_StartSession
428 ( LPDPLOBBYSP iface,
429 LPSPDATA_STARTSESSIONCOMMAND ssc
432 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
433 FIXME( "(%p)->(%p):stub\n", This, ssc );
434 return DP_OK;
438 static const IDPLobbySPVtbl dpLobbySPVT =
441 DPLSP_QueryInterface,
442 DPLSP_AddRef,
443 DPLSP_Release,
445 IDPLobbySPImpl_AddGroupToGroup,
446 IDPLobbySPImpl_AddPlayerToGroup,
447 IDPLobbySPImpl_CreateGroup,
448 IDPLobbySPImpl_CreateGroupInGroup,
449 IDPLobbySPImpl_DeleteGroupFromGroup,
450 IDPLobbySPImpl_DeletePlayerFromGroup,
451 IDPLobbySPImpl_DestroyGroup,
452 IDPLobbySPImpl_EnumSessionsResponse,
453 IDPLobbySPImpl_GetSPDataPointer,
454 IDPLobbySPImpl_HandleMessage,
455 IDPLobbySPImpl_SendChatMessage,
456 IDPLobbySPImpl_SetGroupName,
457 IDPLobbySPImpl_SetPlayerName,
458 IDPLobbySPImpl_SetSessionDesc,
459 IDPLobbySPImpl_SetSPDataPointer,
460 IDPLobbySPImpl_StartSession