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.

189 lines
5.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: Monitor.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Definition of the class CMonitor
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: fengsun Created 02/05/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "ArrayPtr.h"
  15. #include <ras.h>
  16. #include "ConTable.h"
  17. class CCmConnection;
  18. struct tagCmConnectedInfo; // CM_CONNECTED_INFO
  19. struct tagCmHangupInfo; // CM_HANGUP_INFO
  20. //+---------------------------------------------------------------------------
  21. //
  22. // class CMonitor
  23. //
  24. // Description: Class CMonitor manage all connected CM conaction. It has
  25. // data/functions not specific to a particular connection.
  26. // It also manage the communication with
  27. // other CM components like CMDIAL.DLL.
  28. //
  29. // History: fengsun Created 1/22/98
  30. //
  31. //----------------------------------------------------------------------------
  32. class CMonitor
  33. {
  34. public:
  35. CMonitor();
  36. ~CMonitor();
  37. public:
  38. //
  39. // Static public functions, can be called without CMonitor instance
  40. //
  41. // Called by ::WinMain
  42. static int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pszCmdLine, int iCmdShow);
  43. static HINSTANCE GetInstance() {return m_hInst;};
  44. static HWND GetMonitorWindow() {MYDBGASSERT(m_pThis); return m_pThis->m_hwndMonitor;}
  45. static void MinimizeWorkingSet();
  46. static void RestoreWorkingSet();
  47. static BOOL ConnTableGetEntry(IN LPCTSTR pszEntry, OUT CM_CONNECTION* pCmEntry);
  48. static void RemoveConnection(CCmConnection* pConnection, BOOL fClearTable);
  49. static void MoveToReconnectingConn(CCmConnection* pConnection);
  50. protected:
  51. enum {
  52. //
  53. // this message is posted from connection thread to remove a connection
  54. // from shared table and internal array.
  55. // We use PostMessage, because all the operation on this array is handled
  56. // by monitor thread. Other wise we need CriticalSection to protect the array.
  57. // When both array are empty, cmmon exit
  58. // wParam is one of the value below, lParam is pointer to the connection
  59. //
  60. WM_REMOVE_CONNECTION = WM_USER + 1,
  61. };
  62. //
  63. // wParam for WM_REMOVE_CONNECTION message
  64. //
  65. enum {
  66. REMOVE_CONNECTION, // Remove from Connected/Reconnecting Array
  67. MOVE_TO_RECONNECTING // Move from connected array to reconnecting array
  68. };
  69. HANDLE m_hProcess; // the process handle for the monitor, used to changed working set
  70. // The Connection Table file mapping
  71. CConnectionTable m_SharedTable;
  72. // the invisible monitor window handle message from cmdial32.dll and connection thread
  73. HWND m_hwndMonitor;
  74. // Internal array for connected connection
  75. // Can only be accessed from the monitor thread
  76. CPtrArray m_InternalConnArray;
  77. // Array of reconnecting connections
  78. // Can only be accessed from the monitor thread
  79. // If both array are down to 0, cmmon exits
  80. CPtrArray m_ReconnectConnArray;
  81. // Called on start up
  82. // Open Connection Table
  83. // CreateMonitorWindow, SharedTable.SetHwndMonotor()
  84. BOOL Initialize();
  85. // Called upon exit
  86. // Close all the connections, terminate all thread
  87. // Release connection table
  88. void Terminate();
  89. // Register a window class and create the invisible monitorwindow
  90. HWND CreateMonitorWindow();
  91. // The Monitor window procedure, process all the message
  92. static LRESULT CALLBACK MonitorWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  93. protected:
  94. //
  95. // Message handler
  96. //
  97. // upon receiving connected message from cmdial32.dll
  98. // Create the CcmConnection object, add to internal table
  99. void OnConnected(const tagCmConnectedInfo* pConnectedInfo);
  100. // Upon hangup request from CMDIAL32.DLL
  101. // Look up the InternalConnArray for the connection
  102. // Call pConnection->PostHangupMsg();
  103. // Hangup is done in connection thread
  104. void OnHangup(const tagCmHangupInfo* pHangupInfo);
  105. //
  106. // Upon WM_QUERYENDSESSION message, we walk the table of connections
  107. // and call pConnection->OnEndSession on them so they will hangup and
  108. // clean themselves up.
  109. //
  110. BOOL OnQueryEndSession(BOOL fLogOff) const;
  111. // Upon WM_REMOVE_CONNECTION message posted by connection thread
  112. void OnRemoveConnection(DWORD dwRequestType, CCmConnection* pConnection);
  113. // Look up the connection array for a connection by name
  114. CCmConnection* LookupConnection(const CPtrArray& PtrArray, const TCHAR* pServiceName) const;
  115. // Look up the connection array for a connection by connection pointer
  116. int LookupConnection(const CPtrArray& ConnArray, const CCmConnection* pConnection) const;
  117. // Maintain or drop connections across a Fast User Switch
  118. BOOL HandleFastUserSwitch(DWORD dwAction);
  119. protected:
  120. // The exe instance handle
  121. static HINSTANCE m_hInst;
  122. // Used by static function MonitorWindowProc
  123. static CMonitor* m_pThis;
  124. #ifdef DEBUG
  125. void AssertValid() const; // protected: not safe to call in other thread
  126. #endif
  127. };
  128. inline void CMonitor::MinimizeWorkingSet()
  129. {
  130. MYDBGASSERT(m_pThis->m_hProcess);
  131. if (m_pThis->m_hProcess)
  132. {
  133. SetProcessWorkingSetSize(m_pThis->m_hProcess, 128*1024, 384*1024);
  134. }
  135. }
  136. inline void CMonitor::RestoreWorkingSet()
  137. {
  138. MYDBGASSERT(m_pThis->m_hProcess);
  139. if (m_pThis->m_hProcess)
  140. {
  141. SetProcessWorkingSetSize(m_pThis->m_hProcess, 0, 0);
  142. }
  143. }
  144. inline BOOL CMonitor::ConnTableGetEntry(IN LPCTSTR pszEntry, OUT CM_CONNECTION* pCmEntry)
  145. {
  146. MYDBGASSERT(pCmEntry);
  147. MYDBGASSERT(m_pThis);
  148. return (SUCCEEDED(m_pThis->m_SharedTable.GetEntry(pszEntry, pCmEntry)));
  149. }