lobbysp.c 10.7 KB
Newer Older
1 2 3
/* This contains the implementation of the Lobby Service
 * Providers interface required to communicate with Direct Play
 *
4
 * Copyright 2001 Peter Hunnisett
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
19 20 21
 */

#include "winerror.h"
22
#include "wine/debug.h"
23 24 25 26 27

#include "lobbysp.h"
#include "dplay_global.h"
#include "dpinit.h"

28
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
29 30 31 32 33 34 35 36 37 38 39 40 41

/* Prototypes */
static BOOL DPLSP_CreateIUnknown( LPVOID lpSP );
static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP );
static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp );
static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP );


/* Predefine the interface */
typedef struct IDPLobbySPImpl IDPLobbySPImpl;

typedef struct tagDPLobbySPIUnknownData
{
42
  LONG              ulObjRef;
43 44 45 46 47 48 49 50 51
  CRITICAL_SECTION  DPLSP_lock;
} DPLobbySPIUnknownData;

typedef struct tagDPLobbySPData
{
  IDirectPlay2Impl* dplay;
} DPLobbySPData;

#define DPLSP_IMPL_FIELDS \
52
   LONG ulInterfaceRef; \
53 54 55 56 57
   DPLobbySPIUnknownData* unk; \
   DPLobbySPData* sp;

struct IDPLobbySPImpl
{
58
  const IDPLobbySPVtbl *lpVtbl;
59 60 61 62
  DPLSP_IMPL_FIELDS
};

/* Forward declaration of virtual tables */
63
static const IDPLobbySPVtbl dpLobbySPVT;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

HRESULT DPLSP_CreateInterface( REFIID riid, LPVOID* ppvObj, IDirectPlay2Impl* dp )
{
  TRACE( " for %s\n", debugstr_guid( riid ) );

  *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
                       sizeof( IDPLobbySPImpl ) );

  if( *ppvObj == NULL )
  {
    return DPERR_OUTOFMEMORY;
  }

  if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
  {
79
    IDPLobbySPImpl *This = (IDPLobbySPImpl *)*ppvObj;
80
    This->lpVtbl = &dpLobbySPVT;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  }
  else
  {
    /* Unsupported interface */
    HeapFree( GetProcessHeap(), 0, *ppvObj );
    *ppvObj = NULL;

    return E_NOINTERFACE;
  }

  /* Initialize it */
  if( DPLSP_CreateIUnknown( *ppvObj ) &&
      DPLSP_CreateDPLobbySP( *ppvObj, dp )
    )
  {
    IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );
    return S_OK;
  }

  /* Initialize failed, destroy it */
  DPLSP_DestroyDPLobbySP( *ppvObj );
  DPLSP_DestroyIUnknown( *ppvObj );

  HeapFree( GetProcessHeap(), 0, *ppvObj );
  *ppvObj = NULL;

  return DPERR_NOMEMORY;
}

static BOOL DPLSP_CreateIUnknown( LPVOID lpSP )
{
112
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
113

114
  This->unk = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->unk) ) );
115 116 117 118 119 120 121

  if ( This->unk == NULL )
  {
    return FALSE;
  }

  InitializeCriticalSection( &This->unk->DPLSP_lock );
122
  This->unk->DPLSP_lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDPLobbySPImpl*->DPLobbySPIUnknownData*->DPLSP_lock");
123 124 125 126 127 128

  return TRUE;
}

static BOOL DPLSP_DestroyIUnknown( LPVOID lpSP )
{
129
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
130

131
  This->unk->DPLSP_lock.DebugInfo->Spare[0] = 0;
132 133 134 135 136 137 138 139
  DeleteCriticalSection( &This->unk->DPLSP_lock );
  HeapFree( GetProcessHeap(), 0, This->unk );

  return TRUE;
}

static BOOL DPLSP_CreateDPLobbySP( LPVOID lpSP, IDirectPlay2Impl* dp )
{
140
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
141

142
  This->sp = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(This->sp) ) );
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

  if ( This->sp == NULL )
  {
    return FALSE;
  }

  This->sp->dplay = dp;

  /* Normally we should be keeping a reference, but since only the dplay
   * interface that created us can destroy us, we do not keep a reference
   * to it (ie we'd be stuck with always having one reference to the dplay
   * object, and hence us, around).
   * NOTE: The dp object does reference count us.
   *
   * FIXME: This is a kludge to get around a problem where a queryinterface
   *        is used to get a new interface and then is closed. We will then
   *        reference garbage. However, with this we will never deallocate
   *        the interface we store. The correct fix is to require all
   *        DP internal interfaces to use the This->dp2 interface which
   *        should be changed to This->dp
   */
  IDirectPlayX_AddRef( (LPDIRECTPLAY2)dp );


  return TRUE;
}

