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.

235 lines
7.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1999.
  5. //
  6. // File: Categ.hxx
  7. //
  8. // Contents: Categorization classes
  9. //
  10. // Classes: CCategorize
  11. //
  12. // History: 30-Mar-95 dlee Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #pragma once
  16. class CCategorize : public CTableSource
  17. {
  18. public:
  19. CCategorize( CCategorizationSpec & rCatSpec,
  20. unsigned iSpec,
  21. CCategorize * pParent,
  22. CMutexSem & mutex );
  23. // CTableSource methods
  24. SCODE GetRows( HWATCHREGION hRegion,
  25. WORKID widStart,
  26. CI_TBL_CHAPT chapt,
  27. CTableColumnSet const & rOutColumns,
  28. CGetRowsParams & rGetParams,
  29. WORKID& rwidNextRowToTransfer );
  30. void LokGetOneColumn( WORKID wid,
  31. CTableColumn const & rOutColumn,
  32. BYTE * pbOut,
  33. PVarAllocator & rVarAllocator );
  34. SCODE GetRowsAt( HWATCHREGION hRegion,
  35. WORKID widStart,
  36. CI_TBL_CHAPT chapt,
  37. DBROWOFFSET cRowsToMove,
  38. CTableColumnSet const & rOutColumns,
  39. CGetRowsParams & rGetParams,
  40. WORKID & rwidLastRowTransferred );
  41. SCODE GetRowsAtRatio( HWATCHREGION hRegion,
  42. ULONG num,
  43. ULONG denom,
  44. CI_TBL_CHAPT chapt,
  45. CTableColumnSet const & rOutColumns,
  46. CGetRowsParams & rGetParams,
  47. WORKID & rwidLastRowTransferred );
  48. void RestartPosition( CI_TBL_CHAPT chapt);
  49. SCODE LocateRelativeRow( WORKID widStart,
  50. CI_TBL_CHAPT chapt,
  51. DBROWOFFSET cRows,
  52. WORKID & rwidRowOut,
  53. DBROWOFFSET & rcRowsResidual );
  54. SCODE GetApproximatePosition( CI_TBL_CHAPT chapt,
  55. CI_TBL_BMK bmk,
  56. DBCOUNTITEM * pulNumerator,
  57. DBCOUNTITEM * pulDenominator );
  58. SCODE GetNotifications( CNotificationParams & Params )
  59. { return 0; }
  60. void EnableNotifications()
  61. {
  62. CLock lock( _mutex );
  63. if ( ! _fNotificationsEnabled )
  64. {
  65. // copy visible to dynamic
  66. _fNotificationsEnabled = TRUE;
  67. _aDynamicCategories.Duplicate( _aVisibleCategories );
  68. }
  69. }
  70. void NotificationTimeRefresh()
  71. {
  72. // copy dynamic to visible
  73. CLock lock( _mutex );
  74. Win4Assert( _fNotificationsEnabled );
  75. _aVisibleCategories.Duplicate( _aDynamicCategories );
  76. }
  77. // Methods for doing the categorization work
  78. unsigned LokAssignCategory( CCategParams &params );
  79. void RemoveRow( CI_TBL_CHAPT chapt,
  80. WORKID wid,
  81. WORKID widNext );
  82. WORKID GetFirstWorkid( CI_TBL_CHAPT category )
  83. {
  84. CLock lock( _mutex );
  85. return _aVisibleCategories[ _FindCategory( category ) ].widFirst;
  86. }
  87. unsigned GetRowCount( CI_TBL_CHAPT category )
  88. {
  89. CLock lock( _mutex );
  90. return _aVisibleCategories[ _FindCategory( category) ].cRows;
  91. }
  92. WORKID GetFirstWorkidOfNextCategory( CI_TBL_CHAPT category )
  93. {
  94. CLock lock( _mutex );
  95. unsigned iCat = _FindCategory( category ) + 1;
  96. if ( iCat < _aVisibleCategories.Count() )
  97. return _aVisibleCategories[ iCat ].widFirst;
  98. else
  99. return widInvalid;
  100. }
  101. WORKID GetCurrentPositionThisLevel( CI_TBL_CHAPT cat )
  102. { return _aVisibleCategories[ _FindCategory( cat) ].widGetNextRowsPos; }
  103. WORKID GetCurrentPosition( CI_TBL_CHAPT cat )
  104. {
  105. if ( 0 != _pParent )
  106. return _pParent->GetCurrentPositionThisLevel( cat );
  107. else
  108. return _widCurrent;
  109. }
  110. WORKID SetCurrentPosition( CI_TBL_CHAPT cat, WORKID widPos )
  111. {
  112. if ( 0 != _pParent )
  113. _pParent->SetCurrentPositionThisLevel( cat, widPos );
  114. else
  115. _widCurrent = widPos;
  116. return widPos;
  117. }
  118. WORKID SetCurrentPositionThisLevel( CI_TBL_CHAPT cat, WORKID widPos )
  119. {
  120. _aVisibleCategories[ _FindCategory( cat) ].widGetNextRowsPos = widPos;
  121. return widPos;
  122. }
  123. void SetChild( CTableSource * pChild )
  124. { _pChild = pChild; }
  125. private:
  126. BOOL _isCategorized() { return 0 != _pParent; }
  127. unsigned _FindCategory( CI_TBL_CHAPT cat );
  128. unsigned _FindWritableCategory( CI_TBL_CHAPT cat );
  129. unsigned _GenCategory() { return _iCategoryGen++; }
  130. unsigned _InsertNewCategory( WORKID wid, unsigned iInsertBefore )
  131. {
  132. CCategory cat( wid );
  133. cat.catID = _GenCategory();
  134. _WritableArray().Insert( cat, iInsertBefore );
  135. return cat.catID;
  136. }
  137. void _IncrementRowCount( CI_TBL_CHAPT category )
  138. { _WritableArray( _FindWritableCategory( category ) ).cRows++; }
  139. // categorizer for this level of categorization (or 0)
  140. CCategorize * _pParent;
  141. // table source that's one level down
  142. CTableSource * _pChild;
  143. // CAsyncQuery's mutex for serialization
  144. CMutexSem & _mutex;
  145. // 1-based index into categorization specs
  146. unsigned _iSpec;
  147. // next category # to be created
  148. unsigned _iCategoryGen;
  149. // current position of GetNextRows when _pParent is 0
  150. WORKID _widCurrent;
  151. // hint of where to look first when looking up a category id
  152. unsigned _iFindHint;
  153. // TRUE if notifications are turned on and new rows are put into the
  154. // dynamic array, while the visible array remains constant until
  155. // Refresh() is invoked by the client and the dynamic version is
  156. // copied into the visible version.
  157. // FALSE if visible version is the only one ever used
  158. BOOL _fNotificationsEnabled;
  159. class CCategory
  160. {
  161. public:
  162. CCategory( unsigned wid ) :
  163. widFirst( wid ),
  164. catID( 0 ),
  165. catParent( 0 ),
  166. widGetNextRowsPos( WORKID_TBLBEFOREFIRST ),
  167. cRows( 1 ) {}
  168. CCategory() {}
  169. WORKID widFirst;
  170. CI_TBL_CHAPT catID;
  171. CI_TBL_CHAPT catParent;
  172. WORKID widGetNextRowsPos;
  173. unsigned cRows;
  174. };
  175. // returns the array to which updates can be made
  176. CDynArrayInPlace<CCategory> & _WritableArray()
  177. { return _fNotificationsEnabled ? _aDynamicCategories :
  178. _aVisibleCategories; }
  179. // returns an element in the array to which updates can be made
  180. CCategory & _WritableArray( unsigned iEntry )
  181. { return _WritableArray()[ iEntry ]; }
  182. CDynArrayInPlace<CCategory> _aDynamicCategories;
  183. CDynArrayInPlace<CCategory> _aVisibleCategories;
  184. };