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.

151 lines
3.0 KiB

  1. #ifndef _DATASETCACHE_HXX_
  2. #define _DATASETCACHE_HXX_
  3. class DATA_SET_CACHE_ENTRY
  4. {
  5. public:
  6. DATA_SET_CACHE_ENTRY()
  7. {
  8. }
  9. virtual ~DATA_SET_CACHE_ENTRY()
  10. {
  11. }
  12. HRESULT
  13. Create(
  14. WCHAR * pszSubPath,
  15. DWORD dwMatchDataSetNumber,
  16. DWORD dwPrefixDataSetNumber
  17. );
  18. BOOL
  19. QueryDoesMatch(
  20. STRU & strPath,
  21. DWORD * pdwDataSetNumber
  22. )
  23. {
  24. if ( pdwDataSetNumber == NULL )
  25. {
  26. DBG_ASSERT( FALSE );
  27. return FALSE;
  28. }
  29. *pdwDataSetNumber = 0;
  30. if ( strPath.QueryCCH() < _strSubPath.QueryCCH() )
  31. {
  32. return FALSE;
  33. }
  34. if ( memcmp( strPath.QueryStr(),
  35. _strSubPath.QueryStr(),
  36. _strSubPath.QueryCB() ) == 0 )
  37. {
  38. if ( strPath.QueryCCH() == _strSubPath.QueryCCH() )
  39. {
  40. *pdwDataSetNumber = _dwMatchDataSetNumber;
  41. }
  42. else
  43. {
  44. *pdwDataSetNumber = _dwPrefixDataSetNumber;
  45. }
  46. return TRUE;
  47. }
  48. return FALSE;
  49. }
  50. private:
  51. STRU _strSubPath;
  52. DWORD _dwMatchDataSetNumber;
  53. DWORD _dwPrefixDataSetNumber;
  54. };
  55. class DATA_SET_CACHE
  56. {
  57. public:
  58. DATA_SET_CACHE()
  59. : _cRefs( 1 ),
  60. _cEntries( 0 ),
  61. _bufEntries( _abEntries, sizeof( _abEntries ) )
  62. {
  63. }
  64. virtual ~DATA_SET_CACHE()
  65. {
  66. DATA_SET_CACHE_ENTRY * pDataSetCacheEntry;
  67. for (DWORD i = 0; i < _cEntries; i++ )
  68. {
  69. pDataSetCacheEntry = QueryEntries()[ i ];
  70. DBG_ASSERT( pDataSetCacheEntry != NULL );
  71. delete pDataSetCacheEntry;
  72. }
  73. }
  74. static
  75. HRESULT
  76. Initialize(
  77. VOID
  78. );
  79. static
  80. VOID
  81. Terminate(
  82. VOID
  83. )
  84. {
  85. }
  86. HRESULT
  87. Create(
  88. STRU & strSiteRoot
  89. );
  90. HRESULT
  91. GetDataSetNumber(
  92. STRU & strMetabasePath,
  93. DWORD * pdwDataSetNumber
  94. );
  95. VOID
  96. ReferenceDataSetCache(
  97. VOID
  98. )
  99. {
  100. InterlockedIncrement( &_cRefs );
  101. }
  102. VOID
  103. DereferenceDataSetCache(
  104. VOID
  105. )
  106. {
  107. if ( InterlockedDecrement( &_cRefs ) == 0 )
  108. {
  109. delete this;
  110. }
  111. }
  112. private:
  113. DATA_SET_CACHE_ENTRY **
  114. QueryEntries(
  115. VOID
  116. )
  117. {
  118. return (DATA_SET_CACHE_ENTRY**) _bufEntries.QueryPtr();
  119. }
  120. LONG _cRefs;
  121. STRU _strSiteRoot;
  122. DWORD _cEntries;
  123. BUFFER _bufEntries;
  124. BYTE _abEntries[ 64 ];
  125. static DWORD sm_cMaxCacheEntries;
  126. };
  127. #endif