static BOOL DPLSP_DestroyDPLobbySP( LPVOID lpSP )
{
172
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)lpSP;
173 174 175 176 177 178 179 180

  HeapFree( GetProcessHeap(), 0, This->sp );

  return TRUE;
}

static
HRESULT WINAPI DPLSP_QueryInterface
181
( LPDPLOBBYSP iface,
182
  REFIID riid,
183
  LPVOID* ppvObj
184 185
)
{
186
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  TRACE("(%p)->(%s,%p)\n", This, debugstr_guid( riid ), ppvObj );

  *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
                       sizeof( *This ) );

  if( *ppvObj == NULL )
  {
    return DPERR_OUTOFMEMORY;
  }

  CopyMemory( *ppvObj, This, sizeof( *This )  );
  (*(IDPLobbySPImpl**)ppvObj)->ulInterfaceRef = 0;

  if( IsEqualGUID( &IID_IDPLobbySP, riid ) )
  {
202
    IDPLobbySPImpl *This = (IDPLobbySPImpl *)*ppvObj;
203
    This->lpVtbl = &dpLobbySPVT;
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  }
  else
  {
    /* Unsupported interface */
    HeapFree( GetProcessHeap(), 0, *ppvObj );
    *ppvObj = NULL;

    return E_NOINTERFACE;
  }

  IDPLobbySP_AddRef( (LPDPLOBBYSP)*ppvObj );

  return S_OK;
}

219
static
220 221 222 223
ULONG WINAPI DPLSP_AddRef
( LPDPLOBBYSP iface )
{
  ULONG ulInterfaceRefCount, ulObjRefCount;
224
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
225 226 227 228

  ulObjRefCount       = InterlockedIncrement( &This->unk->ulObjRef );
  ulInterfaceRefCount = InterlockedIncrement( &This->ulInterfaceRef );

229
  TRACE( "ref count incremented to %u:%u for %p\n",
230 231 232 233 234 235 236 237 238 239
         ulInterfaceRefCount, ulObjRefCount, This );

  return ulObjRefCount;
}

static
ULONG WINAPI DPLSP_Release
( LPDPLOBBYSP iface )
{
  ULONG ulInterfaceRefCount, ulObjRefCount;
240
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
241 242 243 244

  ulObjRefCount       = InterlockedDecrement( &This->unk->ulObjRef );
  ulInterfaceRefCount = InterlockedDecrement( &This->ulInterfaceRef );

245
  TRACE( "ref count decremented to %u:%u for %p\n",
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
         ulInterfaceRefCount, ulObjRefCount, This );

  /* Deallocate if this is the last reference to the object */
  if( ulObjRefCount == 0 )
  {
     DPLSP_DestroyDPLobbySP( This );
     DPLSP_DestroyIUnknown( This );
  }

  if( ulInterfaceRefCount == 0 )
  {
    HeapFree( GetProcessHeap(), 0, This );
  }

  return ulInterfaceRefCount;
}

263
static
264
HRESULT WINAPI IDPLobbySPImpl_AddGroupToGroup
265 266
( LPDPLOBBYSP iface,
  LPSPDATA_ADDREMOTEGROUPTOGROUP argtg
267 268
)
{
269
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
270 271 272 273
  FIXME( "(%p)->(%p):stub\n", This, argtg );
  return DP_OK;
}

274
static
275
HRESULT WINAPI IDPLobbySPImpl_AddPlayerToGroup
276 277
( LPDPLOBBYSP iface,
  LPSPDATA_ADDREMOTEPLAYERTOGROUP arptg
278 279
)
{
280
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
281 282 283 284
  FIXME( "(%p)->(%p):stub\n", This, arptg );
  return DP_OK;
}

285
static
286
HRESULT WINAPI IDPLobbySPImpl_CreateGroup
287 288
( LPDPLOBBYSP iface,
  LPSPDATA_CREATEREMOTEGROUP crg
289 290
)
{
291
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
292 293 294 295
  FIXME( "(%p)->(%p):stub\n", This, crg );
  return DP_OK;
}

