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
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 = *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 = lpSP;
114 This->unk = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->unk) ) );
116 if ( This->unk == NULL )
121 InitializeCriticalSection( &This->unk->DPLSP_lock );
122 This->unk->DPLSP_lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDPLobbySPImpl*->DPLobbySPIUnknownData*->DPLSP_lock");
127 static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
129 IDPLobbySPImpl *This = lpSP;
131 This->unk->DPLSP_lock.DebugInfo->Spare[0] = 0;
132 DeleteCriticalSection( &This->unk->DPLSP_lock );
133 HeapFree( GetProcessHeap(), 0, This->unk );
138 static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp )
140 IDPLobbySPImpl *This = lpSP;
142 This->sp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->sp) ) );
144 if ( This->sp == NULL )
149 This->sp->dplay = dp;
154 static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
156 IDPLobbySPImpl *This = lpSP;
158 HeapFree( GetProcessHeap(), 0, This->sp );
164 HRESULT WINAPI DPLSP_QueryInterface
170 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
171 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );
173 *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
176 if( *ppvObj == NULL )
178 return DPERR_OUTOFMEMORY;
181 CopyMemory( *ppvObj, This, sizeof( *This ) );
182 (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0;
184 if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
186 IDPLobbySPImpl *This = *ppvObj;
187 This->lpVtbl = &dpLobbySPVT;
191 /* Unsupported interface */
192 HeapFree( GetProcessHeap(), 0, *ppvObj );
195 return E_NOINTERFACE;
198 IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
204 ULONG WINAPI DPLSP_AddRef
205 ( LPDPLOBBYSP iface )
207 ULONG ulInterfaceRefCount, ulObjRefCount;
208 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
210 ulObjRefCount = InterlockedIncrement( &This->unk->ulObjRef );
211 ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );
213 TRACE( "ref count incremented to %u:%u for %p\n",
214 ulInterfaceRefCount, ulObjRefCount, This );
216 return ulObjRefCount;
220 ULONG WINAPI DPLSP_Release
221 ( LPDPLOBBYSP iface )
223 ULONG ulInterfaceRefCount, ulObjRefCount;
224 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
226 ulObjRefCount = InterlockedDecrement( &This->unk->ulObjRef );
227 ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );
229 TRACE( "ref count decremented to %u:%u for %p\n",
230 ulInterfaceRefCount, ulObjRefCount, This );
232 /* Deallocate if this is the last reference to the object */
233 if( ulObjRefCount == 0 )
235 DPLSP_DestroyDPLobbySP( This );
236 DPLSP_DestroyIUnknown( This );
239 if( ulInterfaceRefCount == 0 )
241 HeapFree( GetProcessHeap(), 0, This );
244 return ulInterfaceRefCount;
248 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
250 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
253 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
254 FIXME( "(%p)->(%p):stub\n", This, argtg );
259 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
261 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
264 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
265 FIXME( "(%p)->(%p):stub\n", This, arptg );
270 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
272 LPSPDATA_CREATEREMOTEGROUP crg
275 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
276 FIXME( "(%p)->(%p):stub\n", This, crg );
281 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
283 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
286 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
287 FIXME( "(%p)->(%p):stub\n", This, crgig );
292 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
294 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
297 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
298 FIXME( "(%p)->(%p):stub\n", This, drgfg );
303 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
305 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
308 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
309 FIXME( "(%p)->(%p):stub\n", This, drpfg );
314 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
316 LPSPDATA_DESTROYREMOTEGROUP drg
319 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
320 FIXME( "(%p)->(%p):stub\n", This, drg );
325 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
327 LPSPDATA_ENUMSESSIONSRESPONSE er
330 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
331 FIXME( "(%p)->(%p):stub\n", This, er );
336 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
341 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
342 FIXME( "(%p)->(%p):stub\n", This, lplpData );
347 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
349 LPSPDATA_HANDLEMESSAGE hm
352 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
353 FIXME( "(%p)->(%p):stub\n", This, hm );
358 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
360 LPSPDATA_CHATMESSAGE cm
363 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
364 FIXME( "(%p)->(%p):stub\n", This, cm );
369 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
371 LPSPDATA_SETREMOTEGROUPNAME srgn
374 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
375 FIXME( "(%p)->(%p):stub\n", This, srgn );
380 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
382 LPSPDATA_SETREMOTEPLAYERNAME srpn
385 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
386 FIXME( "(%p)->(%p):stub\n", This, srpn );
391 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
393 LPSPDATA_SETSESSIONDESC ssd
396 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
397 FIXME( "(%p)->(%p):stub\n", This, ssd );
402 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
407 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
408 FIXME( "(%p)->(%p):stub\n", This, lpData );
413 HRESULT WINAPI IDPLobbySPImpl_StartSession
415 LPSPDATA_STARTSESSIONCOMMAND ssc
418 IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
419 FIXME( "(%p)->(%p):stub\n", This, ssc );
424 static const IDPLobbySPVtbl dpLobbySPVT =
427 DPLSP_QueryInterface,
431 IDPLobbySPImpl_AddGroupToGroup,
432 IDPLobbySPImpl_AddPlayerToGroup,
433 IDPLobbySPImpl_CreateGroup,
434 IDPLobbySPImpl_CreateGroupInGroup,
435 IDPLobbySPImpl_DeleteGroupFromGroup,
436 IDPLobbySPImpl_DeletePlayerFromGroup,
437 IDPLobbySPImpl_DestroyGroup,
438 IDPLobbySPImpl_EnumSessionsResponse,
439 IDPLobbySPImpl_GetSPDataPointer,
440 IDPLobbySPImpl_HandleMessage,
441 IDPLobbySPImpl_SendChatMessage,
442 IDPLobbySPImpl_SetGroupName,
443 IDPLobbySPImpl_SetPlayerName,
444 IDPLobbySPImpl_SetSessionDesc,
445 IDPLobbySPImpl_SetSPDataPointer,
446 IDPLobbySPImpl_StartSession