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.

400 lines
8.7 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. LONG cRef = InterlockedDecrement(&m_cRef);
  98. if (0 != cRef)
  99. {
  100. _ASSERT(cRef > 0);
  101. return cRef;
  102. }
  103. delete this;
  104. return 0;
  105. }
  106. //***************************************************************************
  107. // HRESULT CSWbemMethod::InterfaceSupportsErrorInfo
  108. //
  109. // DESCRIPTION:
  110. //
  111. // Standard Com ISupportErrorInfo functions.
  112. //
  113. //***************************************************************************
  114. STDMETHODIMP CSWbemMethod::InterfaceSupportsErrorInfo (IN REFIID riid)
  115. {
  116. return (IID_ISWbemMethod == riid) ? S_OK : S_FALSE;
  117. }
  118. //***************************************************************************
  119. //
  120. // SCODE CSWbemMethod::get_Name
  121. //
  122. // DESCRIPTION:
  123. //
  124. // Retrieve the method name
  125. //
  126. // PARAMETERS:
  127. //
  128. // pName holds the name on return
  129. //
  130. // RETURN VALUES:
  131. //
  132. // WBEM_S_NO_ERROR success
  133. // WBEM_E_INVALID_PARAMETER bad input parameters
  134. // WBEM_E_FAILED otherwise
  135. //
  136. //***************************************************************************
  137. HRESULT CSWbemMethod::get_Name (
  138. BSTR *pName
  139. )
  140. {
  141. HRESULT hr = WBEM_S_NO_ERROR;
  142. ResetLastErrors ();
  143. if (NULL == pName)
  144. hr = WBEM_E_INVALID_PARAMETER;
  145. else
  146. *pName = SysAllocString (m_name);
  147. if (FAILED(hr))
  148. m_Dispatch.RaiseException (hr);
  149. return hr;
  150. }
  151. //***************************************************************************
  152. //
  153. // SCODE CSWbemMethod::get_InParameters
  154. //
  155. // DESCRIPTION:
  156. //
  157. // Retrieve the method in parameters signature
  158. //
  159. // PARAMETERS:
  160. //
  161. // ppInSignature addresses the in signature on return
  162. //
  163. // RETURN VALUES:
  164. //
  165. // WBEM_S_NO_ERROR success
  166. // WBEM_E_INVALID_PARAMETER bad input parameters
  167. // WBEM_E_FAILED otherwise
  168. //
  169. //***************************************************************************
  170. HRESULT CSWbemMethod::get_InParameters (
  171. ISWbemObject **ppInSignature
  172. )
  173. {
  174. HRESULT hr = WBEM_E_FAILED;
  175. ResetLastErrors ();
  176. if (NULL == ppInSignature)
  177. hr = WBEM_E_INVALID_PARAMETER;
  178. else
  179. {
  180. *ppInSignature = NULL;
  181. if (m_pIWbemClassObject)
  182. {
  183. IWbemClassObject *pInSig = NULL;
  184. /*
  185. * Note that if there are no in parameters, the following
  186. * call will succeed but pInSig will be NULL.
  187. */
  188. if ((WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod
  189. (m_name, 0, &pInSig, NULL))) && pInSig)
  190. {
  191. CSWbemObject *pObject = new CSWbemObject (m_pSWbemServices, pInSig);
  192. if (!pObject)
  193. hr = WBEM_E_OUT_OF_MEMORY;
  194. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  195. (PPVOID) ppInSignature)))
  196. delete pObject;
  197. pInSig->Release ();
  198. }
  199. }
  200. }
  201. if (FAILED(hr))
  202. m_Dispatch.RaiseException (hr);
  203. return hr;
  204. }
  205. //***************************************************************************
  206. //
  207. // SCODE CSWbemMethod::get_OutParameters
  208. //
  209. // DESCRIPTION:
  210. //
  211. // Retrieve the method out parameters signature
  212. //
  213. // PARAMETERS:
  214. //
  215. // ppOutSignature addresses the out signature on return
  216. //
  217. // RETURN VALUES:
  218. //
  219. // WBEM_S_NO_ERROR success
  220. // WBEM_E_INVALID_PARAMETER bad input parameters
  221. // WBEM_E_FAILED otherwise
  222. //
  223. //***************************************************************************
  224. HRESULT CSWbemMethod::get_OutParameters (
  225. ISWbemObject **ppOutSignature
  226. )
  227. {
  228. HRESULT hr = WBEM_E_FAILED;
  229. ResetLastErrors ();
  230. if (NULL == ppOutSignature)
  231. hr = WBEM_E_INVALID_PARAMETER;
  232. else
  233. {
  234. *ppOutSignature = NULL;
  235. if (m_pIWbemClassObject)
  236. {
  237. IWbemClassObject *pOutSig = NULL;
  238. /*
  239. * Note that if there are no in parameters, the following
  240. * call will succeed but pOutSig will be NULL.
  241. */
  242. if ((WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod
  243. (m_name, 0, NULL, &pOutSig))) && pOutSig)
  244. {
  245. CSWbemObject *pObject = new CSWbemObject (m_pSWbemServices, pOutSig);
  246. if (!pObject)
  247. hr = WBEM_E_OUT_OF_MEMORY;
  248. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  249. (PPVOID) ppOutSignature)))
  250. delete pObject;
  251. pOutSig->Release ();
  252. }
  253. }
  254. }
  255. if (FAILED(hr))
  256. m_Dispatch.RaiseException (hr);
  257. return hr;
  258. }
  259. //***************************************************************************
  260. //
  261. // SCODE CSWbemMethod::get_Origin
  262. //
  263. // DESCRIPTION:
  264. //
  265. // Retrieve the method origin
  266. //
  267. // PARAMETERS:
  268. //
  269. // pOrigin holds the origin class on return
  270. //
  271. // RETURN VALUES:
  272. //
  273. // WBEM_S_NO_ERROR success
  274. // WBEM_E_INVALID_PARAMETER bad input parameters
  275. // WBEM_E_FAILED otherwise
  276. //
  277. //***************************************************************************
  278. HRESULT CSWbemMethod::get_Origin (
  279. BSTR *pOrigin
  280. )
  281. {
  282. HRESULT hr = WBEM_S_NO_ERROR;
  283. ResetLastErrors ();
  284. if (NULL == pOrigin)
  285. hr = WBEM_E_INVALID_PARAMETER;
  286. else
  287. {
  288. if (m_pIWbemClassObject)
  289. m_pIWbemClassObject->GetMethodOrigin (m_name, pOrigin);
  290. if (NULL == *pOrigin)
  291. *pOrigin = SysAllocString (OLESTR(""));
  292. }
  293. if (FAILED(hr))
  294. m_Dispatch.RaiseException (hr);
  295. return hr;
  296. }
  297. //***************************************************************************
  298. //
  299. // SCODE CSWbemMethod::get_Qualifiers_
  300. //
  301. // DESCRIPTION:
  302. //
  303. // Retrieve the method qualifier set
  304. //
  305. // PARAMETERS:
  306. //
  307. // ppQualSet addresses the qualifier set on return
  308. //
  309. // RETURN VALUES:
  310. //
  311. // WBEM_S_NO_ERROR success
  312. // WBEM_E_INVALID_PARAMETER bad input parameters
  313. // WBEM_E_FAILED otherwise
  314. //
  315. //***************************************************************************
  316. HRESULT CSWbemMethod::get_Qualifiers_ (
  317. ISWbemQualifierSet **ppQualSet
  318. )
  319. {
  320. HRESULT hr = WBEM_E_FAILED;
  321. ResetLastErrors ();
  322. if (NULL == ppQualSet)
  323. hr = WBEM_E_INVALID_PARAMETER;
  324. else if (m_pIWbemClassObject)
  325. {
  326. IWbemQualifierSet *pQualSet = NULL;
  327. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethodQualifierSet
  328. (m_name, &pQualSet)))
  329. {
  330. if (!(*ppQualSet = new CSWbemQualifierSet (pQualSet)))
  331. hr = WBEM_E_OUT_OF_MEMORY;
  332. pQualSet->Release ();
  333. }
  334. }
  335. if (FAILED(hr))
  336. m_Dispatch.RaiseException (hr);
  337. return hr;
  338. }