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.

206 lines
6.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: EBufHdlr.Cxx
  7. //
  8. // Contents: Implementation of the CEntryBufferHandler
  9. //
  10. // Classes: CEntryBufferHandler
  11. //
  12. // History: 18-Mar-93 AmyA Created from wordlist.cxx and
  13. // sort.cxx
  14. //
  15. //----------------------------------------------------------------------------
  16. #include <pch.cxx>
  17. #pragma hdrstop
  18. #include <fdaemon.hxx>
  19. #include <entrybuf.hxx>
  20. #include "ebufhdlr.hxx"
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Member: CEntryBufferHandler::CEntryBufferHandler, public
  24. //
  25. // Synopsis: Constructor
  26. //
  27. // Arguments: [cbMemory] -- suggested size of entry buffer
  28. //
  29. // History: 18-Mar-93 AmyA Created.
  30. //
  31. //----------------------------------------------------------------------------
  32. CEntryBufferHandler::CEntryBufferHandler( ULONG cbMemory,
  33. BYTE * buffer,
  34. CFilterDaemon& fDaemon,
  35. CiProxy & proxy,
  36. CPidMapper & pidMap )
  37. : _entryBuf ( cbMemory, buffer ),
  38. _wordListFull ( FALSE ),
  39. _filterDaemon ( fDaemon ),
  40. _cFilteredBlocks( 0 )
  41. {
  42. }
  43. //+---------------------------------------------------------------------------
  44. //
  45. // Member: CEntryBufferHandler::FlushBuffer, private
  46. //
  47. // Synopsis: Sorts entry buffer and calls CWordList::PutEntryBuffer()
  48. //
  49. // Expects: Sentinel entry added to _entryBuf.
  50. //
  51. // History: 18-Mar-93 AmyA Created.
  52. //
  53. //----------------------------------------------------------------------------
  54. void CEntryBufferHandler::FlushBuffer()
  55. {
  56. _entryBuf.Sort();
  57. _entryBuf.Done(); // prepare buffer to be sent to kernel
  58. SCODE sc = _filterDaemon.FilterDataReady ( _entryBuf.GetBuffer(),
  59. _entryBuf.GetSize() );
  60. _wordListFull = (sc == FDAEMON_W_WORDLISTFULL );
  61. _entryBuf.ReInit();
  62. if ( FAILED(sc) )
  63. {
  64. ciDebugOut(( DEB_ERROR,
  65. "FilterDataReady call from FlushBuffer failed sc 0x%x. "
  66. "Buffer contents lost.\n", sc ));
  67. THROW( CException( sc ) );
  68. }
  69. }
  70. //+---------------------------------------------------------------------------
  71. //
  72. // Member: CEntryBufferHandler::Done, public
  73. //
  74. // Synopsis: indicate end of the CEntryBufferHandler
  75. //
  76. // Effects: Flushes entry buffer, then calls CommitWordList
  77. //
  78. // History: 22-May-91 Brianb Created
  79. // 18-Mar-93 AmyA Moved from CWordList.
  80. //
  81. // Note: This method can not throw exceptions
  82. //
  83. //----------------------------------------------------------------------------
  84. void CEntryBufferHandler::Done()
  85. {
  86. TRY
  87. {
  88. _entryBuf.AddSentinel();
  89. if ( _entryBuf.Count() != 0 )
  90. {
  91. FlushBuffer();
  92. }
  93. }
  94. CATCH (CException, e)
  95. {
  96. ciDebugOut (( DEB_ERROR,
  97. "CEntryBufferHandler::Done failed, status=0x%x\n",
  98. e.GetErrorCode() ));
  99. }
  100. END_CATCH
  101. }
  102. //+---------------------------------------------------------------------------
  103. //
  104. // Member: CEntryBufferHandler::Init, public
  105. //
  106. // Synopsis: Reinitializes class after Done has been called.
  107. //
  108. // Effects: Resets _wordListFull and calls ReInit on entry buffer
  109. //
  110. // History: 04-May-93 AmyA Created
  111. //
  112. //----------------------------------------------------------------------------
  113. void CEntryBufferHandler::Init()
  114. {
  115. ciDebugOut (( DEB_ITRACE | DEB_NOCOMPNAME, "CEntryBufferHandler::Init\n" ));
  116. _wordListFull = FALSE;
  117. _entryBuf.ReInit();
  118. }
  119. //+-------------------------------------------------------------------------
  120. //
  121. // Member: CEntryBufferHandler::SetWid, public
  122. //
  123. // Synopsis: Sets the WorkId to which future AddEntry calls apply.
  124. //
  125. // Arguments: [widFake] -- fake WorkId
  126. //
  127. // History: 20-May-92 KyleP Created
  128. // 18-Mar-93 AmyA Moved from CWordList.
  129. //
  130. //--------------------------------------------------------------------------
  131. void CEntryBufferHandler::SetWid( WORKID widFake )
  132. {
  133. Win4Assert ( widFake != widInvalid );
  134. _CurrentWidIndex = widFake;
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Member: CEntryBufferHandler::AddEntry, public
  139. //
  140. // Synopsis: Adds an entry (key, workid, etc.) to the CEntryBuffer
  141. //
  142. // Effects: Adds a <key, propid, workid, occurrence>
  143. // tuple to the sort.
  144. //
  145. // Arguments: [key] -- Normalized key
  146. // [occ] -- Occurrence
  147. //
  148. // History: 07-Mar-91 KyleP Created.
  149. // 22-May-91 Brianb Changed to use own sorter
  150. // 07-Jun-91 BartoszM Rewrote
  151. // 18-Mar-93 AmyA Moved from CWordList.
  152. //
  153. //----------------------------------------------------------------------------
  154. void CEntryBufferHandler::AddEntry(
  155. const CKeyBuf & key,
  156. OCCURRENCE occ )
  157. {
  158. ciAssert ( key.Count() != 0 );
  159. ciAssert ( key.Pid() != pidInvalid );
  160. if ( !_entryBuf.WillFit ( key.Count() ) )
  161. {
  162. ciDebugOut (( DEB_ITRACE | DEB_NOCOMPNAME, "+" ));
  163. _entryBuf.AddSentinel();
  164. FlushBuffer();
  165. //
  166. // Check if the filtering has exceeded its space limit
  167. //
  168. _cFilteredBlocks++;
  169. if ( _cFilteredBlocks > _ulMaxFilteredBlocks )
  170. {
  171. ciDebugOut(( DEB_WARN, "Filtering a document has exceeded its space limit\n" ));
  172. QUIETTHROW( CException( FDAEMON_E_TOOMANYFILTEREDBLOCKS ) );
  173. }
  174. }
  175. Win4Assert ( _CurrentWidIndex != widInvalid );
  176. _entryBuf.AddEntry ( key.Count(),
  177. key.GetBuf(),
  178. key.Pid(),
  179. _CurrentWidIndex,
  180. occ);
  181. }