Develop and Download Open Source Software

Browse Subversion Repository

Contents of /WinCS/MasterView.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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


1 #include "stdafx.h"
2 #include "WinCS.h"
3 #include "MasterView.h"
4
5 IMPLEMENT_DYNAMIC(CMasterView, CDialog)
6
7 BEGIN_MESSAGE_MAP(CMasterView, CDialog)
8 ON_BN_CLICKED(IDOK, &CMasterView::OnBnClickedOk)
9 ON_BN_CLICKED(IDC_BTN_MASTER_SEND, &CMasterView::OnBnClickedBtnMasterSend)
10 ON_WM_CTLCOLOR()
11 ON_BN_CLICKED(IDC_BTN_MASTER_PLUGIN_TRANSFER, &CMasterView::OnBnClickedBtnMasterPluginDistribution)
12 ON_BN_CLICKED(IDC_CHECK_PLUGIN_LOCK, &CMasterView::OnBnClickedCheckPluginLock)
13 END_MESSAGE_MAP()
14
15 //////////////////////////////////////////////////////////////////////////
16
17 CMasterView::CMasterView(CWnd* pParent /*=NULL*/)
18 : CDialog(CMasterView::IDD, pParent),
19 m_fPluginLocked(FALSE)
20 {
21 }
22
23 CMasterView::~CMasterView()
24 {
25 }
26
27 void CMasterView::DoDataExchange(CDataExchange* pDX)
28 {
29 CDialog::DoDataExchange(pDX);
30 DDX_Control(pDX, IDC_LIST_MASTER_NODELIST, m_xNodeList);
31 DDX_Control(pDX, IDC_EDIT_MASTER_INPUT, m_xEditInput);
32 DDX_Control(pDX, IDC_EDIT_MASTER_CONSOLE, m_xEditConsole);
33 DDX_Control(pDX, IDC_EDIT_MASTER_SYSTEM_SLAVES, m_xEditSlaves);
34 DDX_Control(pDX, IDC_EDIT_MASTER_SYSTEM_PROCESSORS, m_xEditProcessors);
35 DDX_Control(pDX, IDC_EDIT_MASTER_BENCHMARK_NODES, m_xEditNodes);
36 DDX_Control(pDX, IDC_EDIT_MASTER_BENCHMARK_SCORE, m_xEditScore);
37 DDX_Control(pDX, IDC_EDIT_MASTER_BENCHMARK_RUNTIME, m_xEditRuntime);
38 DDX_Control(pDX, IDC_EDIT_MASTER_PLUGIN, m_xEditPlugin);
39 DDX_Control(pDX, IDC_EDIT_MASTER_BENCHMARK_TESTTIME, m_xEditTestTime);
40 DDX_Control(pDX, IDC_BTN_MASTER_PLUGIN_TRANSFER, m_xBtnTransfer);
41 DDX_Control(pDX, IDC_CHECK_PLUGIN_LOCK, m_xCheckLock);
42 }
43
44 BOOL CMasterView::OnInitDialog()
45 {
46 CDialog::OnInitDialog();
47
48 LVCOLUMN lvc;
49 CRect cr;
50
51 lvc.mask = (LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM);
52 m_xNodeList.GetClientRect(&cr);
53
54 lvc.fmt = LVCFMT_RIGHT;
55 lvc.cx = (cr.right - cr.left) * 3 / 30;
56 lvc.pszText = _T("ID");
57 m_xNodeList.InsertColumn(0, &lvc);
58
59 lvc.fmt = LVCFMT_RIGHT;
60 lvc.cx = (cr.right - cr.left) * 8 / 30;
61 lvc.pszText = _T("IP Address");
62 m_xNodeList.InsertColumn(1, &lvc);
63
64 lvc.fmt = LVCFMT_RIGHT;
65 lvc.cx = (cr.right - cr.left) * 4 / 30;
66 lvc.pszText = _T("Port");
67 m_xNodeList.InsertColumn(2, &lvc);
68
69 lvc.fmt = LVCFMT_RIGHT;
70 lvc.cx = (cr.right - cr.left) * 4 / 30;
71 lvc.pszText = _T("CPU");
72 m_xNodeList.InsertColumn(3, &lvc);
73
74 lvc.fmt = LVCFMT_CENTER;
75 lvc.cx = (cr.right - cr.left) * 5 / 30;
76 lvc.pszText = _T("Type");
77 m_xNodeList.InsertColumn(4, &lvc);
78
79 lvc.fmt = LVCFMT_CENTER;
80 lvc.cx = (cr.right - cr.left) * 5 / 30;
81 lvc.pszText = _T("State");
82 m_xNodeList.InsertColumn(5, &lvc);
83
84 m_xNodeList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
85 m_xEditInput.SetFocus();
86
87 m_xEditSlaves.SetWindowText(STRING_ZERO);
88 m_xEditProcessors.SetWindowText(STRING_ZERO);
89 m_xEditNodes.SetWindowText(STRING_NONE);
90 m_xEditScore.SetWindowText(STRING_NONE);
91 m_xEditRuntime.SetWindowText(STRING_NONE);
92 m_xEditTestTime.SetWindowText(STRING_NONE);
93
94 return FALSE;
95 }
96
97 BOOL CMasterView::PreTranslateMessage(MSG* pMsg)
98 {
99 if ((pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) &&
100 (GetFocus() != NULL && GetFocus() == GetDlgItem(IDC_EDIT_MASTER_INPUT)))
101 {
102 SendTextMessage();
103 return TRUE;
104 }
105
106 return CDialog::PreTranslateMessage(pMsg);
107 }
108
109 HBRUSH CMasterView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
110 {
111 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
112 int nCtlID = pWnd->GetDlgCtrlID();
113
114 switch (nCtlID)
115 {
116 case IDC_EDIT_MASTER_CONSOLE:
117 case IDC_EDIT_MASTER_SYSTEM_SLAVES:
118 case IDC_EDIT_MASTER_SYSTEM_PROCESSORS:
119 case IDC_EDIT_MASTER_BENCHMARK_NODES:
120 case IDC_EDIT_MASTER_BENCHMARK_SCORE:
121 case IDC_EDIT_MASTER_BENCHMARK_RUNTIME:
122 case IDC_EDIT_MASTER_BENCHMARK_TESTTIME:
123 case IDC_EDIT_MASTER_PLUGIN:
124 hbr = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
125 pDC->SetBkColor(RGB(255, 255, 255));
126 break;
127 }
128
129 return hbr;
130 }
131
132 void CMasterView::SendTextMessage()
133 {
134 CString cs;
135 m_xEditInput.GetWindowText(m_MsgString);
136
137 if (m_MsgString.GetLength() > 0)
138 {
139 cs.Format(_T("Local message : (%s)\r\n>> %s"), GetNowTime(), m_MsgString);
140 AddConsoleText(cs);
141 GetParent()->SendMessage(WM_SEND_TEXT);
142 m_xEditInput.SetWindowText(STRING_EMPTY);
143 }
144
145 m_xEditInput.SetFocus();
146 }
147
148 void CMasterView::OnBnClickedBtnMasterSend()
149 {
150 SendTextMessage();
151 }
152
153 int CMasterView::SearchNodeListIndex(WORD wNodeID)
154 {
155 int nIndex = -1;
156 UINT nItemCount;
157 BOOL find = FALSE;
158
159 CSingleLock sl(&m_cs, TRUE);
160 nItemCount = m_xNodeList.GetItemCount();
161
162 for (UINT i = 0; i < nItemCount; i++)
163 {
164 if (m_xNodeList.GetItemText(i, 0) == DwToString(wNodeID))
165 {
166 nIndex = i;
167 break;
168 }
169 }
170
171 return nIndex;
172 }
173
174 void CMasterView::SetNodeState(WORD wNodeID, WORD wNodeState)
175 {
176 CString cs;
177 LVITEM lvi;
178 int nIndex = SearchNodeListIndex(wNodeID);
179
180 if (nIndex != -1)
181 {
182 CSingleLock sl(&m_cs, TRUE);
183
184 lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
185 cs = GetNodeState(wNodeState);
186 lvi.iItem = nIndex;
187 lvi.iSubItem = 5;
188 lvi.pszText = MC_CStoSTR(cs);
189 m_xNodeList.SetItem(&lvi);
190 }
191 }
192
193 void CMasterView::SetNodeProcessors(WORD wNodeID, DWORD dwProcessors)
194 {
195 CString cs;
196 LVITEM lvi;
197 int nIndex = SearchNodeListIndex(wNodeID);
198
199 if (nIndex != -1)
200 {
201 CSingleLock sl(&m_cs, TRUE);
202
203 lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
204 cs = DwToString(dwProcessors);
205 lvi.iItem = nIndex;
206 lvi.iSubItem = 3;
207 lvi.pszText = MC_CStoSTR(cs);
208 m_xNodeList.SetItem(&lvi);
209 }
210 }
211
212 void CMasterView::AddNodeList(NODE_DATA nd)
213 {
214 CString cs;
215 LVITEM lvi;
216 UINT nListSize;
217 int nIndex;
218
219 nIndex = SearchNodeListIndex(nd.wNodeID);
220
221 if (nIndex == -1)
222 {
223 CSingleLock sl(&m_cs, TRUE);
224
225 lvi.mask = (LVIF_TEXT | LVIF_IMAGE);
226 nListSize = m_xNodeList.GetItemCount();
227
228 cs = DwToString(nd.wNodeID);
229 lvi.iItem = nListSize;
230 lvi.iSubItem = 0;
231 lvi.pszText = MC_CStoSTR(cs);
232 m_xNodeList.InsertItem(&lvi);
233
234 cs = DwToIPAddress(nd.dwAddress);
235 lvi.iItem = nListSize;
236 lvi.iSubItem = 1;
237 lvi.pszText = MC_CStoSTR(cs);
238 m_xNodeList.SetItem(&lvi);
239
240 cs = DwToString(nd.wPort);
241 lvi.iItem = nListSize;
242 lvi.iSubItem = 2;
243 lvi.pszText = MC_CStoSTR(cs);
244 m_xNodeList.SetItem(&lvi);
245
246 cs = DwToString(nd.dwProcessors);
247 lvi.iItem = nListSize;
248 lvi.iSubItem = 3;
249 lvi.pszText = MC_CStoSTR(cs);
250 m_xNodeList.SetItem(&lvi);
251
252 cs = GetNodeType(nd.wNodeType);
253 lvi.iItem = nListSize;
254 lvi.iSubItem = 4;
255 lvi.pszText = MC_CStoSTR(cs);
256 m_xNodeList.SetItem(&lvi);
257
258 cs = GetNodeState(nd.wNodeState);
259 lvi.iItem = nListSize;
260 lvi.iSubItem = 5;
261 lvi.pszText = MC_CStoSTR(cs);
262 m_xNodeList.SetItem(&lvi);
263 }
264 }
265
266 void CMasterView::RemoveNodeList(WORD wNodeID)
267 {
268 int nIndex = SearchNodeListIndex(wNodeID);
269
270 if (nIndex != -1)
271 {
272 CSingleLock sl(&m_cs, TRUE);
273 m_xNodeList.DeleteItem(nIndex);
274 }
275 }
276
277
278 CString CMasterView::GetNodeState(WORD wNodeState)
279 {
280 CString cs;
281
282 switch (wNodeState)
283 {
284 case WCS_STATE_WAITING:
285 cs = _T("Waiting");
286 break;
287
288 case WCS_STATE_EXECUTING:
289 cs = _T("Executing");
290 break;
291
292 case WCS_STATE_BENCHMARKING:
293 cs = _T("Benchmarking");
294 break;
295 }
296
297 return cs;
298 }
299
300 CString CMasterView::GetNodeType(WORD wNodeType)
301 {
302 CString cs;
303
304 switch (wNodeType)
305 {
306 case WCS_NODE_MASTER:
307 cs = _T("Master");
308 break;
309
310 case WCS_NODE_SLAVE:
311 cs = _T("Slave");
312 break;
313 }
314
315 return cs;
316 }
317
318 void CMasterView::AddConsoleText(const CString &csText, BOOL fReturn)
319 {
320 CString cs;
321 BOOL bFocus;
322 int nLastPos;
323
324 if (csText.GetLength() < 1)
325 {
326 return;
327 }
328
329 cs.Format(_T("%s%s"), csText, fReturn ? STRING_RETURN : STRING_EMPTY);
330 nLastPos = m_xEditConsole.GetWindowTextLength();
331 bFocus = FALSE;
332
333 if (::GetFocus() == m_xEditConsole.m_hWnd)
334 {
335 bFocus = TRUE;
336 GetParent()->SetFocus();
337 }
338
339 m_xEditConsole.SetSel(nLastPos, nLastPos);
340 m_xEditConsole.ReplaceSel(cs);
341
342 if (bFocus)
343 {
344 m_xEditConsole.SetFocus();
345 }
346 }
347
348 void CMasterView::OnBnClickedBtnMasterPluginDistribution()
349 {
350 GetParent()->SendMessage(WM_PLUGIN_TRANSFER);
351 }
352
353 void CMasterView::OnBnClickedCheckPluginLock()
354 {
355 m_fPluginLocked = (m_xCheckLock.GetCheck() == BST_CHECKED);
356 GetParent()->SendMessage(WM_PLUGIN_LOCK, (WPARAM)m_fPluginLocked, 0);
357 }
358
359 void CMasterView::SetSlaves(DWORD dwCount)
360 {
361 m_xEditSlaves.SetWindowText(DwToString(dwCount));
362 }
363
364 void CMasterView::SetProcessors(DWORD dwCount)
365 {
366 m_xEditProcessors.SetWindowText(DwToString(dwCount));
367 }
368
369 void CMasterView::SetPluginName(const CString &cs)
370 {
371 m_xEditPlugin.SetWindowText(cs);
372 }
373
374 void CMasterView::ClearConsoleText()
375 {
376 m_xEditConsole.SetWindowText(STRING_EMPTY);
377 }
378
379 void CMasterView::GetSendMessage(CString &cs)
380 {
381 cs = m_MsgString;
382 }
383
384 void CMasterView::GetConsoleText(CString &cs)
385 {
386 m_xEditConsole.GetWindowText(cs);
387 }
388
389 void CMasterView::SetBenchmarkNodes(DWORD dwCount)
390 {
391 m_xEditNodes.SetWindowText(DwToString(dwCount));
392 }
393
394 void CMasterView::SetBenchmarkScore(double dbScore)
395 {
396 CString cs;
397 cs.Format(_T("%.4lf GFLOPS"), dbScore);
398 m_xEditScore.SetWindowText(cs);
399 }
400
401 void CMasterView::SetBenchmarkRuntime(double dbRuntime)
402 {
403 m_xEditRuntime.SetWindowText(DbToHMSTime(dbRuntime));
404 }
405
406 void CMasterView::SetBenchmarkTestTime(const CString &cs)
407 {
408 m_xEditTestTime.SetWindowText(cs);
409 }
410
411 void CMasterView::ResetBenchmark()
412 {
413 m_xEditNodes.SetWindowText(STRING_NONE);
414 m_xEditScore.SetWindowText(STRING_NONE);
415 m_xEditRuntime.SetWindowText(STRING_NONE);
416 m_xEditTestTime.SetWindowText(STRING_NONE);
417 }
418
419 //////////////////////////////////////////////////////////////////////////

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