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.

469 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: tableseg.hxx
  7. //
  8. // Contents: CTableSegment class declaration
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1-16-95 srikants Moved from bigtable.hxx
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. #include <tblsink.hxx>
  19. #include <querydef.hxx>
  20. #include <coldesc.hxx>
  21. #include <tablecol.hxx>
  22. #include <tbrowkey.hxx>
  23. //+-------------------------------------------------------------------------
  24. //
  25. // Class: CNotificationSync
  26. //
  27. // Purpose: Synchronization information for notifications.
  28. //
  29. //--------------------------------------------------------------------------
  30. class CRequestServer;
  31. class CNotificationSync
  32. {
  33. public:
  34. CNotificationSync( HANDLE hEvent ) :
  35. _hCancelEvent( hEvent ),
  36. _pServer( 0 ) {}
  37. CNotificationSync( CRequestServer *pServer ) :
  38. _hCancelEvent( 0 ),
  39. _pServer( pServer ) {}
  40. HANDLE GetCancelEvent()
  41. {
  42. Win4Assert( 0 == _pServer );
  43. return _hCancelEvent;
  44. }
  45. BOOL IsSvcMode() { return 0 != _pServer; }
  46. CRequestServer * GetRequestServer()
  47. {
  48. Win4Assert( 0 == _hCancelEvent );
  49. return _pServer;
  50. }
  51. private:
  52. HANDLE _hCancelEvent;
  53. CRequestServer * _pServer;
  54. };
  55. //+-------------------------------------------------------------------------
  56. //
  57. // Class: CNotificationParams
  58. //
  59. // Purpose: Bundles the notification parameters so they are easy to
  60. // pass from place to place.
  61. //
  62. //--------------------------------------------------------------------------
  63. enum ENotifyType { notifyAdd, notifyDelete, notifyModify };
  64. class CNotificationParams
  65. {
  66. public:
  67. CNotificationParams()
  68. {
  69. memset(_acRows,0,sizeof _acRows);
  70. memset(_apRows,0,sizeof _apRows);
  71. }
  72. ~CNotificationParams()
  73. {
  74. delete _apRows[notifyAdd];
  75. delete _apRows[notifyDelete];
  76. delete _apRows[notifyModify];
  77. }
  78. CI_TBL_BMK * GetRows(ENotifyType type) { return _apRows[type]; }
  79. void SetRows(ENotifyType type,CI_TBL_BMK * p) { _apRows[type] = p; }
  80. ULONG GetCount(ENotifyType type) { return _acRows[type]; }
  81. void SetCount(ENotifyType type, ULONG c) { _acRows[type] = c; }
  82. ULONG IncrementCount(ENotifyType type) { return _acRows[type]++; }
  83. BOOL AnyNotifications() { return 0 != _acRows[notifyAdd] ||
  84. 0 != _acRows[notifyDelete] ||
  85. 0 != _acRows[notifyModify]; }
  86. void Marshall(CNotificationParams &rFrom)
  87. {
  88. memcpy(_acRows,rFrom._acRows,sizeof _acRows);
  89. }
  90. void UnMarshall(CNotificationParams &rFrom)
  91. { Marshall(rFrom); }
  92. ULONG MarshalledSize() { return sizeof CNotificationParams; }
  93. void Resize(ENotifyType type,ULONG cNew)
  94. { _apRows[type] = renewx(_apRows[type],
  95. _acRows[type],
  96. _acRows[type] + cNew); }
  97. void SetHROW(ENotifyType type,ULONG index,CI_TBL_BMK hrow)
  98. { _apRows[type][index] = hrow; }
  99. private:
  100. ULONG _acRows[3];
  101. CI_TBL_BMK * _apRows[3];
  102. };
  103. //
  104. // Forward declaration of classes
  105. //
  106. class CQueryIterator;
  107. class CRetriever;
  108. class CTableCursor;
  109. class CTableSegIter;
  110. class CTableWindow;
  111. class CGetRowsParams;
  112. //+---------------------------------------------------------------------------
  113. //
  114. // Class: CTableSource
  115. //
  116. // Purpose: Abstract base class for a source of rows from the bigtable
  117. // categorization tables
  118. //
  119. // History: 3-20-95 srikants Created (Split from CTableSegment)
  120. //
  121. // Notes:
  122. //
  123. //----------------------------------------------------------------------------
  124. class CTableSource
  125. {
  126. public:
  127. CTableSource()
  128. : _fFwdFetchPrev( TRUE ),
  129. _fFirstGetNextRows( TRUE )
  130. {
  131. }
  132. virtual SCODE GetRows( HWATCHREGION hRegion,
  133. WORKID widStart,
  134. CI_TBL_CHAPT chapt,
  135. CTableColumnSet const & rOutColumns,
  136. CGetRowsParams & rGetParams,
  137. WORKID& rwidNextRowToTransfer ) = 0;
  138. virtual SCODE GetRowsAt( HWATCHREGION hRegion,
  139. WORKID widStart,
  140. CI_TBL_CHAPT chapt,
  141. DBROWOFFSET cRowsToMove,
  142. CTableColumnSet const & rOutColumns,
  143. CGetRowsParams & rGetParams,
  144. WORKID & rwidLastRowTransferred ) = 0;
  145. virtual SCODE GetRowsAtRatio( HWATCHREGION hRegion,
  146. ULONG num,
  147. ULONG denom,
  148. CI_TBL_CHAPT chapt,
  149. CTableColumnSet const & rOutColumns,
  150. CGetRowsParams & rGetParams,
  151. WORKID & rwidLastRowTransferred ) = 0;
  152. virtual SCODE GetApproximatePosition( CI_TBL_CHAPT chapt,
  153. CI_TBL_BMK bmk,
  154. DBCOUNTITEM * pulNumerator,
  155. DBCOUNTITEM * pulDenominator) = 0;
  156. virtual void RestartPosition ( CI_TBL_CHAPT chapt )
  157. {
  158. _fFwdFetchPrev = TRUE;
  159. _fFirstGetNextRows = TRUE;
  160. }
  161. virtual void LokGetOneColumn( WORKID wid,
  162. CTableColumn const & rOutColumn,
  163. BYTE * pbOut,
  164. PVarAllocator & rVarAllocator )
  165. { Win4Assert(!"Never called!"); }
  166. virtual WORKID GetCurrentPosition( CI_TBL_CHAPT chapt ) = 0;
  167. virtual WORKID SetCurrentPosition( CI_TBL_CHAPT chapt, WORKID wid ) = 0;
  168. BOOL GetFwdFetchPrev() { return _fFwdFetchPrev; }
  169. void SetFwdFetchPrev( BOOL fFwdFetch) { _fFwdFetchPrev = fFwdFetch; }
  170. BOOL IsFirstGetNextRows() { return _fFirstGetNextRows; }
  171. void ResetFirstGetNextRows() { _fFirstGetNextRows = FALSE; }
  172. private:
  173. BOOL _fFwdFetchPrev; // Fetch direction of previous GetNextRows call
  174. BOOL _fFirstGetNextRows; // Is this the first GetNextRows call ?
  175. };
  176. //+---------------------------------------------------------------------------
  177. //
  178. // Class: CCompareResult ()
  179. //
  180. // Purpose: To hold the result of a comparison of a row with a segment.
  181. // (For CompareRange).
  182. //
  183. // History: 3-20-95 srikants Created
  184. //
  185. // Notes:
  186. //
  187. //----------------------------------------------------------------------------
  188. class CCompareResult
  189. {
  190. public:
  191. enum ECompareResult { eInRange, eLesser, eGreater, eUnknown };
  192. CCompareResult( ECompareResult rslt = eUnknown ) : _rslt(rslt) {}
  193. ECompareResult Get() const { return _rslt; }
  194. int GetComp() const { return _iComp; }
  195. void Set( ECompareResult rslt ) { _rslt = rslt; }
  196. void Set( int iComp )
  197. {
  198. _iComp = iComp;
  199. if ( 0 == iComp )
  200. {
  201. _rslt = eInRange;
  202. }
  203. else if ( iComp > 0 )
  204. {
  205. _rslt = eGreater;
  206. }
  207. else
  208. {
  209. _rslt = eLesser;
  210. }
  211. }
  212. BOOL IsUnknown() const { return eUnknown == _rslt; }
  213. BOOL IsEQ() const { return eInRange == _rslt ; }
  214. BOOL IsGT() const { return eGreater == _rslt; }
  215. BOOL IsLT() const { return eLesser == _rslt; }
  216. BOOL IsLE() const { return eLesser == _rslt || eInRange == _rslt; }
  217. BOOL IsGE() const { return eGreater == _rslt || eInRange == _rslt; }
  218. BOOL IsNE() const { return eInRange != _rslt; }
  219. private:
  220. ECompareResult _rslt;
  221. int _iComp;
  222. };
  223. //+---------------------------------------------------------------------------
  224. //
  225. // Class: CTableSegment
  226. //
  227. // Purpose: Base class for a segment in the bigtable.
  228. //
  229. // History: 3-20-95 srikants Created ( Split into CTableSource and
  230. // CTableSegment )
  231. //
  232. // Notes:
  233. //
  234. //----------------------------------------------------------------------------
  235. class CTableSegment: public CDoubleLink, public CTableSink
  236. {
  237. public:
  238. enum ETableSegType { eWindow, eBucket, eLargeTable };
  239. CTableSegment( ETableSegType eType, ULONG segId,
  240. const CSortSet & sortSet,
  241. CTableKeyCompare & comparator)
  242. : _type(eType), _segId(segId),
  243. _refCount(0), _fZombie(0),
  244. _lowKey(sortSet),
  245. _highKey(sortSet),
  246. _comparator(comparator)
  247. {
  248. _next = _prev = 0;
  249. }
  250. CTableSegment( CTableSegment & src, ULONG segId )
  251. :_type(src._type), _segId(segId),
  252. _refCount(0), _fZombie(0),
  253. _lowKey( src._lowKey.GetSortSet() ),
  254. _highKey( src._highKey.GetSortSet() ),
  255. _comparator(src._comparator)
  256. {
  257. _next = _prev = 0;
  258. }
  259. virtual ~CTableSegment()
  260. {
  261. Win4Assert( ! InUse() );
  262. }
  263. virtual BOOL PutRow( CRetriever & obj, CTableRowKey & currKey ) = 0;
  264. virtual DBCOUNTITEM RowCount() = 0;
  265. //
  266. // Column manipulation
  267. //
  268. virtual BOOL RowOffset(WORKID wid, ULONG& riRow)
  269. {
  270. Win4Assert( !"Should not be called\n" );
  271. return FALSE;
  272. }
  273. //
  274. // Row Deletions.
  275. //
  276. virtual void RemoveRow( PROPVARIANT const & varUnique )
  277. {
  278. Win4Assert( !"Must Not Be Called" );
  279. }
  280. virtual BOOL RemoveRow( PROPVARIANT const & varUnique,
  281. WORKID & widNext,
  282. CI_TBL_CHAPT & chapt ) = 0;
  283. //
  284. // Sort related methods.
  285. //
  286. virtual BOOL IsRowInSegment( WORKID wid ) = 0;
  287. ETableSegType GetSegmentType() const { return _type; }
  288. BOOL IsWindow() const { return eWindow == _type; }
  289. BOOL IsBucket() const { return eBucket == _type; }
  290. ULONG GetSegId() const { return _segId; }
  291. virtual BOOL IsEmptyForQuery() = 0;
  292. virtual BOOL IsGettingFull() = 0;
  293. virtual BOOL IsSortedSplit( ULONG & riSplit ) = 0;
  294. BOOL InUse() const { return 0 != _refCount; }
  295. void Reference() { _refCount++; }
  296. void Release()
  297. {
  298. Win4Assert( _refCount > 0 );
  299. _refCount--;
  300. }
  301. BOOL IsZombie() const { return _fZombie; }
  302. void Zombify() { _fZombie = TRUE; }
  303. CTableRowKey & GetLowestKey() { return _lowKey; }
  304. CTableRowKey & GetHighestKey() { return _highKey; }
  305. #ifdef CIEXTMODE
  306. void CiExtDump(void *ciExtSelf);
  307. #endif
  308. protected:
  309. ETableSegType _type;
  310. const ULONG _segId;
  311. unsigned _refCount;
  312. BOOL _fZombie;
  313. CTableRowKey _lowKey; // Lowest row in this segment
  314. CTableRowKey _highKey; // Highest row in this segment
  315. CTableKeyCompare & _comparator; // Comparator
  316. };
  317. //+---------------------------------------------------------------------------
  318. //
  319. // Class: CTableSegRef
  320. //
  321. // Purpose: A class to automatically de-reference the table segment
  322. // if there is a failure.
  323. //
  324. // History: 3-09-95 srikants Created
  325. //
  326. // Notes:
  327. //
  328. //----------------------------------------------------------------------------
  329. class CTableSegRef
  330. {
  331. public:
  332. CTableSegRef( CTableSegment * pTableSeg = 0 ) : _pTableSeg(pTableSeg)
  333. {
  334. }
  335. ~CTableSegRef()
  336. {
  337. if ( _pTableSeg )
  338. {
  339. _pTableSeg->Release();
  340. }
  341. }
  342. void Set( CTableSegment * pTableSeg )
  343. {
  344. Win4Assert( 0 == _pTableSeg );
  345. _pTableSeg = pTableSeg;
  346. }
  347. CTableSegment * Get()
  348. {
  349. return _pTableSeg;
  350. }
  351. CTableSegment * Transfer()
  352. {
  353. CTableSegment * pTemp = _pTableSeg;
  354. _pTableSeg = 0;
  355. return pTemp;
  356. }
  357. private:
  358. CTableSegment * _pTableSeg;
  359. };
  360. class CTableBucket;
  361. typedef XPtr<CTableSegment> XTableSegment;