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.

396 lines
8.2 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // METHOD.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemMethod
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemMethod::CSWbemMethod
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemMethod::CSWbemMethod(
  23. CSWbemServices *pService,
  24. IWbemClassObject *pIWbemClassObject,
  25. BSTR name
  26. )
  27. {
  28. m_Dispatch.SetObj (this, IID_ISWbemMethod,
  29. CLSID_SWbemMethod, L"SWbemMethod");
  30. m_cRef=1;
  31. m_pIWbemClassObject = pIWbemClassObject;
  32. m_pIWbemClassObject->AddRef ();
  33. m_pSWbemServices = pService;
  34. if (m_pSWbemServices)
  35. m_pSWbemServices->AddRef ();
  36. m_name = SysAllocString (name);
  37. InterlockedIncrement(&g_cObj);
  38. }
  39. //***************************************************************************
  40. //
  41. // CSWbemMethod::~CSWbemMethod
  42. //
  43. // DESCRIPTION:
  44. //
  45. // Destructor.
  46. //
  47. //***************************************************************************
  48. CSWbemMethod::~CSWbemMethod(void)
  49. {
  50. InterlockedDecrement(&g_cObj);
  51. if (m_pIWbemClassObject)
  52. m_pIWbemClassObject->Release ();
  53. if (m_pSWbemServices)
  54. m_pSWbemServices->Release ();
  55. SysFreeString (m_name);
  56. }
  57. //***************************************************************************
  58. // HRESULT CSWbemMethod::QueryInterface
  59. // long CSWbemMethod::AddRef
  60. // long CSWbemMethod::Release
  61. //
  62. // DESCRIPTION:
  63. //
  64. // Standard Com IUNKNOWN functions.
  65. //
  66. //***************************************************************************
  67. STDMETHODIMP CSWbemMethod::QueryInterface (
  68. IN REFIID riid,
  69. OUT LPVOID *ppv
  70. )
  71. {
  72. *ppv=NULL;
  73. if (IID_IUnknown==riid)
  74. *ppv = reinterpret_cast<IUnknown*>(this);
  75. else if (IID_ISWbemMethod==riid)
  76. *ppv = (ISWbemMethod *)this;
  77. else if (IID_IDispatch==riid)
  78. *ppv = (IDispatch *)this;
  79. else if (IID_ISupportErrorInfo==riid)
  80. *ppv = (ISupportErrorInfo *)this;
  81. else if (IID_IProvideClassInfo==riid)
  82. *ppv = (IProvideClassInfo *)this;
  83. if (NULL!=*ppv)
  84. {
  85. ((LPUNKNOWN)*ppv)->AddRef();
  86. return NOERROR;
  87. }
  88. return ResultFromScode(E_NOINTERFACE);
  89. }
  90. STDMETHODIMP_(ULONG) CSWbemMethod::AddRef(void)
  91. {
  92. InterlockedIncrement(&m_cRef);
  93. return m_cRef;
  94. }
  95. STDMETHODIMP_(ULONG) CSWbemMethod::Release(void)
  96. {
  97. InterlockedDecrement(&m_cRef);
  98. if (0L!=m_cRef)
  99. return m_cRef;
  100. delete this;
  101. return 0;
  102. }
  103. //***************************************************************************
  104. // HRESULT CSWbemMethod::InterfaceSupportsErrorInfo
  105. //
  106. // DESCRIPTION:
  107. //
  108. // Standard Com ISupportErrorInfo functions.
  109. //
  110. //***************************************************************************
  111. STDMETHODIMP CSWbemMethod::InterfaceSupportsErrorInfo (IN REFIID riid)
  112. {
  113. return (IID_ISWbemMethod == riid) ? S_OK : S_FALSE;
  114. }
  115. //***************************************************************************
  116. //
  117. // SCODE CSWbemMethod::get_Name
  118. //
  119. // DESCRIPTION:
  120. //
  121. // Retrieve the method name
  122. //
  123. // PARAMETERS:
  124. //
  125. // pName holds the name on return
  126. //
  127. // RETURN VALUES:
  128. //
  129. // WBEM_S_NO_ERROR success
  130. // WBEM_E_INVALID_PARAMETER bad input parameters
  131. // WBEM_E_FAILED otherwise
  132. //
  133. //***************************************************************************
  134. HRESULT CSWbemMethod::get_Name (
  135. BSTR *pName
  136. )
  137. {
  138. HRESULT hr = WBEM_S_NO_ERROR;
  139. ResetLastErrors ();
  140. if (NULL == pName)
  141. hr = WBEM_E_INVALID_PARAMETER;
  142. else
  143. *pName = SysAllocString (m_name);
  144. if (FAILED(hr))
  145. m_Dispatch.RaiseException (hr);
  146. return hr;
  147. }
  148. //***************************************************************************
  149. //
  150. // SCODE CSWbemMethod::get_InParameters
  151. //
  152. // DESCRIPTION:
  153. //
  154. // Retrieve the method in parameters signature
  155. //
  156. // PARAMETERS:
  157. //
  158. // ppInSignature addresses the in signature on return
  159. //
  160. // RETURN VALUES:
  161. //
  162. // WBEM_S_NO_ERROR success
  163. // WBEM_E_INVALID_PARAMETER bad input parameters
  164. // WBEM_E_FAILED otherwise
  165. //
  166. //***************************************************************************
  167. HRESULT CSWbemMethod::get_InParameters (
  168. ISWbemObject **ppInSignature
  169. )
  170. {
  171. HRESULT hr = WBEM_E_FAILED;
  172. ResetLastErrors ();
  173. if (NULL == ppInSignature)
  174. hr = WBEM_E_INVALID_PARAMETER;
  175. else
  176. {
  177. *ppInSignature = NULL;
  178. if (m_pIWbemClassObject)
  179. {
  180. IWbemClassObject *pInSig = NULL;
  181. /*
  182. * Note that if there are no in parameters, the following
  183. * call will succeed but pInSig will be NULL.
  184. */
  185. if ((WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod
  186. (m_name, 0, &pInSig, NULL))) && pInSig)
  187. {
  188. CSWbemObject *pObject = new CSWbemObject (m_pSWbemServices, pInSig);
  189. if (!pObject)
  190. hr = WBEM_E_OUT_OF_MEMORY;
  191. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  192. (PPVOID) ppInSignature)))
  193. delete pObject;
  194. pInSig->Release ();
  195. }
  196. }
  197. }
  198. if (FAILED(hr))
  199. m_Dispatch.RaiseException (hr);
  200. return hr;
  201. }
  202. //***************************************************************************
  203. //
  204. // SCODE CSWbemMethod::get_OutParameters
  205. //
  206. // DESCRIPTION:
  207. //
  208. // Retrieve the method out parameters signature
  209. //
  210. // PARAMETERS:
  211. //
  212. // ppOutSignature addresses the out signature on return
  213. //
  214. // RETURN VALUES:
  215. //
  216. // WBEM_S_NO_ERROR success
  217. // WBEM_E_INVALID_PARAMETER bad input parameters
  218. // WBEM_E_FAILED otherwise
  219. //
  220. //***************************************************************************
  221. HRESULT CSWbemMethod::get_OutParameters (
  222. ISWbemObject **ppOutSignature
  223. )
  224. {
  225. HRESULT hr = WBEM_E_FAILED;
  226. ResetLastErrors ();
  227. if (NULL == ppOutSignature)
  228. hr = WBEM_E_INVALID_PARAMETER;
  229. else
  230. {
  231. *ppOutSignature = NULL;
  232. if (m_pIWbemClassObject)
  233. {
  234. IWbemClassObject *pOutSig = NULL;
  235. /*
  236. * Note that if there are no in parameters, the following
  237. * call will succeed but pOutSig will be NULL.
  238. */
  239. if ((WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod
  240. (m_name, 0, NULL, &pOutSig))) && pOutSig)
  241. {
  242. CSWbemObject *pObject = new CSWbemObject (m_pSWbemServices, pOutSig);
  243. if (!pObject)
  244. hr = WBEM_E_OUT_OF_MEMORY;
  245. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  246. (PPVOID) ppOutSignature)))
  247. delete pObject;
  248. pOutSig->Release ();
  249. }
  250. }
  251. }
  252. if (FAILED(hr))
  253. m_Dispatch.RaiseException (hr);
  254. return hr;
  255. }
  256. //***************************************************************************
  257. //
  258. // SCODE CSWbemMethod::get_Origin
  259. //
  260. // DESCRIPTION:
  261. //
  262. // Retrieve the method origin
  263. //
  264. // PARAMETERS:
  265. //
  266. // pOrigin holds the origin class on return
  267. //
  268. // RETURN VALUES:
  269. //
  270. // WBEM_S_NO_ERROR success
  271. // WBEM_E_INVALID_PARAMETER bad input parameters
  272. // WBEM_E_FAILED otherwise
  273. //
  274. //***************************************************************************
  275. HRESULT CSWbemMethod::get_Origin (
  276. BSTR *pOrigin
  277. )
  278. {
  279. HRESULT hr = WBEM_S_NO_ERROR;
  280. ResetLastErrors ();
  281. if (NULL == pOrigin)
  282. hr = WBEM_E_INVALID_PARAMETER;
  283. else
  284. {
  285. if (m_pIWbemClassObject)
  286. m_pIWbemClassObject->GetMethodOrigin (m_name, pOrigin);
  287. if (NULL == *pOrigin)
  288. *pOrigin = SysAllocString (OLESTR(""));
  289. }
  290. if (FAILED(hr))
  291. m_Dispatch.RaiseException (hr);
  292. return hr;
  293. }
  294. //***************************************************************************
  295. //
  296. // SCODE CSWbemMethod::get_Qualifiers_
  297. //
  298. // DESCRIPTION:
  299. //
  300. // Retrieve the method qualifier set
  301. //
  302. // PARAMETERS:
  303. //
  304. // ppQualSet addresses the qualifier set on return
  305. //
  306. // RETURN VALUES:
  307. //
  308. // WBEM_S_NO_ERROR success
  309. // WBEM_E_INVALID_PARAMETER bad input parameters
  310. // WBEM_E_FAILED otherwise
  311. //
  312. //***************************************************************************
  313. HRESULT CSWbemMethod::get_Qualifiers_ (
  314. ISWbemQualifierSet **ppQualSet
  315. )
  316. {
  317. HRESULT hr = WBEM_E_FAILED;
  318. ResetLastErrors ();
  319. if (NULL == ppQualSet)
  320. hr = WBEM_E_INVALID_PARAMETER;
  321. else if (m_pIWbemClassObject)
  322. {
  323. IWbemQualifierSet *pQualSet = NULL;
  324. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethodQualifierSet
  325. (m_name, &pQualSet)))
  326. {
  327. if (!(*ppQualSet = new CSWbemQualifierSet (pQualSet)))
  328. hr = WBEM_E_OUT_OF_MEMORY;
  329. pQualSet->Release ();
  330. }
  331. }
  332. if (FAILED(hr))
  333. m_Dispatch.RaiseException (hr);
  334. return hr;
  335. }