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.

417 lines
12 KiB

  1. /******************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. WrapperBase.cpp
  5. Abstract:
  6. Implementation of SearchEngine::WrapperBase
  7. Revision History:
  8. Davide Massarenti (dmassare) 04/28/2001
  9. created
  10. ******************************************************************************/
  11. #include "stdafx.h"
  12. /////////////////////////////////////////////////////////////////////
  13. namespace SearchEngine
  14. {
  15. struct WrapperConfig : public MPC::Config::TypeConstructor
  16. {
  17. DECLARE_CONFIG_MAP(WrapperConfig);
  18. CComBSTR m_bstrName;
  19. CComBSTR m_bstrDescription;
  20. CComBSTR m_bstrHelpURL;
  21. CComBSTR m_bstrScope;
  22. ////////////////////////////////////////
  23. ////////////////////////////////////////
  24. //
  25. // MPC::Config::TypeConstructor
  26. //
  27. DEFINE_CONFIG_DEFAULTTAG();
  28. DECLARE_CONFIG_METHODS ();
  29. //
  30. ////////////////////////////////////////
  31. };
  32. };
  33. CFG_BEGIN_FIELDS_MAP(SearchEngine::WrapperConfig)
  34. CFG_ELEMENT( L"NAME" , BSTR, m_bstrName ),
  35. CFG_ELEMENT( L"DESCRIPTION", BSTR, m_bstrDescription ),
  36. CFG_ELEMENT( L"SCOPE" , BSTR, m_bstrScope ),
  37. CFG_ELEMENT( L"HELP_URL" , BSTR, m_bstrHelpURL ),
  38. CFG_END_FIELDS_MAP()
  39. CFG_BEGIN_CHILD_MAP(SearchEngine::WrapperConfig)
  40. CFG_END_CHILD_MAP()
  41. DEFINE_CFG_OBJECT(SearchEngine::WrapperConfig, L"CONFIG_DATA")
  42. DEFINE_CONFIG_METHODS__NOCHILD(SearchEngine::WrapperConfig)
  43. /////////////////////////////////////////////////////////////////////
  44. SearchEngine::WrapperBase::WrapperBase()
  45. {
  46. m_bEnabled = VARIANT_TRUE; // VARIANT_BOOL m_bEnabled;
  47. //
  48. // CComBSTR m_bstrID;
  49. // CComBSTR m_bstrOwner;
  50. //
  51. // CComBSTR m_bstrName;
  52. // CComBSTR m_bstrDescription;
  53. // CComBSTR m_bstrHelpURL;
  54. // CComBSTR m_bstrScope;
  55. //
  56. // CComBSTR m_bstrQueryString;
  57. m_lNumResult = 100; // long m_lNumResult;
  58. // CComPtr<IPCHSEManagerInternal> m_pSEMgr;
  59. //
  60. // Taxonomy::HelpSet m_ths;
  61. // CComPtr<CPCHCollection> m_pParamDef;
  62. // ParamMap m_aParam;
  63. }
  64. SearchEngine::WrapperBase::~WrapperBase()
  65. {
  66. Clean();
  67. }
  68. HRESULT SearchEngine::WrapperBase::Clean()
  69. {
  70. return S_OK;
  71. }
  72. ////////////////////////////////////////////////////////////////////////////////
  73. STDMETHODIMP SearchEngine::WrapperBase::get_Enabled( /*[out, retval]*/ VARIANT_BOOL *pVal )
  74. {
  75. __HCP_BEGIN_PROPERTY_GET2("SearchEngine::WrapperBase::get_Enabled",hr,pVal,m_bEnabled);
  76. __HCP_END_PROPERTY(hr);
  77. }
  78. STDMETHODIMP SearchEngine::WrapperBase::put_Enabled( /*[in]*/ VARIANT_BOOL newVal )
  79. {
  80. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::put_Enabled",hr);
  81. m_bEnabled = newVal;
  82. __HCP_END_PROPERTY(hr);
  83. }
  84. STDMETHODIMP SearchEngine::WrapperBase::get_Owner( /*[out, retval]*/ BSTR *pVal )
  85. {
  86. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::get_Owner",hr,pVal);
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrOwner, pVal ));
  88. __HCP_END_PROPERTY(hr);
  89. }
  90. STDMETHODIMP SearchEngine::WrapperBase::get_Description( /*[out, retval]*/ BSTR *pVal )
  91. {
  92. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::get_Description",hr,pVal);
  93. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrDescription, pVal ));
  94. __HCP_END_PROPERTY(hr);
  95. }
  96. STDMETHODIMP SearchEngine::WrapperBase::get_Name( /*[out, retval]*/ BSTR *pVal )
  97. {
  98. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::get_Name",hr,pVal);
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrName, pVal ));
  100. __HCP_END_PROPERTY(hr);
  101. }
  102. STDMETHODIMP SearchEngine::WrapperBase::get_ID( /*[out, retval]*/ BSTR *pVal )
  103. {
  104. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::get_ID",hr,pVal);
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrID, pVal ));
  106. __HCP_END_PROPERTY(hr);
  107. }
  108. STDMETHODIMP SearchEngine::WrapperBase::get_HelpURL( /*[out, retval]*/ BSTR *pVal )
  109. {
  110. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::get_HelpURL",hr,pVal);
  111. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_bstrHelpURL, pVal ));
  112. __HCP_END_PROPERTY(hr);
  113. }
  114. STDMETHODIMP SearchEngine::WrapperBase::get_SearchTerms( /*[out, retval]*/ VARIANT *pVal )
  115. {
  116. return S_OK;
  117. }
  118. ////////////////////
  119. VARIANT* SearchEngine::WrapperBase::GetParamInternal( /*[in]*/ LPCWSTR szParamName )
  120. {
  121. ParamMapIter it;
  122. it = m_aParam.find( szParamName );
  123. return (it == m_aParam.end()) ? NULL : &it->second;
  124. }
  125. HRESULT SearchEngine::WrapperBase::CreateParam( /*[in/out]*/ CPCHCollection* coll, /*[in]*/ const ParamItem_Definition* def )
  126. {
  127. __HCP_FUNC_ENTRY( "SearchEngine::WrapperBase::CreateParam" );
  128. HRESULT hr;
  129. CComPtr<ParamItem> obj;
  130. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  131. {
  132. ParamItem_Data& data = obj->Data();
  133. data.m_pteParamType = def->m_pteParamType;
  134. data.m_bRequired = def->m_bRequired;
  135. data.m_bVisible = def->m_bVisible;
  136. data.m_bstrName = def->m_szName;
  137. if(def->m_iDisplayString)
  138. {
  139. (void)MPC::LocalizeString( def->m_iDisplayString, data.m_bstrDisplayString, /*fMUI*/true );
  140. }
  141. else if(def->m_szDisplayString)
  142. {
  143. data.m_bstrDisplayString = def->m_szDisplayString;
  144. }
  145. if(def->m_szData)
  146. {
  147. VARTYPE vt;
  148. switch(data.m_pteParamType)
  149. {
  150. case PARAM_UI1 : vt = VT_UI1 ; break;
  151. case PARAM_I2 : vt = VT_I2 ; break;
  152. case PARAM_I4 : vt = VT_I4 ; break;
  153. case PARAM_R4 : vt = VT_R4 ; break;
  154. case PARAM_R8 : vt = VT_R8 ; break;
  155. case PARAM_BOOL: vt = VT_BOOL ; break;
  156. case PARAM_DATE: vt = VT_DATE ; break;
  157. case PARAM_BSTR: vt = VT_BSTR ; break;
  158. case PARAM_I1 : vt = VT_I1 ; break;
  159. case PARAM_UI2 : vt = VT_UI2 ; break;
  160. case PARAM_UI4 : vt = VT_UI4 ; break;
  161. case PARAM_INT : vt = VT_INT ; break;
  162. case PARAM_UINT: vt = VT_UINT ; break;
  163. case PARAM_LIST: vt = VT_BSTR ; break;
  164. default : vt = VT_EMPTY; break;
  165. }
  166. if(vt != VT_EMPTY)
  167. {
  168. data.m_varData = def->m_szData;
  169. if(FAILED(data.m_varData.ChangeType( vt )) || data.m_varData.vt != vt)
  170. {
  171. data.m_varData.Clear();
  172. }
  173. }
  174. }
  175. if(data.m_pteParamType != PARAM_LIST)
  176. {
  177. __MPC_EXIT_IF_METHOD_FAILS(hr, AddParam( data.m_bstrName, data.m_varData ));
  178. }
  179. }
  180. __MPC_EXIT_IF_METHOD_FAILS(hr, coll->AddItem( obj ));
  181. hr = S_OK;
  182. __HCP_FUNC_CLEANUP;
  183. __HCP_FUNC_EXIT(hr);
  184. }
  185. HRESULT SearchEngine::WrapperBase::CreateListOfParams( /*[in]*/ CPCHCollection* coll )
  186. {
  187. __HCP_FUNC_ENTRY( "SearchEngine::WrapperBase::CreateListOfParams" );
  188. HRESULT hr;
  189. const ParamItem_Definition* lst = NULL;
  190. int len = 0;
  191. __MPC_EXIT_IF_METHOD_FAILS(hr, GetParamDefinition( lst, len ));
  192. while(len-- > 0)
  193. {
  194. __MPC_EXIT_IF_METHOD_FAILS(hr, CreateParam( coll, lst++ ));
  195. }
  196. hr = S_OK;
  197. __HCP_FUNC_CLEANUP;
  198. __HCP_FUNC_EXIT(hr);
  199. }
  200. HRESULT SearchEngine::WrapperBase::GetParamDefinition( /*[out]*/ const ParamItem_Definition*& lst, /*[out]*/ int& len )
  201. {
  202. lst = NULL;
  203. len = 0;
  204. return S_OK;
  205. }
  206. STDMETHODIMP SearchEngine::WrapperBase::Param( /*[out,retval]*/ IPCHCollection* *ppC )
  207. {
  208. __HCP_BEGIN_PROPERTY_GET("SearchEngine::WrapperBase::Param",hr,ppC);
  209. if(!m_pParamDef)
  210. {
  211. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_pParamDef ));
  212. __MPC_EXIT_IF_METHOD_FAILS(hr, CreateListOfParams ( m_pParamDef ));
  213. }
  214. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pParamDef.QueryInterface( ppC ));
  215. __HCP_END_PROPERTY(hr);
  216. }
  217. STDMETHODIMP SearchEngine::WrapperBase::AddParam( /*[in]*/ BSTR bstrParamName, /*[in]*/ VARIANT newVal )
  218. {
  219. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::AddParam",hr);
  220. std::pair<ParamMapIter, bool> item;
  221. __MPC_PARAMCHECK_BEGIN(hr)
  222. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrParamName);
  223. __MPC_PARAMCHECK_END();
  224. item = m_aParam.insert( ParamMap::value_type( bstrParamName, CComVariant() ) ); item.first->second = newVal;
  225. __HCP_END_PROPERTY(hr);
  226. }
  227. STDMETHODIMP SearchEngine::WrapperBase::GetParam( /*[in]*/ BSTR bstrParamName, /*[out,retval]*/ VARIANT *pVal )
  228. {
  229. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::AddParam",hr);
  230. VARIANT* v;
  231. __MPC_PARAMCHECK_BEGIN(hr)
  232. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrParamName);
  233. __MPC_PARAMCHECK_NOTNULL(pVal);
  234. __MPC_PARAMCHECK_END();
  235. v = GetParamInternal( bstrParamName );
  236. if(!v)
  237. {
  238. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ERROR_INVALID_PARAMETER);
  239. }
  240. __MPC_EXIT_IF_METHOD_FAILS(hr, ::VariantCopy( pVal, v ));
  241. __HCP_END_PROPERTY(hr);
  242. }
  243. STDMETHODIMP SearchEngine::WrapperBase::DelParam( /*[in]*/ BSTR bstrParamName )
  244. {
  245. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::AddParam",hr);
  246. __MPC_PARAMCHECK_BEGIN(hr)
  247. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrParamName);
  248. __MPC_PARAMCHECK_END();
  249. m_aParam.erase( bstrParamName );
  250. __HCP_END_PROPERTY(hr);
  251. }
  252. ////////////////////////////////////////////////////////////////////////////////
  253. STDMETHODIMP SearchEngine::WrapperBase::get_QueryString( /*[out, retval]*/ BSTR *pVal )
  254. {
  255. MPC::SmartLock<_ThreadModel> lock( this );
  256. return MPC::GetBSTR( m_bstrQueryString, pVal );
  257. }
  258. STDMETHODIMP SearchEngine::WrapperBase::put_QueryString( /*[in]*/ BSTR newVal )
  259. {
  260. MPC::SmartLock<_ThreadModel> lock( this );
  261. return MPC::PutBSTR( m_bstrQueryString, newVal, false );
  262. }
  263. STDMETHODIMP SearchEngine::WrapperBase::get_NumResult(/*[out, retval]*/ long *pVal )
  264. {
  265. __HCP_BEGIN_PROPERTY_GET2("SearchEngine::WrapperBase::get_NumResult",hr,pVal,m_lNumResult);
  266. __HCP_END_PROPERTY(hr);
  267. }
  268. STDMETHODIMP SearchEngine::WrapperBase::put_NumResult( /*[in]*/ long newVal )
  269. {
  270. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::put_NumResult",hr);
  271. m_lNumResult = newVal;
  272. __HCP_END_PROPERTY(hr);
  273. }
  274. ////////////////////
  275. STDMETHODIMP SearchEngine::WrapperBase::Initialize( /*[in]*/ BSTR bstrID, /*[in]*/ BSTR bstrSKU, /*[in]*/ long lLCID, /*[in]*/ BSTR bstrData )
  276. {
  277. if(STRINGISPRESENT(bstrID)) m_bstrID = bstrID;
  278. if(bstrData)
  279. {
  280. SearchEngine::WrapperConfig cfg;
  281. MPC::XmlUtil xml;
  282. bool fLoaded;
  283. bool fFound;
  284. if(SUCCEEDED(xml.LoadAsString( bstrData, NULL, fLoaded )) && fLoaded)
  285. {
  286. if(SUCCEEDED(MPC::Config::LoadXmlUtil( &cfg, xml )))
  287. {
  288. if(cfg.m_bstrName ) m_bstrName = cfg.m_bstrName ;
  289. if(cfg.m_bstrDescription) m_bstrDescription = cfg.m_bstrDescription;
  290. if(cfg.m_bstrHelpURL ) m_bstrHelpURL = cfg.m_bstrHelpURL ;
  291. if(cfg.m_bstrScope ) m_bstrScope = cfg.m_bstrScope ;
  292. }
  293. }
  294. }
  295. return m_ths.Initialize( bstrSKU, lLCID );
  296. }
  297. STDMETHODIMP SearchEngine::WrapperBase::SECallbackInterface( /*[in]*/ IPCHSEManagerInternal* pMgr )
  298. {
  299. __HCP_BEGIN_PROPERTY_PUT("SearchEngine::WrapperBase::SECallbackInterface",hr);
  300. m_pSEMgr = pMgr;
  301. __HCP_END_PROPERTY(hr);
  302. }