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.

141 lines
4.1 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 000
  5. *
  6. * File: power.h
  7. *
  8. * Contents: Interface file for CConsolePower
  9. *
  10. * History: 25-Feb-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #pragma once
  14. #include "refcount.h"
  15. class CConsolePower;
  16. /*+-------------------------------------------------------------------------*
  17. * CConsolePowerWnd
  18. *
  19. * Receives WM_POWERBROADCAST messages on behalf of a CConsolePower object.
  20. *--------------------------------------------------------------------------*/
  21. class CConsolePowerWnd : public CWindowImpl<CConsolePowerWnd, CWindow, CNullTraits>
  22. {
  23. public:
  24. CConsolePowerWnd (CConsolePower* pConsolePower);
  25. ~CConsolePowerWnd ();
  26. SC ScCreate ();
  27. BEGIN_MSG_MAP(CConsolePower)
  28. MESSAGE_HANDLER (WM_POWERBROADCAST, OnPowerBroadcast);
  29. END_MSG_MAP()
  30. LRESULT OnPowerBroadcast (UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  31. private:
  32. CConsolePower* const m_pConsolePower; // weak reference
  33. };
  34. /*+-------------------------------------------------------------------------*
  35. * CConsolePower
  36. *
  37. * Implements IConsolePower and IConnectionPoint for IID_IConsolePowerSink.
  38. *--------------------------------------------------------------------------*/
  39. class CConsolePower :
  40. public CComObjectRootEx<CComSingleThreadModel>,
  41. public CComCoClass<CConsolePower, &CLSID_ConsolePower>,
  42. public IConnectionPointContainerImpl<CConsolePower>,
  43. public IConnectionPointImpl<CConsolePower, &IID_IConsolePowerSink>,
  44. public IConsolePower
  45. {
  46. public:
  47. enum
  48. {
  49. eIndex_System, // for ES_SYSTEM_REQUIRED
  50. eIndex_Display, // for ES_DISPLAY_REQUIRED
  51. // must be last
  52. eIndex_Count,
  53. };
  54. CConsolePower();
  55. ~CConsolePower();
  56. DECLARE_NOT_AGGREGATABLE(CConsolePower)
  57. DECLARE_MMC_OBJECT_REGISTRATION (
  58. g_szMmcndmgrDll, // implementing DLL
  59. CLSID_ConsolePower, // CLSID
  60. _T("ConsolePower Class"), // class name
  61. _T("ConsolePower.ConsolePower.1"), // ProgID
  62. _T("ConsolePower.ConsolePower")) // version-independent ProgID
  63. BEGIN_COM_MAP(CConsolePower)
  64. COM_INTERFACE_ENTRY(IConsolePower)
  65. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  66. END_COM_MAP()
  67. BEGIN_CONNECTION_POINT_MAP(CConsolePower)
  68. CONNECTION_POINT_ENTRY(IID_IConsolePowerSink)
  69. END_CONNECTION_POINT_MAP()
  70. // IConsolePower methods
  71. STDMETHOD(SetExecutionState) (DWORD dwAdd, DWORD dwRemove);
  72. STDMETHOD(ResetIdleTimer) (DWORD dwFlags);
  73. DECLARE_PROTECT_FINAL_CONSTRUCT()
  74. HRESULT FinalConstruct();
  75. LRESULT OnPowerBroadcast (WPARAM wParam, LPARAM lParam);
  76. private:
  77. class CExecutionCounts
  78. {
  79. public:
  80. CExecutionCounts ();
  81. public:
  82. LONG m_rgCount[CConsolePower::eIndex_Count];
  83. };
  84. class CTlsExecutionCounts : public CExecutionCounts
  85. {
  86. public:
  87. CTlsExecutionCounts();
  88. ~CTlsExecutionCounts();
  89. static CTlsExecutionCounts* GetThreadInstance (DWORD dwTlsIndex);
  90. SC ScSetThreadInstance (DWORD dwTlsIndex);
  91. private:
  92. enum { Uninitialized = TLS_OUT_OF_INDEXES };
  93. DWORD m_dwTlsIndex;
  94. };
  95. typedef CRefCountedObject<CTlsExecutionCounts> CRefCountedTlsExecutionCounts;
  96. typedef EXECUTION_STATE (WINAPI* ExecutionStateFunc)(EXECUTION_STATE);
  97. static SC ScGetThreadCounts (CRefCountedTlsExecutionCounts** ppThreadCounts);
  98. private:
  99. CConsolePowerWnd m_wndPower;
  100. CExecutionCounts m_Counts;
  101. CRefCountedTlsExecutionCounts::SmartPtr m_spThreadCounts;
  102. static const DWORD s_dwTlsIndex;
  103. static const DWORD s_rgExecStateFlag[eIndex_Count];
  104. static const ExecutionStateFunc s_FuncUninitialized;
  105. static ExecutionStateFunc SetThreadExecutionState_;
  106. };