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.

367 lines
13 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. WMIParser.h
  5. Abstract:
  6. This file contains the declaration of the classes that are part of
  7. the WMIParser library.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 07/25/99
  10. created
  11. ******************************************************************************/
  12. #if !defined(__INCLUDED___PCH___WMIPARSER_H___)
  13. #define __INCLUDED___PCH___WMIPARSER_H___
  14. /////////////////////////////////////////////////////////////////////////////
  15. namespace WMIParser
  16. {
  17. class InstanceName;
  18. class ValueReference;
  19. /////////////////////////////////////////////////////////////////////////////
  20. class InstanceNameItem // Hungarian: wmipini
  21. {
  22. friend InstanceName;
  23. private:
  24. MPC::wstring m_szValue;
  25. ValueReference* m_wmipvrValue;
  26. public:
  27. InstanceNameItem();
  28. InstanceNameItem( /*[in]*/ const InstanceNameItem& wmipini );
  29. ~InstanceNameItem();
  30. InstanceNameItem& operator=( /*[in]*/ const InstanceNameItem& wmipini );
  31. bool operator==( /*[in]*/ InstanceNameItem const &wmipini ) const;
  32. bool operator< ( /*[in]*/ InstanceNameItem const &wmipini ) const;
  33. };
  34. class InstanceName // Hungarian: wmipin
  35. {
  36. friend class Instance;
  37. public:
  38. typedef std::map<MPC::wstringUC,InstanceNameItem> KeyMap;
  39. typedef KeyMap::iterator KeyIter;
  40. typedef KeyMap::const_iterator KeyIterConst;
  41. private:
  42. MPC::XmlUtil m_xmlNode; // This instance in the Xml DOM.
  43. MPC::wstring m_szNamespace; // Namespace of the instance in CIM.
  44. MPC::wstring m_szClass; // Name of the class for this instance.
  45. KeyMap m_mapKeyBinding; // Set of keys.
  46. HRESULT ParseNamespace( );
  47. HRESULT ParseKey ( /*[in] */ IXMLDOMNode* pxdnNode, /*[out]*/ InstanceNameItem& wmipini, /*[out]*/ bool& fEmpty );
  48. HRESULT ParseKeys ( );
  49. public:
  50. InstanceName();
  51. ~InstanceName();
  52. bool operator==( /*[in]*/ InstanceName const &wmipin ) const;
  53. bool operator< ( /*[in]*/ InstanceName const &wmipin ) const;
  54. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode, /*[out]*/ bool& fEmpty );
  55. HRESULT get_Namespace( /*[out]*/ MPC::wstring& szNamespace );
  56. HRESULT get_Class ( /*[out]*/ MPC::wstring& szClass );
  57. HRESULT get_KeyBinding( /*[out]*/ KeyIterConst& itBegin, /*[out]*/ KeyIterConst& itEnd );
  58. };
  59. class Value // Hungarian: wmipv
  60. {
  61. private:
  62. long m_lData; // Length of the data value.
  63. BYTE* m_rgData; // Data value.
  64. MPC::wstring m_szData; // Data value.
  65. public:
  66. Value();
  67. virtual ~Value();
  68. bool operator==( /*[in]*/ Value const &wmipv ) const;
  69. HRESULT Parse( /*[in] */ IXMLDOMNode* pxdnNode, /*[in]*/ LPCWSTR szTag );
  70. HRESULT get_Data( /*[out]*/ long& lData, /*[out]*/ BYTE*& rgData );
  71. HRESULT get_Data( /*[out]*/ MPC::wstring& szData );
  72. };
  73. class ValueReference // Hungarian: wmipvr
  74. {
  75. private:
  76. InstanceName m_wmipin;
  77. public:
  78. ValueReference();
  79. virtual ~ValueReference();
  80. bool operator==( /*[in]*/ ValueReference const &wmipvr ) const;
  81. bool operator< ( /*[in]*/ ValueReference const &wmipvr ) const;
  82. HRESULT Parse( /*[in] */ IXMLDOMNode* pxdnNode );
  83. HRESULT get_Data( /*[out]*/ InstanceName*& wmipin );
  84. };
  85. /////////////////////////////////////////////////////////////////////////////
  86. class Property // Hungarian: wmipp
  87. {
  88. protected:
  89. MPC::XmlUtil m_xmlNode; // This property in the Xml DOM.
  90. MPC::wstring m_szName; // Name of the property.
  91. MPC::wstring m_szType; // Type of the value for this property.
  92. public:
  93. Property();
  94. virtual ~Property();
  95. bool operator==( /*[in]*/ LPCWSTR strName ) const;
  96. bool operator==( /*[in]*/ const MPC::wstring& szName ) const;
  97. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode );
  98. HRESULT get_Node( /*[out]*/ IXMLDOMNode* *pxdnNode );
  99. HRESULT get_Name( /*[out]*/ MPC::wstring& szName );
  100. HRESULT get_Type( /*[out]*/ MPC::wstring& szType );
  101. };
  102. class Property_Scalar : public Property // Hungarian: wmipps
  103. {
  104. private:
  105. Value m_wmipvData;
  106. public:
  107. Property_Scalar();
  108. virtual ~Property_Scalar();
  109. bool operator==( /*[in]*/ Property_Scalar const &wmipps ) const;
  110. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode );
  111. HRESULT get_Data( /*[out]*/ MPC::wstring& szData );
  112. HRESULT put_Data( /*[in] */ const MPC::wstring& szData, /*[out]*/ bool& fFound );
  113. };
  114. class Property_Array : public Property // Hungarian: wmippa
  115. {
  116. private:
  117. typedef std::list<Value> ElemList;
  118. typedef ElemList::iterator ElemIter;
  119. typedef ElemList::const_iterator ElemIterConst;
  120. ElemList m_lstElements;
  121. public:
  122. Property_Array();
  123. virtual ~Property_Array();
  124. bool operator==( /*[in]*/ Property_Array const &wmippa ) const;
  125. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode );
  126. HRESULT get_Data( /*[in]*/ int iIndex, /*[out]*/ MPC::wstring& szData );
  127. HRESULT put_Data( /*[in]*/ int iIndex, /*[in] */ const MPC::wstring& szData, /*[out]*/ bool& fFound );
  128. };
  129. class Property_Reference : public Property // Hungarian: wmippr
  130. {
  131. private:
  132. ValueReference m_wmipvrData;
  133. public:
  134. Property_Reference();
  135. virtual ~Property_Reference();
  136. bool operator==( /*[in]*/ Property_Reference const &wmippr ) const;
  137. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode );
  138. HRESULT get_Data( /*[out]*/ ValueReference*& wmipvr );
  139. };
  140. /////////////////////////////////////////////////////////////////////////////
  141. class Instance // Hungarian: wmipi
  142. {
  143. friend class Instance_Less_ByClass;
  144. friend class Instance_Less_ByKey;
  145. public:
  146. typedef std::map<MPC::wstring,Property_Scalar> PropMap;
  147. typedef PropMap::iterator PropIter;
  148. typedef PropMap::const_iterator PropIterConst;
  149. typedef std::map<MPC::wstring,Property_Array> ArrayMap;
  150. typedef ArrayMap::iterator ArrayIter;
  151. typedef ArrayMap::const_iterator ArrayIterConst;
  152. typedef std::map<MPC::wstring,Property_Reference> ReferenceMap;
  153. typedef ReferenceMap::iterator ReferenceIter;
  154. typedef ReferenceMap::const_iterator ReferenceIterConst;
  155. private:
  156. MPC::XmlUtil m_xmlNode; // This instance in the Xml DOM.
  157. Property_Scalar m_wmippTimeStamp; // Timestamp of this instance.
  158. bool m_fTimeStamp; //
  159. Property_Scalar m_wmippChange; // Change status of this instance.
  160. bool m_fChange; //
  161. InstanceName m_wmipinIdentity; // Set of keys.
  162. bool m_fPropertiesParsed; // Flags to indicate if properties are already parsed or not.
  163. PropMap m_mapPropertiesScalar; // Map of all the scalar properties of this instance.
  164. ArrayMap m_mapPropertiesArray; // Map of all the array properties of this instance.
  165. ReferenceMap m_mapPropertiesReference; // Map of all the reference properties of this instance.
  166. HRESULT ParseIdentity ( /*[in] */ IXMLDOMNode* pxdnNode, /*[out]*/ bool& fEmpty );
  167. HRESULT ParseProperties ( );
  168. HRESULT ParsePropertiesScalar ( );
  169. HRESULT ParsePropertiesArray ( );
  170. HRESULT ParsePropertiesReference( );
  171. public:
  172. Instance();
  173. ~Instance();
  174. bool operator==( /*[in]*/ Instance const &wmipi ) const;
  175. HRESULT put_Node( /*[in] */ IXMLDOMNode* pxdnNode, /*[out]*/ bool& fEmpty );
  176. HRESULT get_Node( /*[out]*/ IXMLDOMNode* *pxdnNode );
  177. HRESULT get_Namespace( /*[out]*/ MPC::wstring& szNamespace );
  178. HRESULT get_Class ( /*[out]*/ MPC::wstring& szClass );
  179. HRESULT get_TimeStamp( /*[out]*/ Property_Scalar*& wmippTimeStamp, /*[out]*/ bool& fFound );
  180. HRESULT get_Change ( /*[out]*/ Property_Scalar*& wmippChange );
  181. HRESULT get_Identity ( /*[out]*/ InstanceName*& wmipin );
  182. HRESULT get_Properties ( /*[out]*/ PropIterConst& itBegin, /*[out]*/ PropIterConst& itEnd );
  183. HRESULT get_PropertiesArray ( /*[out]*/ ArrayIterConst& itBegin, /*[out]*/ ArrayIterConst& itEnd );
  184. HRESULT get_PropertiesReference( /*[out]*/ ReferenceIterConst& itBegin, /*[out]*/ ReferenceIterConst& itEnd );
  185. bool CompareByClass( /*[in]*/ Instance const &wmipi ) const;
  186. bool CompareByKey ( /*[in]*/ Instance const &wmipi ) const;
  187. };
  188. class Instance_Less_ByClass
  189. {
  190. public:
  191. bool operator()( /*[in]*/ Instance* const &, /*[in]*/ Instance* const & ) const;
  192. };
  193. class Instance_Less_ByKey
  194. {
  195. public:
  196. bool operator()( /*[in]*/ Instance* const &, /*[in]*/ Instance* const & ) const;
  197. };
  198. /////////////////////////////////////////////////////////////////////////////
  199. class Snapshot // Hungarian: wmips
  200. {
  201. public:
  202. typedef std::list<Instance> InstList;
  203. typedef InstList::iterator InstIter;
  204. typedef InstList::const_iterator InstIterConst;
  205. private:
  206. MPC::XmlUtil m_xmlNode; // This snapshot in the Xml DOM.
  207. CComPtr<IXMLDOMNode> m_xdnInstances; // Position of the parent of all instances.
  208. InstList m_lstInstances; // List of all the instances of this snapshot.
  209. HRESULT Parse();
  210. public:
  211. Snapshot();
  212. ~Snapshot();
  213. HRESULT put_Node ( /*[in] */ IXMLDOMNode* pxdnNode );
  214. HRESULT get_Node ( /*[out]*/ IXMLDOMNode* *pxdnNode );
  215. HRESULT get_NodeForInstances( /*[out]*/ IXMLDOMNode* *pxdnNode );
  216. HRESULT get_Instances( /*[out]*/ InstIterConst& itBegin, /*[out]*/ InstIterConst& itEnd );
  217. HRESULT clone_Instance( /*[in]*/ Instance* pwmipiOld, /*[out]*/ Instance*& pwmipiNew );
  218. HRESULT New ( );
  219. HRESULT Load( /*[in]*/ LPCWSTR szFile, /*[in]*/ LPCWSTR szRootTag );
  220. HRESULT Save( /*[in]*/ LPCWSTR szFile );
  221. };
  222. /////////////////////////////////////////////////////////////////////////////
  223. typedef std::map<Instance*,Instance*,Instance_Less_ByKey> ClusterByKeyMap;
  224. typedef ClusterByKeyMap::iterator ClusterByKeyIter;
  225. typedef ClusterByKeyMap::const_iterator ClusterByKeyIterConst;
  226. class Cluster
  227. {
  228. ClusterByKeyMap m_map;
  229. public:
  230. Cluster() {};
  231. HRESULT Add ( /*[in] */ Instance* wmipiInst );
  232. HRESULT Find( /*[in] */ Instance* wmipiInst, /*[out]*/ Instance*& wmipiRes, /*[out]*/ bool& fFound );
  233. HRESULT Enum( /*[out]*/ ClusterByKeyIter& itBegin , /*[out]*/ ClusterByKeyIter& itEnd );
  234. };
  235. typedef std::map<Instance*,Cluster,Instance_Less_ByClass> ClusterByClassMap;
  236. typedef ClusterByClassMap::iterator ClusterByClassIter;
  237. typedef ClusterByClassMap::const_iterator ClusterByClassIterConst;
  238. /////////////////////////////////////////////////////////////////////////////
  239. HRESULT DistributeOnCluster( /*[in]*/ ClusterByClassMap& cluster, /*[in]*/ Snapshot& wmips );
  240. HRESULT CompareSnapshots( /*[in] */ BSTR bstrFilenameT0 ,
  241. /*[in] */ BSTR bstrFilenameT1 ,
  242. /*[in] */ BSTR bstrFilenameDiff ,
  243. /*[out,retval]*/ VARIANT_BOOL *pVal );
  244. };
  245. #endif // !defined(__INCLUDED___PCH___WMIPARSER_H___)