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.

322 lines
9.4 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation
  4. //
  5. // OBJECT.CPP
  6. //
  7. // rogerbo 19-June-98 Created.
  8. //
  9. // Defines the async implementation of ISWbemObjectEx
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include "objsink.h"
  14. HRESULT STDMETHODCALLTYPE CSWbemObject::PutAsync_(
  15. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  16. /* [defaultvalue][optional][in] */ long iFlags,
  17. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  18. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  19. {
  20. HRESULT hr = WBEM_E_FAILED;
  21. ResetLastErrors ();
  22. if (m_pSWbemServices && m_pIWbemClassObject)
  23. {
  24. if (pAsyncNotify)
  25. {
  26. // Figure out whether this is a class or instance
  27. VARIANT var;
  28. VariantInit (&var);
  29. if (WBEM_S_NO_ERROR == m_pIWbemClassObject->Get (WBEMS_SP_GENUS, 0, &var, NULL, NULL))
  30. {
  31. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  32. m_pIServiceProvider);
  33. IWbemServices *pIService = m_pSWbemServices->GetIWbemServices ();
  34. if (WBEM_GENUS_CLASS == var.lVal)
  35. {
  36. // Save the class name for later
  37. VARIANT nameVar;
  38. VariantInit (&nameVar);
  39. /*
  40. * Note we must check that returned value is a BSTR - it could be a VT_NULL if
  41. * the __CLASS property has not yet been set.
  42. */
  43. if ((WBEM_S_NO_ERROR == m_pIWbemClassObject->Get (WBEMS_SP_CLASS, 0, &nameVar, NULL, NULL))
  44. && (VT_BSTR == V_VT(&nameVar)))
  45. {
  46. if (pIService)
  47. {
  48. // Create the sink
  49. CWbemObjectSink *pWbemObjectSink;
  50. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  51. m_pSWbemServices, pAsyncNotify, pAsyncContext, true, nameVar.bstrVal);
  52. if (pSink)
  53. {
  54. CSWbemSecurity *pSecurity = m_pSWbemServices->GetSecurityInfo ();
  55. if (pSecurity)
  56. {
  57. bool needToResetSecurity = false;
  58. HANDLE hThreadToken = NULL;
  59. if (pSecurity->SetSecurity (needToResetSecurity, hThreadToken))
  60. hr = pIService->PutClassAsync (m_pIWbemClassObject, iFlags,
  61. pIContext, pSink);
  62. // Check to see if we need to release the stub (either we failed locally
  63. // or via a re-entrant call to SetStatus
  64. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  65. if (needToResetSecurity)
  66. pSecurity->ResetSecurity (hThreadToken);
  67. pSecurity->Release ();
  68. }
  69. }
  70. }
  71. }
  72. VariantClear (&nameVar);
  73. }
  74. else
  75. {
  76. if (pIService)
  77. {
  78. // Create the sink
  79. CWbemObjectSink *pWbemObjectSink;
  80. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  81. m_pSWbemServices, pAsyncNotify, pAsyncContext, true);
  82. if (pSink)
  83. {
  84. CSWbemSecurity *pSecurity = m_pSWbemServices->GetSecurityInfo ();
  85. if (pSecurity)
  86. {
  87. bool needToResetSecurity = false;
  88. HANDLE hThreadToken = NULL;
  89. if (pSecurity->SetSecurity (needToResetSecurity, hThreadToken))
  90. hr = pIService->PutInstanceAsync (m_pIWbemClassObject, iFlags, pIContext, pSink);
  91. // Check to see if we need to release the stub (either we failed locally
  92. // or via a re-entrant call to SetStatus
  93. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  94. // Restore original privileges on this thread
  95. if (needToResetSecurity)
  96. pSecurity->ResetSecurity (hThreadToken);
  97. pSecurity->Release ();
  98. }
  99. }
  100. }
  101. }
  102. SetWbemError (m_pSWbemServices);
  103. if (pIService)
  104. pIService->Release ();
  105. if (pIContext)
  106. pIContext->Release ();
  107. }
  108. VariantClear (&var);
  109. } else
  110. hr = wbemErrInvalidParameter;
  111. }
  112. if (FAILED(hr) && m_pDispatch)
  113. m_pDispatch->RaiseException (hr);
  114. return hr;
  115. }
  116. HRESULT STDMETHODCALLTYPE CSWbemObject::DeleteAsync_(
  117. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  118. /* [defaultvalue][optional][in] */ long iFlags,
  119. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  120. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  121. {
  122. HRESULT hr = WBEM_E_FAILED;
  123. ResetLastErrors ();
  124. if (m_pSWbemServices)
  125. {
  126. if (m_pIWbemClassObject)
  127. {
  128. // Get the object path to pass to the IWbemServices call
  129. CComBSTR bsPath;
  130. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  131. hr = m_pSWbemServices->DeleteAsync (pAsyncNotify, bsPath, iFlags,
  132. objContext, pAsyncContext);
  133. }
  134. }
  135. if (FAILED(hr) && m_pDispatch)
  136. m_pDispatch->RaiseException (hr);
  137. return hr;
  138. }
  139. HRESULT STDMETHODCALLTYPE CSWbemObject::InstancesAsync_(
  140. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  141. /* [defaultvalue][optional][in] */ long iFlags,
  142. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  143. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  144. {
  145. HRESULT hr = WBEM_E_FAILED;
  146. ResetLastErrors ();
  147. if (m_pSWbemServices && m_pIWbemClassObject)
  148. {
  149. // Get the object path to pass to the IWbemServices call
  150. CComBSTR bsPath;
  151. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  152. hr = m_pSWbemServices->InstancesOfAsync (pAsyncNotify, bsPath,
  153. iFlags, objContext, pAsyncContext);
  154. }
  155. if (FAILED(hr) && m_pDispatch)
  156. m_pDispatch->RaiseException (hr);
  157. return hr;
  158. }
  159. HRESULT STDMETHODCALLTYPE CSWbemObject::SubclassesAsync_(
  160. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  161. /* [defaultvalue][optional][in] */ long iFlags,
  162. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  163. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  164. {
  165. HRESULT hr = WBEM_E_FAILED;
  166. ResetLastErrors ();
  167. if (m_pSWbemServices && m_pIWbemClassObject)
  168. {
  169. // Get the object path to pass to the IWbemServices call
  170. CComBSTR bsPath;
  171. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  172. hr = m_pSWbemServices->SubclassesOfAsync (pAsyncNotify, bsPath, iFlags,
  173. objContext, pAsyncContext);
  174. }
  175. if (FAILED(hr) && m_pDispatch)
  176. m_pDispatch->RaiseException (hr);
  177. return hr;
  178. }
  179. HRESULT STDMETHODCALLTYPE CSWbemObject::AssociatorsAsync_(
  180. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  181. /* [defaultvalue][optional][in] */ BSTR strAssocClass,
  182. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  183. /* [defaultvalue][optional][in] */ BSTR strResultRole,
  184. /* [defaultvalue][optional][in] */ BSTR strRole,
  185. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  186. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  187. /* [defaultvalue][optional][in] */ BSTR strRequiredAssocQualifier,
  188. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  189. /* [defaultvalue][optional][in] */ long iFlags,
  190. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  191. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  192. {
  193. HRESULT hr = WBEM_E_FAILED;
  194. ResetLastErrors ();
  195. if (m_pSWbemServices && m_pIWbemClassObject)
  196. {
  197. // Get the object path to pass to the IWbemServices call
  198. CComBSTR bsPath;
  199. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  200. hr = m_pSWbemServices->AssociatorsOfAsync (pAsyncNotify, bsPath, strAssocClass, strResultClass,
  201. strResultRole, strRole, bClassesOnly, bSchemaOnly,
  202. strRequiredAssocQualifier, strRequiredQualifier, iFlags,
  203. objContext, pAsyncContext);
  204. }
  205. if (FAILED(hr) && m_pDispatch)
  206. m_pDispatch->RaiseException (hr);
  207. return hr;
  208. }
  209. HRESULT STDMETHODCALLTYPE CSWbemObject::ReferencesAsync_(
  210. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  211. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  212. /* [defaultvalue][optional][in] */ BSTR strRole,
  213. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  214. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  215. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  216. /* [defaultvalue][optional][in] */ long iFlags,
  217. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  218. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  219. {
  220. HRESULT hr = WBEM_E_FAILED;
  221. ResetLastErrors ();
  222. if (m_pSWbemServices && m_pIWbemClassObject)
  223. {
  224. // Get the object path to pass to the IWbemServices call
  225. CComBSTR bsPath;
  226. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  227. hr = m_pSWbemServices->ReferencesToAsync (pAsyncNotify, bsPath,
  228. strResultClass, strRole, bClassesOnly, bSchemaOnly,
  229. strRequiredQualifier, iFlags, objContext, pAsyncContext);
  230. }
  231. if (FAILED(hr) && m_pDispatch)
  232. m_pDispatch->RaiseException (hr);
  233. return hr;
  234. }
  235. HRESULT STDMETHODCALLTYPE CSWbemObject::ExecMethodAsync_(
  236. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  237. /* [in] */ BSTR strMethodName,
  238. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objInParams,
  239. /* [defaultvalue][optional][in] */ long iFlags,
  240. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  241. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext)
  242. {
  243. HRESULT hr = WBEM_E_FAILED;
  244. ResetLastErrors ();
  245. if (m_pSWbemServices && m_pIWbemClassObject)
  246. {
  247. // Get the object path to pass to the IWbemServices call
  248. CComBSTR bsPath;
  249. if (CSWbemObjectPath::GetObjectPath (m_pIWbemClassObject, bsPath))
  250. hr = m_pSWbemServices->ExecMethodAsync (pAsyncNotify, bsPath, strMethodName,
  251. objInParams, iFlags, objContext, pAsyncContext);
  252. }
  253. if (FAILED(hr) && m_pDispatch)
  254. m_pDispatch->RaiseException (hr);
  255. return hr;
  256. }