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.

184 lines
5.4 KiB

  1. //******************************************************************************
  2. //
  3. // POLLER.H
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #ifndef __WBEM_POLLER__H_
  9. #define __WBEM_POLLER__H_
  10. #include <tss.h>
  11. #include <wbemcomn.h>
  12. #include <map>
  13. #include <analyser.h>
  14. #include <evsink.h>
  15. #pragma warning(disable: 4786)
  16. class CEssNamespace;
  17. class CBasePollingInstruction : public CTimerInstruction
  18. {
  19. public:
  20. void AddRef();
  21. void Release();
  22. int GetInstructionType() {return INSTTYPE_INTERNAL;}
  23. virtual CWbemTime GetNextFiringTime(CWbemTime LastFiringTime,
  24. OUT long* plFiringCount) const;
  25. virtual CWbemTime GetFirstFiringTime() const;
  26. virtual HRESULT Fire(long lNumTimes, CWbemTime NextFiringTime);
  27. bool DeleteTimer();
  28. public:
  29. CBasePollingInstruction(CEssNamespace* pNamespace);
  30. virtual ~CBasePollingInstruction();
  31. HRESULT Initialize(LPCWSTR wszLanguage,
  32. LPCWSTR wszQuery, DWORD dwMsInterval,
  33. bool bAffectsQuota = false);
  34. void Cancel();
  35. protected:
  36. long m_lRef;
  37. CEssNamespace* m_pNamespace;
  38. BSTR m_strLanguage;
  39. BSTR m_strQuery;
  40. CWbemInterval m_Interval;
  41. IServerSecurity* m_pSecurity;
  42. bool m_bUsedQuota;
  43. bool m_bCancelled;
  44. HANDLE m_hTimer;
  45. CCritSec m_cs;
  46. protected:
  47. HRESULT ExecQuery();
  48. virtual HRESULT ProcessObject(_IWmiObject* pObj) = 0;
  49. virtual HRESULT ProcessQueryDone(HRESULT hresQuery,
  50. IWbemClassObject* pError) = 0;
  51. virtual BOOL CompareTo(CBasePollingInstruction* pOther);
  52. static void staticTimerCallback(void* pParam, BOOLEAN);
  53. void Destroy();
  54. };
  55. class CPollingInstruction : public CBasePollingInstruction
  56. {
  57. public:
  58. CPollingInstruction(CEssNamespace* pNamespace);
  59. ~CPollingInstruction();
  60. HRESULT Initialize(LPCWSTR wszLanguage,
  61. LPCWSTR wszQuery, DWORD dwMsInterval,
  62. DWORD dwEventMask,
  63. CEventFilter* pDest);
  64. HRESULT FirstExecute();
  65. protected:
  66. DWORD m_dwEventMask;
  67. CEventFilter* m_pDest;
  68. bool m_bOnRestart;
  69. void* m_pUser;
  70. struct CCachedObject
  71. {
  72. BSTR m_strPath;
  73. _IWmiObject* m_pObject;
  74. CCachedObject(_IWmiObject* pObject);
  75. ~CCachedObject();
  76. BOOL IsValid(){ return (NULL != m_strPath); };
  77. static int __cdecl compare(const void* pelem1, const void* pelem2);
  78. };
  79. typedef CUniquePointerArray<CCachedObject> CCachedArray;
  80. CCachedArray* m_papPrevObjects;
  81. CCachedArray* m_papCurrentObjects;
  82. friend class CPoller;
  83. protected:
  84. HRESULT RaiseCreationEvent(CCachedObject* pNewObj);
  85. HRESULT RaiseDeletionEvent(CCachedObject* pOldObj);
  86. HRESULT RaiseModificationEvent(CCachedObject* pNewObj,
  87. CCachedObject* pOldObj = NULL);
  88. static SYSFREE_ME BSTR GetObjectClass(CCachedObject* pObj);
  89. HRESULT ProcessObject(_IWmiObject* pObj);
  90. HRESULT ProcessQueryDone(HRESULT hresQuery,
  91. IWbemClassObject* pError);
  92. HRESULT SubtractMemory(CCachedArray* pArray);
  93. HRESULT ResetPrevious();
  94. DWORD ComputeObjectMemory(_IWmiObject* pObj);
  95. };
  96. class CEventFilterContainer;
  97. class CPoller
  98. {
  99. public:
  100. CPoller(CEssNamespace* pEssNamespace);
  101. ~CPoller();
  102. void Clear();
  103. HRESULT ActivateFilter(CEventFilter* pDest,
  104. LPCWSTR wszQuery, QL_LEVEL_1_RPN_EXPRESSION* pExp);
  105. HRESULT DeactivateFilter(CEventFilter* pDest);
  106. HRESULT VirtuallyStopPolling();
  107. HRESULT CancelUnnecessaryPolling();
  108. void DumpStatistics(FILE* f, long lFlags);
  109. protected:
  110. CEssNamespace* m_pNamespace;
  111. CQueryAnalyser m_Analyser;
  112. BOOL m_bInResync;
  113. CCritSec m_cs;
  114. struct FilterInfo
  115. {
  116. BOOL m_bActive;
  117. DWORD_PTR m_dwFilterId;
  118. };
  119. typedef std::map<CPollingInstruction*, FilterInfo, std::less<CPollingInstruction*>,
  120. wbem_allocator<FilterInfo> > CInstructionMap;
  121. CInstructionMap m_mapInstructions;
  122. friend class CKeyTest;
  123. class CKeyTest : public CInstructionTest
  124. {
  125. DWORD_PTR m_dwKey;
  126. CInstructionMap& m_mapInstructions;
  127. public:
  128. CKeyTest(DWORD_PTR dwKey, CInstructionMap& mapInstructions)
  129. : m_dwKey(dwKey), m_mapInstructions(mapInstructions)
  130. {}
  131. BOOL operator()(CTimerInstruction* pToTest)
  132. {
  133. CInstructionMap::iterator it =
  134. m_mapInstructions.find((CPollingInstruction*)pToTest);
  135. if(it == m_mapInstructions.end())
  136. return FALSE;
  137. if ( !it->second.m_bActive && m_dwKey == 0xFFFFFFFF )
  138. return TRUE;
  139. return (it->second.m_dwFilterId == m_dwKey);
  140. }
  141. };
  142. protected:
  143. HRESULT AddInstruction(DWORD_PTR dwKey, CPollingInstruction* pInst);
  144. HRESULT ListNonProvidedClasses(IN CClassInformation* pInfo,
  145. IN DWORD dwDesiredMask,
  146. OUT CClassInfoArray& aNonProvided);
  147. BOOL IsClassDynamic(IWbemClassObject* pClass);
  148. BOOL AddDynamicClass(IWbemClassObject* pClass, DWORD dwDesiredMask,
  149. OUT CClassInfoArray& aNonProvided);
  150. };
  151. #endif