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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/debug.h"
25 #include "dplay_global.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
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
43 CRITICAL_SECTION DPLSP_lock;
44 } DPLobbySPIUnknownData;
46 typedef struct tagDPLobbySPData
48 IDirectPlay2Impl* dplay;
51 #define DPLSP_IMPL_FIELDS \
52 LONG ulInterfaceRef; \
53 DPLobbySPIUnknownData* unk; \
58 const IDPLobbySPVtbl *lpVtbl;
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 ) );
74 return DPERR_OUTOFMEMORY;
77 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
79 IDPLobbySPImpl *This = (IDPLobbySPImpl *)*ppvObj;
80 This->lpVtbl = &dpLobbySPVT;
84 /* Unsupported interface */
85 HeapFree( GetProcessHeap(), 0, *ppvObj );
92 if( DPLSP_CreateIUnknown( *ppvObj ) &&
93 DPLSP_CreateDPLobbySP( *ppvObj, dp )
96 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
100 /* Initialize failed, destroy it */
101 DPLSP_DestroyDPLobbySP( *ppvObj );
102 DPLSP_DestroyIUnknown( *ppvObj );
104 HeapFree( GetProcessHeap(), 0, *ppvObj );
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 )
121 InitializeCriticalSection( &This->unk->DPLSP_lock );
126 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
128 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
130 DeleteCriticalSection( &This->unk->DPLSP_lock );
131 HeapFree( GetProcessHeap(), 0, This->unk );
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 )
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 );
168 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
170 IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
172 HeapFree( GetProcessHeap(), 0, This->sp );
178 HRESULT WINAPI DPLSP_QueryInterface
184 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
185 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
187 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
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;
205 /* Unsupported interface */
206 HeapFree( GetProcessHeap(), 0, *ppvObj );
209 return E_NOINTERFACE;
212 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
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;
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;
262 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
264 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
267 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
268 FIXME( "(%p)->(%p):stub\n", This, argtg );
273 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
275 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
278 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
279 FIXME( "(%p)->(%p):stub\n", This, arptg );
284 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
286 LPSPDATA_CREATEREMOTEGROUP crg
289 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
290 FIXME( "(%p)->(%p):stub\n", This, crg );
295 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
297 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
300 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
301 FIXME( "(%p)->(%p):stub\n", This, crgig );
306 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
308 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
311 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
312 FIXME( "(%p)->(%p):stub\n", This, drgfg );
317 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
319 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
322 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
323 FIXME( "(%p)->(%p):stub\n", This, drpfg );
328 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
330 LPSPDATA_DESTROYREMOTEGROUP drg
333 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
334 FIXME( "(%p)->(%p):stub\n", This, drg );
339 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
341 LPSPDATA_ENUMSESSIONSRESPONSE er
344 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
345 FIXME( "(%p)->(%p):stub\n", This, er );
350 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
355 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
356 FIXME( "(%p)->(%p):stub\n", This, lplpData );
361 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
363 LPSPDATA_HANDLEMESSAGE hm
366 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
367 FIXME( "(%p)->(%p):stub\n", This, hm );
372 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
374 LPSPDATA_CHATMESSAGE cm
377 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
378 FIXME( "(%p)->(%p):stub\n", This, cm );
383 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
385 LPSPDATA_SETREMOTEGROUPNAME srgn
388 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
389 FIXME( "(%p)->(%p):stub\n", This, srgn );
394 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
396 LPSPDATA_SETREMOTEPLAYERNAME srpn
399 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
400 FIXME( "(%p)->(%p):stub\n", This, srpn );
405 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
407 LPSPDATA_SETSESSIONDESC ssd
410 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
411 FIXME( "(%p)->(%p):stub\n", This, ssd );
416 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
421 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
422 FIXME( "(%p)->(%p):stub\n", This, lpData );
427 HRESULT WINAPI IDPLobbySPImpl_StartSession
429 LPSPDATA_STARTSESSIONCOMMAND ssc
432 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
433 FIXME( "(%p)->(%p):stub\n", This, ssc );
438 static const IDPLobbySPVtbl dpLobbySPVT =
441 DPLSP_QueryInterface,
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