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.

247 lines
6.0 KiB

  1. // ServerStatus.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #define __FILE_ID__ 82
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. struct TSrvStatusColInfo
  11. {
  12. DWORD dwStrRes; // column header string
  13. DWORD dwWidth; // column width
  14. };
  15. static TSrvStatusColInfo s_colInfo[] =
  16. {
  17. IDS_SRV_COL_SERVER, 133,
  18. IDS_SRV_COL_STATUS, 120
  19. };
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CServerStatusDlg dialog
  22. CServerStatusDlg::CServerStatusDlg(CClientConsoleDoc* pDoc, CWnd* pParent /*=NULL*/)
  23. : CFaxClientDlg(CServerStatusDlg::IDD, pParent),
  24. m_pDoc(pDoc)
  25. {
  26. ASSERT(m_pDoc);
  27. }
  28. void CServerStatusDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CFaxClientDlg::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CServerStatusDlg)
  32. DDX_Control(pDX, IDC_LIST_SERVER, m_listServer);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CServerStatusDlg, CFaxClientDlg)
  36. //{{AFX_MSG_MAP(CServerStatusDlg)
  37. ON_NOTIFY(LVN_KEYDOWN, IDC_LIST_SERVER, OnKeydownListCp)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CServerStatusDlg message handlers
  42. BOOL
  43. CServerStatusDlg::OnInitDialog()
  44. {
  45. DWORD dwRes = ERROR_SUCCESS;
  46. DBG_ENTER(TEXT("CServerStatusDlg::OnInitDialog"));
  47. CFaxClientDlg::OnInitDialog();
  48. //
  49. // init CListCtrl
  50. //
  51. m_listServer.SetExtendedStyle (LVS_EX_FULLROWSELECT | // Entire row is selected
  52. LVS_EX_INFOTIP | // Allow tooltips
  53. LVS_EX_ONECLICKACTIVATE); // Hover cursor effect
  54. m_listServer.SetImageList (&CLeftView::m_ImageList, LVSIL_SMALL);
  55. int nRes;
  56. CString cstrHeader;
  57. DWORD nCols = sizeof(s_colInfo)/sizeof(s_colInfo[0]);
  58. //
  59. // init column
  60. //
  61. for(int i=0; i < nCols; ++i)
  62. {
  63. //
  64. // load title string
  65. //
  66. m_dwLastError = LoadResourceString (cstrHeader, s_colInfo[i].dwStrRes);
  67. if(ERROR_SUCCESS != m_dwLastError)
  68. {
  69. CALL_FAIL (RESOURCE_ERR, TEXT ("LoadResourceString"), m_dwLastError);
  70. EndDialog(IDABORT);
  71. return FALSE;
  72. }
  73. //
  74. // insert column
  75. //
  76. nRes = m_listServer.InsertColumn(i, cstrHeader, LVCFMT_LEFT, s_colInfo[i].dwWidth);
  77. if(nRes != i)
  78. {
  79. m_dwLastError = GetLastError();
  80. CALL_FAIL (WINDOW_ERR, TEXT ("CListView::InsertColumn"), m_dwLastError);
  81. EndDialog(IDABORT);
  82. return FALSE;
  83. }
  84. }
  85. //
  86. // fill list control with servers
  87. //
  88. m_dwLastError = RefreshServerList();
  89. if(ERROR_SUCCESS != m_dwLastError)
  90. {
  91. CALL_FAIL (GENERAL_ERR, TEXT ("RefreshServerList"), m_dwLastError);
  92. EndDialog(IDABORT);
  93. return FALSE;
  94. }
  95. return TRUE;
  96. }
  97. DWORD
  98. CServerStatusDlg::RefreshServerList()
  99. /*++
  100. Routine name : CServerStatusDlg::RefreshServerList
  101. Routine description:
  102. fill in list control with servers statuses
  103. Author:
  104. Alexander Malysh (AlexMay), Apr, 2000
  105. Arguments:
  106. Return Value:
  107. Standard Win32 error code
  108. --*/
  109. {
  110. DWORD dwRes = ERROR_SUCCESS;
  111. DBG_ENTER(TEXT("CCoverPagesDlg::RefreshServerList"), dwRes);
  112. if(!m_listServer.DeleteAllItems())
  113. {
  114. dwRes = ERROR_CAN_NOT_COMPLETE;
  115. CALL_FAIL (WINDOW_ERR, TEXT ("CListView::DeleteAllItems"), dwRes);
  116. return dwRes;
  117. }
  118. const SERVERS_LIST& srvList = m_pDoc->GetServersList();
  119. int nItem, nRes;
  120. CString cstrName;
  121. CString cstrStatus;
  122. TreeIconType iconIndex;
  123. CServerNode* pServerNode;
  124. for (SERVERS_LIST::iterator it = srvList.begin(); it != srvList.end(); ++it)
  125. {
  126. //
  127. // get server name
  128. //
  129. pServerNode = *it;
  130. try
  131. {
  132. cstrName = pServerNode->Machine();
  133. }
  134. catch(...)
  135. {
  136. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  137. CALL_FAIL (MEM_ERR, TEXT("CString::operator="), dwRes);
  138. return dwRes;
  139. }
  140. if(cstrName.GetLength() == 0)
  141. {
  142. dwRes = LoadResourceString(cstrName, IDS_LOCAL_SERVER);
  143. if(ERROR_SUCCESS != dwRes)
  144. {
  145. CALL_FAIL (GENERAL_ERR, TEXT("LoadResourceString"), dwRes);
  146. return dwRes;
  147. }
  148. }
  149. //
  150. // get server status
  151. //
  152. dwRes = pServerNode->GetActivity(cstrStatus, iconIndex);
  153. if(ERROR_SUCCESS != dwRes)
  154. {
  155. CALL_FAIL (GENERAL_ERR, TEXT("CServerNode::GetActivity"), dwRes);
  156. return dwRes;
  157. }
  158. nItem = m_listServer.GetItemCount();
  159. //
  160. // insert server row
  161. //
  162. nItem = m_listServer.InsertItem(nItem, cstrName, iconIndex);
  163. if(nItem < 0)
  164. {
  165. dwRes = ERROR_CAN_NOT_COMPLETE;
  166. CALL_FAIL (WINDOW_ERR, TEXT ("CListView::InsertItem"), dwRes);
  167. return dwRes;
  168. }
  169. //
  170. // display server status
  171. //
  172. nRes = m_listServer.SetItemText(nItem, 1, cstrStatus);
  173. if(!nRes)
  174. {
  175. dwRes = ERROR_CAN_NOT_COMPLETE;
  176. CALL_FAIL (WINDOW_ERR, TEXT ("CListView::SetItemText"), dwRes);
  177. return dwRes;
  178. }
  179. }
  180. return dwRes;
  181. } // CServerStatusDlg::RefreshServerList
  182. void
  183. CServerStatusDlg::OnKeydownListCp(NMHDR* pNMHDR, LRESULT* pResult)
  184. {
  185. DWORD dwRes = ERROR_SUCCESS;
  186. DBG_ENTER(TEXT("CCoverPagesDlg::OnKeydownListCp"));
  187. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  188. if(VK_F5 == pLVKeyDow->wVKey)
  189. {
  190. //
  191. // F5 was pressed
  192. //
  193. dwRes = RefreshServerList();
  194. if(ERROR_SUCCESS != dwRes)
  195. {
  196. CALL_FAIL (GENERAL_ERR, TEXT ("RefreshServerList"), dwRes);
  197. }
  198. }
  199. *pResult = 0;
  200. }