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 "dplayx_global.h"
24 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
);
25 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
);
26 static BOOL
DPLSP_CreateDPLobbySP( void *lpSP
, IDirectPlayImpl
*dp
);
27 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
);
30 /* Predefine the interface */
31 typedef struct IDPLobbySPImpl IDPLobbySPImpl
;
33 typedef struct tagDPLobbySPIUnknownData
36 CRITICAL_SECTION DPLSP_lock
;
37 } DPLobbySPIUnknownData
;
39 typedef struct tagDPLobbySPData
41 IDirectPlayImpl
*dplay
;
44 #define DPLSP_IMPL_FIELDS \
45 LONG ulInterfaceRef; \
46 DPLobbySPIUnknownData* unk; \
51 const IDPLobbySPVtbl
*lpVtbl
;
55 /* Forward declaration of virtual tables */
56 static const IDPLobbySPVtbl dpLobbySPVT
;
58 HRESULT
DPLSP_CreateInterface( REFIID riid
, void **ppvObj
, IDirectPlayImpl
*dp
)
60 TRACE( " for %s\n", debugstr_guid( riid
) );
62 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
63 sizeof( IDPLobbySPImpl
) );
67 return DPERR_OUTOFMEMORY
;
70 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
72 IDPLobbySPImpl
*This
= *ppvObj
;
73 This
->lpVtbl
= &dpLobbySPVT
;
77 /* Unsupported interface */
78 HeapFree( GetProcessHeap(), 0, *ppvObj
);
85 if( DPLSP_CreateIUnknown( *ppvObj
) &&
86 DPLSP_CreateDPLobbySP( *ppvObj
, dp
)
89 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
93 /* Initialize failed, destroy it */
94 DPLSP_DestroyDPLobbySP( *ppvObj
);
95 DPLSP_DestroyIUnknown( *ppvObj
);
97 HeapFree( GetProcessHeap(), 0, *ppvObj
);
100 return DPERR_NOMEMORY
;
103 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
)
105 IDPLobbySPImpl
*This
= lpSP
;
107 This
->unk
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof( *(This
->unk
) ) );
109 if ( This
->unk
== NULL
)
114 InitializeCriticalSection( &This
->unk
->DPLSP_lock
);
115 This
->unk
->DPLSP_lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDPLobbySPImpl*->DPLobbySPIUnknownData*->DPLSP_lock");
120 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
)
122 IDPLobbySPImpl
*This
= lpSP
;
124 This
->unk
->DPLSP_lock
.DebugInfo
->Spare
[0] = 0;
125 DeleteCriticalSection( &This
->unk
->DPLSP_lock
);
126 HeapFree( GetProcessHeap(), 0, This
->unk
);
131 static BOOL
DPLSP_CreateDPLobbySP( void *lpSP
, IDirectPlayImpl
*dp
)
133 IDPLobbySPImpl
*This
= lpSP
;
135 This
->sp
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof( *(This
->sp
) ) );
137 if ( This
->sp
== NULL
)
142 This
->sp
->dplay
= dp
;
147 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
)
149 IDPLobbySPImpl
*This
= lpSP
;
151 HeapFree( GetProcessHeap(), 0, This
->sp
);
157 HRESULT WINAPI DPLSP_QueryInterface
163 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
164 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid( riid
), ppvObj
);
166 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
169 if( *ppvObj
== NULL
)
171 return DPERR_OUTOFMEMORY
;
174 CopyMemory( *ppvObj
, This
, sizeof( *This
) );
175 (*(IDPLobbySPImpl
**)ppvObj
)->ulInterfaceRef
= 0;
177 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
179 IDPLobbySPImpl
*This
= *ppvObj
;
180 This
->lpVtbl
= &dpLobbySPVT
;
184 /* Unsupported interface */
185 HeapFree( GetProcessHeap(), 0, *ppvObj
);
188 return E_NOINTERFACE
;
191 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
197 ULONG WINAPI DPLSP_AddRef
198 ( LPDPLOBBYSP iface
)
200 ULONG ulInterfaceRefCount
, ulObjRefCount
;
201 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
203 ulObjRefCount
= InterlockedIncrement( &This
->unk
->ulObjRef
);
204 ulInterfaceRefCount
= InterlockedIncrement( &This
->ulInterfaceRef
);
206 TRACE( "ref count incremented to %u:%u for %p\n",
207 ulInterfaceRefCount
, ulObjRefCount
, This
);
209 return ulObjRefCount
;
213 ULONG WINAPI DPLSP_Release
214 ( LPDPLOBBYSP iface
)
216 ULONG ulInterfaceRefCount
, ulObjRefCount
;
217 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
219 ulObjRefCount
= InterlockedDecrement( &This
->unk
->ulObjRef
);
220 ulInterfaceRefCount
= InterlockedDecrement( &This
->ulInterfaceRef
);
222 TRACE( "ref count decremented to %u:%u for %p\n",
223 ulInterfaceRefCount
, ulObjRefCount
, This
);
225 /* Deallocate if this is the last reference to the object */
226 if( ulObjRefCount
== 0 )
228 DPLSP_DestroyDPLobbySP( This
);
229 DPLSP_DestroyIUnknown( This
);
232 if( ulInterfaceRefCount
== 0 )
234 HeapFree( GetProcessHeap(), 0, This
);
237 return ulInterfaceRefCount
;
241 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
243 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
246 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
247 FIXME( "(%p)->(%p):stub\n", This
, argtg
);
252 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
254 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
257 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
258 FIXME( "(%p)->(%p):stub\n", This
, arptg
);
263 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
265 LPSPDATA_CREATEREMOTEGROUP crg
268 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
269 FIXME( "(%p)->(%p):stub\n", This
, crg
);
274 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
276 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
279 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
280 FIXME( "(%p)->(%p):stub\n", This
, crgig
);
285 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
287 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
290 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
291 FIXME( "(%p)->(%p):stub\n", This
, drgfg
);
296 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
298 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
301 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
302 FIXME( "(%p)->(%p):stub\n", This
, drpfg
);
307 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
309 LPSPDATA_DESTROYREMOTEGROUP drg
312 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
313 FIXME( "(%p)->(%p):stub\n", This
, drg
);
318 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
320 LPSPDATA_ENUMSESSIONSRESPONSE er
323 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
324 FIXME( "(%p)->(%p):stub\n", This
, er
);
329 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
334 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
335 FIXME( "(%p)->(%p):stub\n", This
, lplpData
);
340 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
342 LPSPDATA_HANDLEMESSAGE hm
345 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
346 FIXME( "(%p)->(%p):stub\n", This
, hm
);
351 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
353 LPSPDATA_CHATMESSAGE cm
356 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
357 FIXME( "(%p)->(%p):stub\n", This
, cm
);
362 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
364 LPSPDATA_SETREMOTEGROUPNAME srgn
367 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
368 FIXME( "(%p)->(%p):stub\n", This
, srgn
);
373 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
375 LPSPDATA_SETREMOTEPLAYERNAME srpn
378 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
379 FIXME( "(%p)->(%p):stub\n", This
, srpn
);
384 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
386 LPSPDATA_SETSESSIONDESC ssd
389 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
390 FIXME( "(%p)->(%p):stub\n", This
, ssd
);
395 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
400 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
401 FIXME( "(%p)->(%p):stub\n", This
, lpData
);
406 HRESULT WINAPI IDPLobbySPImpl_StartSession
408 LPSPDATA_STARTSESSIONCOMMAND ssc
411 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
412 FIXME( "(%p)->(%p):stub\n", This
, ssc
);
417 static const IDPLobbySPVtbl dpLobbySPVT
=
420 DPLSP_QueryInterface
,
424 IDPLobbySPImpl_AddGroupToGroup
,
425 IDPLobbySPImpl_AddPlayerToGroup
,
426 IDPLobbySPImpl_CreateGroup
,
427 IDPLobbySPImpl_CreateGroupInGroup
,
428 IDPLobbySPImpl_DeleteGroupFromGroup
,
429 IDPLobbySPImpl_DeletePlayerFromGroup
,
430 IDPLobbySPImpl_DestroyGroup
,
431 IDPLobbySPImpl_EnumSessionsResponse
,
432 IDPLobbySPImpl_GetSPDataPointer
,
433 IDPLobbySPImpl_HandleMessage
,
434 IDPLobbySPImpl_SendChatMessage
,
435 IDPLobbySPImpl_SetGroupName
,
436 IDPLobbySPImpl_SetPlayerName
,
437 IDPLobbySPImpl_SetSessionDesc
,
438 IDPLobbySPImpl_SetSPDataPointer
,
439 IDPLobbySPImpl_StartSession