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.

241 lines
5.1 KiB

  1. // TestSE.cpp : Implementation of CTestSE
  2. #include "stdafx.h"
  3. #include "HelpServiceTypeLib_i.c"
  4. #include "testwrapper_i.c"
  5. #include <Utility.h>
  6. #define SETESTID 0x2000
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CTestSE : IPCHSEWrapperItem
  9. CTestSE::CTestSE()
  10. {
  11. m_bEnabled = VARIANT_TRUE;
  12. m_lNumResult = 0;
  13. m_pSEMgr = NULL;
  14. //
  15. // These strings will have to be changed to be read dynamically from
  16. // the initialization data
  17. //
  18. m_bstrOwner = L"Microsoft";
  19. m_bstrName = L"Test Search Wrapper";
  20. m_bstrDescription = L"Test Wrapper";
  21. m_bstrHelpURL = "";
  22. m_bstrID = "16AF1738-E7BB-43c6-8B67-A07E21690029";
  23. AddParam(CComBSTR("NumResults"), CComVariant(20));
  24. AddParam(CComBSTR("QueryDelayMillisec"), CComVariant(500));
  25. }
  26. CPCHSEParamItem* CreateParamObject(ParamTypeEnum pte, BSTR bstrName, VARIANT_BOOL bReq)
  27. {
  28. __HCP_FUNC_ENTRY( "CreateParamObject" );
  29. HRESULT hr;
  30. CComPtr<CPCHSEParamItem> pPIObj;
  31. //
  32. // Create the item to be inserted into the list
  33. //
  34. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pPIObj ));
  35. //
  36. // Stuff the data
  37. //
  38. __MPC_EXIT_IF_METHOD_FAILS(hr, pPIObj->put_Type ( pte ));
  39. __MPC_EXIT_IF_METHOD_FAILS(hr, pPIObj->put_Name ( bstrName ));
  40. __MPC_EXIT_IF_METHOD_FAILS(hr, pPIObj->put_Display ( bstrName ));
  41. __MPC_EXIT_IF_METHOD_FAILS(hr, pPIObj->put_Required ( bReq ));
  42. __MPC_FUNC_CLEANUP;
  43. return pPIObj.Detach();
  44. }
  45. STDMETHODIMP CTestSE::Result( /*[in]*/ long lStart, /*[in]*/ long lEnd, /*[out, retval]*/ IPCHCollection* *ppC )
  46. {
  47. HRESULT hr = S_OK;
  48. MPC::SmartLock<_ThreadModel> lock( this );
  49. CComPtr<CPCHCollection> pColl;
  50. int i;
  51. VARIANT vValue;
  52. unsigned int iResults = 0;
  53. if(ppC == NULL) return E_POINTER;
  54. //
  55. // Create the Enumerator and fill it with jobs.
  56. //
  57. if(FAILED(hr= MPC::CreateInstance( &pColl )))
  58. {
  59. goto end;
  60. }
  61. if (m_bEnabled)
  62. {
  63. //
  64. // Get the number of parameters
  65. //
  66. if (FAILED(GetParam(CComBSTR("NumResults"), &vValue)))
  67. {
  68. iResults = 10;
  69. }
  70. else
  71. {
  72. iResults = vValue.uintVal;
  73. }
  74. //
  75. // Create 10 items and fill it with data
  76. //
  77. for (i = 0; i < iResults; i++)
  78. {
  79. CComPtr<CPCHSEResultItem> pRIObj;
  80. WCHAR wszIter[10];
  81. CComBSTR bstrString;
  82. //
  83. // Create the item to be inserted into the list
  84. //
  85. if (FAILED(hr=MPC::CreateInstance( &pRIObj )))
  86. {
  87. break;
  88. }
  89. //
  90. // Print out the iteration
  91. //
  92. swprintf(wszIter, L"%d", i);
  93. //
  94. // Stuff in the data
  95. //
  96. bstrString = L"Title ";
  97. bstrString.Append(wszIter);
  98. pRIObj->put_Title(bstrString);
  99. bstrString = L"URI ";
  100. bstrString.Append(wszIter);
  101. pRIObj->put_URI(bstrString);
  102. pRIObj->put_Rank ( (double)i/10 );
  103. pRIObj->put_Hits ( i );
  104. pRIObj->put_Location (CComBSTR("Test"));
  105. pRIObj->put_ContentType ( i );
  106. //
  107. // Add to enumerator
  108. //
  109. if (FAILED(hr = pColl->AddItem(pRIObj)))
  110. {
  111. goto end;
  112. }
  113. }
  114. }
  115. if (FAILED(hr=pColl.QueryInterface( ppC )))
  116. {
  117. goto end;
  118. }
  119. end:
  120. return hr;
  121. }
  122. STDMETHODIMP CTestSE::get_SearchTerms( /*[out, retval]*/ VARIANT *pvTerms )
  123. {
  124. return S_OK;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CTestSE : IPCHSEWrapperInternal
  128. STDMETHODIMP CTestSE::AbortQuery()
  129. {
  130. Thread_Abort();
  131. return S_OK;
  132. }
  133. HRESULT CTestSE::ExecQuery()
  134. {
  135. __MPC_FUNC_ENTRY( SETESTID, "CTestSE::ExecQuery" );
  136. HRESULT hr = S_OK;
  137. VARIANT vValue;
  138. unsigned int iDelay;
  139. CComPtr<IPCHSEManagerInternal> pSEMgr = m_pSEMgr;
  140. if (m_bEnabled)
  141. {
  142. //
  143. // Get the number of parameters
  144. //
  145. if (FAILED(GetParam(CComBSTR("QueryDelayMillisec"), &vValue)))
  146. {
  147. iDelay = 1000;
  148. }
  149. else
  150. {
  151. iDelay = vValue.uintVal;
  152. }
  153. Sleep(iDelay);
  154. //
  155. // Call the SearchManager's OnComplete
  156. //
  157. if (Thread_IsAborted() == false)
  158. {
  159. __MPC_EXIT_IF_METHOD_FAILS(hr, pSEMgr->WrapperComplete( 0, this ));
  160. }
  161. }
  162. __MPC_FUNC_CLEANUP;
  163. Thread_Abort();
  164. __MPC_FUNC_EXIT(hr);
  165. }
  166. STDMETHODIMP CTestSE::ExecAsyncQuery()
  167. {
  168. __MPC_FUNC_ENTRY( SETESTID, "CTestSE::ExecAsyncQuery" );
  169. HRESULT hr = S_OK;
  170. //
  171. // Create a thread to execute the query
  172. //
  173. __MPC_EXIT_IF_METHOD_FAILS(hr, Thread_Start( this, ExecQuery, NULL ));
  174. __MPC_FUNC_CLEANUP;
  175. __MPC_FUNC_EXIT(hr);
  176. }
  177. STDMETHODIMP CTestSE::Initialize( /*[in]*/ BSTR bstrID, /*[in]*/ BSTR bstrSKU, /*[in]*/ long lLCID, /*[in]*/ BSTR bstrData )
  178. {
  179. //
  180. // Add your routine here to initialize your wrapper
  181. //
  182. return S_OK;
  183. }
  184. STDMETHODIMP CTestSE::SECallbackInterface( /*[in]*/ IPCHSEManagerInternal* pMgr )
  185. {
  186. __MPC_FUNC_ENTRY( SETESTID, "CTestSE::SECallbackInterface" );
  187. HRESULT hr;
  188. MPC::SmartLock<_ThreadModel> lock( this );
  189. m_pSEMgr = pMgr;
  190. hr = S_OK;
  191. __MPC_FUNC_EXIT(hr);
  192. }