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.

373 lines
7.7 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // PROPSET.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemPropertySet
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemMethodSet::CSWbemMethodSet
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemMethodSet::CSWbemMethodSet(CSWbemServices *pService, IWbemClassObject *pObject)
  23. {
  24. m_Dispatch.SetObj (this, IID_ISWbemMethodSet,
  25. CLSID_SWbemMethodSet, L"SWbemMethodSet");
  26. m_pIWbemClassObject = pObject;
  27. m_pIWbemClassObject->AddRef ();
  28. m_pSWbemServices = pService;
  29. if (m_pSWbemServices)
  30. m_pSWbemServices->AddRef ();
  31. m_cRef=1;
  32. InterlockedIncrement(&g_cObj);
  33. // Set up the Count. We can do this because this is a read-only interface
  34. m_Count = 0;
  35. pObject->BeginMethodEnumeration (0);
  36. BSTR bstrName = NULL;
  37. while (WBEM_S_NO_ERROR == pObject->NextMethod (0, &bstrName, NULL, NULL))
  38. {
  39. SysFreeString (bstrName);
  40. m_Count++;
  41. }
  42. pObject->EndMethodEnumeration ();
  43. }
  44. //***************************************************************************
  45. //
  46. // CSWbemMethodSet::~CSWbemMethodSet
  47. //
  48. // DESCRIPTION:
  49. //
  50. // Destructor.
  51. //
  52. //***************************************************************************
  53. CSWbemMethodSet::~CSWbemMethodSet()
  54. {
  55. InterlockedDecrement(&g_cObj);
  56. if (m_pIWbemClassObject)
  57. {
  58. m_pIWbemClassObject->EndMethodEnumeration ();
  59. m_pIWbemClassObject->Release ();
  60. }
  61. if (m_pSWbemServices)
  62. m_pSWbemServices->Release ();
  63. }
  64. //***************************************************************************
  65. // HRESULT CSWbemMethodSet::QueryInterface
  66. // long CSWbemMethodSet::AddRef
  67. // long CSWbemMethodSet::Release
  68. //
  69. // DESCRIPTION:
  70. //
  71. // Standard Com IUNKNOWN functions.
  72. //
  73. //***************************************************************************
  74. STDMETHODIMP CSWbemMethodSet::QueryInterface (
  75. IN REFIID riid,
  76. OUT LPVOID *ppv
  77. )
  78. {
  79. *ppv=NULL;
  80. if (IID_IUnknown==riid)
  81. *ppv = reinterpret_cast<IUnknown*>(this);
  82. else if (IID_ISWbemMethodSet==riid)
  83. *ppv = (ISWbemMethodSet *)this;
  84. else if (IID_IDispatch==riid)
  85. *ppv = (IDispatch *)this;
  86. else if (IID_ISupportErrorInfo==riid)
  87. *ppv = (ISupportErrorInfo *)this;
  88. else if (IID_IProvideClassInfo==riid)
  89. *ppv = (IProvideClassInfo *)this;
  90. if (NULL!=*ppv)
  91. {
  92. ((LPUNKNOWN)*ppv)->AddRef();
  93. return NOERROR;
  94. }
  95. return ResultFromScode(E_NOINTERFACE);
  96. }
  97. STDMETHODIMP_(ULONG) CSWbemMethodSet::AddRef(void)
  98. {
  99. InterlockedIncrement(&m_cRef);
  100. return m_cRef;
  101. }
  102. STDMETHODIMP_(ULONG) CSWbemMethodSet::Release(void)
  103. {
  104. InterlockedDecrement(&m_cRef);
  105. if (0L!=m_cRef)
  106. return m_cRef;
  107. delete this;
  108. return 0;
  109. }
  110. //***************************************************************************
  111. // HRESULT CSWbemMethodSet::InterfaceSupportsErrorInfo
  112. //
  113. // DESCRIPTION:
  114. //
  115. // Standard Com ISupportErrorInfo functions.
  116. //
  117. //***************************************************************************
  118. STDMETHODIMP CSWbemMethodSet::InterfaceSupportsErrorInfo (IN REFIID riid)
  119. {
  120. return (IID_ISWbemMethodSet == riid) ? S_OK : S_FALSE;
  121. }
  122. //***************************************************************************
  123. //
  124. // SCODE CSWbemMethodSet::Item
  125. //
  126. // DESCRIPTION:
  127. //
  128. // Get a method
  129. //
  130. // PARAMETERS:
  131. //
  132. // bsName The name of the method
  133. // lFlags Flags
  134. // ppProp On successful return addresses the ISWbemMethod
  135. //
  136. // RETURN VALUES:
  137. //
  138. // WBEM_S_NO_ERROR success
  139. // WBEM_E_INVALID_PARAMETER bad input parameters
  140. // WBEM_E_FAILED otherwise
  141. //
  142. // Other WBEM error codes may be returned by ConnectServer etc., in which
  143. // case these are passed on to the caller.
  144. //
  145. //***************************************************************************
  146. HRESULT CSWbemMethodSet::Item (
  147. BSTR bsName,
  148. long lFlags,
  149. ISWbemMethod ** ppMethod
  150. )
  151. {
  152. HRESULT hr = WBEM_E_FAILED;
  153. ResetLastErrors ();
  154. if (NULL == ppMethod)
  155. hr = WBEM_E_INVALID_PARAMETER;
  156. else
  157. {
  158. *ppMethod = NULL;
  159. if (m_pIWbemClassObject)
  160. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod (bsName, lFlags, NULL, NULL)))
  161. {
  162. if (!(*ppMethod =
  163. new CSWbemMethod (m_pSWbemServices, m_pIWbemClassObject, bsName)))
  164. hr = WBEM_E_OUT_OF_MEMORY;
  165. }
  166. }
  167. if (FAILED(hr))
  168. m_Dispatch.RaiseException (hr);
  169. return hr;
  170. }
  171. //***************************************************************************
  172. //
  173. // SCODE CSWbemMethodSet::BeginEnumeration
  174. //
  175. // DESCRIPTION:
  176. //
  177. // Begin an enumeration of the methods
  178. //
  179. // RETURN VALUES:
  180. //
  181. // WBEM_S_NO_ERROR success
  182. // WBEM_E_INVALID_PARAMETER bad input parameters
  183. // WBEM_E_FAILED otherwise
  184. //
  185. //***************************************************************************
  186. HRESULT CSWbemMethodSet::BeginEnumeration (
  187. )
  188. {
  189. HRESULT hr = WBEM_E_FAILED;
  190. ResetLastErrors ();
  191. if (m_pIWbemClassObject)
  192. {
  193. hr = m_pIWbemClassObject->EndEnumeration ();
  194. hr = m_pIWbemClassObject->BeginMethodEnumeration (0);
  195. }
  196. if (FAILED(hr))
  197. m_Dispatch.RaiseException (hr);
  198. return hr;
  199. }
  200. //***************************************************************************
  201. //
  202. // SCODE CSWbemMethodSet::Next
  203. //
  204. // DESCRIPTION:
  205. //
  206. // Get next method in enumeration
  207. //
  208. // PARAMETERS:
  209. //
  210. // lFlags Flags
  211. // ppMethod Next method (or NULL if end of enumeration)
  212. //
  213. // RETURN VALUES:
  214. //
  215. // WBEM_S_NO_ERROR success
  216. // WBEM_E_INVALID_PARAMETER bad input parameters
  217. // WBEM_E_FAILED otherwise
  218. //
  219. //***************************************************************************
  220. HRESULT CSWbemMethodSet::Next (
  221. long lFlags,
  222. ISWbemMethod ** ppMethod
  223. )
  224. {
  225. HRESULT hr = WBEM_E_FAILED;
  226. ResetLastErrors ();
  227. if (NULL == ppMethod)
  228. hr = WBEM_E_INVALID_PARAMETER;
  229. else
  230. {
  231. *ppMethod = NULL;
  232. if (m_pIWbemClassObject)
  233. {
  234. BSTR bsName = NULL;
  235. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->NextMethod (lFlags, &bsName, NULL, NULL)))
  236. {
  237. if (!(*ppMethod = new CSWbemMethod (m_pSWbemServices, m_pIWbemClassObject, bsName)))
  238. hr = WBEM_E_OUT_OF_MEMORY;
  239. SysFreeString (bsName);
  240. }
  241. }
  242. }
  243. if (FAILED(hr))
  244. m_Dispatch.RaiseException (hr);
  245. return hr;
  246. }
  247. //***************************************************************************
  248. //
  249. // SCODE CSWbemMethodSet::get__NewEnum
  250. //
  251. // DESCRIPTION:
  252. //
  253. // Return an IEnumVARIANT-supporting interface for collections
  254. //
  255. // PARAMETERS:
  256. //
  257. // ppUnk on successful return addresses the IUnknown interface
  258. //
  259. // RETURN VALUES:
  260. //
  261. // S_OK success
  262. // E_FAIL otherwise
  263. //
  264. //***************************************************************************
  265. HRESULT CSWbemMethodSet::get__NewEnum (
  266. IUnknown **ppUnk
  267. )
  268. {
  269. HRESULT hr = E_FAIL;
  270. ResetLastErrors ();
  271. if (NULL != ppUnk)
  272. {
  273. *ppUnk = NULL;
  274. CMethodSetEnumVar *pEnum = new CMethodSetEnumVar (this);
  275. if (!pEnum)
  276. hr = WBEM_E_OUT_OF_MEMORY;
  277. else if (FAILED(hr = pEnum->QueryInterface (IID_IUnknown, (PPVOID) ppUnk)))
  278. delete pEnum;
  279. }
  280. if (FAILED(hr))
  281. m_Dispatch.RaiseException (hr);
  282. return hr;
  283. }
  284. //***************************************************************************
  285. //
  286. // SCODE CSWbemMethodSet::get_Count
  287. //
  288. // DESCRIPTION:
  289. //
  290. // Return the number of items in the collection
  291. //
  292. // PARAMETERS:
  293. //
  294. // plCount on successful return addresses value
  295. //
  296. // RETURN VALUES:
  297. //
  298. // S_OK success
  299. // E_FAIL otherwise
  300. //
  301. //***************************************************************************
  302. HRESULT CSWbemMethodSet::get_Count (
  303. long *plCount
  304. )
  305. {
  306. HRESULT hr = E_FAIL;
  307. ResetLastErrors ();
  308. if (NULL != plCount)
  309. {
  310. *plCount = m_Count;
  311. hr = S_OK;
  312. }
  313. if (FAILED(hr))
  314. m_Dispatch.RaiseException (hr);
  315. return hr;
  316. }