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.

133 lines
4.0 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. SLEEPER.H
  5. Abstract:
  6. MinMax controls.
  7. History:
  8. --*/
  9. #ifndef ___WBEM_SLEEPER__H_
  10. #define ___WBEM_SLEEPER__H_
  11. #include "sync.h"
  12. #include "wstring.h"
  13. //******************************************************************************
  14. //
  15. // class CLimitControl
  16. //
  17. // Limits the growth of a certain quantity by delaying requests to add to it.
  18. // This is an abstract base class for the classes that actually implement a
  19. // a particular enforcement strategy.
  20. //
  21. // Clients of this object call Add to request to increase the controlled
  22. // quantity (which will often sleep), and Remove to inform it that the quantity
  23. // is being reduced (which may or may not affect the sleeping clients)
  24. //
  25. //******************************************************************************
  26. class POLARITY CLimitControl
  27. {
  28. protected:
  29. DWORD m_dwMembers;
  30. public:
  31. CLimitControl();
  32. virtual ~CLimitControl(){}
  33. virtual HRESULT AddMember();
  34. virtual HRESULT RemoveMember();
  35. virtual HRESULT Add(DWORD dwHowMuch, DWORD dwMemberTotal,
  36. DWORD* pdwSleep = NULL) = 0;
  37. virtual HRESULT Remove(DWORD dwHowMuch) = 0;
  38. };
  39. //******************************************************************************
  40. //
  41. // class CMinMaxLimitControl
  42. //
  43. // This derivative of CLimitControl controls the growth of a quantity by
  44. // slowing down (sleeping) progressively longer periods of time after the
  45. // quantity exceeds the lower threshold --- m_dwMin. The growth of the
  46. // sleep interval is linear, and is calculates to reach m_dwSleepAnMax
  47. // milliseconds by the time the quantity reaches m_dwMax. At that point, an
  48. // error message is logged, but the sleep interval stays at m_dwSleepAtMax.
  49. //
  50. // m_nLog is the index of the log file (e.g. LOG_ESS), m_wsName is the name
  51. // of the controlled quantity to use in the log message
  52. //
  53. //******************************************************************************
  54. class POLARITY CMinMaxLimitControl : public CLimitControl
  55. {
  56. protected:
  57. DWORD m_dwMin;
  58. DWORD m_dwMax;
  59. DWORD m_dwSleepAtMax;
  60. int m_nLog;
  61. WString m_wsName;
  62. DWORD m_dwCurrentTotal;
  63. BOOL m_bMessageLogged;
  64. CCritSec m_cs;
  65. public:
  66. CMinMaxLimitControl(int nLog, LPCWSTR wszName);
  67. void SetMin(DWORD dwMin) {m_dwMin = dwMin;}
  68. void SetMax(DWORD dwMax) {m_dwMax = dwMax;}
  69. void SetSleepAtMax(DWORD dwSleepAtMax) {m_dwSleepAtMax = dwSleepAtMax;}
  70. virtual HRESULT Add(DWORD dwHowMuch, DWORD dwMemberTotal,
  71. DWORD* pdwSleep = NULL);
  72. virtual HRESULT Remove(DWORD dwHowMuch);
  73. protected:
  74. HRESULT ComputePenalty(DWORD dwNewTotal, DWORD dwMemberTotal,
  75. DWORD* pdwSleep, BOOL* pbLog);
  76. };
  77. //******************************************************************************
  78. //
  79. // class CRegistryMinMaxLimitControl
  80. //
  81. // This derivative of CMinMaxLimitControl gets its limiting information from
  82. // the specified place in the registry
  83. //
  84. // m_hHive holds the hive, m_wsKey the path to the key (e.g. "SOFTWARE\\MSFT"),
  85. // m_wsMinValueName, m_wsMaxValueName, and m_wsSleepAtMaxValueName hold the
  86. // names of the registry values holding the values of these parameters, as
  87. // described in CMinMaxLimitControl
  88. //
  89. //******************************************************************************
  90. class POLARITY CRegistryMinMaxLimitControl : public CMinMaxLimitControl
  91. {
  92. protected:
  93. WString m_wsKey;
  94. WString m_wsMinValueName;
  95. WString m_wsMaxValueName;
  96. WString m_wsSleepAtMaxValueName;
  97. public:
  98. CRegistryMinMaxLimitControl(int nLog, LPCWSTR wszName,
  99. LPCWSTR wszKey, LPCWSTR wszMinValueName,
  100. LPCWSTR wszMaxValueName,
  101. LPCWSTR wszSleepAtMaxValueName)
  102. : CMinMaxLimitControl(nLog, wszName), m_wsKey(wszKey),
  103. m_wsMinValueName(wszMinValueName),
  104. m_wsMaxValueName(wszMaxValueName),
  105. m_wsSleepAtMaxValueName(wszSleepAtMaxValueName)
  106. {}
  107. HRESULT Reread();
  108. };
  109. #endif