Ignore:
Timestamp:
Mar 14, 2001, 12:13:28 AM (24 years ago)
Author:
hugh
Message:

Synced with WINE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/DPlayX/dplaysp.cpp

    r4446 r5311  
    1 // $Id: dplaysp.cpp,v 1.3 2000-10-06 19:49:04 hugh Exp $
     1// $Id: dplaysp.cpp,v 1.4 2001-03-13 23:13:27 hugh Exp $
    22/* This contains the implementation of the interface Service
    33 * Providers require to communicate with Direct Play
     
    5858  IDirectPlay2Impl* dplay; /* FIXME: This should perhaps be iface not impl */
    5959
    60   LPVOID lpPlayerData; /* FIXME: Need to figure out how this actually behaves */
    61   DWORD dwPlayerDataSize;
    6260} DirectPlaySPData;
    6361
     
    7573/* Forward declaration of virtual tables */
    7674extern ICOM_VTABLE(IDirectPlaySP) directPlaySPVT;
     75
     76/* This structure is passed to the DP object for safe keeping */
     77typedef struct tagDP_SPPLAYERDATA
     78{
     79  LPVOID lpPlayerLocalData;
     80  DWORD  dwPlayerLocalDataSize;
     81
     82  LPVOID lpPlayerRemoteData;
     83  DWORD  dwPlayerRemoteDataSize;
     84} DP_SPPLAYERDATA, *LPDP_SPPLAYERDATA;
    7785
    7886
     
    177185  /* IDirectPlayX_AddRef( (LPDIRECTPLAY2)dp ); */
    178186
     187  /* FIXME: This is a kludge to get around a problem where a queryinterface
     188   *        is used to get a new interface and then is closed. We will then
     189   *        reference garbage. However, with this we will never deallocate
     190   *        the interface we store. The correct fix is to require all
     191   *        DP internal interfaces to use the This->dp2 interface which
     192   *        should be changed to This->dp
     193   */
     194  IDirectPlayX_AddRef( (LPDIRECTPLAY2)dp );
     195
    179196  return TRUE;
    180197}
     
    375392)
    376393{
    377   ICOM_THIS(IDirectPlaySPImpl,iface);
    378 
    379   TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() );
    380   FIXME( "(%p)->(0x%08lx,%p,%p,0x%08lx): stub\n",
     394  HRESULT hr;
     395  LPDP_SPPLAYERDATA lpPlayerData;
     396  ICOM_THIS(IDirectPlaySPImpl,iface);
     397
     398/*  TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() ); */
     399  TRACE( "(%p)->(0x%08lx,%p,%p,0x%08lx)\n",
    381400         This, idPlayer, lplpData, lpdwDataSize, dwFlags );
    382401
     402  hr = DP_GetSPPlayerData( This->sp->dplay, idPlayer, (LPVOID*)&lpPlayerData );
     403
     404  if( FAILED(hr) )
     405  {
     406    TRACE( "Couldn't get player data: %s\n", DPLAYX_HresultToString(hr) );
     407    return DPERR_INVALIDPLAYER;
     408  }
     409
    383410  /* What to do in the case where there is nothing set yet? */
    384 
    385   *lplpData     = This->sp->lpPlayerData;
    386   *lpdwDataSize = This->sp->dwPlayerDataSize;
    387 
    388   return DP_OK;
     411  if( dwFlags == DPSET_LOCAL )
     412  {
     413    if( lpPlayerData->lpPlayerLocalData )
     414    {
     415      HeapFree( GetProcessHeap(), 0, lpPlayerData->lpPlayerLocalData );
     416    }
     417
     418    *lplpData     = lpPlayerData->lpPlayerLocalData;
     419    *lpdwDataSize = lpPlayerData->dwPlayerLocalDataSize;
     420  }
     421  else if( dwFlags == DPSET_REMOTE )
     422  {
     423    if( lpPlayerData->lpPlayerRemoteData )
     424    {
     425      HeapFree( GetProcessHeap(), 0, lpPlayerData->lpPlayerRemoteData );
     426    }
     427
     428    *lplpData     = lpPlayerData->lpPlayerRemoteData;
     429    *lpdwDataSize = lpPlayerData->dwPlayerRemoteDataSize;
     430  }
     431
     432  if( *lplpData == NULL )
     433  {
     434    hr = DPERR_GENERIC;
     435  }
     436
     437  return hr;
    389438}
    390439
     
    403452  ICOM_THIS(IDirectPlaySPImpl,iface);
    404453
    405   TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() );
     454/*  TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() ); */
    406455  FIXME( "(%p)->(%p,0x%08lx,%p): mostly stub\n",
    407456         This, lpMessageBody, dwMessageBodySize, lpMessageHeader );
     
    421470  {
    422471    /* Name server needs to handle this request */
     472    /* FIXME: This should be done in direct play handler */
    423473    case DPMSGCMD_ENUMSESSIONSREQUEST:
    424474    {
     
    442492
    443493    /* Name server needs to handle this request */
     494    /* FIXME: This should be done in direct play handler */
    444495    case DPMSGCMD_ENUMSESSIONSREPLY:
    445496    {
     
    450501
    451502      /* No reply expected */
    452 
    453       break;
    454     }
    455 
    456     case DPMSGCMD_GETNAMETABLE:
    457     case DPMSGCMD_GETNAMETABLEREPLY:
    458     case DPMSGCMD_NEWPLAYERIDREPLY:
    459     case DPMSGCMD_REQUESTNEWPLAYERID:
     503      hr = DP_OK;
     504
     505      break;
     506    }
     507
     508    /* Pass everything else to Direct Play */
     509    default:
    460510    {
    461511      DPSP_REPLYDATA data;
     
    465515
    466516      /* Pass this message to the dplay interface to handle */
    467       DP_HandleMessage( This->sp->dplay, lpMessageBody, dwMessageBodySize,
     517      hr = DP_HandleMessage( This->sp->dplay, lpMessageBody, dwMessageBodySize,
    468518                        lpMessageHeader, wCommandId, wVersion,
    469519                        &data.lpMessage, &data.dwMessageSize );
     
    488538      break;
    489539    }
    490 
    491     default:
    492       FIXME( "Unknown Command of %u and size 0x%08lx\n",
    493              lpMsg->wCommandId, dwMessageBodySize );
    494540  }
    495541
     
    748794)
    749795{
    750   ICOM_THIS(IDirectPlaySPImpl,iface);
    751 
    752   /* FIXME: I'm not sure if this stuff should be associated with the DPlay
    753    *        player lists. How else would this stuff get deleted?
    754    */
    755 
    756   TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() );
    757   FIXME( "(%p)->(0x%08lx,%p,0x%08lx,0x%08lx): stub\n",
     796  HRESULT           hr;
     797  LPDP_SPPLAYERDATA lpPlayerEntry;
     798  LPVOID            lpPlayerData;
     799
     800  ICOM_THIS(IDirectPlaySPImpl,iface);
     801
     802/*  TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() ); */
     803  TRACE( "(%p)->(0x%08lx,%p,0x%08lx,0x%08lx)\n",
    758804         This, idPlayer, lpData, dwDataSize, dwFlags );
    759805
    760   This->sp->lpPlayerData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
    761 
    762   This->sp->dwPlayerDataSize = dwDataSize;
    763   CopyMemory( This->sp->lpPlayerData, lpData, dwDataSize );
    764 
    765   return DP_OK;
     806  hr = DP_GetSPPlayerData( This->sp->dplay, idPlayer, (LPVOID*)&lpPlayerEntry );
     807  if( FAILED(hr) )
     808  {
     809    /* Player must not exist */
     810    return DPERR_INVALIDPLAYER;
     811  }
     812
     813  lpPlayerData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
     814  CopyMemory( lpPlayerData, lpData, dwDataSize );
     815
     816  if( dwFlags == DPSET_LOCAL )
     817  {
     818    lpPlayerEntry->lpPlayerLocalData = lpPlayerData;
     819    lpPlayerEntry->dwPlayerLocalDataSize = dwDataSize;
     820  }
     821  else if( dwFlags == DPSET_REMOTE )
     822  {
     823    lpPlayerEntry->lpPlayerRemoteData = lpPlayerData;
     824    lpPlayerEntry->dwPlayerRemoteDataSize = dwDataSize;
     825  }
     826
     827  hr = DP_SetSPPlayerData( This->sp->dplay, idPlayer, lpPlayerEntry );
     828
     829  return hr;
    766830}
    767831
     
    789853)
    790854{
    791   ICOM_THIS(IDirectPlaySPImpl,iface);
    792 
    793   TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() );
     855  HRESULT hr = DP_OK;
     856  ICOM_THIS(IDirectPlaySPImpl,iface);
     857
     858/*  TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() ); */
    794859  TRACE( "(%p)->(%p,%p,0x%08lx)\n",
    795860         This, lplpData, lpdwDataSize, dwFlags );
     
    797862#if 0
    798863  /* This is what the documentation says... */
    799   if( dwFlags != 0 )
     864  if( dwFlags != DPSET_REMOTE )
    800865  {
    801866    return DPERR_INVALIDPARAMS;
     
    806871   * thing?
    807872   */
    808   if( dwFlags != 0 )
     873  if( dwFlags != DPSET_REMOTE )
    809874  {
    810875    FIXME( "Undocumented dwFlags 0x%08lx used\n", dwFlags );
    811876  }
    812877#endif
     878
     879  /* FIXME: What to do in the case where this isn't initialized yet? */
    813880
    814881  /* Yes, we're supposed to return a pointer to the memory we have stored! */
     
    817884    *lpdwDataSize = This->sp->dwSpRemoteDataSize;
    818885    *lplpData     = This->sp->lpSpRemoteData;
     886
     887    if( This->sp->lpSpRemoteData == NULL )
     888    {
     889      hr = DPERR_GENERIC;
     890    }
    819891  }
    820892  else if( dwFlags == DPSET_LOCAL )
     
    822894    *lpdwDataSize = This->sp->dwSpLocalDataSize;
    823895    *lplpData     = This->sp->lpSpLocalData;
    824   }
    825 
    826   return DP_OK;
     896
     897    if( This->sp->lpSpLocalData == NULL )
     898    {
     899      hr = DPERR_GENERIC;
     900    }
     901  }
     902
     903  return hr;
    827904}
    828905
     
    838915  ICOM_THIS(IDirectPlaySPImpl,iface);
    839916
    840   TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() );
     917/*  TRACE( "Called on process 0x%08lx\n", GetCurrentProcessId() ); */
    841918  TRACE( "(%p)->(%p,0x%08lx,0x%08lx)\n",
    842919         This, lpData, dwDataSize, dwFlags );
     
    844921#if 0
    845922  /* This is what the documentation says... */
    846   if( dwFlags != 0 )
     923  if( dwFlags != DPSET_REMOTE )
    847924  {
    848925    return DPERR_INVALIDPARAMS;
     
    853930   * thing?
    854931   */
    855   if( dwFlags != 0 )
     932  if( dwFlags != DPSET_REMOTE )
    856933  {
    857934    FIXME( "Undocumented dwFlags 0x%08lx used\n", dwFlags );
     
    859936#endif
    860937
    861   if( dwFlags == DPSET_REMOTE )
    862   {
    863     lpSpData = DPLAYX_PrivHeapAlloc( HEAP_ZERO_MEMORY, dwDataSize );
    864   }
    865   else
    866   {
    867     lpSpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
    868   }
    869 
     938  lpSpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
    870939  CopyMemory( lpSpData, lpData, dwDataSize );
    871940
     
    873942  if( dwFlags == DPSET_REMOTE )
    874943  {
    875     /* FIXME: This doesn't strictly make sense as there is no means to share
    876      *        this shared data. Must be misinterpreting something...
    877      */
    878944    if( This->sp->lpSpRemoteData )
    879945    {
    880       DPLAYX_PrivHeapFree( This->sp->lpSpRemoteData );
    881     }
    882 
    883     /* NOTE: dwDataSize is also stored in the heap structure */
     946      HeapFree( GetProcessHeap(), 0, This->sp->lpSpRemoteData );
     947    }
     948
    884949    This->sp->dwSpRemoteDataSize = dwDataSize;
    885950    This->sp->lpSpRemoteData = lpSpData;
     
    933998  IDirectPlaySPImpl_SendComplete
    934999};
     1000
     1001
     1002/* DP external interfaces to call into DPSP interface */
     1003
     1004/* Allocate the structure */
     1005extern LPVOID DPSP_CreateSPPlayerData(void)
     1006{
     1007  TRACE( "Creating SPPlayer data struct\n" );
     1008  return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
     1009                    sizeof( DP_SPPLAYERDATA ) );
     1010}
     1011
Note: See TracChangeset for help on using the changeset viewer.