Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /WinCS/BMSystemDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download) (as text)
Wed Feb 10 18:21:00 2010 UTC (14 years, 2 months ago) by sho1get
File MIME type: text/x-c++src
File size: 9101 byte(s)


1 sho1get 11 #include "stdafx.h"
2     #include "WinCS.h"
3     #include "BMSystemDlg.h"
4     #include "FlopsHelpDlg.h"
5    
6     IMPLEMENT_DYNAMIC(CBMSystemDlg, CDialog)
7    
8     BEGIN_MESSAGE_MAP(CBMSystemDlg, CDialog)
9     ON_BN_CLICKED(IDOK, &CBMSystemDlg::OnBnClickedOk)
10     ON_BN_CLICKED(IDC_BTN_BMSYSTEM_CLOSE, &CBMSystemDlg::OnBnClickedBtnBmsystemClose)
11     ON_BN_CLICKED(IDC_BTN_BMSYSTEM_HELP, &CBMSystemDlg::OnBnClickedBtnBmsystemHelp)
12     ON_WM_CTLCOLOR()
13     ON_WM_SYSCOMMAND()
14     ON_BN_CLICKED(IDC_BTN_BMSYSTEM_LOG, &CBMSystemDlg::OnBnClickedBtnBmsystemLog)
15     END_MESSAGE_MAP()
16    
17     //////////////////////////////////////////////////////////////////////////
18    
19     CBMSystemDlg::CBMSystemDlg(CWnd* pParent /*=NULL*/)
20     : CDialog(CBMSystemDlg::IDD, pParent),
21     m_fEnd(FALSE),
22     m_hTimer(NULL)
23     {
24     m_hIcon = AfxGetApp()->LoadIcon(IDI_BENCHMARK);
25     }
26    
27     CBMSystemDlg::~CBMSystemDlg()
28     {
29     if (!m_fEnd)
30     {
31     StopTimer();
32     }
33     }
34    
35     void CBMSystemDlg::DoDataExchange(CDataExchange* pDX)
36     {
37     CDialog::DoDataExchange(pDX);
38     DDX_Control(pDX, IDC_LIST_BMSYSTEM_NODE, m_xNodeList);
39     DDX_Control(pDX, IDC_PRG_BMSYSTEM_PROGRESS, m_xProgress);
40     DDX_Control(pDX, IDC_TXT_BMSYSTEM_PERCENT, m_xTxtPercent);
41     DDX_Control(pDX, IDC_IMG_BMSYSTEM_LOADER, m_xImgLoader);
42     DDX_Control(pDX, IDC_TXT_BMSYSTEM_STATE, m_xTxtState);
43     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_RUNTIME, m_xEditRuntime);
44     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_NODES, m_xEditNodes);
45     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_TOTAL, m_xEditTotal);
46     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_AVERAGE, m_xEditAverage);
47     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_PROCESSORS, m_xEditProcessors);
48     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_HIGH, m_xEditHigh);
49     DDX_Control(pDX, IDC_EDIT_BMSYSTEM_LOW, m_xEditLow);
50     DDX_Control(pDX, IDC_BTN_BMSYSTEM_LOG, m_xBtnLog);
51     }
52    
53     HBRUSH CBMSystemDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
54     {
55     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
56     int nCtlID = pWnd->GetDlgCtrlID();
57    
58     switch (nCtlID)
59     {
60     case IDC_EDIT_BMSYSTEM_AVERAGE:
61     case IDC_EDIT_BMSYSTEM_NODES:
62     case IDC_EDIT_BMSYSTEM_PROCESSORS:
63     case IDC_EDIT_BMSYSTEM_RUNTIME:
64     case IDC_EDIT_BMSYSTEM_TOTAL:
65     case IDC_EDIT_BMSYSTEM_HIGH:
66     case IDC_EDIT_BMSYSTEM_LOW:
67     hbr = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
68     pDC->SetBkColor(RGB(255, 255, 255));
69     break;
70     }
71    
72     return hbr;
73     }
74    
75     void CBMSystemDlg::OnSysCommand(UINT nID, LPARAM lParam)
76     {
77     if (nID == SC_CLOSE)
78     {
79     return;
80     }
81    
82     CDialog::OnSysCommand(nID, lParam);
83     }
84    
85     BOOL CBMSystemDlg::OnInitDialog()
86     {
87     CDialog::OnInitDialog();
88    
89     LVCOLUMN lvc;
90     LVITEM lvi;
91     CString cs;
92     CRect cr;
93     UINT nSize, nProcessors;
94    
95     SetIcon(m_hIcon, TRUE);
96     SetIcon(m_hIcon, FALSE);
97    
98     lvc.mask = (LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM);
99     m_xNodeList.GetClientRect(&cr);
100    
101     lvc.fmt = LVCFMT_RIGHT;
102     lvc.cx = (cr.right - cr.left) * 3 / 30;
103     lvc.pszText = _T("ID");
104     m_xNodeList.InsertColumn(0, &lvc);
105    
106     lvc.fmt = LVCFMT_RIGHT;
107     lvc.cx = (cr.right - cr.left) * 8 / 30;
108     lvc.pszText = _T("IP Address");
109     m_xNodeList.InsertColumn(1, &lvc);
110    
111     lvc.fmt = LVCFMT_RIGHT;
112     lvc.cx = (cr.right - cr.left) * 6 / 30;
113     lvc.pszText = _T("Progress");
114     m_xNodeList.InsertColumn(2, &lvc);
115    
116     lvc.fmt = LVCFMT_RIGHT;
117     lvc.cx = (cr.right - cr.left) * 6 / 30;
118     lvc.pszText = _T("Runtime");
119     m_xNodeList.InsertColumn(3, &lvc);
120    
121     lvc.fmt = LVCFMT_RIGHT;
122     lvc.cx = (cr.right - cr.left) * 6 / 30;
123     lvc.pszText = _T("GFLOPS");
124     m_xNodeList.InsertColumn(4, &lvc);
125    
126     m_xNodeList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
127     m_xProgress.SetRange(0, 100);
128    
129     if (m_xImgLoader.Load(MAKEINTRESOURCE(IDR_LOADER_INDICATOR), _T("GIF")))
130     {
131     m_xImgLoader.Draw();
132     }
133    
134     m_NodeList.RemoveAt(0);
135     nSize = m_NodeList.GetSize();
136     nProcessors = 0;
137    
138     for (UINT i = 0; i < nSize; i++)
139     {
140     nProcessors += m_NodeList[i].dwProcessors;
141     }
142    
143     lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
144    
145     for (UINT i = 0; i < nSize; i++)
146     {
147     cs = DwToString(m_NodeList[i].wNodeID);
148     lvi.iItem = i;
149     lvi.iSubItem = 0;
150     lvi.pszText = MC_CStoSTR(cs);
151     m_xNodeList.InsertItem(&lvi);
152    
153     cs = DwToIPAddress(m_NodeList[i].dwAddress);
154     lvi.iItem = i;
155     lvi.iSubItem = 1;
156     lvi.pszText = MC_CStoSTR(cs);
157     m_xNodeList.SetItem(&lvi);
158    
159     cs = _T("0%");
160     lvi.iItem = i;
161     lvi.iSubItem = 2;
162     lvi.pszText = MC_CStoSTR(cs);
163     m_xNodeList.SetItem(&lvi);
164    
165     cs = STRING_NONE;
166     lvi.iItem = i;
167     lvi.iSubItem = 3;
168     lvi.pszText = MC_CStoSTR(cs);
169     m_xNodeList.SetItem(&lvi);
170    
171     cs = STRING_NONE;
172     lvi.iItem = i;
173     lvi.iSubItem = 4;
174     lvi.pszText = MC_CStoSTR(cs);
175     m_xNodeList.SetItem(&lvi);
176     }
177    
178     m_xEditNodes.SetWindowText(DwToString(nSize));
179     m_xEditProcessors.SetWindowText(DwToString(nProcessors));
180     m_xEditTotal.SetWindowText(STRING_NONE);
181     m_xEditAverage.SetWindowText(STRING_NONE);
182     m_xEditHigh.SetWindowTextW(STRING_NONE);
183     m_xEditLow.SetWindowText(STRING_NONE);
184     m_xBtnLog.EnableWindow(FALSE);
185    
186     if (!StartTimer())
187     {
188     TRACE1("***** ERROR: StartTimer(%d) *****\n", GetLastError());
189     return EndDialog(IDCANCEL), FALSE;
190     }
191    
192     return FALSE;
193     }
194    
195     void CBMSystemDlg::OnBnClickedBtnBmsystemClose()
196     {
197     CString cs;
198     int nRet;
199    
200     if (m_fEnd)
201     {
202     EndDialog(IDOK);
203     }
204     else
205     {
206     cs.LoadString(IDS_WCS_TEXT_BMTEST_EXIT_CONFIRM);
207     nRet = CMsgBox::Question(MC_CStoSTR(cs), _T("Benchmark Test"));
208    
209     if (nRet == IDYES)
210     {
211     StopTimer();
212     EndDialog(IDCANCEL);
213     }
214     }
215     }
216    
217     void CBMSystemDlg::OnBnClickedBtnBmsystemHelp()
218     {
219     CFlopsHelpDlg dlg;
220     dlg.DoModal();
221     }
222    
223     void CBMSystemDlg::SetNodeList(const NodeDataList &list)
224     {
225     m_NodeList.RemoveAll();
226     m_NodeList.Copy(list);
227     }
228    
229     void CBMSystemDlg::SetProgressPoint(WORD wNodeID, int nPoint)
230     {
231     CString cs;
232     LVITEM lvi;
233     int nIndex = SearchNodeListIndex(wNodeID);
234    
235     if (nIndex != -1)
236     {
237     CSingleLock sl(&m_cs, TRUE);
238    
239     lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
240     cs.Format(_T("%d%%"), nPoint);
241     lvi.iItem = nIndex;
242     lvi.iSubItem = 2;
243     lvi.pszText = MC_CStoSTR(cs);
244     m_xNodeList.SetItem(&lvi);
245     }
246     }
247    
248     void CBMSystemDlg::SetProgress(int nPoint)
249     {
250     CString cs;
251    
252     cs.Format(_T("%d%%"), nPoint);
253     m_xTxtPercent.SetWindowText(cs);
254     m_xProgress.SetPos(nPoint);
255    
256     if (nPoint == 100)
257     {
258     m_xImgLoader.Stop();
259     m_xImgLoader.ShowWindow(SW_HIDE);
260     m_xTxtState.SetWindowText(_T("Finish!"));
261     StopTimer();
262     m_fEnd = TRUE;
263     }
264     }
265    
266     int CBMSystemDlg::SearchNodeListIndex(WORD wNodeID)
267     {
268     int nIndex = -1;
269     UINT nItemCount;
270     BOOL find = FALSE;
271    
272     CSingleLock sl(&m_cs, TRUE);
273     nItemCount = m_xNodeList.GetItemCount();
274    
275     for (UINT i = 0; i < nItemCount; i++)
276     {
277     if (m_xNodeList.GetItemText(i, 0) == DwToString(wNodeID))
278     {
279     nIndex = i;
280     break;
281     }
282     }
283    
284     return nIndex;
285     }
286    
287     void WINAPI CBMSystemDlg::doRuntimeTimer(LPVOID pvContext, BOOLEAN fTimeout)
288     {
289     ((CBMSystemDlg *)pvContext)->RuntimeTimer();
290     }
291    
292     void CBMSystemDlg::RuntimeTimer()
293     {
294     CString cs;
295     m_Stopwatch.GetHMS(cs);
296     m_xEditRuntime.SetWindowText(cs);
297     }
298    
299     BOOL CBMSystemDlg::StartTimer()
300     {
301     m_Stopwatch.Start();
302     RuntimeTimer();
303    
304     if (!CreateTimerQueueTimer(&m_hTimer, NULL, doRuntimeTimer, this, 500, 500, 0))
305     {
306     m_hTimer = NULL;
307     return FALSE;
308     }
309    
310     return TRUE;
311     }
312    
313     void CBMSystemDlg::StopTimer()
314     {
315     if (m_hTimer != NULL)
316     {
317     DeleteTimerQueueTimer(NULL, m_hTimer, NULL);
318     m_hTimer = NULL;
319     }
320     }
321    
322     void CBMSystemDlg::SetTestScore(WORD wNodeID, BM_DATA bm)
323     {
324     CString cs;
325     LVITEM lvi;
326     int nIndex = SearchNodeListIndex(wNodeID);
327    
328     if (nIndex != -1)
329     {
330     CSingleLock sl(&m_cs, TRUE);
331    
332     lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
333    
334     cs = DbToHMSTime(bm.dbRuntime);
335     lvi.iItem = nIndex;
336     lvi.iSubItem = 3;
337     lvi.pszText = MC_CStoSTR(cs);
338     m_xNodeList.SetItem(&lvi);
339    
340     cs.Format(_T("%.4lf"), bm.dbRltAvg);
341     lvi.iItem = nIndex;
342     lvi.iSubItem = 4;
343     lvi.pszText = MC_CStoSTR(cs);
344     m_xNodeList.SetItem(&lvi);
345     }
346     }
347    
348     void CBMSystemDlg::SetSystemScore(BM_SYSTEMSCORE bmScore, const CString &csLogPath)
349     {
350     CString cs;
351    
352     m_LogPath = csLogPath;
353     cs.Format(_T("%.4lf GFLOPS"), bmScore.dbTotal);
354     m_xEditTotal.SetWindowText(cs);
355     cs.Format(_T("%.4lf GFLOPS"), bmScore.dbAvg);
356     m_xEditAverage.SetWindowText(cs);
357     cs.Format(_T("%.4lf GFLOPS"), bmScore.dbHigh);
358     m_xEditHigh.SetWindowText(cs);
359     cs.Format(_T("%.4lf GFLOPS"), bmScore.dbLow);
360     m_xEditLow.SetWindowText(cs);
361     m_xBtnLog.EnableWindow(TRUE);
362     }
363    
364     void CBMSystemDlg::OnBnClickedBtnBmsystemLog()
365     {
366     SHELLEXECUTEINFO sei;
367     CString cs;
368    
369     ZeroMemory(&sei, sizeof(sei));
370     sei.cbSize = sizeof(SHELLEXECUTEINFO);
371     sei.hwnd = m_hWnd;
372     sei.nShow = SW_SHOWNORMAL;
373     sei.fMask = SEE_MASK_NOCLOSEPROCESS;
374     sei.lpFile = MC_CStoSTR(m_LogPath);
375    
376     if(!ShellExecuteEx(&sei) || reinterpret_cast<int>(sei.hInstApp) <= 32)
377     {
378     TRACE1("***** ERROR: OnShowLog(%d) *****\n", GetLastError());
379     cs.LoadString(IDS_WCS_ERROR_SHOW_LOG);
380     AfxMessageBox(cs);
381     return;
382     }
383    
384     WaitForSingleObject(sei.hProcess, INFINITE);
385     CloseHandle(sei.hProcess);
386     }
387    
388     //////////////////////////////////////////////////////////////////////////

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26