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.

381 lines
9.5 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. ADAPCLS.H
  5. Abstract:
  6. History:
  7. --*/
  8. #ifndef __ADAPCLS_H__
  9. #define __ADAPCLS_H__
  10. #include <windows.h>
  11. #include <wbemcomn.h>
  12. #include <wbemcli.h>
  13. #include <wbemint.h>
  14. #include <winperf.h>
  15. #include <wstlallc.h>
  16. #include "adapelem.h"
  17. #include "perfndb.h"
  18. #include <comdef.h>
  19. #include <map>
  20. // Global constants
  21. // ================
  22. #define ADAP_DEFAULT_OBJECT 238L
  23. #define ADAP_DEFAULT_NDB L"009"
  24. #define ADAP_DEFAULT_LANGID 0x0409L
  25. #define ADAP_ROOT_NAMESPACE L"\\\\.\\root\\cimv2"
  26. #define ADAP_PERF_CIM_STAT_INFO L"CIM_StatisticalInformation"
  27. #define ADAP_PERF_BASE_CLASS L"Win32_Perf"
  28. #define ADAP_PERF_RAW_BASE_CLASS L"Win32_PerfRawData"
  29. #define ADAP_PERF_COOKED_BASE_CLASS L"Win32_PerfFormattedData"
  30. enum ClassTypes
  31. {
  32. WMI_ADAP_RAW_CLASS,
  33. WMI_ADAP_COOKED_CLASS,
  34. WMI_ADAP_NUM_TYPES
  35. };
  36. // Class list element states
  37. // =========================
  38. #define ADAP_OBJECT_IS_REGISTERED 0x0001L // Object is in WMI
  39. #define ADAP_OBJECT_IS_DELETED 0x0002L // Object is marked for deletion
  40. #define ADAP_OBJECT_IS_INACTIVE 0x0004L // Perflib did not respond
  41. #define ADAP_OBJECT_IS_NOT_IN_PERFLIB 0x0008L // Object is from an unloaded perflib
  42. #define ADAP_OBJECT_IS_TO_BE_CLEARED 0x0010L // Need to clear registry
  43. class CLocaleDefn : public CAdapElement
  44. ///////////////////////////////////////////////////////////////////////////////
  45. //
  46. // Contains all of the locale information
  47. //
  48. ///////////////////////////////////////////////////////////////////////////////
  49. {
  50. protected:
  51. // Localization values
  52. // ===================
  53. WString m_wstrLangId; // "009"
  54. WString m_wstrLocaleId; // "0x0409"
  55. WString m_wstrSubNameSpace; // "MS_409"
  56. LANGID m_LangId; // 0x0409
  57. LCID m_LocaleId; // 0x0409
  58. // WMI Locale data members
  59. // =======================
  60. IWbemServices* m_pNamespace;
  61. IWbemClassObject* m_apBaseClass[WMI_ADAP_NUM_TYPES];
  62. // Localized Names' Database
  63. // =========================
  64. CPerfNameDb* m_pNameDb;
  65. // Operational members
  66. // ===================
  67. BOOL m_bOK;
  68. HRESULT m_hRes;
  69. // Protected Methods
  70. // =================
  71. HRESULT Initialize();
  72. HRESULT InitializeWMI();
  73. HRESULT InitializeLID();
  74. public:
  75. CLocaleDefn( WCHAR* pwcsLangId,
  76. HKEY hKey );
  77. virtual ~CLocaleDefn();
  78. HRESULT GetLID( int & nLID );
  79. HRESULT GetNamespaceName( WString & wstrNamespaceName );
  80. HRESULT GetNamespace( IWbemServices** ppNamespace );
  81. HRESULT GetNameDb( CPerfNameDb** ppNameDb );
  82. HRESULT GetBaseClass( DWORD dwType, IWbemClassObject** pObject );
  83. HRESULT GetCookedBaseClass( IWbemClassObject** pObject );
  84. BOOL IsOK(){ return m_bOK; }
  85. HRESULT GetHRESULT(){ return m_hRes; };
  86. };
  87. class CLocaleCache : public CAdapElement
  88. ///////////////////////////////////////////////////////////////////////////////
  89. //
  90. // The cache used to manage locale definitions
  91. //
  92. ///////////////////////////////////////////////////////////////////////////////
  93. {
  94. protected:
  95. // The enumeration index
  96. // =====================
  97. int m_nEnumIndex;
  98. // The array of locale definition structures
  99. // =========================================
  100. CRefedPointerArray<CLocaleDefn> m_apLocaleDefn;
  101. public:
  102. CLocaleCache( );
  103. virtual ~CLocaleCache();
  104. HRESULT Initialize();
  105. HRESULT Reset();
  106. HRESULT GetDefaultDefn( CLocaleDefn** ppDefn );
  107. HRESULT BeginEnum();
  108. HRESULT Next( CLocaleDefn** ppLocaleDefn );
  109. HRESULT EndEnum();
  110. };
  111. // forward
  112. class CKnownSvcs;
  113. class CClassElem : public CAdapElement
  114. ////////////////////////////////////////////////////////////////////////////////
  115. //
  116. // CClassElem
  117. //
  118. ////////////////////////////////////////////////////////////////////////////////
  119. {
  120. protected:
  121. // Class properties
  122. // ================
  123. WString m_wstrClassName; // The class name
  124. DWORD m_dwIndex; // The class perf index
  125. WString m_wstrServiceName; // The service name for which the class is a member
  126. BOOL m_bCostly; // The performance type
  127. BOOL m_bReportEventCalled; // did we log something about this in the past
  128. // WMI related
  129. // ===========
  130. IWbemClassObject* m_pDefaultObject; // The WMI class definition
  131. // Operational members
  132. // ===================
  133. CLocaleCache* m_pLocaleCache; // Pointer to the list of locales
  134. DWORD m_dwStatus; // The state of the element
  135. BOOL m_bOk; // The initialization state of this object
  136. CKnownSvcs * m_pKnownSvcs;
  137. // Methods
  138. // =======
  139. HRESULT VerifyLocales();
  140. HRESULT InitializeMembers();
  141. BOOL IsPerfLibUnloaded();
  142. HRESULT Remove(BOOL CleanRegistry);
  143. HRESULT Insert();
  144. HRESULT InsertLocale( CLocaleDefn* pLocaleDefn );
  145. HRESULT CompareLocale( CLocaleDefn* pLocaleDefn, IWbemClassObject* pObj );
  146. public:
  147. CClassElem(IWbemClassObject* pObj,
  148. CLocaleCache* pLocaleCache,
  149. CKnownSvcs * pKnownSvcs = NULL );
  150. CClassElem(PERF_OBJECT_TYPE* pPerfObj,
  151. DWORD dwType, BOOL bCostly,
  152. WString wstrServiceName,
  153. CLocaleCache* pLocaleCache,
  154. CKnownSvcs * pKnownSvcs = NULL );
  155. virtual ~CClassElem();
  156. HRESULT UpdateObj( CClassElem* pEl );
  157. HRESULT Commit();
  158. HRESULT GetClassName( WString& wstr );
  159. HRESULT GetClassName( BSTR* pbStr );
  160. HRESULT GetObject( IWbemClassObject** ppObj );
  161. HRESULT GetServiceName( WString & wstrServiceName );
  162. BOOL SameName( CClassElem* pEl );
  163. BOOL SameObject( CClassElem* pEl );
  164. DWORD GetStatus(void){ return m_dwStatus; };
  165. HRESULT SetStatus( DWORD dwStatus );
  166. HRESULT ClearStatus( DWORD dwStatus );
  167. BOOL CheckStatus( DWORD dwStatus );
  168. BOOL IsOk( void ) { return m_bOk; }
  169. VOID SetKnownSvcs(CKnownSvcs * pKnownSvcs);
  170. };
  171. class CClassList : public CAdapElement
  172. ///////////////////////////////////////////////////////////////////////////////
  173. //
  174. // The base class for caches which manage either the Master class list
  175. // currently in WMI, or the classes found within a given perflib. The
  176. // classes are managed as class information elements.
  177. //
  178. ///////////////////////////////////////////////////////////////////////////////
  179. {
  180. protected:
  181. // The array of class elements
  182. // ===========================
  183. CRefedPointerArray<CClassElem> m_array;
  184. // Pointer to the list of locales
  185. // ==============================
  186. CLocaleCache* m_pLocaleCache;
  187. // Operational members
  188. // ===================
  189. int m_nEnumIndex;
  190. BOOL m_fOK;
  191. HRESULT AddElement( CClassElem* pEl );
  192. HRESULT RemoveAt( int nIndex );
  193. long GetSize( void ) { return m_array.GetSize(); }
  194. public:
  195. CClassList( CLocaleCache* pLocaleCache );
  196. virtual ~CClassList();
  197. BOOL IsOK(){ return m_fOK; }
  198. HRESULT BeginEnum();
  199. HRESULT Next( CClassElem** ppEl );
  200. HRESULT EndEnum();
  201. };
  202. class CPerfClassList : public CClassList
  203. ///////////////////////////////////////////////////////////////////////////////
  204. //
  205. // The class cache for classes found in performance libraries
  206. //
  207. ///////////////////////////////////////////////////////////////////////////////
  208. {
  209. protected:
  210. // The service name for which this list belongs
  211. // ============================================
  212. WString m_wstrServiceName;
  213. HRESULT AddElement( CClassElem *pEl );
  214. public:
  215. CPerfClassList( CLocaleCache* pLocaleCache, WCHAR* pwcsServiceName );
  216. HRESULT AddPerfObject( PERF_OBJECT_TYPE* pObj, DWORD dwType, BOOL bCostly );
  217. };
  218. class ServiceRec
  219. {
  220. friend class CKnownSvcs;
  221. private:
  222. bool m_IsServiceThere;
  223. bool m_bReportEventCalled;
  224. public:
  225. ServiceRec(bool IsThere = false,bool EventCalled = false):m_IsServiceThere(IsThere),m_bReportEventCalled(false){};
  226. bool IsThere(){ return m_IsServiceThere; };
  227. bool IsELCalled(){ return m_bReportEventCalled; };
  228. void SetELCalled(){ m_bReportEventCalled = true;};
  229. };
  230. typedef wbem_allocator<bool> BoolAlloc;
  231. class WCmp{
  232. public:
  233. bool operator()(WString pFirst,WString pSec) const;
  234. };
  235. typedef std::map<WString,ServiceRec,WCmp, BoolAlloc > MapSvc;
  236. class CKnownSvcs
  237. {
  238. public:
  239. CKnownSvcs(WCHAR * pMultiSz);
  240. ~CKnownSvcs();
  241. DWORD Load();
  242. DWORD Save();
  243. DWORD Add(WCHAR * pService);
  244. DWORD Remove(WCHAR * pService);
  245. DWORD Get(WCHAR * pService,ServiceRec ** ppServiceRec);
  246. MapSvc & GetMap(){ return m_SetServices; };
  247. LONG AddRef()
  248. {
  249. return InterlockedIncrement(&m_cRef);
  250. };
  251. LONG Release()
  252. {
  253. LONG lRet = InterlockedDecrement(&m_cRef);
  254. if (0 == lRet) delete this;
  255. return lRet;
  256. }
  257. private:
  258. LONG m_cRef;
  259. WString m_MultiSzName;
  260. MapSvc m_SetServices;
  261. };
  262. class CMasterClassList : public CClassList
  263. ///////////////////////////////////////////////////////////////////////////////
  264. //
  265. // The class cache for classes found in the WMI repository
  266. //
  267. ///////////////////////////////////////////////////////////////////////////////
  268. {
  269. protected:
  270. CKnownSvcs * m_pKnownSvcs;
  271. HRESULT AddElement( CClassElem *pEl, BOOL bDelta );
  272. HRESULT AddClassObject( IWbemClassObject* pObj, BOOL bSourceWMI, BOOL bDelta );
  273. public:
  274. CMasterClassList( CLocaleCache* pLocaleCache, CKnownSvcs * pCKnownSvcs );
  275. ~CMasterClassList();
  276. HRESULT BuildList( WCHAR* wszBaseClass, BOOL bDelta, BOOL bThrottle );
  277. HRESULT Merge( CClassList* pClassList, BOOL bDelta );
  278. HRESULT Commit(BOOL bThrottle);
  279. HRESULT ForceStatus(WCHAR* pServiceName,BOOL bSet,DWORD dwStatus);
  280. #ifdef _DUMP_LIST
  281. HRESULT Dump();
  282. #endif
  283. };
  284. #endif