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.

377 lines
8.1 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. LONG cRef = InterlockedDecrement(&m_cRef);
  105. if (0 != cRef)
  106. {
  107. _ASSERT(cRef > 0);
  108. return cRef;
  109. }
  110. delete this;
  111. return 0;
  112. }
  113. //***************************************************************************
  114. // HRESULT CSWbemMethodSet::InterfaceSupportsErrorInfo
  115. //
  116. // DESCRIPTION:
  117. //
  118. // Standard Com ISupportErrorInfo functions.
  119. //
  120. //***************************************************************************
  121. STDMETHODIMP CSWbemMethodSet::InterfaceSupportsErrorInfo (IN REFIID riid)
  122. {
  123. return (IID_ISWbemMethodSet == riid) ? S_OK : S_FALSE;
  124. }
  125. //***************************************************************************
  126. //
  127. // SCODE CSWbemMethodSet::Item
  128. //
  129. // DESCRIPTION:
  130. //
  131. // Get a method
  132. //
  133. // PARAMETERS:
  134. //
  135. // bsName The name of the method
  136. // lFlags Flags
  137. // ppProp On successful return addresses the ISWbemMethod
  138. //
  139. // RETURN VALUES:
  140. //
  141. // WBEM_S_NO_ERROR success
  142. // WBEM_E_INVALID_PARAMETER bad input parameters
  143. // WBEM_E_FAILED otherwise
  144. //
  145. // Other WBEM error codes may be returned by ConnectServer etc., in which
  146. // case these are passed on to the caller.
  147. //
  148. //***************************************************************************
  149. HRESULT CSWbemMethodSet::Item (
  150. BSTR bsName,
  151. long lFlags,
  152. ISWbemMethod ** ppMethod
  153. )
  154. {
  155. HRESULT hr = WBEM_E_FAILED;
  156. ResetLastErrors ();
  157. if (NULL == ppMethod)
  158. hr = WBEM_E_INVALID_PARAMETER;
  159. else
  160. {
  161. *ppMethod = NULL;
  162. if (m_pIWbemClassObject)
  163. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->GetMethod (bsName, lFlags, NULL, NULL)))
  164. {
  165. if (!(*ppMethod =
  166. new CSWbemMethod (m_pSWbemServices, m_pIWbemClassObject, bsName)))
  167. hr = WBEM_E_OUT_OF_MEMORY;
  168. }
  169. }
  170. if (FAILED(hr))
  171. m_Dispatch.RaiseException (hr);
  172. return hr;
  173. }
  174. //***************************************************************************
  175. //
  176. // SCODE CSWbemMethodSet::BeginEnumeration
  177. //
  178. // DESCRIPTION:
  179. //
  180. // Begin an enumeration of the methods
  181. //
  182. // RETURN VALUES:
  183. //
  184. // WBEM_S_NO_ERROR success
  185. // WBEM_E_INVALID_PARAMETER bad input parameters
  186. // WBEM_E_FAILED otherwise
  187. //
  188. //***************************************************************************
  189. HRESULT CSWbemMethodSet::BeginEnumeration (
  190. )
  191. {
  192. HRESULT hr = WBEM_E_FAILED;
  193. ResetLastErrors ();
  194. if (m_pIWbemClassObject)
  195. {
  196. hr = m_pIWbemClassObject->EndEnumeration ();
  197. hr = m_pIWbemClassObject->BeginMethodEnumeration (0);
  198. }
  199. if (FAILED(hr))
  200. m_Dispatch.RaiseException (hr);
  201. return hr;
  202. }
  203. //***************************************************************************
  204. //
  205. // SCODE CSWbemMethodSet::Next
  206. //
  207. // DESCRIPTION:
  208. //
  209. // Get next method in enumeration
  210. //
  211. // PARAMETERS:
  212. //
  213. // lFlags Flags
  214. // ppMethod Next method (or NULL if end of enumeration)
  215. //
  216. // RETURN VALUES:
  217. //
  218. // WBEM_S_NO_ERROR success
  219. // WBEM_E_INVALID_PARAMETER bad input parameters
  220. // WBEM_E_FAILED otherwise
  221. //
  222. //***************************************************************************
  223. HRESULT CSWbemMethodSet::Next (
  224. long lFlags,
  225. ISWbemMethod ** ppMethod
  226. )
  227. {
  228. HRESULT hr = WBEM_E_FAILED;
  229. ResetLastErrors ();
  230. if (NULL == ppMethod)
  231. hr = WBEM_E_INVALID_PARAMETER;
  232. else
  233. {
  234. *ppMethod = NULL;
  235. if (m_pIWbemClassObject)
  236. {
  237. BSTR bsName = NULL;
  238. if (WBEM_S_NO_ERROR == (hr = m_pIWbemClassObject->NextMethod (lFlags, &bsName, NULL, NULL)))
  239. {
  240. if (!(*ppMethod = new CSWbemMethod (m_pSWbemServices, m_pIWbemClassObject, bsName)))
  241. hr = WBEM_E_OUT_OF_MEMORY;
  242. SysFreeString (bsName);
  243. }
  244. }
  245. }
  246. if (FAILED(hr))
  247. m_Dispatch.RaiseException (hr);
  248. return hr;
  249. }
  250. //***************************************************************************
  251. //
  252. // SCODE CSWbemMethodSet::get__NewEnum
  253. //
  254. // DESCRIPTION:
  255. //
  256. // Return an IEnumVARIANT-supporting interface for collections
  257. //
  258. // PARAMETERS:
  259. //
  260. // ppUnk on successful return addresses the IUnknown interface
  261. //
  262. // RETURN VALUES:
  263. //
  264. // S_OK success
  265. // E_FAIL otherwise
  266. //
  267. //***************************************************************************
  268. HRESULT CSWbemMethodSet::get__NewEnum (
  269. IUnknown **ppUnk
  270. )
  271. {
  272. HRESULT hr = E_FAIL;
  273. ResetLastErrors ();
  274. if (NULL != ppUnk)
  275. {
  276. *ppUnk = NULL;
  277. CMethodSetEnumVar *pEnum = new CMethodSetEnumVar (this);
  278. if (!pEnum)
  279. hr = WBEM_E_OUT_OF_MEMORY;
  280. else if (FAILED(hr = pEnum->QueryInterface (IID_IUnknown, (PPVOID) ppUnk)))
  281. delete pEnum;
  282. }
  283. if (FAILED(hr))
  284. m_Dispatch.RaiseException (hr);
  285. return hr;
  286. }
  287. //***************************************************************************
  288. //
  289. // SCODE CSWbemMethodSet::get_Count
  290. //
  291. // DESCRIPTION:
  292. //
  293. // Return the number of items in the collection
  294. //
  295. // PARAMETERS:
  296. //
  297. // plCount on successful return addresses value
  298. //
  299. // RETURN VALUES:
  300. //
  301. // S_OK success
  302. // E_FAIL otherwise
  303. //
  304. //***************************************************************************
  305. HRESULT CSWbemMethodSet::get_Count (
  306. long *plCount
  307. )
  308. {
  309. HRESULT hr = E_FAIL;
  310. ResetLastErrors ();
  311. if (NULL != plCount)
  312. {
  313. *plCount = m_Count;
  314. hr = S_OK;
  315. }
  316. if (FAILED(hr))
  317. m_Dispatch.RaiseException (hr);
  318. return hr;
  319. }