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.

218 lines
6.1 KiB

  1. //+------------------------------------------------------------
  2. //
  3. // Copyright (C) 1998, Microsoft Corporation
  4. //
  5. // File: icatasync.cpp
  6. //
  7. // Contents: Implementation of CICategorizerAsyncContextIMP
  8. //
  9. // Classes: CICategorizerAsyncContextIMP
  10. //
  11. // Functions:
  12. //
  13. // History:
  14. // jstamerj 1998/07/16 11:25:20: Created.
  15. //
  16. //-------------------------------------------------------------
  17. #include "precomp.h"
  18. #include "simparray.cpp"
  19. //+------------------------------------------------------------
  20. //
  21. // Function: QueryInterface
  22. //
  23. // Synopsis: Returns pointer to this object for IUnknown and ICategorizerAsyncContext
  24. //
  25. // Arguments:
  26. // iid -- interface ID
  27. // ppv -- pvoid* to fill in with pointer to interface
  28. //
  29. // Returns:
  30. // S_OK: Success
  31. // E_NOINTERFACE: Don't support that interface
  32. //
  33. // History:
  34. // jstamerj 980612 14:07:57: Created.
  35. //
  36. //-------------------------------------------------------------
  37. STDMETHODIMP CICategorizerAsyncContextIMP::QueryInterface(
  38. REFIID iid,
  39. LPVOID *ppv)
  40. {
  41. *ppv = NULL;
  42. if(iid == IID_IUnknown) {
  43. *ppv = (LPVOID) this;
  44. } else if (iid == IID_ICategorizerAsyncContext) {
  45. *ppv = (LPVOID) this;
  46. } else {
  47. return E_NOINTERFACE;
  48. }
  49. AddRef();
  50. return S_OK;
  51. }
  52. //+------------------------------------------------------------
  53. //
  54. // Function: AddRef
  55. //
  56. // Synopsis: adds a reference to this object
  57. //
  58. // Arguments: NONE
  59. //
  60. // Returns: New reference count
  61. //
  62. // History:
  63. // jstamerj 980611 20:07:14: Created.
  64. //
  65. //-------------------------------------------------------------
  66. ULONG CICategorizerAsyncContextIMP::AddRef()
  67. {
  68. return InterlockedIncrement((PLONG)&m_cRef);
  69. }
  70. //+------------------------------------------------------------
  71. //
  72. // Function: Release
  73. //
  74. // Synopsis: releases a reference, deletes this object when the
  75. // refcount hits zero.
  76. //
  77. // Arguments: NONE
  78. //
  79. // Returns: New reference count
  80. //
  81. // History:
  82. // jstamerj 980611 20:07:33: Created.
  83. //
  84. //-------------------------------------------------------------
  85. ULONG CICategorizerAsyncContextIMP::Release()
  86. {
  87. LONG lNewRefCount;
  88. lNewRefCount = InterlockedDecrement((PLONG)&m_cRef);
  89. return lNewRefCount;
  90. }
  91. //+------------------------------------------------------------
  92. //
  93. // Function: CICategorizerAsyncContext::CompleteQuery
  94. //
  95. // Synopsis: Accept async completion from a sink
  96. //
  97. // Arguments:
  98. // pvQueryContext: pvoid query context (really a PEVENTPARAMS_SENDQUERY)
  99. // hrResolutionStatus: S_OK unless there was an error talking to DS
  100. // dwcResults: The number of ICategorizerItemAttributes returned
  101. // rgpItemAttributes: Array of pointers to the ICategorizerItemAttributes
  102. // fFinalCompletion:
  103. // FALSE: This is a completion for
  104. // pending results; there will be another completion
  105. // called with more results
  106. // TRUE: This is the final completion call
  107. //
  108. // Returns:
  109. // S_OK: Success
  110. //
  111. // History:
  112. // jstamerj 1998/07/16 11:27:47: Created.
  113. //
  114. //-------------------------------------------------------------
  115. STDMETHODIMP CICategorizerAsyncContextIMP::CompleteQuery(
  116. IN PVOID pvQueryContext,
  117. IN HRESULT hrResolutionStatus,
  118. IN DWORD dwcResults,
  119. IN ICategorizerItemAttributes **rgpItemAttributes,
  120. IN BOOL fFinalCompletion)
  121. {
  122. HRESULT hr;
  123. PEVENTPARAMS_CATSENDQUERY pParams;
  124. CSearchRequestBlock *pBlock;
  125. CatFunctEnterEx((LPARAM)this,
  126. "CICategorizerAsyncContextIMP::CompleteQuery");
  127. DebugTrace((LPARAM)this, "hrResolutionStatus is %08lx", hrResolutionStatus);
  128. DebugTrace((LPARAM)this, "dwcResults for this sink is %ld", dwcResults);
  129. DebugTrace((LPARAM)this, "fFinalCompletion is %d", fFinalCompletion);
  130. pParams = (PEVENTPARAMS_CATSENDQUERY)pvQueryContext;
  131. pBlock = (CSearchRequestBlock *) pParams->pblk;
  132. //
  133. // If the old hrResolutionStatus (saved in pParams) indicates failure, don't do any more work
  134. //
  135. if(SUCCEEDED(pParams->hrResolutionStatus)) {
  136. hr = hrResolutionStatus;
  137. if(SUCCEEDED(hr) && (dwcResults > 0) && (rgpItemAttributes)) {
  138. //
  139. // Add the new array of ICatItemAttrs to the existing array
  140. //
  141. hr = pBlock->AddResults(
  142. dwcResults,
  143. rgpItemAttributes);
  144. if(FAILED(hr))
  145. {
  146. ERROR_LOG("pBlock->AddResults");
  147. }
  148. }
  149. if(FAILED(hr)) {
  150. //
  151. // Remember something failed in pParams
  152. //
  153. pParams->hrResolutionStatus = hr;
  154. ERROR_LOG("--async--");
  155. }
  156. }
  157. if(fFinalCompletion) {
  158. if((pParams->pIMailTransportNotify) &&
  159. FAILED(pParams->hrResolutionStatus)) {
  160. ErrorTrace((LPARAM)this, "Stoping resoltion, error encountered: %08ld",
  161. pParams->hrResolutionStatus);
  162. //
  163. // If the resolution sink is indicating an error, set the error
  164. // and return S_FALSE to the SEO dispatcher so that it will stop
  165. // calling resolve sinks (we're going to fail now anyway, after
  166. // all)
  167. //
  168. hr = pParams->pIMailTransportNotify->Notify(
  169. S_FALSE,
  170. pParams->pvNotifyContext);
  171. _ASSERT(SUCCEEDED(hr));
  172. } else {
  173. if(pParams->pIMailTransportNotify) {
  174. //
  175. // Call the SEO dispatcher completion routine
  176. //
  177. hr = pParams->pIMailTransportNotify->Notify(
  178. S_OK,
  179. pParams->pvNotifyContext);
  180. } else {
  181. //
  182. // Events are disabled; call completion directly
  183. //
  184. hr = CSearchRequestBlock::HrSendQueryCompletion(
  185. S_OK,
  186. pParams);
  187. }
  188. _ASSERT(SUCCEEDED(hr));
  189. }
  190. }
  191. CatFunctLeaveEx((LPARAM)this);
  192. return S_OK;
  193. }