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.

533 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // WaitDlg.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CWaitDlg class.
  10. //
  11. // Author:
  12. // David Potter (davidp) 07-NOV-2000
  13. //
  14. // Notes:
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "StdAfx.h"
  18. #include "CluAdmin.h"
  19. #include "WaitDlg.h"
  20. #include "ExcOper.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Constant Definitions
  28. /////////////////////////////////////////////////////////////////////////////
  29. #define WAIT_DLG_TIMER_ID 10
  30. #define WAIT_DLG_WAIT_TIME 500
  31. #define WAIT_DLG_SKIP_COUNT 6
  32. #define PROGRESS_ICON_COUNT 12
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CWaitDlg dialog
  35. /////////////////////////////////////////////////////////////////////////////
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Message Maps
  38. /////////////////////////////////////////////////////////////////////////////
  39. BEGIN_MESSAGE_MAP( CWaitDlg, CDialog )
  40. //{{AFX_MSG_MAP(CWaitDlg)
  41. ON_BN_CLICKED(IDCANCEL, OnCancel)
  42. ON_WM_CLOSE()
  43. ON_WM_TIMER()
  44. ON_COMMAND(IDCANCEL, OnClose)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. //++
  49. //
  50. // CWaitDlg::CWaitDlg
  51. //
  52. // Routine Description:
  53. // Default constructor.
  54. //
  55. // Arguments:
  56. // pcszMessageIn -- Message to display.
  57. // idsTitleIn -- Title of the dialog.
  58. // pwndParentIn -- Parent window for the dialog.
  59. //
  60. // Return Value:
  61. // None.
  62. //
  63. //--
  64. /////////////////////////////////////////////////////////////////////////////
  65. CWaitDlg::CWaitDlg(
  66. LPCTSTR pcszMessageIn,
  67. UINT idsTitleIn, // = 0
  68. CWnd * pwndParentIn // = NULL
  69. )
  70. : CDialog( IDD, pwndParentIn )
  71. , m_idsTitle( idsTitleIn )
  72. , m_nTickCounter( WAIT_DLG_SKIP_COUNT )
  73. , m_nTotalTickCount( 0 )
  74. , m_timerId( 0 )
  75. {
  76. //{{AFX_DATA_INIT(CWaitDlg)
  77. //}}AFX_DATA_INIT
  78. m_strMessage = pcszMessageIn;
  79. if ( m_idsTitle == 0 )
  80. {
  81. m_idsTitle = IDS_WAIT_TITLE;
  82. }
  83. } //*** CWaitDlg::CWaitDlg()
  84. /////////////////////////////////////////////////////////////////////////////
  85. //++
  86. //
  87. // CWaitDlg::DoDataExchange
  88. //
  89. // Routine Description:
  90. // Do data exchange between the dialog and the class.
  91. //
  92. // Arguments:
  93. // pDX [IN OUT] Data exchange object
  94. //
  95. // Return Value:
  96. // None.
  97. //
  98. //--
  99. /////////////////////////////////////////////////////////////////////////////
  100. void
  101. CWaitDlg::DoDataExchange( CDataExchange * pDX )
  102. {
  103. CDialog::DoDataExchange( pDX );
  104. //{{AFX_DATA_MAP(CWaitDlg)
  105. DDX_Control(pDX, IDC_W_MESSAGE, m_staticMessage);
  106. DDX_Control(pDX, IDC_W_PROGRESS, m_iconProgress);
  107. DDX_Text(pDX, IDC_W_MESSAGE, m_strMessage);
  108. //}}AFX_DATA_MAP
  109. } //*** CWaitDlg::DoDataExchange()
  110. /////////////////////////////////////////////////////////////////////////////
  111. //++
  112. //
  113. // CWaitDlg::OnInitDialog
  114. //
  115. // Routine Description:
  116. // Handler for the WM_INITDIALOG message.
  117. //
  118. // Arguments:
  119. // None.
  120. //
  121. // Return Value:
  122. // TRUE Focus not set yet.
  123. // FALSE Focus already set.
  124. //
  125. //--
  126. /////////////////////////////////////////////////////////////////////////////
  127. BOOL
  128. CWaitDlg::OnInitDialog(void)
  129. {
  130. CString strSubTitle;
  131. CDialog::OnInitDialog();
  132. // Start the timer.
  133. m_timerId = SetTimer( WAIT_DLG_TIMER_ID, WAIT_DLG_WAIT_TIME, NULL );
  134. // Set the title of the dialog.
  135. strSubTitle.LoadString( m_idsTitle );
  136. m_strTitle.Format( _T("%s - %s"), AfxGetApp()->m_pszAppName, strSubTitle );
  137. SetWindowText( m_strTitle );
  138. // Update the progress indicator.
  139. UpdateIndicator();
  140. return TRUE; // return TRUE unless you set the focus to a control
  141. // EXCEPTION: OCX Property Pages should return FALSE
  142. } //*** CWaitDlg::OnInitDialog()
  143. /////////////////////////////////////////////////////////////////////////////
  144. //++
  145. //
  146. // CWaitDlg::OnClose
  147. //
  148. // Routine Description:
  149. // Handler for the BN_CLICKED message on the Cancel push button and
  150. // for the WM_CLOSE message.
  151. //
  152. // Arguments:
  153. // None.
  154. //
  155. // Return Value:
  156. // None.
  157. //
  158. //--
  159. /////////////////////////////////////////////////////////////////////////////
  160. void
  161. CWaitDlg::OnClose( void )
  162. {
  163. CloseTimer();
  164. CDialog::OnClose();
  165. } //*** CWaitDlg::OnClose()
  166. /////////////////////////////////////////////////////////////////////////////
  167. //++
  168. //
  169. // CWaitDlg::CloseTimer
  170. //
  171. // Routine Description:
  172. // Close the timer down.
  173. //
  174. // Arguments:
  175. // None.
  176. //
  177. // Return Value:
  178. // None.
  179. //
  180. //--
  181. /////////////////////////////////////////////////////////////////////////////
  182. void
  183. CWaitDlg::CloseTimer( void )
  184. {
  185. if ( m_timerId != 0 )
  186. {
  187. KillTimer( m_timerId );
  188. } // if: timer is active
  189. m_timerId = 0;
  190. } //*** CWaitDlg::CloseTimer()
  191. /////////////////////////////////////////////////////////////////////////////
  192. //++
  193. //
  194. // CWaitDlg::OnTimer
  195. //
  196. // Routine Description:
  197. // Handler for the WM_TIMER message..
  198. //
  199. // Arguments:
  200. // nIDTimer
  201. //
  202. // Return Value:
  203. // None.
  204. //
  205. //--
  206. /////////////////////////////////////////////////////////////////////////////
  207. void
  208. CWaitDlg::OnTimer( UINT nIDTimer )
  209. {
  210. //
  211. // Don't do anything if it isn't our timer.
  212. //
  213. if ( nIDTimer != WAIT_DLG_TIMER_ID )
  214. goto Cleanup;
  215. //
  216. // Advance the progress indicator.
  217. //
  218. UpdateIndicator();
  219. //
  220. // No need to continue if we're just amusing the user.
  221. //
  222. if ( --m_nTickCounter > 0 )
  223. goto Cleanup;
  224. m_nTickCounter = WAIT_DLG_SKIP_COUNT;
  225. //
  226. // Check here to see if we can exit out.
  227. // This method is typically overridden.
  228. //
  229. OnTimerTick();
  230. Cleanup:
  231. return;
  232. } //*** CWaitDlg::OnTimer()
  233. /////////////////////////////////////////////////////////////////////////////
  234. //++
  235. //
  236. // CWaitDlg::UpdateIndicator
  237. //
  238. // Routine Description:
  239. // Update the indicator control.
  240. //
  241. // Arguments:
  242. // None.
  243. //
  244. // Return Value:
  245. // None.
  246. //
  247. //--
  248. /////////////////////////////////////////////////////////////////////////////
  249. void
  250. CWaitDlg::UpdateIndicator( void )
  251. {
  252. if ( m_nTotalTickCount % (1000 / WAIT_DLG_WAIT_TIME) == 0 )
  253. {
  254. int nTempTickCount = m_nTotalTickCount / (1000 / WAIT_DLG_WAIT_TIME);
  255. HICON hIcon;
  256. hIcon = AfxGetApp()->LoadIcon( IDI_PROGRESS_0 + (nTempTickCount % PROGRESS_ICON_COUNT) );
  257. m_iconProgress.SetIcon( hIcon );
  258. } // if: advancing to the next image
  259. m_nTotalTickCount++;
  260. } //*** CWaitDlg::UpdateIndicator()
  261. //*************************************************************************//
  262. /////////////////////////////////////////////////////////////////////////////
  263. // CWaitForResourceOfflineDlg dialog
  264. /////////////////////////////////////////////////////////////////////////////
  265. /////////////////////////////////////////////////////////////////////////////
  266. // Message Maps
  267. /////////////////////////////////////////////////////////////////////////////
  268. BEGIN_MESSAGE_MAP( CWaitForResourceOfflineDlg, CWaitDlg )
  269. //{{AFX_MSG_MAP(CWaitForResourceOfflineDlg)
  270. //}}AFX_MSG_MAP
  271. END_MESSAGE_MAP()
  272. /////////////////////////////////////////////////////////////////////////////
  273. //++
  274. //
  275. // CWaitForResourceOfflineDlg::CWaitForResourceOfflineDlg
  276. //
  277. // Routine Description:
  278. // Constructor.
  279. //
  280. // Arguments:
  281. // pResIn -- Resource to wait on.
  282. // pwndParentIn -- Parent window for the dialog.
  283. //
  284. // Return Value:
  285. // None.
  286. //
  287. //--
  288. /////////////////////////////////////////////////////////////////////////////
  289. CWaitForResourceOfflineDlg::CWaitForResourceOfflineDlg(
  290. CResource const * pResIn,
  291. CWnd * pwndParentIn // = NULL
  292. )
  293. : CWaitDlg( NULL, IDS_WAIT_FOR_OFFLINE_TITLE, pwndParentIn )
  294. , m_pRes( pResIn )
  295. {
  296. ASSERT( pResIn != NULL );
  297. //{{AFX_DATA_INIT(CWaitForResourceOfflineDlg)
  298. //}}AFX_DATA_INIT
  299. } //*** CWaitForResourceOfflineDlg::CWaitForResourceOfflineDlg()
  300. /////////////////////////////////////////////////////////////////////////////
  301. //++
  302. //
  303. // CWaitForResourceOfflineDlg::OnInitDialog
  304. //
  305. // Routine Description:
  306. // Handler for the WM_INITDIALOG message.
  307. //
  308. // Arguments:
  309. // None.
  310. //
  311. // Return Value:
  312. // TRUE Focus not set yet.
  313. // FALSE Focus already set.
  314. //
  315. //--
  316. /////////////////////////////////////////////////////////////////////////////
  317. BOOL
  318. CWaitForResourceOfflineDlg::OnInitDialog( void )
  319. {
  320. m_strMessage.Format( IDS_WAIT_FOR_OFFLINE_MESSAGE, m_pRes->StrName() );
  321. return CWaitDlg::OnInitDialog();
  322. } //*** CWaitForResourceOfflineDlg::OnInitDialog()
  323. /////////////////////////////////////////////////////////////////////////////
  324. //++
  325. //
  326. // CWaitForResourceOfflineDlg::OnTimerTick
  327. //
  328. // Routine Description:
  329. // Determine whether the timer should be terminated.
  330. //
  331. // Arguments:
  332. // None.
  333. //
  334. // Return Value:
  335. // None.
  336. //
  337. //--
  338. /////////////////////////////////////////////////////////////////////////////
  339. void
  340. CWaitForResourceOfflineDlg::OnTimerTick( void )
  341. {
  342. DWORD dwStatus;
  343. CLUSTER_RESOURCE_STATE crs;
  344. // Get the state of the resource in a loop until either the resource
  345. // is no longer in a pending state or the maximum number of retries
  346. // is exceeded.
  347. // Get the state of the resource.
  348. crs = GetClusterResourceState( m_pRes->Hresource(), NULL, NULL, NULL, NULL );
  349. if ( crs == ClusterResourceStateUnknown )
  350. {
  351. dwStatus = GetLastError();
  352. CloseTimer();
  353. CDialog::OnCancel();
  354. ThrowStaticException( dwStatus, IDS_GET_RESOURCE_STATE_ERROR, m_pRes->StrName() );
  355. } // if: error getting resource state
  356. // See if we reached a stable state.
  357. if ( crs < ClusterResourcePending )
  358. {
  359. CloseTimer();
  360. CDialog::OnOK();
  361. }
  362. } //*** CWaitForResourceOfflineDlg::OnTimerTick()
  363. //*************************************************************************//
  364. /////////////////////////////////////////////////////////////////////////////
  365. // CWaitForResourceOnlineDlg dialog
  366. /////////////////////////////////////////////////////////////////////////////
  367. /////////////////////////////////////////////////////////////////////////////
  368. // Message Maps
  369. /////////////////////////////////////////////////////////////////////////////
  370. BEGIN_MESSAGE_MAP( CWaitForResourceOnlineDlg, CWaitDlg )
  371. //{{AFX_MSG_MAP(CWaitForResourceOnlineDlg)
  372. //}}AFX_MSG_MAP
  373. END_MESSAGE_MAP()
  374. /////////////////////////////////////////////////////////////////////////////
  375. //++
  376. //
  377. // CWaitForResourceOnlineDlg::CWaitForResourceOnlineDlg
  378. //
  379. // Routine Description:
  380. // Constructor.
  381. //
  382. // Arguments:
  383. // pResIn -- Resource to wait on.
  384. // pwndParentIn -- Parent window for the dialog.
  385. //
  386. // Return Value:
  387. // None.
  388. //
  389. //--
  390. /////////////////////////////////////////////////////////////////////////////
  391. CWaitForResourceOnlineDlg::CWaitForResourceOnlineDlg(
  392. CResource const * pResIn,
  393. CWnd * pwndParentIn // = NULL
  394. )
  395. : CWaitDlg( NULL, IDS_WAIT_FOR_ONLINE_TITLE, pwndParentIn )
  396. , m_pRes( pResIn )
  397. {
  398. ASSERT( pResIn != NULL );
  399. //{{AFX_DATA_INIT(CWaitForResourceOnlineDlg)
  400. //}}AFX_DATA_INIT
  401. } //*** CWaitForResourceOnlineDlg::CWaitForResourceOnlineDlg()
  402. /////////////////////////////////////////////////////////////////////////////
  403. //++
  404. //
  405. // CWaitForResourceOnlineDlg::OnInitDialog
  406. //
  407. // Routine Description:
  408. // Handler for the WM_INITDIALOG message.
  409. //
  410. // Arguments:
  411. // None.
  412. //
  413. // Return Value:
  414. // TRUE Focus not set yet.
  415. // FALSE Focus already set.
  416. //
  417. //--
  418. /////////////////////////////////////////////////////////////////////////////
  419. BOOL
  420. CWaitForResourceOnlineDlg::OnInitDialog( void )
  421. {
  422. m_strMessage.Format( IDS_WAIT_FOR_ONLINE_MESSAGE, m_pRes->StrName() );
  423. return CWaitDlg::OnInitDialog();
  424. } //*** CWaitForResourceOnlineDlg::OnInitDialog()
  425. /////////////////////////////////////////////////////////////////////////////
  426. //++
  427. //
  428. // CWaitForResourceOnlineDlg::OnTimerTick
  429. //
  430. // Routine Description:
  431. // Determine whether the timer should be terminated.
  432. //
  433. // Arguments:
  434. // None.
  435. //
  436. // Return Value:
  437. // None.
  438. //
  439. //--
  440. /////////////////////////////////////////////////////////////////////////////
  441. void
  442. CWaitForResourceOnlineDlg::OnTimerTick( void )
  443. {
  444. DWORD dwStatus;
  445. CLUSTER_RESOURCE_STATE crs;
  446. // Get the state of the resource in a loop until either the resource
  447. // is no longer in a pending state or the maximum number of retries
  448. // is exceeded.
  449. // Get the state of the resource.
  450. crs = GetClusterResourceState( m_pRes->Hresource(), NULL, NULL, NULL, NULL );
  451. if ( crs == ClusterResourceStateUnknown )
  452. {
  453. dwStatus = GetLastError();
  454. CloseTimer();
  455. CDialog::OnCancel();
  456. ThrowStaticException( dwStatus, IDS_GET_RESOURCE_STATE_ERROR, m_pRes->StrName() );
  457. } // if: error getting resource state
  458. // See if we reached a stable state.
  459. if ( crs < ClusterResourcePending )
  460. {
  461. CloseTimer();
  462. CDialog::OnOK();
  463. }
  464. } //*** CWaitForResourceOnlineDlg::OnTimerTick()