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.

283 lines
6.3 KiB

  1. //=================================================================
  2. //
  3. // binding.cpp -- Generic association class
  4. //
  5. // Copyright 1999 Microsoft Corporation
  6. //
  7. //=================================================================
  8. #include <stdafx.h>
  9. #include "precomp.h"
  10. #include <assertbreak.h>
  11. #include "Assoc.h"
  12. #include "Binding.h"
  13. bool CompareVariantsNoCase(const VARIANT *v1, const VARIANT *v2)
  14. {
  15. if (v1->vt == v2->vt) {
  16. switch (v1->vt) {
  17. case VT_BOOL: return (v1->boolVal == v2->boolVal);
  18. case VT_UI1: return (v1->bVal == v2->bVal);
  19. case VT_I2: return (v1->iVal == v2->iVal);
  20. case VT_I4: return (v1->lVal == v2->lVal);
  21. case VT_R4: return (v1->fltVal == v2->fltVal);
  22. case VT_R8: return (v1->dblVal == v2->dblVal);
  23. case VT_BSTR: return (0 == _wcsicmp(v1->bstrVal, v2->bstrVal));
  24. default:
  25. ASSERT_BREAK(0);
  26. }
  27. }
  28. return false;
  29. }
  30. CBinding::CBinding(
  31. LPCWSTR pwszClassName,
  32. LPCWSTR pwszNamespaceName,
  33. LPCWSTR pwszLeftClassName,
  34. LPCWSTR pwszRightClassName,
  35. LPCWSTR pwszLeftPropertyName,
  36. LPCWSTR pwszRightPropertyName,
  37. LPCWSTR pwszLeftBindingPropertyName,
  38. LPCWSTR pwszRightBindingPropertyName
  39. )
  40. : CAssociation (
  41. pwszClassName,
  42. pwszNamespaceName,
  43. pwszLeftClassName,
  44. pwszRightClassName,
  45. pwszLeftPropertyName,
  46. pwszRightPropertyName
  47. )
  48. {
  49. ASSERT_BREAK( ( pwszLeftBindingPropertyName != NULL ) && ( pwszRightBindingPropertyName != NULL) );
  50. m_pwszLeftBindingPropertyName = pwszLeftBindingPropertyName;
  51. m_pwszRightBindingPropertyName = pwszRightBindingPropertyName;
  52. }
  53. CBinding::~CBinding()
  54. {
  55. }
  56. //========================
  57. BOOL CBinding::AreRelated(
  58. const CInstance *pLeft,
  59. const CInstance *pRight
  60. )
  61. {
  62. BOOL bRet = FALSE;
  63. variant_t LeftBindingPropertyValue,
  64. RightBindingPropertyValue;
  65. if (pLeft->GetVariant(m_pwszLeftBindingPropertyName, LeftBindingPropertyValue) &&
  66. pRight->GetVariant(m_pwszRightBindingPropertyName, RightBindingPropertyValue) )
  67. {
  68. bRet = CompareVariantsNoCase(&LeftBindingPropertyValue, &RightBindingPropertyValue);
  69. }
  70. else
  71. {
  72. ASSERT_BREAK(0);
  73. }
  74. return bRet;
  75. }
  76. HRESULT CBinding::GetRightInstances(
  77. MethodContext *pMethodContext,
  78. TRefPointerCollection<CInstance> *lefts
  79. )
  80. {
  81. CHString sQuery;
  82. sQuery.Format(L"SELECT __RELPATH, %s FROM %s", m_pwszRightBindingPropertyName, m_pwszRightClassName);
  83. // 'StaticEnumerationCallback' will get called once for each instance
  84. // returned from the query
  85. HRESULT hr = CWbemProviderGlue::GetInstancesByQueryAsynch(
  86. sQuery,
  87. this,
  88. StaticEnumerationCallback,
  89. NULL,
  90. pMethodContext,
  91. lefts);
  92. return hr;
  93. }
  94. HRESULT CBinding::GetLeftInstances(
  95. MethodContext *pMethodContext,
  96. TRefPointerCollection<CInstance> &lefts
  97. )
  98. {
  99. CHString sQuery;
  100. sQuery.Format(L"SELECT __RELPATH, %s FROM %s", m_pwszLeftBindingPropertyName, m_pwszLeftClassName);
  101. return CWbemProviderGlue::GetInstancesByQuery(sQuery, &lefts, pMethodContext);
  102. }
  103. HRESULT CBinding::RetrieveLeftInstance(
  104. LPCWSTR lpwszObjPath,
  105. CInstance **ppInstance,
  106. MethodContext *pMethodContext
  107. )
  108. {
  109. CHStringArray csaProperties;
  110. csaProperties.Add(L"__RELPATH");
  111. csaProperties.Add(m_pwszLeftBindingPropertyName);
  112. return CWbemProviderGlue::GetInstancePropertiesByPath(lpwszObjPath, ppInstance, pMethodContext, csaProperties);
  113. }
  114. HRESULT CBinding::RetrieveRightInstance(
  115. LPCWSTR lpwszObjPath,
  116. CInstance **ppInstance,
  117. MethodContext *pMethodContext
  118. )
  119. {
  120. CHStringArray csaProperties;
  121. csaProperties.Add(L"__RELPATH");
  122. csaProperties.Add(m_pwszRightBindingPropertyName);
  123. return CWbemProviderGlue::GetInstancePropertiesByPath(lpwszObjPath, ppInstance, pMethodContext, csaProperties);
  124. }
  125. // =========================================================================================================
  126. CBinding MyTerminalServiceToSetting(
  127. L"Win32_TerminalServiceToSetting",
  128. L"root\\cimv2",
  129. L"Win32_TerminalService",
  130. L"Win32_TerminalServiceSetting",
  131. L"Element",
  132. L"Setting",
  133. L"Name",
  134. L"ServerName"
  135. );
  136. CBinding MyTerminalTerminalSetting(
  137. L"Win32_TerminalTerminalSetting",
  138. L"root\\cimv2",
  139. L"Win32_Terminal",
  140. L"Win32_TerminalSetting",
  141. L"Element",
  142. L"Setting",
  143. L"TerminalName",
  144. L"TerminalName"
  145. );
  146. CBinding MyTSSessionDirectorySetting(
  147. L"Win32_TSSessionDirectorySetting",
  148. L"root\\cimv2",
  149. L"Win32_TerminalService",
  150. L"Win32_TSSessionDirectory",
  151. L"Element",
  152. L"Setting",
  153. L"Name",
  154. L"SessionDirectoryActive"
  155. );
  156. /*
  157. CBinding MyTSPermissionsSetting(
  158. L"Win32_TSPermissionsSetting",
  159. L"root\\cimv2",
  160. L"Win32_Terminal",
  161. L"Win32_TSAccount",
  162. L"Element",
  163. L"Setting",
  164. L"TerminalName",
  165. L"AccountName"
  166. );
  167. CBinding MyTSNetworkAdapterListSetting(
  168. L"Win32_TSNetworkAdapterListSetting",
  169. L"root\\cimv2",
  170. L"Win32_NetworkAdapter",
  171. L"Win32_TSNetworkAdapterSetting",
  172. L"Element",
  173. L"Setting",
  174. L"DeviceID",
  175. L"TerminalName"
  176. );
  177. */
  178. /*
  179. CBinding MyNetAdaptToNetAdaptConfig(
  180. L"Win32_NetworkAdapterSetting",
  181. L"root\\cimv2",
  182. L"Win32_NetworkAdapter",
  183. L"Win32_NetworkAdapterConfiguration",
  184. L"Element",
  185. L"Setting",
  186. IDS_Index,
  187. IDS_Index);
  188. CBinding PageFileToPagefileSetting(
  189. L"Win32_PageFileElementSetting",
  190. L"root\\cimv2",
  191. L"Win32_PageFileUsage",
  192. L"Win32_PageFileSetting",
  193. L"Element",
  194. L"Setting",
  195. IDS_Name,
  196. IDS_Name);
  197. CBinding MyPrinterSetting(
  198. L"Win32_PrinterSetting",
  199. L"root\\cimv2",
  200. L"Win32_Printer",
  201. L"Win32_PrinterConfiguration",
  202. L"Element",
  203. L"Setting",
  204. IDS_DeviceID,
  205. IDS_Name);
  206. CBinding MyDiskToPartitionSet(
  207. L"Win32_DiskDriveToDiskPartition",
  208. L"root\\cimv2",
  209. L"Win32_DiskDrive",
  210. L"Win32_DiskPartition",
  211. IDS_Antecedent,
  212. IDS_Dependent,
  213. IDS_Index,
  214. IDS_DiskIndex
  215. );
  216. CBinding assocPOTSModemToSerialPort(
  217. L"Win32_POTSModemToSerialPort",
  218. L"root\\cimv2",
  219. L"Win32_SerialPort",
  220. L"Win32_POTSModem",
  221. IDS_Antecedent,
  222. IDS_Dependent,
  223. IDS_DeviceID,
  224. IDS_AttachedTo
  225. );
  226. CBinding OStoQFE(
  227. L"Win32_OperatingSystemQFE",
  228. L"root\\cimv2",
  229. L"Win32_OperatingSystem",
  230. L"Win32_QuickFixEngineering",
  231. IDS_Antecedent,
  232. IDS_Dependent,
  233. IDS_CSName,
  234. IDS_CSName
  235. );
  236. */