Source code of Windows XP (NT5)
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.

286 lines
6.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: Execute.hxx
  7. //
  8. // Contents: Query execution class
  9. //
  10. // Classes: CQAsyncExecute
  11. //
  12. // History: 21-Aug-91 KyleP Created
  13. // 20-Jan-95 DwightKr Split CQExecute into CQueryBase
  14. // & CQExecute
  15. // 11 Mar 95 AlanW Renamed CQExecute to CQAsyncExecute
  16. // and CQueryBase to CQueryExecute
  17. //
  18. //----------------------------------------------------------------------------
  19. #pragma once
  20. #include <worker.hxx>
  21. #include <refcount.hxx>
  22. #include <qoptimiz.hxx>
  23. // forward declared classes
  24. class PWorkIdIter;
  25. class CTableSink;
  26. class CQAsyncExecute;
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Class: CDummyNotify
  30. //
  31. // Purpose: A dummy notification class until notifications are enabled in
  32. // the framework model.
  33. //
  34. // History: 2-18-97 srikants Created
  35. //
  36. //----------------------------------------------------------------------------
  37. class CDummyNotify : public CDoubleLink
  38. {
  39. public:
  40. CDummyNotify()
  41. {
  42. Win4Assert( !"Must not be called" );
  43. }
  44. //
  45. // The magic API
  46. //
  47. virtual void DoIt() = 0;
  48. virtual void ClearNotifyEnabled()
  49. {
  50. //
  51. // override if necessary to set the flag. MUST be done under some
  52. // kind of lock to prevent races.
  53. //
  54. }
  55. WCHAR const * GetScope() const { return 0; }
  56. unsigned ScopeLength() const { return 0; }
  57. //
  58. // Refcounting
  59. //
  60. void AddRef()
  61. {
  62. Win4Assert( !"Must not be called" );
  63. }
  64. void Release()
  65. {
  66. Win4Assert( !"Must not be called" );
  67. }
  68. protected:
  69. void StartNotification( NTSTATUS * pStatus = 0 )
  70. {
  71. Win4Assert( !"Must not be called" );
  72. }
  73. void EnableNotification()
  74. {
  75. Win4Assert( !"Must not be called" );
  76. }
  77. void DisableNotification()
  78. {
  79. Win4Assert( !"Must not be called" );
  80. }
  81. BYTE * GetBuf() { return 0; }
  82. unsigned BufLength() { return 0; }
  83. BOOL BufferOverflow() { return FALSE; }
  84. };
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Class: CQAsyncNotify
  88. //
  89. // Purpose: Helper class for (multi-scope) downlevel notification
  90. //
  91. // History: 22-Feb-96 KyleP Created.
  92. //
  93. //----------------------------------------------------------------------------
  94. // class CQAsyncNotify : public CGenericNotify
  95. class CQAsyncNotify : public CDummyNotify
  96. {
  97. public:
  98. CQAsyncNotify( CQAsyncExecute & Execute,
  99. WCHAR const * pwcScope,
  100. unsigned cwcScope,
  101. BOOL fDeep,
  102. BOOL fVirtual );
  103. ~CQAsyncNotify();
  104. void Abort() { DisableNotification(); }
  105. void DoIt();
  106. private:
  107. CQAsyncExecute & _Execute;
  108. BOOL _fVirtual;
  109. };
  110. typedef class TDoubleList<CQAsyncNotify> CQAsyncNotifyList;
  111. typedef class TFwdListIter<CQAsyncNotify, CQAsyncNotifyList> CFwdCQAsyncNotifyIter;
  112. const LONGLONG eSigCQAsyncExecute = 0x2020636578454151i64; // "QAExec"
  113. //+---------------------------------------------------------------------------
  114. //
  115. // Class: CQAsyncExecute
  116. //
  117. // Purpose: Executes a single query
  118. //
  119. // History: 19-Aug-91 KyleP Created.
  120. // 20-Jan-95 DwightKr Split into 2 classes
  121. //
  122. // Notes: The CQAsyncExecute class is responsible for fully processing
  123. // a single query. There is one CQAsyncExecute object running in
  124. // a given thread at a given time. A CQAsyncExecute object is
  125. // capable of executing multiple queries sequentially.
  126. //
  127. //----------------------------------------------------------------------------
  128. class CQAsyncExecute : public PWorkItem
  129. {
  130. public:
  131. CQAsyncExecute( XQueryOptimizer & opt,
  132. BOOL fEnableNotification,
  133. CTableSink & obt,
  134. ICiCDocStore *pDocStore );
  135. ~CQAsyncExecute();
  136. //
  137. // From PWorkItem
  138. //
  139. void DoIt( CWorkThread * pThread );
  140. void AddRef();
  141. void Release();
  142. //
  143. // For bucket --> window conversion.
  144. //
  145. void Update( PWorkIdIter & widiter );
  146. BOOL FetchDeferredValue( WORKID wid,
  147. CFullPropSpec const & ps,
  148. PROPVARIANT & var );
  149. CSingletonCursor* GetSingletonCursor( BOOL& fAbort ) const
  150. {
  151. return ((CQueryOptimizer*)_xqopt.GetPointer())->QuerySingletonCursor( fAbort );
  152. }
  153. BOOL CanPartialDefer()
  154. {
  155. return _xqopt->CanPartialDefer();
  156. }
  157. # ifdef CIEXTMODE
  158. void CiExtDump(void *ciExtSelf);
  159. # endif
  160. private:
  161. void Resolve( );
  162. void Update( CChangeQueue * pChanges );
  163. void DisableNotification();
  164. void StopNotifications();
  165. void FreeCursor();
  166. inline WORKID GetFirstWorkId();
  167. inline WORKID GetNextWorkId();
  168. WORKID GetWidFromNextComponent();
  169. BOOL CheckExecutionTime( ULONGLONG * pullTimeslize = 0 );
  170. void _SetupNotify( CScopeRestriction const & scope );
  171. //
  172. // Output (table)
  173. //
  174. CTableSink & _obt;
  175. CRefCount _refcount;
  176. //
  177. // Optimized query
  178. //
  179. XQueryOptimizer _xqopt;
  180. XInterface<ICiManager> _xCiManager; // Content index
  181. //
  182. // State
  183. //
  184. CMutexSem _mtx; // Serialization
  185. BOOL _fAbort; // TRUE if abort pending
  186. BOOLEAN _fFirstPass; // TRUE for first rescan
  187. BOOLEAN _fFirstComponent; // TRUE for first component (of OR query)
  188. BOOLEAN _fPendingEnum; // TRUE if full enumeration peding
  189. BOOLEAN _fOnWorkQueue; // TRUE if object waiting to run
  190. BOOLEAN _fRunning; // TRUE if running
  191. BOOLEAN _fMidEnum; // TRUE if working on a full enumeration
  192. //
  193. // Notifications
  194. //
  195. BOOL _fEnableNotification; // TRUE if we can receive notifications
  196. CChangeQueue * _pChangeQueue; // Pending changes
  197. CTimeLimit * _pTimeLimit; // Execution time limit
  198. CGenericCursor * _pcurResolve;
  199. CSingletonCursor * _pcurNotify;
  200. //
  201. // Notification
  202. //
  203. void EnableNotification();
  204. CWorkThread * _pNotifyThread;
  205. friend class CQAsyncNotify;
  206. CQAsyncNotifyList _listNotify;
  207. };
  208. inline void CQAsyncExecute::AddRef()
  209. {
  210. _refcount.AddRef();
  211. }
  212. inline void CQAsyncExecute::Release()
  213. {
  214. _refcount.Release();
  215. }
  216. DECLARE_SMARTP( QAsyncExecute )