Leaked source code of windows server 2003
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.

659 lines
16 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: NTEntry.h
  6. * Content: NameTable Entry Object Header File
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/07/00 mjn Created
  12. * 04/06/00 mjn Added AvailableEvent to block pre-ADD_PLAYER-notification sends
  13. * 05/05/00 mjn Added GetConnectionRef()
  14. * 07/22/00 mjn Added m_dwDNETVersion
  15. * 07/29/00 mjn Added SetIndicated(),ClearIndicated(),IsIndicated()
  16. * 07/30/00 mjn Added m_dwDestoyReason
  17. * 08/02/00 mjn Added m_bilinkQueuedMsgs
  18. * 08/05/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  19. * 08/08/00 mjn Added SetCreated(),ClearCreated(),IsCreated()
  20. * mjn Added SetNeedToDestroy(),ClearNeedToDestroy(),IsNeedToDestroy()
  21. * 09/06/00 mjn Changed SetAddress() to return void instead of HRESULT
  22. * 09/12/00 mjn Added NAMETABLE_ENTRY_FLAG_IN_USE
  23. * 09/17/00 mjn Added m_lNotifyRefCount
  24. * 01/25/01 mjn Fixed 64-bit alignment problem when unpacking entries
  25. *@@END_MSINTERNAL
  26. *
  27. ***************************************************************************/
  28. #ifndef __NTENTRY_H__
  29. #define __NTENTRY_H__
  30. #undef DPF_SUBCOMP
  31. #define DPF_SUBCOMP DN_SUBCOMP_CORE
  32. //**********************************************************************
  33. // Constant definitions
  34. //**********************************************************************
  35. //
  36. // NameTable Entry Status Flags:
  37. //
  38. // INDICATED App was given an INDICATE_CONNECTION message
  39. //
  40. // CREATED App was given a CREATE_PLAYER message
  41. //
  42. // AVAILABLE The entry is available for use.
  43. //
  44. // CONNECTING The player is in the process of connecting.
  45. //
  46. // DISCONNECTING The player/group is in the process of disconnecting.
  47. //
  48. #define NAMETABLE_ENTRY_FLAG_LOCAL 0x00001
  49. #define NAMETABLE_ENTRY_FLAG_HOST 0x00002
  50. #define NAMETABLE_ENTRY_FLAG_ALL_PLAYERS_GROUP 0x00004
  51. #define NAMETABLE_ENTRY_FLAG_GROUP 0x00010
  52. #define NAMETABLE_ENTRY_FLAG_GROUP_MULTICAST 0x00020
  53. #define NAMETABLE_ENTRY_FLAG_GROUP_AUTODESTRUCT 0x00040
  54. #define NAMETABLE_ENTRY_FLAG_PEER 0x00100
  55. #define NAMETABLE_ENTRY_FLAG_CLIENT 0x00200
  56. #define NAMETABLE_ENTRY_FLAG_SERVER 0x00400
  57. #define NAMETABLE_ENTRY_FLAG_CONNECTING 0x01000
  58. #define NAMETABLE_ENTRY_FLAG_AVAILABLE 0x02000
  59. #define NAMETABLE_ENTRY_FLAG_DISCONNECTING 0x04000
  60. #define NAMETABLE_ENTRY_FLAG_INDICATED 0x10000 // INDICATE_CONNECT
  61. #define NAMETABLE_ENTRY_FLAG_CREATED 0x20000 // CREATE_PLAYER
  62. #define NAMETABLE_ENTRY_FLAG_NEED_TO_DESTROY 0x40000
  63. #define NAMETABLE_ENTRY_FLAG_IN_USE 0x80000
  64. //**********************************************************************
  65. // Macro definitions
  66. //**********************************************************************
  67. //**********************************************************************
  68. // Structure definitions
  69. //**********************************************************************
  70. typedef struct IDirectPlay8Address IDirectPlay8Address;
  71. typedef struct _DIRECTNETOBJECT DIRECTNETOBJECT;
  72. class CPackedBuffer;
  73. class CConnection;
  74. //
  75. // Used to pass the NameTable entries
  76. //
  77. typedef struct _DN_NAMETABLE_ENTRY_INFO
  78. {
  79. DPNID dpnid;
  80. DPNID dpnidOwner;
  81. DWORD dwFlags;
  82. DWORD dwVersion;
  83. DWORD dwVersionNotUsed;
  84. DWORD dwDNETVersion;
  85. DWORD dwNameOffset;
  86. DWORD dwNameSize;
  87. DWORD dwDataOffset;
  88. DWORD dwDataSize;
  89. DWORD dwURLOffset;
  90. DWORD dwURLSize;
  91. } DN_NAMETABLE_ENTRY_INFO;
  92. //**********************************************************************
  93. // Variable definitions
  94. //**********************************************************************
  95. //**********************************************************************
  96. // Function prototypes
  97. //**********************************************************************
  98. //**********************************************************************
  99. // Class prototypes
  100. //**********************************************************************
  101. // class for NameTable Entries
  102. class CNameTableEntry
  103. {
  104. public:
  105. #undef DPF_MODNAME
  106. #define DPF_MODNAME "CNameTableEntry::FPMAlloc"
  107. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  108. {
  109. CNameTableEntry* pNTEntry = (CNameTableEntry*)pvItem;
  110. pNTEntry->m_Sig[0] = 'N';
  111. pNTEntry->m_Sig[1] = 'T';
  112. pNTEntry->m_Sig[2] = 'E';
  113. pNTEntry->m_Sig[3] = '*';
  114. if (!DNInitializeCriticalSection(&pNTEntry->m_csEntry))
  115. {
  116. return(FALSE);
  117. }
  118. DebugSetCriticalSectionRecursionCount(&pNTEntry->m_csEntry,0);
  119. if (!DNInitializeCriticalSection(&pNTEntry->m_csMembership))
  120. {
  121. DNDeleteCriticalSection(&pNTEntry->m_csEntry);
  122. return(FALSE);
  123. }
  124. DebugSetCriticalSectionRecursionCount(&pNTEntry->m_csMembership,0);
  125. if (!DNInitializeCriticalSection(&pNTEntry->m_csConnections))
  126. {
  127. DNDeleteCriticalSection(&pNTEntry->m_csMembership);
  128. DNDeleteCriticalSection(&pNTEntry->m_csEntry);
  129. return(FALSE);
  130. }
  131. DebugSetCriticalSectionRecursionCount(&pNTEntry->m_csConnections,0);
  132. pNTEntry->m_bilinkEntries.Initialize();
  133. pNTEntry->m_bilinkDeleted.Initialize();
  134. pNTEntry->m_bilinkMembership.Initialize();
  135. pNTEntry->m_bilinkConnections.Initialize();
  136. pNTEntry->m_bilinkQueuedMsgs.Initialize();
  137. return(TRUE);
  138. };
  139. #undef DPF_MODNAME
  140. #define DPF_MODNAME "CNameTableEntry::FPMInitialize"
  141. static void FPMInitialize( void* pvItem, void* pvContext )
  142. {
  143. CNameTableEntry* pNTEntry = (CNameTableEntry*)pvItem;
  144. pNTEntry->m_pdnObject = static_cast<DIRECTNETOBJECT*>(pvContext);
  145. pNTEntry->m_dpnid = 0;
  146. pNTEntry->m_dpnidOwner = 0;
  147. pNTEntry->m_pvContext = NULL;
  148. pNTEntry->m_lRefCount = 1;
  149. pNTEntry->m_lNotifyRefCount = 0;
  150. DEBUG_ONLY(pNTEntry->m_lNumQueuedMsgs = 0);
  151. pNTEntry->m_dwFlags = 0;
  152. pNTEntry->m_dwDNETVersion = 0;
  153. pNTEntry->m_dwVersion = 0;
  154. pNTEntry->m_dwVersionNotUsed = 0;
  155. pNTEntry->m_dwLatestVersion = 0;
  156. pNTEntry->m_dwDestroyReason = 0;
  157. pNTEntry->m_pwszName = NULL;
  158. pNTEntry->m_dwNameSize = 0;
  159. pNTEntry->m_pvData = NULL;
  160. pNTEntry->m_dwDataSize = 0;
  161. pNTEntry->m_pAddress = NULL;
  162. pNTEntry->m_pConnection = NULL;
  163. DNASSERT(pNTEntry->m_bilinkEntries.IsEmpty());
  164. DNASSERT(pNTEntry->m_bilinkDeleted.IsEmpty());
  165. DNASSERT(pNTEntry->m_bilinkMembership.IsEmpty());
  166. DNASSERT(pNTEntry->m_bilinkConnections.IsEmpty());
  167. DNASSERT(pNTEntry->m_bilinkQueuedMsgs.IsEmpty());
  168. };
  169. #undef DPF_MODNAME
  170. #define DPF_MODNAME "CNameTableEntry::FPMRelease"
  171. static void FPMRelease( void* pvItem )
  172. {
  173. const CNameTableEntry* pNTEntry = (CNameTableEntry*)pvItem;
  174. DNASSERT(pNTEntry->m_bilinkEntries.IsEmpty());
  175. DNASSERT(pNTEntry->m_bilinkDeleted.IsEmpty());
  176. DNASSERT(pNTEntry->m_bilinkMembership.IsEmpty());
  177. DNASSERT(pNTEntry->m_bilinkConnections.IsEmpty());
  178. DNASSERT(pNTEntry->m_bilinkQueuedMsgs.IsEmpty());
  179. };
  180. #undef DPF_MODNAME
  181. #define DPF_MODNAME "CNameTableEntry::FPMDealloc"
  182. static void FPMDealloc( void* pvItem )
  183. {
  184. CNameTableEntry* pNTEntry = (CNameTableEntry*)pvItem;
  185. DNDeleteCriticalSection(&pNTEntry->m_csConnections);
  186. DNDeleteCriticalSection(&pNTEntry->m_csMembership);
  187. DNDeleteCriticalSection(&pNTEntry->m_csEntry);
  188. };
  189. void ReturnSelfToPool( void );
  190. void Lock( void )
  191. {
  192. DNEnterCriticalSection(&m_csEntry);
  193. };
  194. void Unlock( void )
  195. {
  196. DNLeaveCriticalSection(&m_csEntry);
  197. };
  198. #undef DPF_MODNAME
  199. #define DPF_MODNAME "CNameTableEntry::AddRef"
  200. void AddRef(void)
  201. {
  202. LONG lRefCount;
  203. DNASSERT(m_lRefCount > 0);
  204. lRefCount = DNInterlockedIncrement(const_cast<LONG*>(&m_lRefCount));
  205. DPFX(DPFPREP, 3,"NameTableEntry::AddRef [0x%p] RefCount [0x%lx]",this,lRefCount);
  206. };
  207. void Release(void);
  208. void CNameTableEntry::NotifyAddRef( void );
  209. void CNameTableEntry::NotifyRelease( void );
  210. void MakeLocal( void )
  211. {
  212. m_dwFlags |= NAMETABLE_ENTRY_FLAG_LOCAL;
  213. };
  214. BOOL IsLocal( void ) const
  215. {
  216. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_LOCAL)
  217. return(TRUE);
  218. return(FALSE);
  219. };
  220. void MakeHost( void )
  221. {
  222. m_dwFlags |= NAMETABLE_ENTRY_FLAG_HOST;
  223. };
  224. BOOL IsHost( void ) const
  225. {
  226. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_HOST)
  227. return(TRUE);
  228. return(FALSE);
  229. };
  230. void MakeAllPlayersGroup( void )
  231. {
  232. m_dwFlags |= NAMETABLE_ENTRY_FLAG_ALL_PLAYERS_GROUP;
  233. };
  234. BOOL IsAllPlayersGroup( void ) const
  235. {
  236. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_ALL_PLAYERS_GROUP)
  237. return(TRUE);
  238. return(FALSE);
  239. };
  240. void MakeGroup( void )
  241. {
  242. m_dwFlags |= NAMETABLE_ENTRY_FLAG_GROUP;
  243. };
  244. BOOL IsGroup( void ) const
  245. {
  246. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_GROUP)
  247. return(TRUE);
  248. return(FALSE);
  249. };
  250. void MakeMulticastGroup( void )
  251. {
  252. m_dwFlags |= NAMETABLE_ENTRY_FLAG_GROUP_MULTICAST;
  253. };
  254. BOOL IsMulticastGroup( void ) const
  255. {
  256. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_GROUP_MULTICAST)
  257. return(TRUE);
  258. return(FALSE);
  259. };
  260. void MakeAutoDestructGroup( void )
  261. {
  262. m_dwFlags |= NAMETABLE_ENTRY_FLAG_GROUP_AUTODESTRUCT;
  263. };
  264. BOOL IsAutoDestructGroup( void ) const
  265. {
  266. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_GROUP_AUTODESTRUCT)
  267. return(TRUE);
  268. return(FALSE);
  269. };
  270. void MakePeer( void )
  271. {
  272. m_dwFlags |= NAMETABLE_ENTRY_FLAG_PEER;
  273. };
  274. BOOL IsPeer( void ) const
  275. {
  276. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_PEER)
  277. return(TRUE);
  278. return(FALSE);
  279. };
  280. void MakeClient( void )
  281. {
  282. m_dwFlags |= NAMETABLE_ENTRY_FLAG_CLIENT;
  283. };
  284. BOOL IsClient( void ) const
  285. {
  286. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_CLIENT)
  287. return(TRUE);
  288. return(FALSE);
  289. };
  290. #ifndef DPNBUILD_NOSERVER
  291. void MakeServer( void )
  292. {
  293. m_dwFlags |= NAMETABLE_ENTRY_FLAG_SERVER;
  294. };
  295. BOOL IsServer( void ) const
  296. {
  297. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_SERVER)
  298. return(TRUE);
  299. return(FALSE);
  300. };
  301. #endif // !DPNBUILD_NOSERVER
  302. void MakeAvailable( void )
  303. {
  304. m_dwFlags |= NAMETABLE_ENTRY_FLAG_AVAILABLE;
  305. };
  306. void MakeUnavailable( void )
  307. {
  308. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_AVAILABLE);
  309. };
  310. BOOL IsAvailable( void ) const
  311. {
  312. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_AVAILABLE)
  313. return(TRUE);
  314. return(FALSE);
  315. };
  316. void SetIndicated( void )
  317. {
  318. m_dwFlags |= NAMETABLE_ENTRY_FLAG_INDICATED;
  319. };
  320. void ClearIndicated( void )
  321. {
  322. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_INDICATED);
  323. };
  324. BOOL IsIndicated( void ) const
  325. {
  326. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_INDICATED)
  327. {
  328. return(TRUE);
  329. }
  330. return(FALSE);
  331. };
  332. void SetCreated( void )
  333. {
  334. m_dwFlags |= NAMETABLE_ENTRY_FLAG_CREATED;
  335. };
  336. void ClearCreated( void )
  337. {
  338. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_CREATED);
  339. };
  340. BOOL IsCreated( void ) const
  341. {
  342. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_CREATED)
  343. {
  344. return(TRUE);
  345. }
  346. return(FALSE);
  347. };
  348. void SetNeedToDestroy( void )
  349. {
  350. m_dwFlags |= NAMETABLE_ENTRY_FLAG_NEED_TO_DESTROY;
  351. };
  352. void ClearNeedToDestroy( void )
  353. {
  354. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_NEED_TO_DESTROY);
  355. };
  356. BOOL IsNeedToDestroy( void ) const
  357. {
  358. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_NEED_TO_DESTROY)
  359. {
  360. return(TRUE);
  361. }
  362. return(FALSE);
  363. };
  364. void SetInUse( void )
  365. {
  366. m_dwFlags |= NAMETABLE_ENTRY_FLAG_IN_USE;
  367. };
  368. void ClearInUse( void )
  369. {
  370. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_IN_USE);
  371. };
  372. BOOL IsInUse( void ) const
  373. {
  374. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_IN_USE)
  375. {
  376. return( TRUE );
  377. }
  378. return( FALSE );
  379. };
  380. void StartConnecting( void )
  381. {
  382. m_dwFlags |= NAMETABLE_ENTRY_FLAG_CONNECTING;
  383. };
  384. void StopConnecting( void )
  385. {
  386. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_CONNECTING);
  387. };
  388. BOOL IsConnecting( void ) const
  389. {
  390. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_CONNECTING)
  391. return(TRUE);
  392. return(FALSE);
  393. };
  394. void CNameTableEntry::StartDisconnecting( void )
  395. {
  396. m_dwFlags |= NAMETABLE_ENTRY_FLAG_DISCONNECTING;
  397. };
  398. void StopDisconnecting( void )
  399. {
  400. m_dwFlags &= (~NAMETABLE_ENTRY_FLAG_DISCONNECTING);
  401. };
  402. BOOL IsDisconnecting( void ) const
  403. {
  404. if (m_dwFlags & NAMETABLE_ENTRY_FLAG_DISCONNECTING)
  405. return(TRUE);
  406. return(FALSE);
  407. };
  408. void SetDPNID(const DPNID dpnid)
  409. {
  410. m_dpnid = dpnid;
  411. };
  412. DPNID GetDPNID(void) const
  413. {
  414. return(m_dpnid);
  415. };
  416. void SetContext(void *const pvContext)
  417. {
  418. m_pvContext = pvContext;
  419. };
  420. void *GetContext(void)
  421. {
  422. return(m_pvContext);
  423. };
  424. void SetDNETVersion( const DWORD dwDNETVersion )
  425. {
  426. m_dwDNETVersion = dwDNETVersion;
  427. };
  428. DWORD GetDNETVersion( void ) const
  429. {
  430. return( m_dwDNETVersion );
  431. };
  432. void SetVersion(const DWORD dwVersion)
  433. {
  434. m_dwVersion = dwVersion;
  435. };
  436. DWORD GetVersion( void ) const
  437. {
  438. return(m_dwVersion);
  439. };
  440. void SetLatestVersion(const DWORD dwLatestVersion)
  441. {
  442. m_dwLatestVersion = dwLatestVersion;
  443. };
  444. DWORD GetLatestVersion( void ) const
  445. {
  446. return(m_dwLatestVersion);
  447. };
  448. void SetDestroyReason( const DWORD dwReason )
  449. {
  450. m_dwDestroyReason = dwReason;
  451. };
  452. DWORD GetDestroyReason( void ) const
  453. {
  454. return( m_dwDestroyReason );
  455. };
  456. HRESULT CNameTableEntry::UpdateEntryInfo(UNALIGNED WCHAR *const pwszName,
  457. const DWORD dwNameSize,
  458. void *const pvData,
  459. const DWORD dwDataSize,
  460. const DWORD dwInfoFlags,
  461. BOOL fNotify);
  462. WCHAR *GetName( void )
  463. {
  464. return(m_pwszName);
  465. };
  466. DWORD GetNameSize( void ) const
  467. {
  468. return(m_dwNameSize);
  469. };
  470. void *GetData( void )
  471. {
  472. return(m_pvData);
  473. };
  474. DWORD GetDataSize( void ) const
  475. {
  476. return(m_dwDataSize);
  477. };
  478. void SetOwner(const DPNID dpnidOwner)
  479. {
  480. m_dpnidOwner = dpnidOwner;
  481. };
  482. DPNID GetOwner( void ) const
  483. {
  484. return(m_dpnidOwner);
  485. };
  486. void SetAddress( IDirectPlay8Address *const pAddress );
  487. IDirectPlay8Address *GetAddress( void )
  488. {
  489. return(m_pAddress);
  490. };
  491. void SetConnection( CConnection *const pConnection );
  492. CConnection *GetConnection( void )
  493. {
  494. return(m_pConnection);
  495. };
  496. HRESULT CNameTableEntry::GetConnectionRef( CConnection **const ppConnection );
  497. HRESULT CNameTableEntry::PackInfo(CPackedBuffer *const pPackedBuffer);
  498. HRESULT CNameTableEntry::PackEntryInfo(CPackedBuffer *const pPackedBuffer);
  499. HRESULT CNameTableEntry::UnpackEntryInfo(UNALIGNED const DN_NAMETABLE_ENTRY_INFO *const pdnEntryInfo,
  500. BYTE *const pBufferStart);
  501. void CNameTableEntry::PerformQueuedOperations(void);
  502. CBilink m_bilinkEntries;
  503. CBilink m_bilinkDeleted;
  504. CBilink m_bilinkMembership;
  505. CBilink m_bilinkConnections;
  506. CBilink m_bilinkQueuedMsgs;
  507. private:
  508. BYTE m_Sig[4];
  509. DPNID m_dpnid;
  510. DPNID m_dpnidOwner;
  511. void * m_pvContext;
  512. LONG volatile m_lRefCount;
  513. LONG volatile m_lNotifyRefCount;
  514. DWORD volatile m_dwFlags;
  515. DWORD m_dwDNETVersion;
  516. DWORD m_dwVersion;
  517. DWORD m_dwVersionNotUsed;
  518. DWORD volatile m_dwLatestVersion;
  519. DWORD volatile m_dwDestroyReason;
  520. PWSTR m_pwszName;
  521. DWORD m_dwNameSize;
  522. void * m_pvData;
  523. DWORD m_dwDataSize;
  524. IDirectPlay8Address *m_pAddress;
  525. CConnection *m_pConnection;
  526. DIRECTNETOBJECT *m_pdnObject;
  527. #ifndef DPNBUILD_ONLYONETHREAD
  528. DNCRITICAL_SECTION m_csEntry;
  529. DNCRITICAL_SECTION m_csMembership;
  530. DNCRITICAL_SECTION m_csConnections;
  531. #endif // !DPNBUILD_ONLYONETHREAD
  532. public:
  533. DEBUG_ONLY(LONG m_lNumQueuedMsgs);
  534. };
  535. #undef DPF_MODNAME
  536. #endif // __NTENTRY_H__