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"
27 WINE_DEFAULT_DEBUG_CHANNEL(dplay
);
30 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
);
31 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
);
32 static BOOL
DPLSP_CreateDPLobbySP( void *lpSP
, IDirectPlayImpl
*dp
);
33 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
);
36 /* Predefine the interface */
37 typedef struct IDPLobbySPImpl IDPLobbySPImpl
;
39 typedef struct tagDPLobbySPIUnknownData
42 CRITICAL_SECTION DPLSP_lock
;
43 } DPLobbySPIUnknownData
;
45 typedef struct tagDPLobbySPData
47 IDirectPlayImpl
*dplay
;
50 #define DPLSP_IMPL_FIELDS \
51 LONG ulInterfaceRef; \
52 DPLobbySPIUnknownData* unk; \
57 const IDPLobbySPVtbl
*lpVtbl
;
61 /* Forward declaration of virtual tables */
62 static const IDPLobbySPVtbl dpLobbySPVT
;
64 HRESULT
DPLSP_CreateInterface( REFIID riid
, void **ppvObj
, IDirectPlayImpl
*dp
)
66 TRACE( " for %s\n", debugstr_guid( riid
) );
68 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
69 sizeof( IDPLobbySPImpl
) );
73 return DPERR_OUTOFMEMORY
;
76 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
78 IDPLobbySPImpl
*This
= *ppvObj
;
79 This
->lpVtbl
= &dpLobbySPVT
;
83 /* Unsupported interface */
84 HeapFree( GetProcessHeap(), 0, *ppvObj
);
91 if( DPLSP_CreateIUnknown( *ppvObj
) &&
92 DPLSP_CreateDPLobbySP( *ppvObj
, dp
)
95 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
99 /* Initialize failed, destroy it */
100 DPLSP_DestroyDPLobbySP( *ppvObj
);
101 DPLSP_DestroyIUnknown( *ppvObj
);
103 HeapFree( GetProcessHeap(), 0, *ppvObj
);
106 return DPERR_NOMEMORY
;
109 static BOOL
DPLSP_CreateIUnknown( LPVOID lpSP
)
111 IDPLobbySPImpl
*This
= lpSP
;
113 This
->unk
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof( *(This
->unk
) ) );
115 if ( This
->unk
== NULL
)
120 InitializeCriticalSection( &This
->unk
->DPLSP_lock
);
121 This
->unk
->DPLSP_lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IDPLobbySPImpl*->DPLobbySPIUnknownData*->DPLSP_lock");
126 static BOOL
DPLSP_DestroyIUnknown( LPVOID lpSP
)
128 IDPLobbySPImpl
*This
= lpSP
;
130 This
->unk
->DPLSP_lock
.DebugInfo
->Spare
[0] = 0;
131 DeleteCriticalSection( &This
->unk
->DPLSP_lock
);
132 HeapFree( GetProcessHeap(), 0, This
->unk
);
137 static BOOL
DPLSP_CreateDPLobbySP( void *lpSP
, IDirectPlayImpl
*dp
)
139 IDPLobbySPImpl
*This
= lpSP
;
141 This
->sp
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof( *(This
->sp
) ) );
143 if ( This
->sp
== NULL
)
148 This
->sp
->dplay
= dp
;
153 static BOOL
DPLSP_DestroyDPLobbySP( LPVOID lpSP
)
155 IDPLobbySPImpl
*This
= lpSP
;
157 HeapFree( GetProcessHeap(), 0, This
->sp
);
163 HRESULT WINAPI DPLSP_QueryInterface
169 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
170 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid( riid
), ppvObj
);
172 *ppvObj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
175 if( *ppvObj
== NULL
)
177 return DPERR_OUTOFMEMORY
;
180 CopyMemory( *ppvObj
, This
, sizeof( *This
) );
181 (*(IDPLobbySPImpl
**)ppvObj
)->ulInterfaceRef
= 0;
183 if( IsEqualGUID( &IID_IDPLobbySP
, riid
) )
185 IDPLobbySPImpl
*This
= *ppvObj
;
186 This
->lpVtbl
= &dpLobbySPVT
;
190 /* Unsupported interface */
191 HeapFree( GetProcessHeap(), 0, *ppvObj
);
194 return E_NOINTERFACE
;
197 IDPLobbySP_AddRef( (LPDPLOBBYSP
)*ppvObj
);
203 ULONG WINAPI DPLSP_AddRef
204 ( LPDPLOBBYSP iface
)
206 ULONG ulInterfaceRefCount
, ulObjRefCount
;
207 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
209 ulObjRefCount
= InterlockedIncrement( &This
->unk
->ulObjRef
);
210 ulInterfaceRefCount
= InterlockedIncrement( &This
->ulInterfaceRef
);
212 TRACE( "ref count incremented to %u:%u for %p\n",
213 ulInterfaceRefCount
, ulObjRefCount
, This
);
215 return ulObjRefCount
;
219 ULONG WINAPI DPLSP_Release
220 ( LPDPLOBBYSP iface
)
222 ULONG ulInterfaceRefCount
, ulObjRefCount
;
223 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
225 ulObjRefCount
= InterlockedDecrement( &This
->unk
->ulObjRef
);
226 ulInterfaceRefCount
= InterlockedDecrement( &This
->ulInterfaceRef
);
228 TRACE( "ref count decremented to %u:%u for %p\n",
229 ulInterfaceRefCount
, ulObjRefCount
, This
);
231 /* Deallocate if this is the last reference to the object */
232 if( ulObjRefCount
== 0 )
234 DPLSP_DestroyDPLobbySP( This
);
235 DPLSP_DestroyIUnknown( This
);
238 if( ulInterfaceRefCount
== 0 )
240 HeapFree( GetProcessHeap(), 0, This
);
243 return ulInterfaceRefCount
;
247 HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
249 LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
252 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
253 FIXME( "(%p)->(%p):stub\n", This
, argtg
);
258 HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
260 LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
263 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
264 FIXME( "(%p)->(%p):stub\n", This
, arptg
);
269 HRESULT WINAPI IDPLobbySPImpl_CreateGroup
271 LPSPDATA_CREATEREMOTEGROUP crg
274 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
275 FIXME( "(%p)->(%p):stub\n", This
, crg
);
280 HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
282 LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
285 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
286 FIXME( "(%p)->(%p):stub\n", This
, crgig
);
291 HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
293 LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
296 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
297 FIXME( "(%p)->(%p):stub\n", This
, drgfg
);
302 HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
304 LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
307 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
308 FIXME( "(%p)->(%p):stub\n", This
, drpfg
);
313 HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
315 LPSPDATA_DESTROYREMOTEGROUP drg
318 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
319 FIXME( "(%p)->(%p):stub\n", This
, drg
);
324 HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
326 LPSPDATA_ENUMSESSIONSRESPONSE er
329 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
330 FIXME( "(%p)->(%p):stub\n", This
, er
);
335 HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
340 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
341 FIXME( "(%p)->(%p):stub\n", This
, lplpData
);
346 HRESULT WINAPI IDPLobbySPImpl_HandleMessage
348 LPSPDATA_HANDLEMESSAGE hm
351 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
352 FIXME( "(%p)->(%p):stub\n", This
, hm
);
357 HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
359 LPSPDATA_CHATMESSAGE cm
362 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
363 FIXME( "(%p)->(%p):stub\n", This
, cm
);
368 HRESULT WINAPI IDPLobbySPImpl_SetGroupName
370 LPSPDATA_SETREMOTEGROUPNAME srgn
373 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
374 FIXME( "(%p)->(%p):stub\n", This
, srgn
);
379 HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
381 LPSPDATA_SETREMOTEPLAYERNAME srpn
384 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
385 FIXME( "(%p)->(%p):stub\n", This
, srpn
);
390 HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
392 LPSPDATA_SETSESSIONDESC ssd
395 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
396 FIXME( "(%p)->(%p):stub\n", This
, ssd
);
401 HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
406 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
407 FIXME( "(%p)->(%p):stub\n", This
, lpData
);
412 HRESULT WINAPI IDPLobbySPImpl_StartSession
414 LPSPDATA_STARTSESSIONCOMMAND ssc
417 IDPLobbySPImpl
*This
= (IDPLobbySPImpl
*)iface
;
418 FIXME( "(%p)->(%p):stub\n", This
, ssc
);
423 static const IDPLobbySPVtbl dpLobbySPVT
=
426 DPLSP_QueryInterface
,
430 IDPLobbySPImpl_AddGroupToGroup
,
431 IDPLobbySPImpl_AddPlayerToGroup
,
432 IDPLobbySPImpl_CreateGroup
,
433 IDPLobbySPImpl_CreateGroupInGroup
,
434 IDPLobbySPImpl_DeleteGroupFromGroup
,
435 IDPLobbySPImpl_DeletePlayerFromGroup
,
436 IDPLobbySPImpl_DestroyGroup
,
437 IDPLobbySPImpl_EnumSessionsResponse
,
438 IDPLobbySPImpl_GetSPDataPointer
,
439 IDPLobbySPImpl_HandleMessage
,
440 IDPLobbySPImpl_SendChatMessage
,
441 IDPLobbySPImpl_SetGroupName
,
442 IDPLobbySPImpl_SetPlayerName
,
443 IDPLobbySPImpl_SetSessionDesc
,
444 IDPLobbySPImpl_SetSPDataPointer
,
445 IDPLobbySPImpl_StartSession