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.

241 lines
5.4 KiB

  1. //***************************************************************************
  2. //
  3. // VPTASKSU.CPP
  4. //
  5. // Module: WBEM VIEW PROVIDER
  6. //
  7. // Purpose: Contains the union methods taskobject implementation
  8. //
  9. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. //need the following three lines
  13. //to get the security stuff to work
  14. #include "precomp.h"
  15. #include <provexpt.h>
  16. #include <provcoll.h>
  17. #include <provtempl.h>
  18. #include <provmt.h>
  19. #include <typeinfo.h>
  20. #include <process.h>
  21. #include <objbase.h>
  22. #include <objidl.h>
  23. #include <stdio.h>
  24. #include <wbemidl.h>
  25. #include <provcont.h>
  26. #include <provevt.h>
  27. #include <provthrd.h>
  28. #include <provlog.h>
  29. #include <cominit.h>
  30. #include <dsgetdc.h>
  31. #include <lmcons.h>
  32. #include <lmapibuf.h>
  33. #include <instpath.h>
  34. #include <genlex.h>
  35. #include <sql_1.h>
  36. #include <objpath.h>
  37. #include <vpdefs.h>
  38. #include <vpcfac.h>
  39. #include <vpquals.h>
  40. #include <vpserv.h>
  41. #include <vptasks.h>
  42. BOOL WbemTaskObject::CreateAndIndicateUnions(WbemProvErrorObject &a_ErrorObject, int index)
  43. {
  44. BOOL retVal = TRUE;
  45. if (index != -1)
  46. {
  47. retVal = CreateAndIndicate(a_ErrorObject, m_ObjSinkArray[index]);
  48. for (int x = 0; x < m_ObjSinkArray.GetSize(); x++)
  49. {
  50. if (m_ObjSinkArray[x] != NULL)
  51. {
  52. m_ObjSinkArray[x]->Release();
  53. }
  54. }
  55. }
  56. else
  57. {
  58. for (int x = 0; x < m_ObjSinkArray.GetSize(); x++)
  59. {
  60. if ((m_ObjSinkArray[x] != NULL) && SUCCEEDED(m_ObjSinkArray[x]->GetResult()))
  61. {
  62. BOOL t_bRes = CreateAndIndicate(a_ErrorObject, m_ObjSinkArray[x]);
  63. retVal = retVal && t_bRes;
  64. }
  65. else if (retVal)
  66. {
  67. retVal = FALSE;
  68. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  69. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  70. a_ErrorObject.SetMessage ( L"A source query failed." );
  71. }
  72. if (m_ObjSinkArray[x] != NULL)
  73. {
  74. m_ObjSinkArray[x]->Release();
  75. }
  76. }
  77. }
  78. m_ObjSinkArray.RemoveAll();
  79. return retVal;
  80. }
  81. //for unions and associations
  82. BOOL WbemTaskObject::CreateAndIndicate(WbemProvErrorObject &a_ErrorObject, CObjectSinkResults* pSrcs)
  83. {
  84. BOOL retVal = TRUE;
  85. for (int x = 0; x < pSrcs->m_ObjArray.GetSize(); x++)
  86. {
  87. BOOL bIndicate = TRUE;
  88. IWbemClassObject* srcObj = pSrcs->m_ObjArray[x]->GetWrappedObject();
  89. IWbemClassObject* viewObj = NULL;
  90. if ( SUCCEEDED(m_ClassObject->SpawnInstance(0, &viewObj)) )
  91. {
  92. POSITION propPos = m_PropertyMap.GetStartPosition();
  93. while ((propPos != NULL) && bIndicate)
  94. {
  95. CStringW propName;
  96. CPropertyQualifierItem* propProps;
  97. m_PropertyMap.GetNextAssoc(propPos, propName, propProps);
  98. VARIANT v;
  99. CIMTYPE c;
  100. if (propProps->m_SrcPropertyNames[pSrcs->GetIndex()].IsEmpty())
  101. {
  102. if (propProps->IsKey())
  103. {
  104. if (retVal)
  105. {
  106. retVal = FALSE;
  107. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  108. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  109. a_ErrorObject.SetMessage ( L"Failed to set key value for union view instance." );
  110. }
  111. bIndicate = FALSE;
  112. }
  113. }
  114. else
  115. {
  116. if ( SUCCEEDED(srcObj->Get(propProps->m_SrcPropertyNames[pSrcs->GetIndex()], 0, &v, &c, NULL)) )
  117. {
  118. if (((v.vt == VT_NULL) || (v.vt == VT_EMPTY)) && propProps->IsKey())
  119. {
  120. if (retVal)
  121. {
  122. retVal = FALSE;
  123. }
  124. bIndicate = FALSE;
  125. }
  126. else
  127. {
  128. //transpose reference if necessary
  129. //=================================
  130. BOOL bPut = TRUE;
  131. if (m_bAssoc && (propProps->GetCimType() == CIM_REFERENCE))
  132. {
  133. VARIANT vTmp;
  134. DWORD dwNSIndx = pSrcs->m_ObjArray[x]->GetIndex();
  135. CWbemServerWrap** pSrvs = m_NSpaceArray[pSrcs->GetIndex()]->GetServerPtrs();
  136. if (TransposeReference(propProps, v, &vTmp, TRUE, &pSrvs[dwNSIndx]))
  137. {
  138. VariantClear(&v);
  139. VariantInit(&v);
  140. if (FAILED(VariantCopy(&v, &vTmp)))
  141. {
  142. throw Heap_Exception(Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR);
  143. }
  144. }
  145. else
  146. {
  147. if (propProps->IsKey())
  148. {
  149. if (retVal)
  150. {
  151. retVal = FALSE;
  152. }
  153. bIndicate = FALSE;
  154. }
  155. bPut = FALSE;
  156. }
  157. VariantClear(&vTmp);
  158. }
  159. if (bPut && FAILED(viewObj->Put(propName, 0, &v, c)) )
  160. {
  161. if (retVal)
  162. {
  163. retVal = FALSE;
  164. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  165. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  166. a_ErrorObject.SetMessage ( L"Failed to put property" );
  167. }
  168. if (propProps->IsKey())
  169. {
  170. bIndicate = FALSE;
  171. }
  172. }
  173. }
  174. VariantClear(&v);
  175. }
  176. else
  177. {
  178. if (retVal)
  179. {
  180. retVal = FALSE;
  181. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  182. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  183. a_ErrorObject.SetMessage ( L"Failed to get property from Source." ) ;
  184. }
  185. }
  186. }
  187. }
  188. if (bIndicate && m_bIndicate)
  189. {
  190. m_NotificationHandler->Indicate(1, &viewObj);
  191. }
  192. viewObj->Release();
  193. }
  194. else
  195. {
  196. retVal = FALSE;
  197. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  198. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  199. a_ErrorObject.SetMessage ( L"WBEM API FAILURE:- Failed to spawn an instance of the view class." ) ;
  200. break;
  201. }
  202. }
  203. return retVal;
  204. }