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.

323 lines
12 KiB

  1. //***************************************************************************
  2. //
  3. // (c) 1999-2001 by Microsoft Corp. All Rights Reserved.
  4. //
  5. // repcache.h
  6. //
  7. // cvadai 19-Mar-99 Created as prototype for Quasar.
  8. //
  9. //***************************************************************************
  10. #ifndef _REPCACHE_H_
  11. #define _REPCACHE_H_
  12. #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
  13. #include <std.h>
  14. #include <objcache.h>
  15. #include <sqlcache.h>
  16. //***************************************************************************
  17. // CLockCache
  18. //***************************************************************************
  19. #define REPDRVR_FLAG_NONPROP REPDRVR_FLAG_IN_PARAM + REPDRVR_FLAG_OUT_PARAM + REPDRVR_FLAG_QUALIFIER + REPDRVR_FLAG_METHOD
  20. #define REPDRVR_IGNORE_CIMTYPE -1
  21. class LockItem
  22. {
  23. public:
  24. IUnknown *m_pObj;
  25. DWORD m_dwHandleType;
  26. bool m_bLockOnChild;
  27. SQL_ID m_dSourceId;
  28. DWORD m_dwVersion;
  29. LockItem() {m_dSourceId = 0; m_bLockOnChild=false; m_dwHandleType = 0; m_pObj = NULL;}
  30. ~LockItem() {};
  31. };
  32. class LockData
  33. {
  34. typedef std::vector<LockItem *> LockList;
  35. typedef std::map<SQL_ID, bool> SQL_IDMap;
  36. public:
  37. SQL_ID m_dObjectId;
  38. DWORD m_dwStatus;
  39. DWORD m_dwCompositeStatus;
  40. DWORD m_dwVersion;
  41. DWORD m_dwCompositeVersion;
  42. DWORD m_dwNumLocks;
  43. LockList m_List;
  44. SQL_IDMap m_OwnerIds;
  45. LockData() {m_dObjectId = 0; m_dwStatus = 0; m_dwVersion = 0;m_dwNumLocks = 0;};
  46. ~LockData() {};
  47. DWORD GetMaxLock(bool bImmediate, bool bSubScopeOnly=false);
  48. bool LockExists (DWORD dwHandleType);
  49. };
  50. class CLockCache
  51. {
  52. public:
  53. HRESULT GetHandle(SQL_ID ObjId, DWORD dwType, IWmiDbHandle **ppRet);
  54. HRESULT AddLock(bool bImmediate, SQL_ID ObjId, DWORD Type, IUnknown *pUnk, SQL_ID dNsId,
  55. SQL_ID dClassId, CSchemaCache *pCache, bool bChg = false, bool bChildLock = false, SQL_ID SourceId =0,
  56. DWORD *CurrVersion=NULL);
  57. HRESULT DeleteLock(SQL_ID ObjId, bool bChildLock, DWORD HandleType = 0, bool bDelChildren = true, void *pObj=NULL);
  58. HRESULT GetCurrentLock(SQL_ID ObjId, bool bImmediate, DWORD &HandleType, DWORD *Version=NULL);
  59. HRESULT GetAllLocks(SQL_ID ObjId, SQL_ID ClassId, SQL_ID NsId, CSchemaCache *pCache, bool bImmediate, DWORD &HandleType, DWORD *Version=NULL);
  60. bool CanLockHandle (SQL_ID ObjId, DWORD RequestedHandleType, bool bImmediate, bool bSubscopedOnly=true);
  61. bool CanRenderObject (SQL_ID ObjId, SQL_ID ClassId, SQL_ID NsId, CSchemaCache *pCache, DWORD RequestedHandleType, bool bImmediate);
  62. HRESULT IncrementVersion(SQL_ID ObjId);
  63. CLockCache() {InitializeCriticalSection(&m_cs);};
  64. ~CLockCache();
  65. private:
  66. CHashCache<LockData *> m_Cache;
  67. CRITICAL_SECTION m_cs;
  68. };
  69. //***************************************************************************
  70. // CObjectCache
  71. //***************************************************************************
  72. // Object cache. This needs to have a timeout value.
  73. // Also, we need a marker for "strong cache" requests.
  74. struct CacheInfo
  75. {
  76. public:
  77. SQL_ID m_dObjectId;
  78. SQL_ID m_dClassId;
  79. SQL_ID m_dScopeId;
  80. time_t m_tLastAccess;
  81. LPWSTR m_sPath;
  82. IWbemClassObject *m_pObj;
  83. bool m_bStrong;
  84. CacheInfo() {m_sPath = NULL;};
  85. ~CacheInfo()
  86. {
  87. if ( m_pObj != NULL )
  88. {
  89. m_pObj->Release();
  90. }
  91. delete m_sPath;
  92. };
  93. };
  94. class CObjectCache
  95. {
  96. public:
  97. CObjectCache();
  98. ~CObjectCache();
  99. HRESULT GetObject (LPCWSTR lpPath, IWbemClassObject **ppObj, SQL_ID *dScopeId = NULL);
  100. HRESULT GetObjectId (LPCWSTR lpPath, SQL_ID &dObjId, SQL_ID &dClassId, SQL_ID *dScopeId=NULL);
  101. HRESULT GetObject (SQL_ID dObjectId, IWbemClassObject **ppObj, SQL_ID *dScopeId = NULL);
  102. HRESULT PutObject (SQL_ID dObjectId, SQL_ID dClassId, SQL_ID dScopeId,
  103. LPCWSTR lpPath, bool bStrongCache, IWbemClassObject *pObj);
  104. HRESULT DeleteObject (SQL_ID dObjectId);
  105. bool ObjectExists (SQL_ID dObjectId);
  106. HRESULT SetCacheSize(const DWORD dwMaxSize);
  107. HRESULT GetCurrentUsage(DWORD &dwBytesUsed);
  108. HRESULT GetCacheSize(DWORD &dwSizeInBytes);
  109. HRESULT FindFirst(SQL_ID &dObjectId, SQL_ID &dClassId, SQL_ID *dScopeId = NULL);
  110. HRESULT FindNext (SQL_ID dLastId, SQL_ID &dObjectId, SQL_ID &dClassId, SQL_ID *dScopeId = NULL);
  111. void EmptyCache();
  112. private:
  113. DWORD GetSize(IWbemClassObject *pObj);
  114. HRESULT ResizeCache(DWORD dwReqBytes, SQL_ID dLeave, bool bForce=true);
  115. CHashCache<CacheInfo *> m_ObjCache;
  116. //CQuasarStringList m_PathIndex;
  117. DWORD m_dwMaxSize;
  118. DWORD m_dwUsed;
  119. CRITICAL_SECTION m_cs;
  120. };
  121. //***************************************************************************
  122. // CSchemaCache
  123. //***************************************************************************
  124. class PropertyData
  125. {
  126. public:
  127. LPWSTR m_sPropertyName;
  128. SQL_ID m_dwClassID;
  129. DWORD m_dwStorageType;
  130. DWORD m_dwCIMType;
  131. DWORD m_dwFlags;
  132. SQL_ID m_dwRefClassID;
  133. DWORD m_dwQPropID;
  134. LPWSTR m_sDefaultValue;
  135. DWORD m_dwFlavor;
  136. PropertyData();
  137. ~PropertyData(){delete m_sPropertyName; delete m_sDefaultValue;};
  138. DWORD GetSize();
  139. };
  140. struct PropertyList
  141. {
  142. DWORD m_dwPropertyId;
  143. BOOL m_bIsKey;
  144. };
  145. class ClassData
  146. {
  147. public:
  148. typedef std::vector <SQL_ID> SQLIDs;
  149. LPWSTR m_sName;
  150. SQL_ID m_dwClassID;
  151. SQL_ID m_dwSuperClassID;
  152. SQL_ID m_dwDynastyID;
  153. SQL_ID m_dwScopeID;
  154. LPWSTR m_sObjectPath;
  155. PropertyList *m_Properties;
  156. DWORD m_dwNumProps;
  157. DWORD m_dwArraySize;
  158. DWORD m_dwFlags;
  159. SQLIDs m_DerivedIDs;
  160. ClassData();
  161. ~ClassData(){delete m_Properties; delete m_sName; delete m_sObjectPath;};
  162. void InsertProperty (DWORD PropId, BOOL bIsKey);
  163. void DeleteProperty (DWORD PropId);
  164. void InsertDerivedClass (SQL_ID dID);
  165. void DeleteDerivedClass (SQL_ID dID);
  166. DWORD GetSize();
  167. };
  168. class NamespaceData
  169. {
  170. public:
  171. LPWSTR m_sNamespaceName;
  172. LPWSTR m_sNamespaceKey;
  173. SQL_ID m_dNamespaceId;
  174. SQL_ID m_dParentId;
  175. SQL_ID m_dClassId;
  176. NamespaceData() {m_sNamespaceName = NULL; m_sNamespaceKey = NULL; };
  177. ~NamespaceData() {delete m_sNamespaceName; delete m_sNamespaceKey;};
  178. DWORD GetSize();
  179. };
  180. class _bstr_tNoCase
  181. {
  182. public:
  183. inline bool operator()(const _bstr_t ws1, const _bstr_t ws2) const
  184. {return _wcsicmp(ws1, ws2) < 0;}
  185. };
  186. class CSchemaCache
  187. {
  188. typedef std::map <DWORD, DWORD> Properties;
  189. typedef std::map <_bstr_t, SQL_ID, _bstr_tNoCase> ClassNames;
  190. typedef std::map<SQL_ID, ULONG> SQLRefCountMap;
  191. typedef std::vector <SQL_ID> SQLIDs;
  192. public:
  193. CSchemaCache();
  194. ~CSchemaCache();
  195. HRESULT GetPropertyInfo (DWORD dwPropertyID, _bstr_t *sName=NULL, SQL_ID *dwClassID=NULL, DWORD *dwStorageType=NULL,
  196. DWORD *dwCIMType=NULL, DWORD *dwFlags=NULL, SQL_ID *dwRefClassID=NULL, _bstr_t *sDefaultValue=NULL,
  197. DWORD *dwRefPropID=NULL, DWORD *dwFlavor=NULL);
  198. HRESULT GetPropertyID (LPCWSTR lpName, SQL_ID dClassID, DWORD dwFlags, CIMTYPE ct,
  199. DWORD &PropertyID, SQL_ID *ActualClass = NULL, DWORD *Flags = NULL, DWORD *Type = NULL, BOOL bSys = FALSE);
  200. HRESULT AddPropertyInfo (DWORD dwPropertyID, LPCWSTR lpName, SQL_ID dwClassID, DWORD dwStorageType,
  201. DWORD dwCIMType, DWORD dwFlags, SQL_ID dwRefClassID, LPCWSTR lpDefault, DWORD dwRefPropID, DWORD dwFlavor);
  202. bool PropertyChanged (LPCWSTR lpName, SQL_ID dwClassID,DWORD dwCIMType, LPCWSTR lpDefault=NULL,
  203. DWORD dwFlags=0, SQL_ID dwRefClassID=0, DWORD dwRefPropID=0, DWORD dwFlavor=0);
  204. bool IsQualifier(DWORD dwPropertyId);
  205. HRESULT SetAuxiliaryPropertyInfo (DWORD dwPropertyID, LPWSTR lpDefault, DWORD dwRefID);
  206. HRESULT DeleteProperty (DWORD dwPropertyID, SQL_ID dClassId);
  207. HRESULT GetClassInfo (SQL_ID dwClassID, _bstr_t &sPath, SQL_ID &dwSuperClassID, SQL_ID &dwScopeID,
  208. DWORD &dwFlags, _bstr_t *sName = NULL);
  209. HRESULT AddClassInfo (SQL_ID dwClassID, LPCWSTR lpName, SQL_ID dwSuperClassID, SQL_ID dwDynasty, SQL_ID dwScopeID,
  210. LPCWSTR lpPath, DWORD dwFlags);
  211. HRESULT DeleteClass (SQL_ID dwClassID);
  212. HRESULT GetClassID (LPCWSTR lpClassName, SQL_ID dwScopeID, SQL_ID &dClassID, SQL_ID *pDynasty = NULL);
  213. HRESULT GetDynasty (SQL_ID dClassId, SQL_ID &dDynasty, _bstr_t &sClassName);
  214. HRESULT GetClassObject (LPWSTR lpMachineName, LPWSTR lpNamespaceName, SQL_ID dScopeId, SQL_ID dClassId,
  215. IWbemClassObject *pNewObj);
  216. HRESULT GetParentId (SQL_ID dClassId, SQL_ID &dParentId);
  217. HRESULT GetKeyholeProperty (SQL_ID dClassId, DWORD &dwPropID, _bstr_t &sPropName);
  218. bool IsInHierarchy (SQL_ID dParentId, SQL_ID dPotentialChild);
  219. bool IsDerivedClass(SQL_ID dParentId, SQL_ID dPotentialChild);
  220. bool HasImageProp (SQL_ID dClassId);
  221. BOOL Exists (SQL_ID dClassId);
  222. HRESULT GetNamespaceID(LPCWSTR lpKey, SQL_ID &dObjectId);
  223. HRESULT GetNamespaceClass(SQL_ID dScopeId, SQL_ID &dScopeClassId);
  224. HRESULT GetParentNamespace(SQL_ID dObjectId, SQL_ID &dParentId, SQL_ID *dParentClassId = NULL);
  225. HRESULT GetNamespaceName(SQL_ID dObjectId, _bstr_t *sName = NULL, _bstr_t *sKey = NULL);
  226. HRESULT AddNamespace(LPCWSTR lpName, LPCWSTR lpKey, SQL_ID dObjectId, SQL_ID dParentId, SQL_ID m_dClassId);
  227. HRESULT DeleteNamespace(SQL_ID dId);
  228. bool IsSubScope(SQL_ID dParent, SQL_ID dPotentialSubScope);
  229. HRESULT GetSubScopes(SQL_ID dId, SQL_ID **ppScopes, int &iNumScopes);
  230. HRESULT DecorateWbemObj (LPWSTR lpMachineName, LPWSTR lpNamespaceName, SQL_ID dScopeId, IWbemClassObject *pObj, SQL_ID dClassId);
  231. HRESULT GetKeys(SQL_ID dNsID, LPCWSTR lpClassName, CWStringArray &arrKeys);
  232. BOOL IsKey(SQL_ID dClassId, DWORD dwPropID, BOOL &bLocal);
  233. HRESULT SetIsKey (SQL_ID dClassId, DWORD dwPropID, BOOL bIsKey = TRUE);
  234. LPWSTR GetKeyRoot (LPWSTR lpClassName, SQL_ID dScopeId);
  235. HRESULT GetPropertyList (SQL_ID dClassId, Properties &pProps, DWORD *pwNumProps= NULL);
  236. HRESULT ValidateProperty (SQL_ID dObjectId, DWORD dwPropertyID, DWORD dwFlags, CIMTYPE cimtype, DWORD dwStorageType,
  237. LPWSTR lpDefault, BOOL &bChg, BOOL &bIfNoInstances);
  238. HRESULT FindProperty(SQL_ID dObjectId, LPWSTR lpPropName, DWORD dwFlags, CIMTYPE ct);
  239. HRESULT GetDerivedClassList(SQL_ID dObjectId, SQLIDs &ids, int &iNumChildren, BOOL bImmediate = FALSE);
  240. HRESULT GetDerivedClassList(SQL_ID dObjectId, SQL_ID **ppIDs, int &iNumChildren, BOOL bImmediate = FALSE);
  241. HRESULT GetHierarchy(SQL_ID dObjectId, SQL_ID **ppIDs, int &iNumIDs);
  242. HRESULT GetHierarchy(SQL_ID dObjectId, SQLIDs &ids, int &iNumIDs);
  243. void EmptyCache();
  244. DWORD GetTotalSize() {return m_dwTotalSize;};
  245. void SetMaxSize(DWORD dwMax) {m_dwMaxSize = dwMax;};
  246. DWORD GetMaxSize() {return m_dwMaxSize;};
  247. HRESULT ResizeCache();
  248. HRESULT LockDynasty(SQL_ID dDynastyId);
  249. HRESULT UnlockDynasty(SQL_ID dDynastyId);
  250. HRESULT DeleteDynasty(SQL_ID dDynastyId);
  251. BOOL IsSystemClass(SQL_ID dObjectId, SQL_ID dClassId);
  252. DWORD GetWriteToken(SQL_ID dObjectId, SQL_ID dClassId);
  253. private:
  254. CHashCache<PropertyData *> m_Cache;
  255. CHashCache<ClassData *> m_CCache;
  256. ClassNames m_CIndex;
  257. CHashCache<NamespaceData *> m_NamespaceIds;
  258. DWORD m_dwTotalSize;
  259. DWORD m_dwMaxSize;
  260. SQLRefCountMap m_DynastiesInUse;
  261. CRITICAL_SECTION m_cs;
  262. };
  263. #endif