296
static
297
HRESULT WINAPI IDPLobbySPImpl_CreateGroupInGroup
298 299
( LPDPLOBBYSP iface,
  LPSPDATA_CREATEREMOTEGROUPINGROUP crgig
300 301
)
{
302
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
303 304 305 306 307 308
  FIXME( "(%p)->(%p):stub\n", This, crgig );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_DeleteGroupFromGroup
309 310
( LPDPLOBBYSP iface,
  LPSPDATA_DELETEREMOTEGROUPFROMGROUP drgfg
311 312
)
{
313
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
314 315 316 317 318 319
  FIXME( "(%p)->(%p):stub\n", This, drgfg );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_DeletePlayerFromGroup
320 321
( LPDPLOBBYSP iface,
  LPSPDATA_DELETEREMOTEPLAYERFROMGROUP drpfg
322 323
)
{
324
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
325 326 327 328 329 330
  FIXME( "(%p)->(%p):stub\n", This, drpfg );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_DestroyGroup
331 332
( LPDPLOBBYSP iface,
  LPSPDATA_DESTROYREMOTEGROUP drg
333 334
)
{
335
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
336 337 338 339 340 341
  FIXME( "(%p)->(%p):stub\n", This, drg );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_EnumSessionsResponse
342 343
( LPDPLOBBYSP iface,
  LPSPDATA_ENUMSESSIONSRESPONSE er
344 345
)
{
346
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
347 348 349 350 351 352
  FIXME( "(%p)->(%p):stub\n", This, er );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_GetSPDataPointer
353 354
( LPDPLOBBYSP iface,
  LPVOID* lplpData
355 356
)
{
357
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
358 359 360 361 362 363
  FIXME( "(%p)->(%p):stub\n", This, lplpData );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_HandleMessage
364 365
( LPDPLOBBYSP iface,
  LPSPDATA_HANDLEMESSAGE hm
366 367
)
{
368
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
369 370 371 372 373 374
  FIXME( "(%p)->(%p):stub\n", This, hm );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_SendChatMessage
375 376
( LPDPLOBBYSP iface,
  LPSPDATA_CHATMESSAGE cm
377 378
)
{
379
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
380 381 382 383 384 385
  FIXME( "(%p)->(%p):stub\n", This, cm );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_SetGroupName
386 387
( LPDPLOBBYSP iface,
  LPSPDATA_SETREMOTEGROUPNAME srgn
388 389
)
{
390
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
391 392 393 394 395 396
  FIXME( "(%p)->(%p):stub\n", This, srgn );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_SetPlayerName
397 398
( LPDPLOBBYSP iface,
  LPSPDATA_SETREMOTEPLAYERNAME srpn
399 400
)
{
401
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
402 403 404 405 406 407
  FIXME( "(%p)->(%p):stub\n", This, srpn );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_SetSessionDesc
408 409
( LPDPLOBBYSP iface,
  LPSPDATA_SETSESSIONDESC ssd
410 411
)
{
412
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
413 414 415 416 417 418
  FIXME( "(%p)->(%p):stub\n", This, ssd );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_SetSPDataPointer
419 420
( LPDPLOBBYSP iface,
  LPVOID lpData
421 422
)
{
423
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
424 425 426 427 428 429
  FIXME( "(%p)->(%p):stub\n", This, lpData );
  return DP_OK;
}

static
HRESULT WINAPI IDPLobbySPImpl_StartSession
430 431
( LPDPLOBBYSP iface,
  LPSPDATA_STARTSESSIONCOMMAND ssc
432 433
)
{
434
  IDPLobbySPImpl *This = (IDPLobbySPImpl *)iface;
435 436 437 438 439
  FIXME( "(%p)->(%p):stub\n", This, ssc );
  return DP_OK;
}


440
static const IDPLobbySPVtbl dpLobbySPVT =
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
{

  DPLSP_QueryInterface,
  DPLSP_AddRef,
  DPLSP_Release,

  IDPLobbySPImpl_AddGroupToGroup,
  IDPLobbySPImpl_AddPlayerToGroup,
  IDPLobbySPImpl_CreateGroup,
  IDPLobbySPImpl_CreateGroupInGroup,
  IDPLobbySPImpl_DeleteGroupFromGroup,
  IDPLobbySPImpl_DeletePlayerFromGroup,
  IDPLobbySPImpl_DestroyGroup,
  IDPLobbySPImpl_EnumSessionsResponse,
  IDPLobbySPImpl_GetSPDataPointer,
  IDPLobbySPImpl_HandleMessage,
  IDPLobbySPImpl_SendChatMessage,
458 459
  IDPLobbySPImpl_SetGroupName,
  IDPLobbySPImpl_SetPlayerName,
460 461 462 463 464
  IDPLobbySPImpl_SetSessionDesc,
  IDPLobbySPImpl_SetSPDataPointer,
  IDPLobbySPImpl_StartSession

};