Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: trnotify.cpp
  6. * Content: Implementation of the IDirectXVoiceNotify interface
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/26/99 rodtoll Created
  12. * 08/03/99 rodtoll Updated with new parameters for Initialize
  13. * Updated for new initialization order
  14. * 08/05/99 rodtoll Added hook for host migration
  15. * 08/05/99 rodtoll Added new receive parameter
  16. * 08/10/99 rodtoll Initial host migration
  17. * 08/31/99 rodtoll Updated to use new debug libs
  18. * 09/14/99 rodtoll Updated to reflect new parameters for Initialize call
  19. * 09/20/99 rodtoll Updated to check for out of memory errors
  20. * 09/28/99 rodtoll Added release on server interface created by host migration
  21. * 10/05/99 rodtoll Additional comments
  22. * 10/19/99 rodtoll Fix: Bug #113904 - Shutdown issues
  23. * - Added reference count for notify interface, allows
  24. * determination if stopsession should be called from release
  25. * - Fixed host migration break caused by Fix.
  26. * 10/25/99 rodtoll Fix: Bug #114098 - Release/Addref failure from multiple threads
  27. * 12/16/99 rodtoll Fix: Bug #122629 - Updated for new host migration
  28. * 04/07/2000 rodtoll Updated to match changes in DP <--> DPV interface
  29. * 07/22/20000 rodtoll Bug #40296, 38858 - Crashes due to shutdown race condition
  30. * Now ensures that all threads from transport have left and that
  31. * all notificatinos have been processed before shutdown is complete.
  32. * 01/04/2001 rodtoll WinBug #94200 - Remove stray comments
  33. *
  34. ***************************************************************************/
  35. #include "dxvoicepch.h"
  36. extern HRESULT DVC_Create(LPDIRECTVOICECLIENTOBJECT *piDVC);
  37. extern HRESULT DVS_Create(LPDIRECTVOICESERVEROBJECT *piDVS);
  38. #undef DPF_MODNAME
  39. #define DPF_MODNAME "DV_HostMigrate"
  40. //
  41. // DV_HostMigrate
  42. //
  43. // Called by DV_NotifyEvent to handle host migration
  44. //
  45. void DV_HostMigrate( LPDIRECTVOICEOBJECT lpdv, DVID dvidNewHost )
  46. {
  47. LPDIRECTVOICECLIENTOBJECT lpdvcClientObject = NULL;
  48. LPDIRECTVOICESERVEROBJECT lpdvsServerObject = NULL;
  49. DVSESSIONDESC dvSessionDesc;
  50. HRESULT hr = DP_OK;
  51. DPFX(DPFPREP, DVF_INFOLEVEL, "DV_HostMigrate: Notified of a host migration. New Host = 0x%x", dvidNewHost );
  52. // We're the new host! Create and setup a server object for the session host
  53. // When other clients receive the host migrate message this object will
  54. // be contacted with join messages.
  55. //
  56. // If this case is active, we should be a client, afterall why would we host migrate
  57. // to ourselves.
  58. //
  59. if( dvidNewHost == lpdv->lpDVTransport->GetLocalID() )
  60. {
  61. lpdvcClientObject = (LPDIRECTVOICECLIENTOBJECT) lpdv;
  62. DPFX(DPFPREP, DVF_INFOLEVEL, "DV_HostMigrate: We're the new host -- Congrats!" );
  63. // Create a new server object
  64. DVS_Create( &lpdvsServerObject );
  65. // FYI: Casts to a DXTransport, which should be safe unless we implement a different transport
  66. // If you implement different transport object interface then a QI type system will be needed
  67. //
  68. CDirectVoiceDirectXTransport *transport = (CDirectVoiceDirectXTransport *) lpdv->lpDVTransport;
  69. // Initialize the server object
  70. hr = DV_Initialize( lpdvsServerObject, transport->GetTransportInterface(), NULL, NULL, NULL, 0 );
  71. if( FAILED( hr ) )
  72. {
  73. DPFX(DPFPREP, DVF_ERRORLEVEL, "DV_Initialize on new host object failed. hr=0x%x", hr );
  74. return;
  75. }
  76. dvSessionDesc.dwSize = sizeof( DVSESSIONDESC );
  77. hr = lpdvcClientObject->lpDVClientEngine->GetSessionDesc( &dvSessionDesc );
  78. if( FAILED( hr ) )
  79. {
  80. DPFX(DPFPREP, DVF_ERRORLEVEL, "GetSessionInfo failed. hr=0x%x", hr );
  81. lpdvsServerObject->lIntRefCnt = 1;
  82. DVS_Release( lpdvsServerObject );
  83. return;
  84. }
  85. DPFX(DPFPREP, DVF_INFOLEVEL, "DV_HostMigrate: Starting new object" );
  86. lpdvsServerObject->lpDVServerEngine->HostMigrateStart(&dvSessionDesc);
  87. DPFX(DPFPREP, DVF_INFOLEVEL, "DV_HostMigrate: WStartup Complete" );
  88. }
  89. DPFX(DPFPREP, DVF_INFOLEVEL, "DV_HostMigrate: Informing local engine of new host" );
  90. lpdv->lpDVEngine->MigrateHost( dvidNewHost, (LPDIRECTPLAYVOICESERVER) lpdvsServerObject );
  91. // Ok. We need an extra reference to this object to prevent
  92. // the code which detects it needs to call StopSession for
  93. // people who don't call StopSession before calling Release.
  94. /*
  95. // Release this function's reference on the object
  96. if( lpdvsServerObject != NULL )
  97. {
  98. DVS_Release( lpdvsServerObject );
  99. }*/
  100. }
  101. #undef DPF_MODNAME
  102. #define DPF_MODNAME "DV_NotifyEvent"
  103. STDMETHODIMP DV_NotifyEvent( LPDIRECTVOICENOTIFYOBJECT lpDVN, DWORD dwNotifyType, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
  104. {
  105. switch( dwNotifyType )
  106. {
  107. case DVEVENT_MIGRATEHOST:
  108. lpDVN->lpDV->lpDVEngine->MigrateHost( 0, NULL );
  109. break;
  110. case DVEVENT_STARTSESSION:
  111. lpDVN->lpDV->lpDVEngine->StartTransportSession();
  112. break;
  113. case DVEVENT_STOPSESSION:
  114. lpDVN->lpDV->lpDVEngine->StopTransportSession();
  115. break;
  116. case DVEVENT_ADDPLAYER:
  117. lpDVN->lpDV->lpDVEngine->AddPlayer( (DVID) dwParam1 );
  118. break;
  119. case DVEVENT_REMOVEPLAYER:
  120. lpDVN->lpDV->lpDVEngine->RemovePlayer( (DVID) dwParam1 );
  121. break;
  122. case DVEVENT_CREATEGROUP:
  123. lpDVN->lpDV->lpDVEngine->CreateGroup( (DVID) dwParam1 );
  124. break;
  125. case DVEVENT_DELETEGROUP:
  126. lpDVN->lpDV->lpDVEngine->DeleteGroup( (DVID) dwParam1 );
  127. break;
  128. case DVEVENT_ADDPLAYERTOGROUP:
  129. lpDVN->lpDV->lpDVEngine->AddPlayerToGroup( (DVID) dwParam1, (DVID) dwParam2 );
  130. break;
  131. case DVEVENT_REMOVEPLAYERFROMGROUP:
  132. lpDVN->lpDV->lpDVEngine->RemovePlayerFromGroup( (DVID) dwParam1, (DVID) dwParam2 );
  133. break;
  134. case DVEVENT_SENDCOMPLETE:
  135. lpDVN->lpDV->lpDVEngine->SendComplete( (PDVEVENTMSG_SENDCOMPLETE) dwParam1 );
  136. break;
  137. }
  138. return DV_OK;
  139. }
  140. #undef DPF_MODNAME
  141. #define DPF_MODNAME "DV_ReceiveSpeechMessage"
  142. STDMETHODIMP DV_ReceiveSpeechMessage( LPDIRECTVOICENOTIFYOBJECT lpDVN, DVID dvidSource, DVID dvidTo, LPVOID lpMessage, DWORD dwSize )
  143. {
  144. lpDVN->lpDV->lpDVEngine->ReceiveSpeechMessage( dvidSource, lpMessage, dwSize );
  145. return DV_OK;
  146. }
  147. #undef DPF_MODNAME
  148. #define DPF_MODNAME "DV_Notify_Initialize"
  149. STDMETHODIMP DV_Notify_Initialize( LPDIRECTVOICENOTIFYOBJECT lpDVN )
  150. {
  151. return lpDVN->lpDV->lpDVTransport->Initialize();
  152. }
  153. #undef DPF_MODNAME
  154. #define DPF_MODNAME "DV_Notify_AddRef"
  155. STDMETHODIMP DV_Notify_AddRef(LPDIRECTVOICENOTIFYOBJECT lpDVN )
  156. {
  157. lpDVN->lpDV->lpDVTransport->AddRef();
  158. return 0;
  159. }
  160. #undef DPF_MODNAME
  161. #define DPF_MODNAME "DVC_Notify_Release"
  162. STDAPI DVC_Notify_Release(LPDIRECTVOICENOTIFYOBJECT lpDVN )
  163. {
  164. lpDVN->lpDV->lpDVTransport->Release();
  165. return 0;
  166. }
  167. #undef DPF_MODNAME
  168. #define DPF_MODNAME "DVC_Notify_QueryInterface"
  169. STDMETHODIMP DVC_Notify_QueryInterface(LPDIRECTVOICENOTIFYOBJECT lpDVN, REFIID riid, LPVOID * ppvObj )
  170. {
  171. return DVC_QueryInterface( (LPDIRECTVOICECLIENTOBJECT) lpDVN->lpDV, riid, ppvObj );
  172. }
  173. #undef DPF_MODNAME
  174. #define DPF_MODNAME "DVS_Notify_QueryInterface"
  175. STDMETHODIMP DVS_Notify_QueryInterface(LPDIRECTVOICENOTIFYOBJECT lpDVN, REFIID riid, LPVOID * ppvObj )
  176. {
  177. return DVS_QueryInterface( (LPDIRECTVOICESERVEROBJECT) lpDVN->lpDV, riid, ppvObj );
  178. }
  179. #undef DPF_MODNAME
  180. #define DPF_MODNAME "DVS_Notify_Release"
  181. STDAPI DVS_Notify_Release(LPDIRECTVOICENOTIFYOBJECT lpDVN )
  182. {
  183. lpDVN->lpDV->lpDVTransport->Release();
  184. return 0;
  185. }