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.

172 lines
4.0 KiB

  1. //
  2. // inline functions for CCategorizer and related classes
  3. //
  4. #ifndef __CCATFN_H__
  5. #define __CCATFN_H__
  6. #include <transmem.h>
  7. #include "caterr.h"
  8. #include "ccat.h"
  9. #include "cpool.h"
  10. #include "listmacr.h"
  11. #include "icatlistresolve.h"
  12. //
  13. // Make sure the compiler knows about the explicit specialization before it is called
  14. //
  15. template<>
  16. void
  17. ReleaseEmailIDStore(
  18. CEmailIDStore<CCatAddr> *pStore);
  19. //
  20. // CCategorizer inline functions
  21. //
  22. inline
  23. CCategorizer::CCategorizer()
  24. {
  25. m_dwSignature = SIGNATURE_CCAT;
  26. m_pStore = NULL;
  27. m_pICatParams = NULL;
  28. m_cICatParamProps = 0L;
  29. m_cICatListResolveProps = 0L;
  30. m_dwICatParamSystemProp_CCatAddr = 0L;
  31. m_hShutdownEvent = INVALID_HANDLE_VALUE;
  32. m_lRefCount = 0;
  33. m_lDestructionWaiters = 0;
  34. m_ConfigInfo.dwCCatConfigInfoFlags = 0;
  35. m_hrDelayedInit = CAT_S_NOT_INITIALIZED;
  36. m_pCCatNext = NULL;
  37. m_dwInitFlags = 0;
  38. m_fPrepareForShutdown = FALSE;
  39. m_pISMTPServerEx = NULL;
  40. InitializeCriticalSection(&m_csInit);
  41. InitializeSpinLock(&m_PendingResolveListLock);
  42. InitializeListHead(&m_ListHeadPendingResolves);
  43. ZeroMemory(&m_PerfBlock, sizeof(m_PerfBlock));
  44. }
  45. inline
  46. CCategorizer::~CCategorizer()
  47. {
  48. _ASSERT(m_dwSignature == SIGNATURE_CCAT);
  49. m_dwSignature = SIGNATURE_CCAT_INVALID;
  50. if (m_pStore != NULL)
  51. ReleaseEmailIDStore( m_pStore );
  52. if (m_pICatParams)
  53. m_pICatParams->Release();
  54. if (m_hShutdownEvent != INVALID_HANDLE_VALUE)
  55. CloseHandle(m_hShutdownEvent);
  56. if (m_pCCatNext)
  57. m_pCCatNext->Release();
  58. if (m_pISMTPServerEx)
  59. m_pISMTPServerEx->Release();
  60. ReleaseConfigInfo();
  61. DeleteCriticalSection(&m_csInit);
  62. }
  63. //
  64. // set the cancel flag to cancel any ongoing resolves
  65. //
  66. inline void CCategorizer::Cancel()
  67. {
  68. CatFunctEnter("CCategorizer::Cancel");
  69. CancelAllPendingListResolves();
  70. if(m_pStore)
  71. m_pStore->CancelAllLookups();
  72. CatFunctLeave();
  73. }
  74. //
  75. // Call delayed initialize if it hasn't succeeded yet
  76. //
  77. inline HRESULT CCategorizer::DelayedInitializeIfNecessary()
  78. {
  79. HRESULT hr;
  80. CatFunctEnterEx((LPARAM)this, "CCategorizer::DelayedInitializeIfNecessary");
  81. switch(m_hrDelayedInit) {
  82. case S_OK:
  83. hr = S_FALSE;
  84. break;
  85. case CAT_E_INIT_FAILED:
  86. case CAT_S_NOT_INITIALIZED:
  87. EnterCriticalSection(&m_csInit);
  88. //
  89. // Check again, maybe we've been initialized
  90. //
  91. if((m_hrDelayedInit == CAT_S_NOT_INITIALIZED) ||
  92. (m_hrDelayedInit == CAT_E_INIT_FAILED)) {
  93. hr = DelayedInitialize();
  94. if(SUCCEEDED(hr))
  95. m_hrDelayedInit = S_OK;
  96. else {
  97. ERROR_LOG("DelayedInitialize");
  98. m_hrDelayedInit = CAT_E_INIT_FAILED;
  99. }
  100. } else {
  101. //
  102. // We've were initialized after we checked hr but before entering the CS
  103. //
  104. hr = (m_hrDelayedInit == S_OK) ? S_FALSE : CAT_E_INIT_FAILED;
  105. }
  106. LeaveCriticalSection(&m_csInit);
  107. break;
  108. default:
  109. _ASSERT(0 && "developer bozo error");
  110. hr = E_FAIL;
  111. break;
  112. }
  113. DebugTrace((LPARAM)this, "Returning hr %08lx", hr);
  114. CatFunctLeaveEx((LPARAM)this);
  115. return hr;
  116. }
  117. //
  118. // Add a pending list resolve
  119. //
  120. inline VOID CCategorizer::AddPendingListResolve(
  121. CICategorizerListResolveIMP *pListResolve)
  122. {
  123. AcquireSpinLock(&m_PendingResolveListLock);
  124. InsertTailList(&m_ListHeadPendingResolves, &(pListResolve->m_li));
  125. ReleaseSpinLock(&m_PendingResolveListLock);
  126. }
  127. //
  128. // Remove a pending list resolve
  129. //
  130. inline VOID CCategorizer::RemovePendingListResolve(
  131. CICategorizerListResolveIMP *pListResolve)
  132. {
  133. AcquireSpinLock(&m_PendingResolveListLock);
  134. RemoveEntryList(&(pListResolve->m_li));
  135. ReleaseSpinLock(&m_PendingResolveListLock);
  136. }
  137. #endif //__CCATFN_H__