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.

240 lines
4.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 - 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: vnametbl.h
  6. * Content: Voice Name Table Routines
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/26/00 rodtoll Created
  12. * 06/02/00 rodtoll Updated so host migration algorithm returns ID as well as order ID
  13. * 06/21/2000 rodtoll Fixed bug in error handling (not yet encountered -- but good to fix).
  14. * 07/01/2000 rodtoll Bug #38280 - DVMSGID_DELETEVOICEPLAYER messages are being sent in non-peer to peer sessions
  15. * Nametable will now only unravel with messages if session is peer to peer.
  16. * 07/09/2000 rodtoll Added signature bytes
  17. * 08/28/2000 masonb Voice Merge: Changed classhash.h to classhashvc.h
  18. * 04/09/2001 rodtoll WINBUG #364126 - DPVoice : Memory leak when Initializing 2 Voice Servers with same DPlay transport
  19. *
  20. ***************************************************************************/
  21. #ifndef __NAMETABLE_H
  22. #define __NAMETABLE_H
  23. #undef DPF_SUBCOMP
  24. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  25. #define VSIG_VOICENAMETABLE 'BTNV'
  26. #define VSIG_VOICENAMETABLE_FREE 'BTN_'
  27. #undef DPF_MODNAME
  28. #define DPF_MODNAME "ClassHash_Hash"
  29. inline DWORD_PTR ClassHash_Hash( const DVID &dvidKey, UINT_PTR HashBitCount )
  30. {
  31. DWORD_PTR hashResult;
  32. hashResult = dvidKey;
  33. // Clear upper bits
  34. hashResult <<= ((sizeof(DWORD_PTR)*8)-HashBitCount);
  35. // Restore value
  36. hashResult >>= ((sizeof(DWORD_PTR)*8)-HashBitCount);
  37. return hashResult;
  38. }
  39. #define VOICE_NAMETABLE_START_BITDEPTH 6
  40. #define VOICE_NAMETABLE_GROW_BITDEPTH 2
  41. volatile class CVoiceNameTable
  42. {
  43. public:
  44. #undef DPF_MODNAME
  45. #define DPF_MODNAME "CVoiceNameTable::CVoiceNameTable"
  46. CVoiceNameTable( )
  47. {
  48. m_dwSignature = VSIG_VOICENAMETABLE;
  49. m_fInitialized = FALSE;
  50. };
  51. #undef DPF_MODNAME
  52. #define DPF_MODNAME "CVoiceNameTable::~CVoiceNameTable"
  53. ~CVoiceNameTable()
  54. {
  55. DeInitialize(FALSE, NULL, NULL);
  56. m_dwSignature = VSIG_VOICENAMETABLE_FREE;
  57. }
  58. HRESULT DeInitialize(BOOL fUnRavel, PVOID pvContext, LPDVMESSAGEHANDLER pvMessageHandler);
  59. #undef DPF_MODNAME
  60. #define DPF_MODNAME "CVoiceNameTable::Initialize"
  61. inline HRESULT Initialize()
  62. {
  63. BOOL fResult;
  64. if (!DNInitializeCriticalSection( &m_csTableLock ))
  65. {
  66. return DVERR_OUTOFMEMORY;
  67. }
  68. fResult = m_nameTable.Initialize( VOICE_NAMETABLE_START_BITDEPTH, VOICE_NAMETABLE_GROW_BITDEPTH );
  69. if( !fResult )
  70. {
  71. DPFX(DPFPREP, 0, "Failed to initialize hash table" );
  72. DNDeleteCriticalSection( &m_csTableLock );
  73. return DVERR_GENERIC;
  74. }
  75. m_fInitialized = TRUE;
  76. return DV_OK;
  77. };
  78. DWORD GetLowestHostOrderID(DVID *pdvidHost);
  79. #undef DPF_MODNAME
  80. #define DPF_MODNAME "CVoiceNameTable::IsEntry"
  81. BOOL IsEntry( const DVID dvidID )
  82. {
  83. BOOL fResult;
  84. CVoicePlayer *pEntry;
  85. Lock();
  86. fResult = m_nameTable.Find( dvidID, &pEntry );
  87. UnLock();
  88. return fResult;
  89. }
  90. #undef DPF_MODNAME
  91. #define DPF_MODNAME "CVoiceNameTable::GetEntry"
  92. inline HRESULT GetEntry( const DVID dvidID, CVoicePlayer **ppEntry, BOOL fAddReference )
  93. {
  94. BOOL fFound;
  95. Lock();
  96. fFound = m_nameTable.Find( dvidID, ppEntry );
  97. if( !fFound )
  98. {
  99. *ppEntry = NULL;
  100. UnLock();
  101. return DVERR_INVALIDPLAYER;
  102. }
  103. DNASSERT( *ppEntry != NULL );
  104. if( fAddReference )
  105. {
  106. (*ppEntry)->AddRef();
  107. }
  108. UnLock();
  109. return DV_OK;
  110. }
  111. #undef DPF_MODNAME
  112. #define DPF_MODNAME "CVoiceNameTable::AddEntry"
  113. inline HRESULT AddEntry( const DVID dvidID, CVoicePlayer *pEntry )
  114. {
  115. BOOL fFound;
  116. CVoicePlayer *pTmpEntry;
  117. Lock();
  118. fFound = m_nameTable.Find( dvidID, &pTmpEntry );
  119. if( fFound )
  120. {
  121. UnLock();
  122. return DVERR_GENERIC;
  123. }
  124. pEntry->AddRef();
  125. fFound = m_nameTable.Insert( dvidID, pEntry );
  126. if( !fFound )
  127. {
  128. pEntry->Release();
  129. UnLock();
  130. return DVERR_GENERIC;
  131. }
  132. UnLock();
  133. return DV_OK;
  134. }
  135. #undef DPF_MODNAME
  136. #define DPF_MODNAME "CVoiceNameTable::DeleteEntry"
  137. inline HRESULT DeleteEntry( const DVID dvidID )
  138. {
  139. BOOL fFound;
  140. CVoicePlayer *pTmpEntry;
  141. Lock();
  142. fFound = m_nameTable.Find( dvidID, &pTmpEntry );
  143. if( !fFound )
  144. {
  145. UnLock();
  146. return DVERR_GENERIC;
  147. }
  148. m_nameTable.Remove( dvidID );
  149. DNASSERT( pTmpEntry != NULL );
  150. // Regardless of if it was found..
  151. // Drop the reference count
  152. pTmpEntry->Release();
  153. if( !fFound )
  154. {
  155. UnLock();
  156. return DVERR_GENERIC;
  157. }
  158. UnLock();
  159. return DV_OK;
  160. }
  161. #undef DPF_MODNAME
  162. #define DPF_MODNAME "CVoiceNameTable::Lock"
  163. inline void Lock()
  164. {
  165. DNEnterCriticalSection( &m_csTableLock );
  166. }
  167. #undef DPF_MODNAME
  168. #define DPF_MODNAME "CVoiceNameTable::UnLock"
  169. inline void UnLock()
  170. {
  171. DNLeaveCriticalSection( &m_csTableLock );
  172. }
  173. protected:
  174. DWORD m_dwSignature;
  175. CClassHash<CVoicePlayer,DVID> m_nameTable;
  176. DNCRITICAL_SECTION m_csTableLock;
  177. BOOL m_fInitialized;
  178. };
  179. #undef DPF_MODNAME
  180. #endif