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.

291 lines
7.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: GroupMem.h
  6. * Content: Group Membership Object Header File
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/03/00 mjn Created
  12. * 08/05/99 mjn Modified SetMembership to perform duplicate check and get NameTable version internally
  13. * 09/17/99 mjn Added GROUP_MEMBER_FLAG_NEED_TO_ADD,GROUP_MEMBER_FLAG_NEED_TO_REMOVE
  14. *@@END_MSINTERNAL
  15. *
  16. ***************************************************************************/
  17. #ifndef __GROUPMEM_H__
  18. #define __GROUPMEM_H__
  19. //**********************************************************************
  20. // Constant definitions
  21. //**********************************************************************
  22. #define GROUP_MEMBER_FLAG_VALID 0x0001
  23. #define GROUP_MEMBER_FLAG_AVAILABLE 0x0002
  24. #define GROUP_MEMBER_FLAG_NEED_TO_ADD 0x0004
  25. #define GROUP_MEMBER_FLAG_NEED_TO_REMOVE 0x0008
  26. //**********************************************************************
  27. // Macro definitions
  28. //**********************************************************************
  29. //**********************************************************************
  30. // Structure definitions
  31. //**********************************************************************
  32. class CPackedBuffer;
  33. class CGroupConnection;
  34. class CNameTableEntry;
  35. typedef struct _DIRECTNETOBJECT DIRECTNETOBJECT;
  36. //
  37. // Used to pass NameTable group membership
  38. //
  39. typedef struct _DN_NAMETABLE_MEMBERSHIP_INFO
  40. {
  41. DPNID dpnidPlayer;
  42. DPNID dpnidGroup;
  43. DWORD dwVersion;
  44. DWORD dwVersionNotUsed;
  45. } DN_NAMETABLE_MEMBERSHIP_INFO, *PDN_NAMETABLE_MEMBERSHIP_INFO;
  46. //**********************************************************************
  47. // Variable definitions
  48. //**********************************************************************
  49. //**********************************************************************
  50. // Function prototypes
  51. //**********************************************************************
  52. //**********************************************************************
  53. // Class prototypes
  54. //**********************************************************************
  55. // class for Group Members
  56. class CGroupMember
  57. {
  58. public:
  59. #undef DPF_MODNAME
  60. #define DPF_MODNAME "CGroupMember::FPMAlloc"
  61. static BOOL FPMAlloc( void* pvItem, void* pvContext )
  62. {
  63. CGroupMember* pGroupMember = (CGroupMember*)pvItem;
  64. pGroupMember->m_Sig[0] = 'G';
  65. pGroupMember->m_Sig[1] = 'M';
  66. pGroupMember->m_Sig[2] = 'E';
  67. pGroupMember->m_Sig[3] = 'M';
  68. if (!DNInitializeCriticalSection(&pGroupMember->m_cs))
  69. {
  70. return(FALSE);
  71. }
  72. DebugSetCriticalSectionRecursionCount(&pGroupMember->m_cs,0);
  73. pGroupMember->m_bilinkPlayers.Initialize();
  74. pGroupMember->m_bilinkGroups.Initialize();
  75. return(TRUE);
  76. };
  77. #undef DPF_MODNAME
  78. #define DPF_MODNAME "CGroupMember::FPMInitialize"
  79. static void FPMInitialize( void* pvItem, void* pvContext )
  80. {
  81. CGroupMember* pGroupMember = (CGroupMember*)pvItem;
  82. pGroupMember->m_pdnObject = static_cast<DIRECTNETOBJECT*>(pvContext);
  83. pGroupMember->m_dwFlags = 0;
  84. pGroupMember->m_lRefCount = 1;
  85. pGroupMember->m_pGroup = NULL;
  86. pGroupMember->m_pPlayer = NULL;
  87. pGroupMember->m_pGroupConnection = NULL;
  88. DNASSERT(pGroupMember->m_bilinkPlayers.IsEmpty());
  89. DNASSERT(pGroupMember->m_bilinkGroups.IsEmpty());
  90. };
  91. #undef DPF_MODNAME
  92. #define DPF_MODNAME "CGroupMember::FPMRelease"
  93. static void FPMRelease( void* pvItem )
  94. {
  95. const CGroupMember* pGroupMember = (CGroupMember*)pvItem;
  96. DNASSERT(pGroupMember->m_bilinkPlayers.IsEmpty());
  97. DNASSERT(pGroupMember->m_bilinkGroups.IsEmpty());
  98. };
  99. #undef DPF_MODNAME
  100. #define DPF_MODNAME "CGroupMember::FPMDealloc"
  101. static void FPMDealloc( void* pvItem )
  102. {
  103. CGroupMember* pGroupMember = (CGroupMember*)pvItem;
  104. DNDeleteCriticalSection(&pGroupMember->m_cs);
  105. };
  106. void MakeValid( void )
  107. {
  108. m_dwFlags |= GROUP_MEMBER_FLAG_VALID;
  109. };
  110. void MakeInvalid( void )
  111. {
  112. m_dwFlags &= (~GROUP_MEMBER_FLAG_VALID);
  113. };
  114. BOOL IsValid( void ) const
  115. {
  116. if (m_dwFlags & GROUP_MEMBER_FLAG_VALID)
  117. return(TRUE);
  118. return(FALSE);
  119. };
  120. #undef DPF_MODNAME
  121. #define DPF_MODNAME "CGroupMember::MakeAvailable"
  122. void MakeAvailable( void )
  123. {
  124. DNASSERT(m_pGroup != NULL);
  125. DNASSERT(m_pPlayer != NULL);
  126. m_dwFlags |= GROUP_MEMBER_FLAG_AVAILABLE;
  127. };
  128. #undef DPF_MODNAME
  129. #define DPF_MODNAME "CGroupMember::MakeUnavailable"
  130. void MakeUnavailable( void )
  131. {
  132. m_dwFlags &= (~GROUP_MEMBER_FLAG_AVAILABLE);
  133. };
  134. BOOL IsAvailable( void ) const
  135. {
  136. if (m_dwFlags & GROUP_MEMBER_FLAG_AVAILABLE)
  137. return(TRUE);
  138. return(FALSE);
  139. };
  140. void SetNeedToAdd( void )
  141. {
  142. m_dwFlags |= GROUP_MEMBER_FLAG_NEED_TO_ADD;
  143. };
  144. void ClearNeedToAdd( void )
  145. {
  146. m_dwFlags &= (~GROUP_MEMBER_FLAG_NEED_TO_ADD);
  147. };
  148. BOOL IsNeedToAdd( void ) const
  149. {
  150. if (m_dwFlags & GROUP_MEMBER_FLAG_NEED_TO_ADD)
  151. {
  152. return( TRUE );
  153. }
  154. return( FALSE );
  155. };
  156. void SetNeedToRemove( void )
  157. {
  158. m_dwFlags |= GROUP_MEMBER_FLAG_NEED_TO_REMOVE;
  159. };
  160. void ClearNeedToRemove( void )
  161. {
  162. m_dwFlags &= (~GROUP_MEMBER_FLAG_NEED_TO_REMOVE);
  163. };
  164. BOOL IsNeedToRemove( void ) const
  165. {
  166. if (m_dwFlags & GROUP_MEMBER_FLAG_NEED_TO_REMOVE)
  167. {
  168. return( TRUE );
  169. }
  170. return( FALSE );
  171. };
  172. void AddRef( void )
  173. {
  174. DNInterlockedIncrement(&m_lRefCount);
  175. };
  176. void Release( void );
  177. void ReturnSelfToPool( void );
  178. void Lock( void )
  179. {
  180. DNEnterCriticalSection(&m_cs);
  181. };
  182. void Unlock( void )
  183. {
  184. DNLeaveCriticalSection(&m_cs);
  185. };
  186. void CGroupMember::RemoveMembership( DWORD *const pdnVersion );
  187. void SetVersion( const DWORD dwVersion )
  188. {
  189. m_dwVersion = dwVersion;
  190. };
  191. DWORD GetVersion( void ) const
  192. {
  193. return(m_dwVersion);
  194. };
  195. HRESULT CGroupMember::SetMembership(CNameTableEntry *const pGroup,
  196. CNameTableEntry *const pPlayer,
  197. DWORD *const pdwVersion);
  198. CNameTableEntry *GetGroup( void )
  199. {
  200. return(m_pGroup);
  201. };
  202. CNameTableEntry *GetPlayer( void )
  203. {
  204. return(m_pPlayer);
  205. };
  206. void SetGroupConnection( CGroupConnection *const pGroupConnection );
  207. CGroupConnection *GetGroupConnection( void )
  208. {
  209. return(m_pGroupConnection);
  210. };
  211. HRESULT CGroupMember::PackMembershipInfo(CPackedBuffer *const pPackedBuffer);
  212. CBilink m_bilinkPlayers; // Players in this group
  213. CBilink m_bilinkGroups; // Groups this player belongs to
  214. private:
  215. BYTE m_Sig[4];
  216. DWORD m_dwFlags;
  217. LONG m_lRefCount;
  218. CNameTableEntry *m_pPlayer;
  219. CNameTableEntry *m_pGroup;
  220. CGroupConnection *m_pGroupConnection;
  221. DWORD m_dwVersion;
  222. DWORD m_dwVersionNotUsed;
  223. DIRECTNETOBJECT *m_pdnObject;
  224. #ifndef DPNBUILD_ONLYONETHREAD
  225. DNCRITICAL_SECTION m_cs;
  226. #endif // !DPNBUILD_ONLYONETHREAD
  227. };
  228. #undef DPF_MODNAME
  229. #endif // __GROUPMEM_H__