1 /* This contains the implementation of the Lobby Service
2 * Providers interface required to communicate with Direct Play
4 * Copyright 2001 Peter Hunnisett <hunnise@nortelnetworks.com>
8 #include "debugtools.h"
11 #include "dplay_global.h"
14 DEFAULT_DEBUG_CHANNEL(dplay
);
17 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
);
18 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
);
19 static BOOL
DPLSP_CreateDPLobbySP( LPVOID lpSP
, IDirectPlay2Impl
* dp
);
20 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
);
23 /* Predefine the interface */
24 typedef struct IDPLobbySPImpl IDPLobbySPImpl
;
26 typedef struct tagDPLobbySPIUnknownData
29 CRITICAL_SECTION DPLSP_lock
;
30 } DPLobbySPIUnknownData
;
32 typedef struct tagDPLobbySPData
34 IDirectPlay2Impl
* dplay
;
37 #define DPLSP_IMPL_FIELDS \
38 ULONG ulInterfaceRef; \
39 DPLobbySPIUnknownData* unk; \
44 ICOM_VFIELD(IDPLobbySP
);
48 /* Forward declaration of virtual tables */
49 static ICOM_VTABLE(IDPLobbySP
) dpLobbySPVT
;
52 HRESULT
DPLSP_CreateInterface( REFIID riid
, LPVOID
* ppvObj
, IDirectPlay2Impl
* dp
)
54 TRACE( " for %s\n", debugstr_guid( riid
) );
56 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
57 sizeof( IDPLobbySPImpl
) );
61 return DPERR_OUTOFMEMORY
;
64 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
66 ICOM_THIS(IDPLobbySPImpl
,*ppvObj
);
67 ICOM_VTBL(This
) = &dpLobbySPVT
;
71 /* Unsupported interface */
72 HeapFree( GetProcessHeap(), 0, *ppvObj
);
79 if( DPLSP_CreateIUnknown( *ppvObj
) &&
80 DPLSP_CreateDPLobbySP( *ppvObj
, dp
)
83 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
87 /* Initialize failed, destroy it */
88 DPLSP_DestroyDPLobbySP( *ppvObj
);
89 DPLSP_DestroyIUnknown( *ppvObj
);
91 HeapFree( GetProcessHeap(), 0, *ppvObj
);
94 return DPERR_NOMEMORY
;
97 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
)
99 ICOM_THIS(IDPLobbySPImpl
,lpSP
);
101 This
->unk
= (DPLobbySPIUnknownData
*)HeapAlloc( GetProcessHeap(),
103 sizeof( *(This
->unk
) ) );
105 if ( This
->unk
== NULL
)
110 InitializeCriticalSection( &This
->unk
->DPLSP_lock
);
115 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
)
117 ICOM_THIS(IDPLobbySPImpl
,lpSP
);
119 DeleteCriticalSection( &This
->unk
->DPLSP_lock
);
120 HeapFree( GetProcessHeap(), 0, This
->unk
);
125 static BOOL
DPLSP_CreateDPLobbySP( LPVOID lpSP
, IDirectPlay2Impl
* dp
)
127 ICOM_THIS(IDPLobbySPImpl
,lpSP
);
129 This
->sp
= (DPLobbySPData
*)HeapAlloc( GetProcessHeap(),
131 sizeof( *(This
->sp
) ) );
133 if ( This
->sp
== NULL
)
138 This
->sp
->dplay
= dp
;
140 /* Normally we should be keeping a reference, but since only the dplay
141 * interface that created us can destroy us, we do not keep a reference
142 * to it (ie we'd be stuck with always having one reference to the dplay
143 * object, and hence us, around).
144 * NOTE: The dp object does reference count us.
146 * FIXME: This is a kludge to get around a problem where a queryinterface
147 * is used to get a new interface and then is closed. We will then
148 * reference garbage. However, with this we will never deallocate
149 * the interface we store. The correct fix is to require all
150 * DP internal interfaces to use the This->dp2 interface which
151 * should be changed to This->dp
153 IDirectPlayX_AddRef( (LPDIRECTPLAY2
)dp
);
159 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
)
161 ICOM_THIS(IDPLobbySPImpl
,lpSP
);
163 HeapFree( GetProcessHeap(), 0, This
->sp
);
169 HRESULT WINAPI DPLSP_QueryInterface
175 ICOM_THIS(IDPLobbySPImpl
,iface
);
176 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid( riid
), ppvObj
);
178 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
181 if( *ppvObj
== NULL
)
183 return DPERR_OUTOFMEMORY
;
186 CopyMemory( *ppvObj
, This
, sizeof( *This
) );
187 (*(IDPLobbySPImpl
**)ppvObj
)->ulInterfaceRef
= 0;
189 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
191 ICOM_THIS(IDPLobbySPImpl
,*ppvObj
);
192 ICOM_VTBL(This
) = &dpLobbySPVT
;
196 /* Unsupported interface */
197 HeapFree( GetProcessHeap(), 0, *ppvObj
);
200 return E_NOINTERFACE
;
203 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
209 ULONG WINAPI DPLSP_AddRef
210 ( LPDPLOBBYSP iface
)
212 ULONG ulInterfaceRefCount
, ulObjRefCount
;
213 ICOM_THIS(IDPLobbySPImpl
,iface
);
215 ulObjRefCount
= InterlockedIncrement( &This
->unk
->ulObjRef
);
216 ulInterfaceRefCount
= InterlockedIncrement( &This
->ulInterfaceRef
);
218 TRACE( "ref count incremented to %lu:%lu for %p\n",
219 ulInterfaceRefCount
, ulObjRefCount
, This
);
221 return ulObjRefCount
;
225 ULONG WINAPI DPLSP_Release
226 ( LPDPLOBBYSP iface
)
228 ULONG ulInterfaceRefCount
, ulObjRefCount
;
229 ICOM_THIS(IDPLobbySPImpl
,iface
);
231 ulObjRefCount
= InterlockedDecrement( &This
->unk
->ulObjRef
);
232 ulInterfaceRefCount
= InterlockedDecrement( &This
->ulInterfaceRef
);
234 TRACE( "ref count decremented to %lu:%lu for %p\n",
235 ulInterfaceRefCount
, ulObjRefCount
, This
);
237 /* Deallocate if this is the last reference to the object */
238 if( ulObjRefCount
== 0 )
240 DPLSP_DestroyDPLobbySP( This
);
241 DPLSP_DestroyIUnknown( This
);
244 if( ulInterfaceRefCount
== 0 )
246 HeapFree( GetProcessHeap(), 0, This
);
249 return ulInterfaceRefCount
;
253 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
255 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
258 ICOM_THIS(IDPLobbySPImpl
,iface
);
259 FIXME( "(%p)->(%p):stub\n", This
, argtg
);
264 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
266 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
269 ICOM_THIS(IDPLobbySPImpl
,iface
);
270 FIXME( "(%p)->(%p):stub\n", This
, arptg
);
275 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
277 LPSPDATA_CREATEREMOTEGROUP crg
280 ICOM_THIS(IDPLobbySPImpl
,iface
);
281 FIXME( "(%p)->(%p):stub\n", This
, crg
);
286 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
288 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
291 ICOM_THIS(IDPLobbySPImpl
,iface
);
292 FIXME( "(%p)->(%p):stub\n", This
, crgig
);
297 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
299 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
302 ICOM_THIS(IDPLobbySPImpl
,iface
);
303 FIXME( "(%p)->(%p):stub\n", This
, drgfg
);
308 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
310 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
313 ICOM_THIS(IDPLobbySPImpl
,iface
);
314 FIXME( "(%p)->(%p):stub\n", This
, drpfg
);
319 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
321 LPSPDATA_DESTROYREMOTEGROUP drg
324 ICOM_THIS(IDPLobbySPImpl
,iface
);
325 FIXME( "(%p)->(%p):stub\n", This
, drg
);
330 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
332 LPSPDATA_ENUMSESSIONSRESPONSE er
335 ICOM_THIS(IDPLobbySPImpl
,iface
);
336 FIXME( "(%p)->(%p):stub\n", This
, er
);
341 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
346 ICOM_THIS(IDPLobbySPImpl
,iface
);
347 FIXME( "(%p)->(%p):stub\n", This
, lplpData
);
352 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
354 LPSPDATA_HANDLEMESSAGE hm
357 ICOM_THIS(IDPLobbySPImpl
,iface
);
358 FIXME( "(%p)->(%p):stub\n", This
, hm
);
363 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
365 LPSPDATA_CHATMESSAGE cm
368 ICOM_THIS(IDPLobbySPImpl
,iface
);
369 FIXME( "(%p)->(%p):stub\n", This
, cm
);
374 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
376 LPSPDATA_SETREMOTEGROUPNAME srgn
379 ICOM_THIS(IDPLobbySPImpl
,iface
);
380 FIXME( "(%p)->(%p):stub\n", This
, srgn
);
385 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
387 LPSPDATA_SETREMOTEPLAYERNAME srpn
390 ICOM_THIS(IDPLobbySPImpl
,iface
);
391 FIXME( "(%p)->(%p):stub\n", This
, srpn
);
396 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
398 LPSPDATA_SETSESSIONDESC ssd
401 ICOM_THIS(IDPLobbySPImpl
,iface
);
402 FIXME( "(%p)->(%p):stub\n", This
, ssd
);
407 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
412 ICOM_THIS(IDPLobbySPImpl
,iface
);
413 FIXME( "(%p)->(%p):stub\n", This
, lpData
);
418 HRESULT WINAPI IDPLobbySPImpl_StartSession
420 LPSPDATA_STARTSESSIONCOMMAND ssc
423 ICOM_THIS(IDPLobbySPImpl
,iface
);
424 FIXME( "(%p)->(%p):stub\n", This
, ssc
);
429 static struct ICOM_VTABLE(IDPLobbySP
) dpLobbySPVT
=
431 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
433 DPLSP_QueryInterface
,
437 IDPLobbySPImpl_AddGroupToGroup
,
438 IDPLobbySPImpl_AddPlayerToGroup
,
439 IDPLobbySPImpl_CreateGroup
,
440 IDPLobbySPImpl_CreateGroupInGroup
,
441 IDPLobbySPImpl_DeleteGroupFromGroup
,
442 IDPLobbySPImpl_DeletePlayerFromGroup
,
443 IDPLobbySPImpl_DestroyGroup
,
444 IDPLobbySPImpl_EnumSessionsResponse
,
445 IDPLobbySPImpl_GetSPDataPointer
,
446 IDPLobbySPImpl_HandleMessage
,
447 IDPLobbySPImpl_SendChatMessage
,
448 IDPLobbySPImpl_SetGroupName
,
449 IDPLobbySPImpl_SetPlayerName
,
450 IDPLobbySPImpl_SetSessionDesc
,
451 IDPLobbySPImpl_SetSPDataPointer
,
452 IDPLobbySPImpl_StartSession