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.

237 lines
12 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. MCP_config.h
  5. Abstract:
  6. This file contains the declaration of the ....
  7. Revision History:
  8. Davide Massarenti (Dmassare) 01/09/2000
  9. created
  10. ******************************************************************************/
  11. #if !defined(__INCLUDED___MPC___CONFIG_H___)
  12. #define __INCLUDED___MPC___CONFIG_H___
  13. #include <MPC_main.h>
  14. #include <MPC_trace.h>
  15. #include <MPC_com.h>
  16. #include <MPC_utils.h>
  17. #include <MPC_xml.h>
  18. /////////////////////////////////////////////////////////////////////////
  19. #define DECLARE_CONFIG_MAP(x) \
  20. typedef x _ConfigMapClass; \
  21. static const MPC::Config::DefinitionOfTag _cfg_tag;\
  22. static const MPC::Config::DefinitionOfTag* _cfg_table_tags[];\
  23. static const MPC::Config::DefinitionOfAttribute _cfg_table_attributes[];
  24. #define DEFINE_CONFIG_DEFAULTTAG() static const MPC::Config::DefinitionOfTag* GetDefTag() { return &_cfg_tag; }
  25. #define DECLARE_CONFIG_METHODS() \
  26. LPCWSTR GetTag() const;\
  27. void* GetOffset( size_t offset ) const;\
  28. HRESULT CreateInstance( const MPC::Config::DefinitionOfTag* tag, MPC::Config::TypeConstructor*& defSubType );\
  29. HRESULT LoadNode( IXMLDOMNode* xdn );\
  30. HRESULT SaveNode( IXMLDOMNode* xdn ) const;
  31. ////////////////////
  32. #define CFG_OFFSET(x) offsetof(_ConfigMapClass, x)
  33. #define CFG_BEGIN_FIELDS_MAP(x) const MPC::Config::DefinitionOfAttribute x::_cfg_table_attributes[] = {
  34. #define CFG_VALUE(type,y) { MPC::Config::XT_value , NULL, MPC::Config::MT_##type , CFG_OFFSET(y), false, 0 , NULL }
  35. #define CFG_ATTRIBUTE(name,type,y) { MPC::Config::XT_attribute, name, MPC::Config::MT_##type , CFG_OFFSET(y), false, 0 , NULL }
  36. #define CFG_ELEMENT(name,type,y) { MPC::Config::XT_element , name, MPC::Config::MT_##type , CFG_OFFSET(y), false, 0 , NULL }
  37. #define CFG_VALUE__TRISTATE(type,y,flag) { MPC::Config::XT_value , NULL, MPC::Config::MT_##type , CFG_OFFSET(y), true , CFG_OFFSET(flag), NULL }
  38. #define CFG_ATTRIBUTE__TRISTATE(name,type,y,flag) { MPC::Config::XT_attribute, name, MPC::Config::MT_##type , CFG_OFFSET(y), true , CFG_OFFSET(flag), NULL }
  39. #define CFG_ELEMENT__TRISTATE(name,type,y,flag) { MPC::Config::XT_element , name, MPC::Config::MT_##type , CFG_OFFSET(y), true , CFG_OFFSET(flag), NULL }
  40. #define CFG_VALUE__BITFIELD(y,lookup) { MPC::Config::XT_value , NULL, MPC::Config::MT_bitfield, CFG_OFFSET(y), false, 0 , lookup }
  41. #define CFG_ATTRIBUTE__BITFIELD(name,y,lookup) { MPC::Config::XT_attribute, name, MPC::Config::MT_bitfield, CFG_OFFSET(y), false, 0 , lookup }
  42. #define CFG_ELEMENT__BITFIELD(name,y,lookup) { MPC::Config::XT_element , name, MPC::Config::MT_bitfield, CFG_OFFSET(y), false, 0 , lookup }
  43. #define CFG_END_FIELDS_MAP() { MPC::Config::XT_invalid } };
  44. ////////////////////
  45. #define CFG_BEGIN_CHILD_MAP(x) const MPC::Config::DefinitionOfTag* x::_cfg_table_tags[] = {
  46. #define CFG_CHILD(y) y::GetDefTag(),
  47. #define CFG_END_CHILD_MAP() NULL };
  48. ////////////////////
  49. #define DEFINE_CFG_OBJECT(x,tag) const MPC::Config::DefinitionOfTag x::_cfg_tag = { tag, _cfg_table_tags, _cfg_table_attributes };
  50. ////////////////////////////////////////////////////////////////////////////////
  51. #define DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(x,tag,defSubType) \
  52. \
  53. LPCWSTR x::GetTag() const { return _cfg_tag.m_szTag; } \
  54. \
  55. void* x::GetOffset( size_t offset ) const { return (void*)((BYTE*)this + offset); } \
  56. \
  57. HRESULT x::CreateInstance( const MPC::Config::DefinitionOfTag* tag, MPC::Config::TypeConstructor*& defSubType ) \
  58. { \
  59. HRESULT hr;
  60. #define DEFINE_CONFIG_METHODS_SAVENODE_SECTION(x, xdn) \
  61. \
  62. return E_FAIL; \
  63. } \
  64. \
  65. HRESULT x::LoadNode( IXMLDOMNode* xdn ) \
  66. { \
  67. return MPC::Config::LoadNode( this, &_cfg_tag, xdn ); \
  68. } \
  69. \
  70. HRESULT x::SaveNode( IXMLDOMNode* xdn ) const \
  71. { \
  72. HRESULT hr; \
  73. \
  74. if(SUCCEEDED(hr = MPC::Config::SaveNode( this, &_cfg_tag, xdn ))) \
  75. {
  76. #define DEFINE_CONFIG_METHODS_END(x) \
  77. } \
  78. \
  79. return hr; \
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////
  82. #define DEFINE_CONFIG_METHODS__NOCHILD(x) \
  83. \
  84. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(x,tag,defSubType) \
  85. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(x,xdn) \
  86. DEFINE_CONFIG_METHODS_END(x)
  87. ////////////////////////////////////////////////////////////////////////////////
  88. namespace MPC
  89. {
  90. namespace Config
  91. {
  92. typedef enum
  93. {
  94. XT_invalid ,
  95. XT_attribute, // Means attribute of the current element.
  96. XT_value , // Means value of the current element
  97. XT_element , // Means sub-element.
  98. } XMLTypes;
  99. typedef enum
  100. {
  101. MT_bool ,
  102. MT_BOOL ,
  103. MT_VARIANT_BOOL,
  104. MT_int ,
  105. MT_long ,
  106. MT_DWORD ,
  107. MT_float ,
  108. MT_double ,
  109. MT_DATE ,
  110. MT_DATE_US ,
  111. MT_DATE_CIM ,
  112. MT_CHAR ,
  113. MT_WCHAR ,
  114. MT_BSTR ,
  115. MT_string ,
  116. MT_wstring ,
  117. MT_bitfield
  118. } MemberTypes;
  119. ////////////////////////////////////////
  120. struct TypeConstructor; // The class you have to inherit from in order to load/save your state.
  121. struct DefinitionOfTag; // Definition of objects.
  122. struct DefinitionOfAttribute; // Definition of member variables.
  123. ////////////////////////////////////////
  124. struct TypeConstructor
  125. {
  126. virtual LPCWSTR GetTag() const = 0;
  127. virtual void* GetOffset( size_t offset ) const = 0;
  128. virtual HRESULT CreateInstance( const DefinitionOfTag* tag, TypeConstructor*& defSubType ) = 0;
  129. virtual HRESULT LoadNode ( IXMLDOMNode* xdn ) = 0;
  130. virtual HRESULT SaveNode ( IXMLDOMNode* xdn ) const = 0;
  131. };
  132. struct DefinitionOfAttribute
  133. {
  134. XMLTypes m_xt;
  135. LPCWSTR m_szName;
  136. MemberTypes m_mtType;
  137. size_t m_offset;
  138. bool m_fPresenceFlag;
  139. size_t m_offsetPresence;
  140. const StringToBitField* m_Lookup;
  141. };
  142. struct DefinitionOfTag
  143. {
  144. LPCWSTR m_szTag;
  145. const DefinitionOfTag** m_tblSubTags;
  146. const DefinitionOfAttribute* m_tblAttributes;
  147. const DefinitionOfTag* FindSubTag ( /*[in]*/ LPCWSTR szTag ) const;
  148. const DefinitionOfAttribute* FindAttribute( /*[in]*/ XMLTypes xt, /*[in]*/ LPCWSTR szName ) const;
  149. };
  150. ////////////////////////////////////////
  151. void ClearValue( /*[in]*/ TypeConstructor* defType, /*[in]*/ const DefinitionOfAttribute* defField );
  152. HRESULT LoadValue ( /*[in]*/ TypeConstructor* defType, /*[in]*/ const DefinitionOfAttribute* defField, /*[in/out]*/ CComVariant& value, /*[in] */ bool fFound );
  153. HRESULT SaveValue ( /*[in]*/ const TypeConstructor* defType, /*[in]*/ const DefinitionOfAttribute* defField, /*[out ]*/ CComVariant& value, /*[out]*/ bool& fFound );
  154. HRESULT LoadNode ( /*[in]*/ TypeConstructor* defType, /*[in]*/ const DefinitionOfTag* defTag, /*[in]*/ IXMLDOMNode* xdn );
  155. HRESULT SaveNode ( /*[in]*/ const TypeConstructor* defType, /*[in]*/ const DefinitionOfTag* defTag, /*[in]*/ IXMLDOMNode* xdn );
  156. HRESULT SaveSubNode( /*[in]*/ const TypeConstructor* defType, /*[in]*/ IXMLDOMNode* xdn );
  157. HRESULT LoadXmlUtil( /*[in]*/ TypeConstructor* defType, /*[in ]*/ MPC::XmlUtil& xml );
  158. HRESULT SaveXmlUtil( /*[in]*/ const TypeConstructor* defType, /*[out]*/ MPC::XmlUtil& xml );
  159. HRESULT LoadStream( /*[in]*/ TypeConstructor* defType, /*[in ]*/ IStream* pStream );
  160. HRESULT SaveStream( /*[in]*/ const TypeConstructor* defType, /*[out]*/ IStream* *ppStream );
  161. HRESULT LoadFile( /*[in]*/ TypeConstructor* defType, /*[in]*/ LPCWSTR szFile );
  162. HRESULT SaveFile( /*[in]*/ const TypeConstructor* defType, /*[in]*/ LPCWSTR szFile );
  163. ////////////////////////////////////////
  164. template <class Container> HRESULT SaveList( /*[in]*/ Container& cnt, /*[in]*/ IXMLDOMNode* xdn )
  165. {
  166. HRESULT hr = S_OK;
  167. for(Container::const_iterator it=cnt.begin(); it != cnt.end(); it++)
  168. {
  169. if(FAILED(hr = MPC::Config::SaveSubNode( &(*it), xdn ))) break;
  170. }
  171. return hr;
  172. }
  173. }; // namespace Config
  174. }; // namespace MPC
  175. /////////////////////////////////////////////////////////////////////////
  176. #endif // !defined(__INCLUDED___MPC___CONFIG_H___)