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.

162 lines
5.6 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////////////////
  2. // FILE: hashentr.h
  3. // PURPOSE: hash entry in the retry hash table
  4. // HISTORY:
  5. // NimishK 05-14-98 Created
  6. ///////////////////////////////////////////////////////////////////////////////////////////////
  7. #ifndef __HASHENTR_H__
  8. #define __HASHENTR_H__
  9. #include <hshroute.h>
  10. #define MAX_RETRY_DOMAIN_NAME_LEN (258 + ROUTE_HASH_PREFIX_SIZE)
  11. #define RETRY_ENTRY_SIGNATURE_VALID 'reSV'
  12. #define RETRY_ENTRY_SIGNATURE_FREE 'reSF'
  13. typedef VOID (*CALLBACKFN)(PVOID pvContext);
  14. #define INVALID_CALLBACK ((CALLBACKFN)(~0))
  15. /////////////////////////////////////////////////////////////////////////////////
  16. // CRETRY_HASH_ENTRY:
  17. //
  18. // An entry in the retry hash table. We will also add the same entry into a queue
  19. // ordered by retry time. A dedicated thread will walk the thread to retry domains
  20. // if it is time.
  21. // The hash key is the name of the domain
  22. // Need to add CPool backed memory allocation
  23. //
  24. /////////////////////////////////////////////////////////////////////////////////
  25. class CRETRY_HASH_ENTRY
  26. {
  27. public:
  28. //One Cpool for all entries in all instances of the retry table
  29. static CPool PoolForHashEntries;
  30. // override the mem functions to use CPool functions
  31. void *operator new (size_t cSize)
  32. { return PoolForHashEntries.Alloc(); }
  33. void operator delete (void *pInstance)
  34. { PoolForHashEntries.Free(pInstance); }
  35. protected:
  36. DWORD m_Signature;
  37. LONG m_RefCount;
  38. BOOL m_InQ;
  39. BOOL m_InTable;
  40. FILETIME m_ftEntryInsertedTime;
  41. FILETIME m_ftRetryTime;
  42. DWORD m_cFailureCount;
  43. CALLBACKFN m_pfnCallbackFn;
  44. PVOID m_pvCallbackContext;
  45. char m_szDomainName[MAX_RETRY_DOMAIN_NAME_LEN];
  46. public:
  47. LIST_ENTRY m_QLEntry; //List Entry for adding to RETRYQ
  48. LIST_ENTRY m_HLEntry; //List Entry for adding to BUCKET queue in HASH table
  49. CRETRY_HASH_ENTRY(char * szDomainName, DWORD cbDomainName,
  50. DWORD dwScheduleID, GUID *pguidRouting,
  51. FILETIME* InsertedTime)
  52. {
  53. m_Signature = RETRY_ENTRY_SIGNATURE_VALID;
  54. m_RefCount = 0;
  55. m_InQ = FALSE;
  56. m_InTable = FALSE;
  57. m_ftEntryInsertedTime = *InsertedTime;
  58. m_pvCallbackContext = NULL;
  59. m_pfnCallbackFn = NULL;
  60. //Hash schedule ID and router guid to domain name
  61. CreateRouteHash(cbDomainName, szDomainName, ROUTE_HASH_SCHEDULE_ID,
  62. pguidRouting, dwScheduleID, m_szDomainName, sizeof(m_szDomainName));
  63. #ifdef DEBUG
  64. m_hTranscriptHandle = INVALID_HANDLE_VALUE;
  65. m_szTranscriptFile[0] = '\0';
  66. #endif
  67. }
  68. //Query list entries
  69. LIST_ENTRY & QueryHListEntry(void) {return ( m_HLEntry);}
  70. LIST_ENTRY & QueryQListEntry(void) {return ( m_QLEntry);}
  71. //Domain name used as HASH key
  72. void SetHashKey(char * SearchData) { lstrcpy(m_szDomainName,SearchData);}
  73. char * GetHashKey(void) { return m_szDomainName;}
  74. //Insert and RetryTimes
  75. void SetInsertTime(FILETIME* ftEntryInsertTime) { m_ftEntryInsertedTime = *ftEntryInsertTime;}
  76. void SetRetryReleaseTime(FILETIME* ftRetryTime) { m_ftRetryTime = *ftRetryTime;}
  77. FILETIME GetInsertTime(void){return m_ftEntryInsertedTime;}
  78. FILETIME GetRetryTime(void){return m_ftRetryTime;}
  79. DWORD GetFailureCount(void){return m_cFailureCount;}
  80. void SetFailureCount(DWORD cFailureCount){m_cFailureCount = cFailureCount;}
  81. void SetInQ(void) { m_InQ = TRUE;}
  82. void ClearInQ(void) { m_InQ = FALSE;}
  83. BOOL GetInQ(void) { return m_InQ;}
  84. void SetInTable(void) { m_InTable = TRUE;}
  85. void ClearInTable(void) { m_InTable = FALSE;}
  86. BOOL GetInTable(void) { return m_InTable;}
  87. BOOL IsValid() { return(m_Signature == RETRY_ENTRY_SIGNATURE_VALID);}
  88. //Support for having non-domain based callback functions
  89. BOOL IsCallback() {return(NULL != m_pfnCallbackFn);};
  90. void ExecCallback()
  91. {
  92. _ASSERT(m_pfnCallbackFn);
  93. _ASSERT(INVALID_CALLBACK != m_pfnCallbackFn);
  94. //don't want to call twice, and don't want IsCallBack() to change
  95. m_pfnCallbackFn(m_pvCallbackContext);
  96. m_pfnCallbackFn = INVALID_CALLBACK;
  97. };
  98. void SetCallbackContext(CALLBACKFN pfnCallbackFn, PVOID pvCallbackContext)
  99. {
  100. _ASSERT(pfnCallbackFn);
  101. _ASSERT(INVALID_CALLBACK != pfnCallbackFn);
  102. m_pfnCallbackFn = pfnCallbackFn;
  103. m_pvCallbackContext = pvCallbackContext;
  104. };
  105. //Ref counting on the hash entry
  106. // Insertion into Hash table adds one and insertion into queue adds one
  107. LONG QueryRefCount(void){return m_RefCount;}
  108. LONG IncRefCount(void){return InterlockedIncrement(&m_RefCount);}
  109. void DecRefCount(void)
  110. {
  111. //
  112. if(InterlockedDecrement(&m_RefCount) == 0)
  113. {
  114. //we should not be in the retryQ if the ref
  115. //count is zero
  116. _ASSERT(m_InQ == FALSE);
  117. _ASSERT(m_InTable == FALSE);
  118. delete this;
  119. }
  120. }
  121. ~CRETRY_HASH_ENTRY()
  122. {
  123. m_Signature = RETRY_ENTRY_SIGNATURE_FREE;
  124. _ASSERT(m_InQ == FALSE);
  125. _ASSERT(m_InTable == FALSE);
  126. #ifdef DEBUG
  127. //Close the transcript file
  128. if (INVALID_HANDLE_VALUE != m_hTranscriptHandle)
  129. _VERIFY(CloseHandle(m_hTranscriptHandle));
  130. #endif
  131. }
  132. #ifdef DEBUG
  133. public:
  134. HANDLE m_hTranscriptHandle;
  135. char m_szTranscriptFile[MAX_PATH];
  136. #endif
  137. };
  138. #endif