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.

269 lines
6.0 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // ENUMOBJ.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemObjectSet
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemEventSource::CSWbemEventSource
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemEventSource::CSWbemEventSource(
  23. CSWbemServices *pService,
  24. IEnumWbemClassObject *pIEnumWbemClassObject)
  25. {
  26. m_Dispatch.SetObj (this, IID_ISWbemEventSource,
  27. CLSID_SWbemEventSource, L"SWbemEventSource");
  28. m_cRef=0;
  29. m_pSWbemServices = pService;
  30. if (m_pSWbemServices)
  31. {
  32. m_pSWbemServices->AddRef ();
  33. CSWbemSecurity *pSecurity = m_pSWbemServices->GetSecurityInfo ();
  34. if (pSecurity)
  35. {
  36. m_SecurityInfo = new CSWbemSecurity (pIEnumWbemClassObject,
  37. pSecurity);
  38. pSecurity->Release ();
  39. }
  40. }
  41. InterlockedIncrement(&g_cObj);
  42. }
  43. //***************************************************************************
  44. //
  45. // CSWbemEventSource::~CSWbemEventSource
  46. //
  47. // DESCRIPTION:
  48. //
  49. // Destructor.
  50. //
  51. //***************************************************************************
  52. CSWbemEventSource::~CSWbemEventSource(void)
  53. {
  54. InterlockedDecrement(&g_cObj);
  55. if (m_pSWbemServices)
  56. m_pSWbemServices->Release ();
  57. if (m_SecurityInfo)
  58. m_SecurityInfo->Release ();
  59. }
  60. //***************************************************************************
  61. // HRESULT CSWbemEventSource::QueryInterface
  62. // long CSWbemEventSource::AddRef
  63. // long CSWbemEventSource::Release
  64. //
  65. // DESCRIPTION:
  66. //
  67. // Standard Com IUNKNOWN functions.
  68. //
  69. //***************************************************************************
  70. STDMETHODIMP CSWbemEventSource::QueryInterface (
  71. IN REFIID riid,
  72. OUT LPVOID *ppv
  73. )
  74. {
  75. *ppv=NULL;
  76. if (IID_IUnknown==riid)
  77. *ppv = reinterpret_cast<IUnknown*>(this);
  78. else if (IID_ISWbemEventSource==riid)
  79. *ppv = (ISWbemEventSource*)this;
  80. else if (IID_IDispatch==riid)
  81. *ppv = (IDispatch *)this;
  82. else if (IID_ISupportErrorInfo==riid)
  83. *ppv = (ISupportErrorInfo *)this;
  84. else if (IID_IProvideClassInfo==riid)
  85. *ppv = (IProvideClassInfo *)this;
  86. if (NULL!=*ppv)
  87. {
  88. ((LPUNKNOWN)*ppv)->AddRef();
  89. return NOERROR;
  90. }
  91. return ResultFromScode(E_NOINTERFACE);
  92. }
  93. STDMETHODIMP_(ULONG) CSWbemEventSource::AddRef(void)
  94. {
  95. InterlockedIncrement(&m_cRef);
  96. return m_cRef;
  97. }
  98. STDMETHODIMP_(ULONG) CSWbemEventSource::Release(void)
  99. {
  100. InterlockedDecrement(&m_cRef);
  101. if (0L!=m_cRef)
  102. return m_cRef;
  103. delete this;
  104. return 0;
  105. }
  106. //***************************************************************************
  107. // HRESULT CSWbemEventSource::InterfaceSupportsErrorInfo
  108. //
  109. // DESCRIPTION:
  110. //
  111. // Standard Com ISupportErrorInfo functions.
  112. //
  113. //***************************************************************************
  114. STDMETHODIMP CSWbemEventSource::InterfaceSupportsErrorInfo (IN REFIID riid)
  115. {
  116. return (IID_ISWbemEventSource == riid) ? S_OK : S_FALSE;
  117. }
  118. //***************************************************************************
  119. //
  120. // SCODE CSWbemEventSource::NextEvent
  121. //
  122. // DESCRIPTION:
  123. //
  124. // Get the next event, or timeout
  125. //
  126. // PARAMETERS:
  127. //
  128. // lTimeout Number of ms to wait for object (or wbemTimeoutInfinite for
  129. // indefinite)
  130. // ppObject On return may contain the next element (if any)
  131. //
  132. // RETURN VALUES:
  133. //
  134. // WBEM_S_NO_ERROR success
  135. // WBEM_E_FAILED otherwise
  136. //
  137. //***************************************************************************
  138. HRESULT CSWbemEventSource::NextEvent (
  139. long lTimeout,
  140. ISWbemObject **ppObject
  141. )
  142. {
  143. HRESULT hr = WBEM_E_FAILED;
  144. ResetLastErrors ();
  145. if (NULL == ppObject)
  146. hr = WBEM_E_INVALID_PARAMETER;
  147. else
  148. {
  149. *ppObject = NULL;
  150. if (m_SecurityInfo)
  151. {
  152. IEnumWbemClassObject *pIEnumWbemClassObject =
  153. (IEnumWbemClassObject *) m_SecurityInfo->GetProxy ();
  154. if (pIEnumWbemClassObject)
  155. {
  156. IWbemClassObject *pIWbemClassObject = NULL;
  157. ULONG returned = 0;
  158. bool needToResetSecurity = false;
  159. HANDLE hThreadToken = NULL;
  160. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  161. hr = pIEnumWbemClassObject->Next (lTimeout, 1, &pIWbemClassObject, &returned);
  162. if (needToResetSecurity)
  163. m_SecurityInfo->ResetSecurity (hThreadToken);
  164. if (SUCCEEDED(hr) && (0 < returned) && pIWbemClassObject)
  165. {
  166. CSWbemObject *pObject = new CSWbemObject (m_pSWbemServices, pIWbemClassObject,
  167. m_SecurityInfo);
  168. if (!pObject)
  169. hr = WBEM_E_OUT_OF_MEMORY;
  170. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  171. (PPVOID) ppObject)))
  172. delete pObject;
  173. pIWbemClassObject->Release ();
  174. }
  175. else if (WBEM_S_TIMEDOUT == hr)
  176. {
  177. /*
  178. * Since a timeout would be indistinguishable from an end-of-enumeration
  179. * in automation terms we flag it as a real error rather than an S-CODE.
  180. */
  181. hr = wbemErrTimedout;
  182. }
  183. SetWbemError (m_pSWbemServices);
  184. pIEnumWbemClassObject->Release ();
  185. }
  186. }
  187. }
  188. if (FAILED(hr))
  189. m_Dispatch.RaiseException (hr);
  190. return hr;
  191. }
  192. //***************************************************************************
  193. //
  194. // SCODE CSWbemEventSource::get_Security_
  195. //
  196. // DESCRIPTION:
  197. //
  198. // Return the security configurator
  199. //
  200. // WBEM_S_NO_ERROR success
  201. // WBEM_E_INVALID_PARAMETER bad input parameters
  202. // WBEM_E_FAILED otherwise
  203. //
  204. //***************************************************************************
  205. HRESULT CSWbemEventSource::get_Security_ (
  206. ISWbemSecurity **ppSecurity
  207. )
  208. {
  209. HRESULT hr = WBEM_E_FAILED;
  210. ResetLastErrors ();
  211. if (NULL == ppSecurity)
  212. hr = WBEM_E_INVALID_PARAMETER;
  213. {
  214. *ppSecurity = NULL;
  215. if (m_SecurityInfo)
  216. {
  217. *ppSecurity = m_SecurityInfo;
  218. (*ppSecurity)->AddRef ();
  219. hr = WBEM_S_NO_ERROR;
  220. }
  221. }
  222. if (FAILED(hr))
  223. m_Dispatch.RaiseException (hr);
  224. return hr;
  225. }