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.

334 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. // bugbug, need to handle NULL value for property
  201. rInstIn.GetProperty( &dwNewValue, pwszMofName );
  202. rPropListInout.ScAddProp(
  203. pwszPropName,
  204. dwNewValue,
  205. rOldPropListIn.CbhCurrentValue().pDwordValue->dw
  206. );
  207. }
  208. break;
  209. } // case: FORMAT_DWORD
  210. case CLUSPROP_FORMAT_LONG:
  211. {
  212. {
  213. LONG lNewValue = 0;
  214. // bugbug, need to handle NULL value for property
  215. rInstIn.GetProperty( (DWORD *) &lNewValue, pwszMofName );
  216. rPropListInout.ScAddProp(
  217. pwszPropName,
  218. lNewValue,
  219. rOldPropListIn.CbhCurrentValue().pLongValue->l
  220. );
  221. }
  222. break;
  223. } // case: FORMAT_DWORD
  224. case CLUSPROP_FORMAT_SZ:
  225. {
  226. {
  227. _bstr_t bstrNewValue;
  228. rInstIn.GetProperty( bstrNewValue, pwszMofName );
  229. rPropListInout.ScAddProp( pwszPropName, bstrNewValue );
  230. }
  231. break;
  232. } // case: FORMAT_SZ
  233. case CLUSPROP_FORMAT_EXPAND_SZ:
  234. {
  235. {
  236. _bstr_t bstrNewValue;
  237. rInstIn.GetProperty( bstrNewValue, pwszMofName );
  238. rPropListInout.ScAddExpandSzProp( pwszPropName, bstrNewValue );
  239. }
  240. break;
  241. } // case: FORMAT_SZ
  242. case CLUSPROP_FORMAT_MULTI_SZ:
  243. {
  244. {
  245. LPWSTR pwsz = NULL;
  246. DWORD dwSize;
  247. rInstIn.GetPropertyMultiSz(
  248. &dwSize,
  249. &pwsz,
  250. pwszMofName
  251. );
  252. rPropListInout.ScAddMultiSzProp(
  253. pwszPropName,
  254. pwsz,
  255. rOldPropListIn.CbhCurrentValue().pMultiSzValue->sz
  256. );
  257. delete [] pwsz;
  258. }
  259. break;
  260. } // case: FORMAT_MULTI_SZ
  261. case CLUSPROP_FORMAT_BINARY:
  262. {
  263. {
  264. DWORD dwSize;
  265. PBYTE pByte = NULL;
  266. rInstIn.GetProperty(
  267. &dwSize,
  268. &pByte,
  269. pwszMofName
  270. );
  271. rPropListInout.ScAddProp(
  272. pwszPropName,
  273. pByte,
  274. dwSize,
  275. rOldPropListIn.CbhCurrentValue().pBinaryValue->rgb,
  276. rOldPropListIn.CbhCurrentValue().pBinaryValue->cbLength
  277. );
  278. delete [] pByte;
  279. }
  280. break;
  281. } // case: FORMAT_BINARY
  282. default:
  283. {
  284. TracePrint(("SetCommonProperties: unknown prop type %d", rOldPropListIn.CpfCurrentValueFormat() ));
  285. throw CProvException(
  286. static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER ) );
  287. }
  288. } // switch: on property type
  289. } catch (CProvException& eh) {
  290. if (eh.hrGetError() == WBEM_E_NOT_FOUND) {
  291. TracePrint(("SetCommonProperties: Property %ws not found. Benign error. Continuing", pwszPropName));
  292. } else {
  293. TracePrint(("SetCommonProperties: exception %x. PropName = %ws, MofName = %ws",
  294. eh.hrGetError(), pwszPropName, pwszMofName));
  295. throw;
  296. }
  297. }
  298. }
  299. dwError = rOldPropListIn.ScMoveToNextProperty();
  300. } // while: no error occurred
  301. return;
  302. } //*** CClusterApi::SetObjectProperties()