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.

143 lines
3.2 KiB

  1. //******************************************************************************
  2. //
  3. // Copyright (c) 1999-2000, Microsoft Corporation, All rights reserved
  4. //
  5. //*****************************************************************************
  6. // Quota.h
  7. #ifndef __QUOTA_H
  8. #define __QUOTA_H
  9. #include <map>
  10. enum ESS_QUOTA_INDEX
  11. {
  12. ESSQ_TEMP_SUBSCRIPTIONS,
  13. ESSQ_PERM_SUBSCRIPTIONS,
  14. ESSQ_POLLING_INSTRUCTIONS,
  15. ESSQ_POLLING_MEMORY,
  16. ESSQ_INVALID_INDEX
  17. };
  18. #define ESSQ_INDEX_COUNT ESSQ_INVALID_INDEX
  19. class CSaveCallContext
  20. {
  21. public:
  22. CSaveCallContext(BOOL bSave);
  23. ~CSaveCallContext();
  24. protected:
  25. IWbemCallSecurity *m_pSecurity;
  26. BOOL m_bSaved;
  27. };
  28. class CUserInfo
  29. {
  30. public:
  31. CUserInfo();
  32. CUserInfo(LPBYTE pData, DWORD dwLen);
  33. CUserInfo(const CUserInfo &other)
  34. {
  35. *this = other;
  36. }
  37. ~CUserInfo();
  38. BOOL Init(LPBYTE pData, DWORD dwLen);
  39. const CUserInfo& operator = (const CUserInfo& other);
  40. bool operator == (const CUserInfo& other) const;
  41. bool operator < (const CUserInfo& other) const;
  42. DWORD m_dwUserCount[ESSQ_INDEX_COUNT];
  43. protected:
  44. LPBYTE m_pData;
  45. DWORD m_dwSize;
  46. BOOL m_bAlloced;
  47. BOOL CopyData(LPBYTE pData, DWORD dwLen);
  48. };
  49. class CQuota : public IWbemObjectSink
  50. {
  51. public:
  52. CQuota();
  53. ~CQuota();
  54. HRESULT IncrementQuotaIndex(
  55. ESS_QUOTA_INDEX dwIndex,
  56. CEventFilter *pFilter,
  57. DWORD dwToAdd);
  58. HRESULT DecrementQuotaIndex(
  59. ESS_QUOTA_INDEX dwIndex,
  60. CEventFilter *pFilter,
  61. DWORD dwToRemove);
  62. HRESULT FindUser(CEventFilter* pFilter, void** pUser);
  63. HRESULT FreeUser(void* pUser);
  64. HRESULT IncrementQuotaIndexByUser(ESS_QUOTA_INDEX dwIndex,
  65. void *pUser, DWORD dwToAdd);
  66. HRESULT DecrementQuotaIndexByUser(ESS_QUOTA_INDEX dwIndex, void *pUser,
  67. DWORD dwToRemove);
  68. HRESULT Init(CEss *pEss);
  69. HRESULT Shutdown();
  70. protected:
  71. typedef std::map<CUserInfo, DWORD, std::less<CUserInfo>,
  72. wbem_allocator<DWORD> > CUserMap;
  73. typedef CUserMap::iterator CUserMapIterator;
  74. CEss *m_pEss;
  75. CUserMap m_mapUserInfo;
  76. DWORD m_dwGlobalCount[ESSQ_INDEX_COUNT],
  77. m_dwUserLimits[ESSQ_INDEX_COUNT],
  78. m_dwGlobalLimits[ESSQ_INDEX_COUNT];
  79. CRITICAL_SECTION m_cs;
  80. void UpdateQuotaSettings(IWbemClassObject *pObj);
  81. void Lock()
  82. {
  83. EnterCriticalSection(&m_cs);
  84. }
  85. void Unlock()
  86. {
  87. LeaveCriticalSection(&m_cs);
  88. }
  89. DWORD WINAPI AddRef()
  90. {
  91. return 1;
  92. }
  93. DWORD WINAPI Release()
  94. {
  95. return 1;
  96. }
  97. HRESULT WINAPI QueryInterface(REFIID riid, void **ppv)
  98. {
  99. if (riid == IID_IUnknown || riid == IID_IWbemObjectSink)
  100. {
  101. *ppv = (IWbemObjectSink*) this;
  102. AddRef();
  103. return S_OK;
  104. }
  105. else
  106. return E_NOINTERFACE;
  107. }
  108. HRESULT WINAPI Indicate(long lNumEvents, IWbemEvent** apEvents);
  109. HRESULT WINAPI SetStatus(long, long, BSTR, IWbemClassObject*)
  110. {
  111. return E_NOTIMPL;
  112. }
  113. };
  114. // Global instance of CQuota.
  115. extern CQuota g_quotas;
  116. #endif