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
;
151 /* Normally we should be keeping a reference, but since only the dplay
152 * interface that created us can destroy us, we do not keep a reference
153 * to it (ie we'd be stuck with always having one reference to the dplay
154 * object, and hence us, around).
155 * NOTE: The dp object does reference count us.
157 * FIXME: This is a kludge to get around a problem where a queryinterface
158 * is used to get a new interface and then is closed. We will then
159 * reference garbage. However, with this we will never deallocate
160 * the interface we store. The correct fix is to require all
161 * DP internal interfaces to use the This->dp2 interface which
162 * should be changed to This->dp
164 IDirectPlayX_AddRef( (LPDIRECTPLAY2
)dp
);
170 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
)
172 IDPLobbySPImpl
*This
= lpSP
;
174 HeapFree( GetProcessHeap(), 0, This
->sp
);
180 HRESULT WINAPI DPLSP_QueryInterface
186 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
187 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid( riid
), ppvObj
);
189 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
192 if( *ppvObj
== NULL
)
194 return DPERR_OUTOFMEMORY
;
197 CopyMemory( *ppvObj
, This
, sizeof( *This
) );
198 (*(IDPLobbySPImpl
**)ppvObj
)->ulInterfaceRef
= 0;
200 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
202 IDPLobbySPImpl
*This
= *ppvObj
;
203 This
->lpVtbl
= &dpLobbySPVT
;
207 /* Unsupported interface */
208 HeapFree( GetProcessHeap(), 0, *ppvObj
);
211 return E_NOINTERFACE
;
214 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
220 ULONG WINAPI DPLSP_AddRef
221 ( LPDPLOBBYSP iface
)
223 ULONG ulInterfaceRefCount
, ulObjRefCount
;
224 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
226 ulObjRefCount
= InterlockedIncrement( &This
->unk
->ulObjRef
);
227 ulInterfaceRefCount
= InterlockedIncrement( &This
->ulInterfaceRef
);
229 TRACE( "ref count incremented to %u:%u for %p\n",
230 ulInterfaceRefCount
, ulObjRefCount
, This
);
232 return ulObjRefCount
;
236 ULONG WINAPI DPLSP_Release
237 ( LPDPLOBBYSP iface
)
239 ULONG ulInterfaceRefCount
, ulObjRefCount
;
240 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
242 ulObjRefCount
= InterlockedDecrement( &This
->unk
->ulObjRef
);
243 ulInterfaceRefCount
= InterlockedDecrement( &This
->ulInterfaceRef
);
245 TRACE( "ref count decremented to %u:%u for %p\n",
246 ulInterfaceRefCount
, ulObjRefCount
, This
);
248 /* Deallocate if this is the last reference to the object */
249 if( ulObjRefCount
== 0 )
251 DPLSP_DestroyDPLobbySP( This
);
252 DPLSP_DestroyIUnknown( This
);
255 if( ulInterfaceRefCount
== 0 )
257 HeapFree( GetProcessHeap(), 0, This
);
260 return ulInterfaceRefCount
;
264 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
266 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
269 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
270 FIXME( "(%p)->(%p):stub\n", This
, argtg
);
275 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
277 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
280 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
281 FIXME( "(%p)->(%p):stub\n", This
, arptg
);
286 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
288 LPSPDATA_CREATEREMOTEGROUP crg
291 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
292 FIXME( "(%p)->(%p):stub\n", This
, crg
);
297 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
299 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
302 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
303 FIXME( "(%p)->(%p):stub\n", This
, crgig
);
308 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
310 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
313 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
314 FIXME( "(%p)->(%p):stub\n", This
, drgfg
);
319 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
321 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
324 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
325 FIXME( "(%p)->(%p):stub\n", This
, drpfg
);
330 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
332 LPSPDATA_DESTROYREMOTEGROUP drg
335 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
336 FIXME( "(%p)->(%p):stub\n", This
, drg
);
341 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
343 LPSPDATA_ENUMSESSIONSRESPONSE er
346 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
347 FIXME( "(%p)->(%p):stub\n", This
, er
);
352 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
357 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
358 FIXME( "(%p)->(%p):stub\n", This
, lplpData
);
363 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
365 LPSPDATA_HANDLEMESSAGE hm
368 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
369 FIXME( "(%p)->(%p):stub\n", This
, hm
);
374 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
376 LPSPDATA_CHATMESSAGE cm
379 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
380 FIXME( "(%p)->(%p):stub\n", This
, cm
);
385 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
387 LPSPDATA_SETREMOTEGROUPNAME srgn
390 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
391 FIXME( "(%p)->(%p):stub\n", This
, srgn
);
396 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
398 LPSPDATA_SETREMOTEPLAYERNAME srpn
401 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
402 FIXME( "(%p)->(%p):stub\n", This
, srpn
);
407 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
409 LPSPDATA_SETSESSIONDESC ssd
412 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
413 FIXME( "(%p)->(%p):stub\n", This
, ssd
);
418 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
423 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
424 FIXME( "(%p)->(%p):stub\n", This
, lpData
);
429 HRESULT WINAPI IDPLobbySPImpl_StartSession
431 LPSPDATA_STARTSESSIONCOMMAND ssc
434 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
435 FIXME( "(%p)->(%p):stub\n", This
, ssc
);
440 static const IDPLobbySPVtbl dpLobbySPVT
=
443 DPLSP_QueryInterface
,
447 IDPLobbySPImpl_AddGroupToGroup
,
448 IDPLobbySPImpl_AddPlayerToGroup
,
449 IDPLobbySPImpl_CreateGroup
,
450 IDPLobbySPImpl_CreateGroupInGroup
,
451 IDPLobbySPImpl_DeleteGroupFromGroup
,
452 IDPLobbySPImpl_DeletePlayerFromGroup
,
453 IDPLobbySPImpl_DestroyGroup
,
454 IDPLobbySPImpl_EnumSessionsResponse
,
455 IDPLobbySPImpl_GetSPDataPointer
,
456 IDPLobbySPImpl_HandleMessage
,
457 IDPLobbySPImpl_SendChatMessage
,
458 IDPLobbySPImpl_SetGroupName
,
459 IDPLobbySPImpl_SetPlayerName
,
460 IDPLobbySPImpl_SetSessionDesc
,
461 IDPLobbySPImpl_SetSPDataPointer
,
462 IDPLobbySPImpl_StartSession