Source code of Windows XP (NT5)
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.

529 lines
16 KiB

  1. /*======================================================================================//
  2. | Process Control //
  3. | //
  4. |Copyright (c) 1998 Sequent Computer Systems, Incorporated. All rights reserved. //
  5. | //
  6. |File Name: JobPages.cpp //
  7. | //
  8. |Description: Implementation of Job pages //
  9. | //
  10. |Created: Paul Skoglund 09-1998 //
  11. | //
  12. |Rev History: //
  13. | //
  14. |=======================================================================================*/
  15. #include "stdafx.h"
  16. #include "JobPages.h"
  17. #include "ManagementPages.h"
  18. #include "ManagementRuleWizards.h"
  19. static HRESULT ConstructJobDetailPropPages (LPPROPERTYSHEETCALLBACK lpProvider,
  20. CJobDetailContainer *pContainer,
  21. const PCJobDetail &JobDetail,
  22. const PCSystemParms &SystemParms);
  23. #if _MSC_VER >= 1200
  24. #pragma warning( push )
  25. #endif
  26. #pragma warning( disable : 4800 ) //warning C4800: 'unsigned long' : forcing value to bool 'true' or 'false' (performance warning)
  27. CJobIDPage::CJobIDPage(int nTitle, CJobDetailContainer *pContainer) :
  28. CMySnapInPropertyPageImpl<CJobIDPage>(nTitle),
  29. m_pJobContainer(pContainer), m_bJob(_T("")), m_bComment(_T(""))
  30. {
  31. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  32. PageFields.on = 0;
  33. m_bReadOnly = FALSE;
  34. m_processcountchk = FALSE;
  35. m_processcount = 0;
  36. m_psp.dwFlags |= PSP_HASHELP;
  37. m_pJobContainer->AddRef();
  38. }
  39. CJobIDPage::~CJobIDPage()
  40. {
  41. m_pJobContainer->Release();
  42. }
  43. LRESULT CJobIDPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  44. {
  45. CComBSTR bTitle;
  46. PropSheet_SetTitle( GetParent(), PSH_PROPTITLE, FormatSheetTitle(bTitle, m_bJob, m_pJobContainer->GetConnectionInfo()));
  47. DisableControl(IDC_JOB);
  48. UpdateData(FALSE);
  49. bHandled = FALSE;
  50. // Setting focus when a property page does not work...
  51. return TRUE; // Let the system set the focus
  52. }
  53. LRESULT CJobIDPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  54. {
  55. HELPINFO *phi = (HELPINFO*) lParam;
  56. if (phi && phi->iContextType == HELPINFO_WINDOW)
  57. {
  58. IDCsToIDHs HelpMap[]={{IDC_JOB, HELP_GRPID_NAME },
  59. {IDC_COMMENT, HELP_GRPID_COMMENT },
  60. {IDC_PROCCOUNT_FRAME, HELP_PROCCOUNT_FRAME },
  61. {IDC_PROCESSCOUNT_CHK, HELP_PROCCOUNT_APPLY },
  62. {IDC_PROCESSCOUNT, HELP_PROCCOUNT_MAX },
  63. {IDC_SPIN, HELP_PROCCOUNT_MAX_SPIN },
  64. {0,0} };
  65. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  66. return TRUE;
  67. }
  68. bHandled = FALSE;
  69. return FALSE;
  70. }
  71. BOOL CJobIDPage::OnHelp()
  72. {
  73. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_job_name));
  74. return TRUE;
  75. }
  76. BOOL CJobIDPage::Validate(BOOL bSave)
  77. {
  78. CComBSTR bStr;
  79. CComBSTR bComment;
  80. bStr.Empty();
  81. if (!GetDlgItemText( IDC_JOB, bStr.m_str ) ||
  82. !IsValidName(bStr, FALSE) )
  83. {
  84. HWND hWndCtl = GetDlgItem(IDC_JOB);
  85. if(hWndCtl)
  86. ::SetFocus(hWndCtl);
  87. ITEM_STR strOut;
  88. LoadStringHelper(strOut, IDS_JOBNAME_WARNING);
  89. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  90. return FALSE;
  91. }
  92. if ( !GetDlgItemText(IDC_COMMENT, bComment.m_str) )
  93. bComment = _T("");
  94. if (bComment.Length() > RULE_DESCRIPTION_LEN)
  95. {
  96. HWND hWndCtl = GetDlgItem(IDC_COMMENT);
  97. if(hWndCtl)
  98. ::SetFocus(hWndCtl);
  99. MessageBeep(MB_ICONASTERISK);
  100. return FALSE;
  101. }
  102. LONG_PTR PosErr = 0;
  103. LRESULT processcount = SendDlgItemMessage(IDC_SPIN, UDM_GETPOS32, 0, (LPARAM) &PosErr);
  104. if (PosErr || processcount < 0)
  105. {
  106. HWND hWndCtl = GetDlgItem(IDC_PROCESSCOUNT);
  107. if(hWndCtl)
  108. ::SetFocus(hWndCtl);
  109. MessageBeep(MB_ICONASTERISK);
  110. return FALSE;
  111. }
  112. if (bSave)
  113. {
  114. _tcscpy(m_pJobContainer->m_new.base.mgmtParms.description, bComment);
  115. SetMGMTFlag(m_pJobContainer->m_new.base.mgmtParms.mFlags, PCMFLAG_APPLY_PROC_COUNT_LIMIT, (BST_CHECKED == IsDlgButtonChecked(IDC_PROCESSCOUNT_CHK)));
  116. m_pJobContainer->m_new.base.mgmtParms.procCountLimit = (PROC_COUNT) processcount;
  117. }
  118. return TRUE;
  119. }
  120. BOOL CJobIDPage::UpdateData(BOOL bSaveAndValidate)
  121. {
  122. if (bSaveAndValidate)
  123. {
  124. return Validate(TRUE);
  125. }
  126. else
  127. {
  128. VERIFY(SetDlgItemText( IDC_JOB, m_bJob.m_str ));
  129. VERIFY(SetDlgItemText( IDC_COMMENT, m_bComment.m_str ));
  130. SendDlgItemMessage( IDC_COMMENT, EM_SETLIMITTEXT, RULE_DESCRIPTION_LEN, 0);
  131. CheckDlgButton(IDC_PROCESSCOUNT_CHK, m_processcountchk ? BST_CHECKED : BST_UNCHECKED);
  132. SendDlgItemMessage(IDC_SPIN, UDM_SETRANGE32, 0, MAXLONG-1 );
  133. SendDlgItemMessage(IDC_SPIN, UDM_SETPOS32, 0, m_processcount );
  134. if (m_bReadOnly || !m_processcountchk)
  135. {
  136. DisableControl(IDC_PROCESSCOUNT);
  137. DisableControl(IDC_SPIN);
  138. }
  139. if (m_bReadOnly)
  140. {
  141. DisableControl(IDC_JOB);
  142. DisableControl(IDC_COMMENT);
  143. DisableControl(IDC_PROCESSCOUNT_CHK);
  144. }
  145. return TRUE;
  146. }
  147. }
  148. LRESULT CJobIDPage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  149. {
  150. CComBSTR bStr; // GetDlgItemText returns FALSE, and doesn't create an empty
  151. switch (wID) {
  152. case IDC_JOB:
  153. if (! GetDlgItemText(wID, bStr.m_str) )
  154. bStr = _T("");
  155. PageFields.Fields.jobName = (0 != _tcscmp(bStr, m_bJob));
  156. break;
  157. case IDC_COMMENT:
  158. if (! GetDlgItemText(wID, bStr.m_str) )
  159. bStr = _T("");
  160. PageFields.Fields.comment = (0 != _tcscmp(bStr, m_bComment));
  161. break;
  162. case IDC_PROCESSCOUNT:
  163. {
  164. LRESULT processcount = SendDlgItemMessage(IDC_SPIN, UDM_GETPOS32, 0, 0);
  165. PageFields.Fields.processcount = ((PROC_COUNT) processcount != m_processcount);
  166. }
  167. break;
  168. default:
  169. ASSERT(FALSE);
  170. break;
  171. }
  172. SetModified(PageFields.on);
  173. bHandled = FALSE;
  174. return 0;
  175. }
  176. LRESULT CJobIDPage::OnChk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  177. {
  178. if (wID == IDC_PROCESSCOUNT_CHK)
  179. {
  180. bool checked = (BST_CHECKED == IsDlgButtonChecked(IDC_PROCESSCOUNT_CHK));
  181. PageFields.Fields.processcountchk = (m_processcountchk != checked);
  182. ::EnableWindow(GetDlgItem(IDC_PROCESSCOUNT), checked);
  183. ::EnableWindow(GetDlgItem(IDC_SPIN), checked);
  184. SetModified(PageFields.on);
  185. }
  186. bHandled = FALSE;
  187. return 0;
  188. }
  189. BOOL CJobIDPage::OnApply()
  190. {
  191. if (m_bReadOnly || !PageFields.on)
  192. return TRUE;
  193. if (m_pJobContainer->Apply( GetParent() ))
  194. {
  195. PageFields.on = 0;
  196. m_bComment = m_pJobContainer->m_new.base.mgmtParms.description;
  197. m_processcountchk = (m_pJobContainer->m_new.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_COUNT_LIMIT);
  198. m_processcount = m_pJobContainer->m_new.base.mgmtParms.procCountLimit;
  199. return TRUE;
  200. }
  201. return FALSE;
  202. }
  203. ///////////////////////////////////////////////////////////////////////////
  204. // Unmanaged Procees Page Implementation
  205. CJobUnmanagedPage::CJobUnmanagedPage(int nTitle, CNewJobDetailContainer *pContainer, const PCSystemParms sysParms) :
  206. CMySnapInPropertyPageImpl<CJobUnmanagedPage>(nTitle),
  207. m_pJobContainer(pContainer), m_SystemParms(sysParms), m_bName(_T(""))
  208. {
  209. m_bReadOnly = FALSE;
  210. m_psp.dwFlags |= PSP_HASHELP;
  211. m_pJobContainer->AddRef();
  212. }
  213. CJobUnmanagedPage::~CJobUnmanagedPage()
  214. {
  215. m_pJobContainer->Release();
  216. }
  217. LRESULT CJobUnmanagedPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  218. {
  219. CComBSTR bTitle;
  220. PropSheet_SetTitle( GetParent(), PSH_PROPTITLE, FormatSheetTitle(bTitle, m_bName, m_pJobContainer->GetConnectionInfo()));
  221. DisableControl(IDC_NAME);
  222. if (m_bReadOnly)
  223. DisableControl(IDC_ADD);
  224. UpdateData(FALSE);
  225. bHandled = FALSE;
  226. // Setting focus when a property page does not work...
  227. return TRUE; // Let the system set the focus
  228. }
  229. LRESULT CJobUnmanagedPage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  230. {
  231. HELPINFO *phi = (HELPINFO*) lParam;
  232. if (phi && phi->iContextType == HELPINFO_WINDOW)
  233. {
  234. IDCsToIDHs HelpMap[]={{IDC_NAME, HELP_GRPDEF_NAME },
  235. {IDC_ADD, HELP_GRPDEF_ADD },
  236. {0,0} };
  237. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  238. return TRUE;
  239. }
  240. bHandled = FALSE;
  241. return FALSE;
  242. }
  243. BOOL CJobUnmanagedPage::OnHelp()
  244. {
  245. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_job));
  246. return TRUE;
  247. }
  248. LRESULT CJobUnmanagedPage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  249. {
  250. if (wNotifyCode != BN_CLICKED || wID != IDC_ADD)
  251. {
  252. bHandled = FALSE;
  253. return 1;
  254. }
  255. PCJobDetail JobDetail = { 0 };
  256. JOB_NAME jname;
  257. _tcscpy(jname, m_bName);
  258. if (GroupRuleWizard(IDS_JRULE_DEFINE, JobDetail, m_SystemParms, &jname) )
  259. {
  260. m_pJobContainer->m_new = JobDetail;
  261. ::PostMessage(GetParent(), PSM_PRESSBUTTON, (WPARAM) PSBTN_OK, 0);
  262. }
  263. return 0;
  264. }
  265. BOOL CJobUnmanagedPage::Validate(BOOL bSave)
  266. {
  267. return TRUE;
  268. }
  269. BOOL CJobUnmanagedPage::UpdateData(BOOL bSaveAndValidate)
  270. {
  271. if (bSaveAndValidate)
  272. {
  273. return Validate(TRUE);
  274. }
  275. else
  276. {
  277. VERIFY(SetDlgItemText( IDC_NAME, m_bName.m_str ));
  278. return TRUE;
  279. }
  280. }
  281. BOOL CJobUnmanagedPage::OnApply()
  282. {
  283. if (m_bReadOnly)
  284. return TRUE;
  285. if (m_pJobContainer->Apply(GetParent()) )
  286. return TRUE;
  287. return FALSE;
  288. }
  289. // Property Page Helper functions...
  290. HRESULT CreatePropertyPagesForJobListItem( const PCJobListItem &JobListItem,
  291. LPPROPERTYSHEETCALLBACK lpProvider,
  292. LONG_PTR handle,
  293. CBaseNode *BaseNodePtr )
  294. {
  295. if ( JobListItem.lFlags & PCLFLAG_IS_DEFINED )
  296. {
  297. return CreatePropertyPagesForJobDetail(JobListItem.jobName, lpProvider, handle, BaseNodePtr);
  298. }
  299. PCid hID = BaseNodePtr->GetPCid();
  300. PCSystemInfo sysInfo;
  301. if (!hID ||
  302. !PCGetServiceInfo(hID, &sysInfo, sizeof(sysInfo)) )
  303. {
  304. BaseNodePtr->ReportPCError();
  305. return S_OK;
  306. }
  307. COMPUTER_CONNECTION_INFO ConnInfo;
  308. BaseNodePtr->GetComputerConnectionInfo(ConnInfo);
  309. PCJobDetail JobDetail = { 0 };
  310. _tcscpy(JobDetail.base.jobName, JobListItem.jobName);
  311. CNewJobDetailContainer *pContainer = new CNewJobDetailContainer(JobDetail, BaseNodePtr, handle, hID, ConnInfo, 0, FALSE, -1);
  312. if (pContainer)
  313. {
  314. CJobUnmanagedPage *pPage = new CJobUnmanagedPage(NULL, pContainer, sysInfo.sysParms);
  315. if (pPage)
  316. {
  317. pPage->m_bName = JobListItem.jobName;
  318. lpProvider->AddPage(pPage->Create());
  319. }
  320. pContainer->Release();
  321. pContainer = NULL;
  322. }
  323. return S_OK;
  324. }
  325. HRESULT CreatePropertyPagesForJobDetail( const JOB_NAME &jobName,
  326. LPPROPERTYSHEETCALLBACK lpProvider,
  327. LONG_PTR handle,
  328. CBaseNode *BaseNodePtr )
  329. {
  330. PCid hID = BaseNodePtr->GetPCid();
  331. PCSystemInfo sysInfo;
  332. PCJobDetail JobDetail = { 0 };
  333. _tcscpy(JobDetail.base.jobName, jobName);
  334. PCINT32 nUpdateCtr = 0;
  335. if (!hID ||
  336. !PCGetJobDetail (hID, &JobDetail, sizeof(JobDetail), &nUpdateCtr) ||
  337. !PCGetServiceInfo(hID, &sysInfo, sizeof(sysInfo)) )
  338. {
  339. BaseNodePtr->ReportPCError();
  340. return S_OK;
  341. }
  342. COMPUTER_CONNECTION_INFO ConnInfo;
  343. BaseNodePtr->GetComputerConnectionInfo(ConnInfo);
  344. CJobDetailContainer *pContainer = new CJobDetailContainer(JobDetail, BaseNodePtr, handle, hID, ConnInfo, nUpdateCtr, FALSE, -1);
  345. if (pContainer)
  346. {
  347. ConstructJobDetailPropPages(lpProvider, pContainer, JobDetail, sysInfo.sysParms);
  348. pContainer->Release();
  349. pContainer = NULL;
  350. }
  351. return S_OK;
  352. }
  353. HRESULT ConstructJobDetailPropPages(LPPROPERTYSHEETCALLBACK lpProvider, CJobDetailContainer *pContainer, const PCJobDetail &JobDetail, const PCSystemParms &SystemParms)
  354. {
  355. CJobIDPage *pPage1 = new CJobIDPage(NULL, pContainer);
  356. if (pPage1)
  357. {
  358. pPage1->m_bJob = JobDetail.base.jobName;
  359. pPage1->m_bComment = JobDetail.base.mgmtParms.description;
  360. pPage1->m_processcountchk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_COUNT_LIMIT );
  361. pPage1->m_processcount = JobDetail.base.mgmtParms.procCountLimit;
  362. lpProvider->AddPage(pPage1->Create());
  363. }
  364. CMGMTAffinityPage *pPage2 = new CMGMTAffinityPage(NULL, pContainer, SystemParms.processorMask);
  365. if (pPage2)
  366. {
  367. pPage2->m_affinitychk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_AFFINITY);
  368. pPage2->m_affinity = JobDetail.base.mgmtParms.affinity;
  369. lpProvider->AddPage(pPage2->Create());
  370. }
  371. CMGMTPriorityPage *pPage3 = new CMGMTPriorityPage(NULL, pContainer);
  372. if (pPage3)
  373. {
  374. pPage3->m_prioritychk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_PRIORITY);
  375. pPage3->m_priority = JobDetail.base.mgmtParms.priority;
  376. lpProvider->AddPage(pPage3->Create());
  377. }
  378. CMGMTSchedulingClassPage *pPage4 = new CMGMTSchedulingClassPage(NULL, pContainer);
  379. if (pPage4)
  380. {
  381. pPage4->m_schedClasschk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_SCHEDULING_CLASS);
  382. pPage4->m_schedClass = JobDetail.base.mgmtParms.schedClass;
  383. lpProvider->AddPage(pPage4->Create());
  384. }
  385. CMGMTMemoryPage *pPage5 = new CMGMTMemoryPage(NULL, pContainer);
  386. if (pPage5)
  387. {
  388. pPage5->m_WSchk =(JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_WS_MINMAX);
  389. pPage5->m_minWS = JobDetail.base.mgmtParms.minWS;
  390. pPage5->m_maxWS = JobDetail.base.mgmtParms.maxWS;
  391. pPage5->m_procmemorylimitchk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_MEMORY_LIMIT);
  392. pPage5->m_procmemorylimit = JobDetail.base.mgmtParms.procMemoryLimit;
  393. pPage5->m_jobmemorylimitchk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_MEMORY_LIMIT);
  394. pPage5->m_jobmemorylimit = JobDetail.base.mgmtParms.jobMemoryLimit;
  395. lpProvider->AddPage(pPage5->Create());
  396. }
  397. CMGMTTimePage *pPage6 = new CMGMTTimePage(NULL, pContainer);
  398. if (pPage6)
  399. {
  400. pPage6->m_procusertimechk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_PROC_TIME_LIMIT);
  401. pPage6->m_procusertime = JobDetail.base.mgmtParms.procTimeLimitCNS;
  402. pPage6->m_jobusertimechk = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_APPLY_JOB_TIME_LIMIT);
  403. pPage6->m_jobusertime = JobDetail.base.mgmtParms.jobTimeLimitCNS;
  404. pPage6->m_jobmsgontimelimit = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_MSG_ON_JOB_TIME_LIMIT_HIT);
  405. lpProvider->AddPage(pPage6->Create());
  406. }
  407. CMGMTAdvancedPage *pPage7 = new CMGMTAdvancedPage(NULL, pContainer);
  408. if (pPage7)
  409. {
  410. pPage7->m_endjob = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_END_JOB_WHEN_EMPTY );
  411. pPage7->m_unhandledexcept = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_SET_DIE_ON_UH_EXCEPTION );
  412. pPage7->m_breakaway = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_SET_PROC_BREAKAWAY_OK );
  413. pPage7->m_silentbreakaway = (JobDetail.base.mgmtParms.mFlags & PCMFLAG_SET_SILENT_BREAKAWAY );
  414. lpProvider->AddPage(pPage7->Create());
  415. }
  416. return S_OK;
  417. }
  418. #if _MSC_VER >= 1200
  419. #pragma warning( pop )
  420. #endif