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.

332 lines
7.5 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: MetaUtil object
  6. File: MetaSchm.h
  7. Owner: t-BrianM
  8. This file contains the headers for the CMetaSchemaTable object and
  9. other schema related objects.
  10. ===================================================================*/
  11. #ifndef __METASCHM_H_
  12. #define __METASCHM_H_
  13. #if _MSC_VER >= 1000
  14. #pragma once
  15. #endif // _MSC_VER >= 1000
  16. #include "resource.h" // main symbols
  17. // Ripped from schemini.hxx
  18. struct PropValue {
  19. DWORD dwMetaID;
  20. DWORD dwSynID;
  21. DWORD dwMetaType;
  22. DWORD dwFlags;
  23. DWORD dwMask;
  24. DWORD dwMetaFlags;
  25. DWORD dwUserGroup;
  26. BOOL fMultiValued;
  27. };
  28. // All hash table sizes are prime numbers between powers of 2
  29. // and are ~10x larger than the expected number of items.
  30. #define SCHEMA_HASH_SIZE 181
  31. #define PROPERTY_HASH_SIZE 1559
  32. #define CLASS_HASH_SIZE 181
  33. #define CLASS_PROPERTY_HASH_SIZE 709
  34. /*
  35. * C P r o p I n f o
  36. *
  37. * C P r o p I n f o T a b l e
  38. *
  39. * Internal classes used to store and represent property information
  40. */
  41. class CPropInfoTable;
  42. class CPropInfo {
  43. friend CPropInfoTable;
  44. public:
  45. CPropInfo() : m_dwId(0),
  46. m_tszName(NULL),
  47. m_pType(NULL),
  48. m_pCIdHashNext(NULL),
  49. m_pCNameHashNext(NULL) { }
  50. HRESULT Init(DWORD dwId);
  51. HRESULT SetName(LPCTSTR tszName);
  52. HRESULT SetTypeInfo(PropValue *pType);
  53. ~CPropInfo() {
  54. if (m_tszName != NULL) delete m_tszName;
  55. if (m_pType != NULL) delete m_pType;
  56. }
  57. DWORD GetId() { return m_dwId; }
  58. LPCTSTR GetName() { return m_tszName; }
  59. PropValue *GetTypeInfo() { return m_pType; }
  60. private:
  61. DWORD m_dwId;
  62. LPTSTR m_tszName;
  63. PropValue *m_pType;
  64. CPropInfo *m_pCNameHashNext;
  65. CPropInfo *m_pCIdHashNext;
  66. };
  67. class CPropInfoTable {
  68. public:
  69. CPropInfoTable();
  70. ~CPropInfoTable();
  71. HRESULT Load(CComPtr<IMSAdminBase> &pIMeta, METADATA_HANDLE hMDComp);
  72. void Unload();
  73. CPropInfo *GetPropInfo(DWORD dwId);
  74. CPropInfo *GetPropInfo(LPCTSTR tszName);
  75. private:
  76. BOOL m_fLoaded;
  77. CPropInfo *m_rgCPropIdTable[PROPERTY_HASH_SIZE];
  78. CPropInfo *m_rgCPropNameTable[PROPERTY_HASH_SIZE];
  79. unsigned int IdHash(DWORD dwId) { return dwId % PROPERTY_HASH_SIZE; }
  80. unsigned int NameHash(LPCTSTR tszName);
  81. };
  82. /*
  83. * C C l a s s P r o p I n f o
  84. *
  85. * C C l a s s I n f o
  86. *
  87. * C C l a s s I n f o T a b l e
  88. *
  89. * Internal classes used to store and represent class information
  90. */
  91. class CClassInfoTable;
  92. class CClassInfo;
  93. class CClassPropInfo {
  94. friend CClassInfo;
  95. public:
  96. CClassPropInfo() : m_dwId(0),
  97. m_fMandatory(FALSE),
  98. m_pCHashNext(NULL),
  99. m_pCListNext(NULL) {}
  100. HRESULT Init(DWORD dwId, BOOL fMandatory) {
  101. m_dwId = dwId;
  102. m_fMandatory = fMandatory;
  103. return S_OK;
  104. }
  105. DWORD GetId() { return m_dwId; }
  106. BOOL IsMandatory() { return m_fMandatory; }
  107. CClassPropInfo *GetListNext() { return m_pCListNext; }
  108. private:
  109. DWORD m_dwId;
  110. BOOL m_fMandatory;
  111. // Property default information could also be added...
  112. CClassPropInfo *m_pCHashNext;
  113. CClassPropInfo *m_pCListNext;
  114. };
  115. class CClassInfo {
  116. friend CClassInfoTable;
  117. public:
  118. CClassInfo();
  119. HRESULT Init(LPCTSTR tszName);
  120. ~CClassInfo();
  121. HRESULT Load(CComPtr<IMSAdminBase> &pIMeta, METADATA_HANDLE hMDClasses);
  122. void Unload();
  123. CClassPropInfo *GetProperty(DWORD dwId);
  124. CClassPropInfo *GetOptionalPropList() { return m_pCOptionalPropList; }
  125. CClassPropInfo *GetMandatoryPropList() { return m_pCMandatoryPropList; }
  126. private:
  127. LPTSTR m_tszName;
  128. CClassInfo *m_pCHashNext;
  129. BOOL m_fLoaded;
  130. CClassPropInfo *m_rgCPropTable[CLASS_PROPERTY_HASH_SIZE];
  131. CClassPropInfo *m_pCOptionalPropList;
  132. CClassPropInfo *m_pCMandatoryPropList;
  133. unsigned int Hash(DWORD dwId) { return dwId % CLASS_PROPERTY_HASH_SIZE; }
  134. };
  135. class CClassInfoTable {
  136. public:
  137. CClassInfoTable();
  138. ~CClassInfoTable();
  139. HRESULT Load(CComPtr<IMSAdminBase> &pIMeta, METADATA_HANDLE hMDComp);
  140. void Unload();
  141. CClassInfo *GetClassInfo(LPCTSTR tszName);
  142. private:
  143. BOOL m_fLoaded;
  144. CClassInfo *m_rgCClassTable[CLASS_HASH_SIZE];
  145. unsigned int Hash(LPCTSTR tszName);
  146. };
  147. /*
  148. * C M e t a S c h e m a
  149. *
  150. * Internal class used to store schema information for a machine
  151. */
  152. class CMetaSchemaTable;
  153. class CMetaSchema {
  154. friend CMetaSchemaTable;
  155. public:
  156. CMetaSchema() : m_fPropTableDirty(TRUE),
  157. m_fClassTableDirty(TRUE),
  158. m_tszMachineName(NULL),
  159. m_pCNextSchema(NULL) { }
  160. HRESULT Init(const CComPtr<IMSAdminBase> &pIMeta, LPCTSTR tszMachineName);
  161. ~CMetaSchema() { if (m_tszMachineName != NULL) delete m_tszMachineName; }
  162. CPropInfo *GetPropInfo(DWORD dwId);
  163. CPropInfo *GetPropInfo(LPCTSTR tszName);
  164. CClassInfo *GetClassInfo(LPCTSTR tszClassName);
  165. CClassPropInfo *GetClassPropInfo(LPCTSTR tszClassName, DWORD dwPropId);
  166. CClassPropInfo *GetMandatoryClassPropList(LPCTSTR tszClassName);
  167. CClassPropInfo *GetOptionalClassPropList(LPCTSTR tszClassName);
  168. void ChangeNotification(LPTSTR tszKey, MD_CHANGE_OBJECT *pcoChangeObject);
  169. private:
  170. LPTSTR m_tszMachineName;
  171. BOOL m_fPropTableDirty;
  172. BOOL m_fClassTableDirty;
  173. CPropInfoTable m_CPropInfoTable;
  174. CClassInfoTable m_CClassInfoTable;
  175. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  176. CComPtr<IMSAdminBase> m_pIMeta;
  177. CMetaSchema *m_pCNextSchema;
  178. HRESULT LoadPropTable();
  179. HRESULT LoadClassTable();
  180. };
  181. /*
  182. * C M e t a S c h e m a T a b l e
  183. *
  184. * Implements IMetaSchemaTable. Stores all of the schema information
  185. * for all of the machines. I made it global so it can persist after
  186. * CMetaUtil is destructed.
  187. */
  188. class CMSAdminBaseSink;
  189. class CMetaSchemaTable {
  190. public:
  191. CMetaSchemaTable();
  192. ~CMetaSchemaTable();
  193. DWORD AddRef() { return ++m_dwNumRef; }
  194. DWORD Release() {
  195. m_dwNumRef--;
  196. if (!m_dwNumRef) {
  197. delete this;
  198. return 0;
  199. }
  200. return m_dwNumRef;
  201. }
  202. void Load();
  203. void Unload();
  204. CPropInfo *GetPropInfo(LPCTSTR tszKey, DWORD dwPropId);
  205. CPropInfo *GetPropInfo(LPCTSTR tszKey, LPCTSTR tszPropName);
  206. CClassInfo *GetClassInfo(LPCTSTR tszKey, LPCTSTR tszClassName);
  207. CClassPropInfo *GetClassPropInfo(LPCTSTR tszKey, LPCTSTR tszClassName, DWORD dwPropId);
  208. CClassPropInfo *GetMandatoryClassPropList(LPCTSTR tszKey, LPCTSTR tszClassName);
  209. CClassPropInfo *GetOptionalClassPropList(LPCTSTR tszKey, LPCTSTR tszClassName);
  210. // Event sink callback
  211. HRESULT SinkNotify(DWORD dwMDNumElements, MD_CHANGE_OBJECT pcoChangeObject[]);
  212. private:
  213. DWORD m_dwNumRef;
  214. BOOL m_fLoaded;
  215. CMetaSchema *m_rgCSchemaTable[SCHEMA_HASH_SIZE];
  216. CComObject<CMSAdminBaseSink> *m_CMSAdminBaseSink;
  217. // Pointer to IMSAdminBase so we don't have to recreate it multiple times
  218. CComPtr<IMSAdminBase> m_pIMeta;
  219. CMetaSchema *GetSchema(LPCTSTR tszKey);
  220. unsigned int Hash(LPCTSTR tszName);
  221. };
  222. /*
  223. * C M S A d m i n B a s e S i n k
  224. *
  225. * Minimal ATL COM object that catches change notification events from the
  226. * metabase object and passes them on to the CMetaSchemaTable object.
  227. */
  228. class CMSAdminBaseSink :
  229. public IMSAdminBaseSink,
  230. public CComObjectRoot
  231. {
  232. public:
  233. CMSAdminBaseSink();
  234. ~CMSAdminBaseSink();
  235. BEGIN_COM_MAP(CMSAdminBaseSink)
  236. COM_INTERFACE_ENTRY(IMSAdminBaseSink)
  237. END_COM_MAP()
  238. // DECLARE_NOT_AGGREGATABLE(CMSAdminBaseSink)
  239. // IMSAdminBaseSink
  240. STDMETHOD(SinkNotify)(DWORD dwMDNumElements, MD_CHANGE_OBJECT pcoChangeObject[]);
  241. STDMETHOD(ShutdownNotify)(void);
  242. // No Interface
  243. HRESULT Connect(CComPtr<IMSAdminBase> &pIMeta, CMetaSchemaTable *pCMetaSchemaTable);
  244. void Disconnect();
  245. private:
  246. BOOL m_fConnected;
  247. DWORD m_dwCookie;
  248. CComPtr<IConnectionPoint> m_pIMetaConn;
  249. CMetaSchemaTable *m_pCMetaSchemaTable;
  250. };
  251. #endif // #ifndef __METASCHM_H_