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.

336 lines
12 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusterApi.cpp
  7. //
  8. // Description:
  9. // Implementation of CClusterApi class
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "ClusterApi.h"
  17. #include "ClusterApi.tmh"
  18. //****************************************************************************
  19. //
  20. // CClusterApi
  21. //
  22. //****************************************************************************
  23. //////////////////////////////////////////////////////////////////////////////
  24. //++
  25. //
  26. // void
  27. // CClusterApi::GetObjectProperties(
  28. // const SPropMapEntryArray * pArrayIn,
  29. // CClusPropList & rPropListIn,
  30. // CWbemClassObject & rInstOut,
  31. // BOOL fPrivateIn
  32. // )
  33. //
  34. // Description:
  35. // Get object property from Property list, and save to WMI instance
  36. //
  37. // Arguments:
  38. // pArrayIn -- Array of property names whose value will be retrieve
  39. // rPropListIn -- Reference to cluster object's proplist
  40. // rInstOut -- Reference to WMI instance
  41. // fPrivateIn -- TRUE = properties are private
  42. //
  43. // Return Values:
  44. // none
  45. //
  46. //--
  47. //////////////////////////////////////////////////////////////////////////////
  48. void CClusterApi::GetObjectProperties(
  49. const SPropMapEntryArray * pArrayIn,
  50. CClusPropList & rPropListIn,
  51. CWbemClassObject & rInstOut,
  52. BOOL fPrivateIn
  53. )
  54. {
  55. DWORD dwError;
  56. LPCWSTR pwszPropName;
  57. LPCWSTR pwszMofName;
  58. WCHAR wsz[ MAX_PATH ];
  59. dwError = rPropListIn.ScMoveToFirstProperty();
  60. while ( dwError == ERROR_SUCCESS )
  61. {
  62. pwszPropName = NULL;
  63. pwszMofName = NULL;
  64. pwszPropName = rPropListIn.PszCurrentPropertyName();
  65. pwszMofName = pwszPropName;
  66. if ( pArrayIn )
  67. {
  68. pwszMofName = pArrayIn->PwszLookup( pwszPropName );
  69. }
  70. else if( fPrivateIn )
  71. {
  72. //
  73. // handle dynamic generate private property
  74. //
  75. pwszMofName = PwszSpaceReplace( wsz, pwszMofName, L'_' );
  76. }
  77. if ( pwszMofName != NULL )
  78. {
  79. try
  80. {
  81. switch ( rPropListIn.CpfCurrentValueFormat() )
  82. {
  83. case CLUSPROP_FORMAT_DWORD:
  84. case CLUSPROP_FORMAT_LONG:
  85. {
  86. rInstOut.SetProperty(
  87. rPropListIn.CbhCurrentValue().pDwordValue->dw,
  88. pwszMofName
  89. );
  90. break;
  91. } // case: FORMAT_DWORD && FORMAT_LONG
  92. case CLUSPROP_FORMAT_SZ:
  93. case CLUSPROP_FORMAT_EXPAND_SZ:
  94. case CLUSPROP_FORMAT_EXPANDED_SZ:
  95. {
  96. rInstOut.SetProperty(
  97. rPropListIn.CbhCurrentValue().pStringValue->sz,
  98. pwszMofName
  99. );
  100. break;
  101. } // case: FORMAT_SZ && FORMAT_EXPAND_SZ && FORMAT_EXPANDED_SZ
  102. case CLUSPROP_FORMAT_BINARY:
  103. {
  104. rInstOut.SetProperty(
  105. rPropListIn.CbhCurrentValue().pBinaryValue->cbLength,
  106. rPropListIn.CbhCurrentValue().pBinaryValue->rgb,
  107. pwszMofName
  108. );
  109. break;
  110. } // case: FORMAT_BINARY
  111. case CLUSPROP_FORMAT_MULTI_SZ:
  112. {
  113. rInstOut.SetProperty(
  114. rPropListIn.CbhCurrentValue().pMultiSzValue->cbLength,
  115. rPropListIn.CbhCurrentValue().pMultiSzValue->sz,
  116. pwszMofName
  117. );
  118. break;
  119. } // case: FORMAT_MULTI_SZ
  120. default:
  121. {
  122. throw CProvException(
  123. static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER ) );
  124. }
  125. } // switch : property type
  126. } // try
  127. catch ( ... )
  128. {
  129. }
  130. } // if: MOF name found
  131. dwError = rPropListIn.ScMoveToNextProperty();
  132. } // while: proplist not empty
  133. } //*** CClusterApi::GetObjectProperties()
  134. //////////////////////////////////////////////////////////////////////////////
  135. //++
  136. //
  137. // void
  138. // CClusterApi::SetObjectProperties(
  139. // const SPropMapEntryArray * pArrayIn,
  140. // CClusPropList & rPropListInout,
  141. // CClusPropList & rOldPropListIn,
  142. // CWbemClassObject & rInstIn,
  143. // BOOL fPrivateIn
  144. // )
  145. //
  146. // Description:
  147. // set object property from Property list, and save to WMI instance
  148. //
  149. // Arguments:
  150. // pArrayIn -- Array of property names those value will be retrieve
  151. // rPropListInout -- Reference to cluster object's proplist
  152. // rOldPropListIn -- Reference to proplist with original value
  153. // rInstIn -- Reference to WMI instance
  154. // fPrivateIn -- TRUE = properties are private
  155. //
  156. // Return Values:
  157. // none
  158. //
  159. //--
  160. //////////////////////////////////////////////////////////////////////////////
  161. void CClusterApi::SetObjectProperties(
  162. const SPropMapEntryArray * pArrayIn,
  163. CClusPropList & rPropListInout,
  164. CClusPropList & rOldPropListIn,
  165. CWbemClassObject & rInstIn,
  166. BOOL fPrivateIn
  167. )
  168. {
  169. DWORD dwError = 0;
  170. LPCWSTR pwszPropName = NULL;
  171. LPCWSTR pwszMofName = NULL;
  172. WCHAR wsz[ MAX_PATH ];
  173. dwError = rOldPropListIn.ScMoveToFirstProperty();
  174. while ( ERROR_SUCCESS == dwError )
  175. {
  176. pwszPropName = NULL;
  177. pwszMofName = NULL;
  178. pwszPropName = rOldPropListIn.PszCurrentPropertyName();
  179. pwszMofName = pwszPropName;
  180. if ( pArrayIn )
  181. {
  182. pwszMofName = pArrayIn->PwszLookup( pwszPropName );
  183. }
  184. else if ( fPrivateIn )
  185. {
  186. //
  187. // handle dynamic generate private property
  188. //
  189. pwszMofName = PwszSpaceReplace( wsz, pwszMofName, L'_' );
  190. }
  191. if ( pwszMofName != NULL )
  192. {
  193. try {
  194. switch ( rOldPropListIn.CpfCurrentValueFormat() )
  195. {
  196. case CLUSPROP_FORMAT_DWORD:
  197. {
  198. {
  199. DWORD dwNewValue = 0;
  200. DWORD dwOldValue = 0;
  201. // bugbug, need to handle NULL value for property
  202. rInstIn.GetProperty( &dwNewValue, pwszMofName );
  203. rPropListInout.ScAddProp(
  204. pwszPropName,
  205. dwNewValue,
  206. rOldPropListIn.CbhCurrentValue().pDwordValue->dw
  207. );
  208. }
  209. break;
  210. } // case: FORMAT_DWORD
  211. case CLUSPROP_FORMAT_LONG:
  212. {
  213. {
  214. LONG lNewValue = 0;
  215. LONG lOldValue = 0;
  216. // bugbug, need to handle NULL value for property
  217. rInstIn.GetProperty( (DWORD *) &lNewValue, pwszMofName );
  218. rPropListInout.ScAddProp(
  219. pwszPropName,
  220. lNewValue,
  221. rOldPropListIn.CbhCurrentValue().pLongValue->l
  222. );
  223. }
  224. break;
  225. } // case: FORMAT_DWORD
  226. case CLUSPROP_FORMAT_SZ:
  227. {
  228. {
  229. _bstr_t bstrNewValue;
  230. rInstIn.GetProperty( bstrNewValue, pwszMofName );
  231. rPropListInout.ScAddProp( pwszPropName, bstrNewValue );
  232. }
  233. break;
  234. } // case: FORMAT_SZ
  235. case CLUSPROP_FORMAT_EXPAND_SZ:
  236. {
  237. {
  238. _bstr_t bstrNewValue;
  239. rInstIn.GetProperty( bstrNewValue, pwszMofName );
  240. rPropListInout.ScAddExpandSzProp( pwszPropName, bstrNewValue );
  241. }
  242. break;
  243. } // case: FORMAT_SZ
  244. case CLUSPROP_FORMAT_MULTI_SZ:
  245. {
  246. {
  247. LPWSTR pwsz = NULL;
  248. DWORD dwSize;
  249. rInstIn.GetPropertyMultiSz(
  250. &dwSize,
  251. &pwsz,
  252. pwszMofName
  253. );
  254. rPropListInout.ScAddMultiSzProp(
  255. pwszPropName,
  256. pwsz,
  257. rOldPropListIn.CbhCurrentValue().pMultiSzValue->sz
  258. );
  259. delete [] pwsz;
  260. }
  261. break;
  262. } // case: FORMAT_MULTI_SZ
  263. case CLUSPROP_FORMAT_BINARY:
  264. {
  265. {
  266. DWORD dwSize;
  267. PBYTE pByte = NULL;
  268. rInstIn.GetProperty(
  269. &dwSize,
  270. &pByte,
  271. pwszMofName
  272. );
  273. rPropListInout.ScAddProp(
  274. pwszPropName,
  275. pByte,
  276. dwSize,
  277. rOldPropListIn.CbhCurrentValue().pBinaryValue->rgb,
  278. rOldPropListIn.CbhCurrentValue().pBinaryValue->cbLength
  279. );
  280. delete [] pByte;
  281. }
  282. break;
  283. } // case: FORMAT_BINARY
  284. default:
  285. {
  286. TracePrint(("SetCommonProperties: unknown prop type %d", rOldPropListIn.CpfCurrentValueFormat() ));
  287. throw CProvException(
  288. static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER ) );
  289. }
  290. } // switch: on property type
  291. } catch (CProvException& eh) {
  292. if (eh.hrGetError() == WBEM_E_NOT_FOUND) {
  293. TracePrint(("SetCommonProperties: Property %ws not found. Benign error. Continuing", pwszPropName));
  294. } else {
  295. TracePrint(("SetCommonProperties: exception %x. PropName = %ws, MofName = %ws",
  296. eh.hrGetError(), pwszPropName, pwszMofName));
  297. throw;
  298. }
  299. }
  300. }
  301. dwError = rOldPropListIn.ScMoveToNextProperty();
  302. } // while: no error occurred
  303. return;
  304. } //*** CClusterApi::SetObjectProperties()