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.

1272 lines
26 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmsesst.cpp
  5. Abstract:
  6. This class is the phase component, which keeps track the status/totals for a phase of a
  7. session.
  8. Author:
  9. Chuck Bardeen [cbardeen] 14-Feb-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "wsb.h"
  14. #include "job.h"
  15. #include "hsmphase.h"
  16. #define WSB_TRACE_IS WSB_TRACE_BIT_JOB
  17. static USHORT iCount = 0;
  18. HRESULT
  19. CHsmPhase::AddItem(
  20. IN IFsaScanItem* pItem,
  21. IN HRESULT hrItem
  22. )
  23. /*++
  24. Implements:
  25. IHsmPhasePriv::AddItem().
  26. --*/
  27. {
  28. HRESULT hr = S_OK;
  29. LONGLONG size;
  30. WsbTraceIn(OLESTR("CHsmPhase::AddItem"), OLESTR(""));
  31. try {
  32. // Did they give us a valid item to compare to?
  33. WsbAssert(0 != pItem, E_POINTER);
  34. // Get the size of the file.
  35. WsbAffirmHr(pItem->GetLogicalSize(&size));
  36. // Update the appropriate stats.
  37. switch (hrItem) {
  38. case S_OK:
  39. m_items++;
  40. m_size += size;
  41. break;
  42. case S_FALSE:
  43. case JOB_E_FILEEXCLUDED:
  44. case JOB_E_DOESNTMATCH:
  45. case FSA_E_REPARSE_NOT_WRITTEN_FILE_CHANGED:
  46. case HSM_E_FILE_CHANGED:
  47. m_skippedItems++;
  48. m_skippedSize += size;
  49. break;
  50. default:
  51. m_errorItems++;
  52. m_errorSize += size;
  53. break;
  54. }
  55. } WsbCatch(hr);
  56. WsbTraceOut(OLESTR("CHsmPhase::AddItem"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  57. return(hr);
  58. }
  59. HRESULT
  60. CHsmPhase::Clone(
  61. OUT IHsmPhase** ppPhase
  62. )
  63. /*++
  64. Implements:
  65. IHsmPhase::Clone().
  66. --*/
  67. {
  68. HRESULT hr = S_OK;
  69. CComPtr<IHsmPhase> pPhase;
  70. WsbTraceIn(OLESTR("CHsmPhase::Clone"), OLESTR(""));
  71. try {
  72. // Did they give us a valid item?
  73. WsbAssert(0 != ppPhase, E_POINTER);
  74. *ppPhase = 0;
  75. // Create the new instance.
  76. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhase, (void**) &pPhase));
  77. // Fill it in with the new values.
  78. WsbAffirmHr(CopyTo(pPhase));
  79. // Return it to the caller.
  80. *ppPhase = pPhase;
  81. pPhase->AddRef();
  82. } WsbCatch(hr);
  83. WsbTraceOut(OLESTR("CHsmPhase::Clone"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  84. return(hr);
  85. }
  86. HRESULT
  87. CHsmPhase::Clone(
  88. OUT IHsmPhasePriv** ppPhasePriv
  89. )
  90. /*++
  91. Implements:
  92. IHsmPhasePriv::Clone().
  93. --*/
  94. {
  95. HRESULT hr = S_OK;
  96. CComPtr<IHsmPhasePriv> pPhasePriv;
  97. WsbTraceIn(OLESTR("CHsmPhase::Clone"), OLESTR(""));
  98. try {
  99. // Did they give us a valid item?
  100. WsbAssert(0 != ppPhasePriv, E_POINTER);
  101. *ppPhasePriv = 0;
  102. // Create the new instance.
  103. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  104. // Fill it in with the new values.
  105. WsbAffirmHr(CopyTo(pPhasePriv));
  106. // Return it to the caller.
  107. *ppPhasePriv = pPhasePriv;
  108. pPhasePriv->AddRef();
  109. } WsbCatch(hr);
  110. WsbTraceOut(OLESTR("CHsmPhase::Clone"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  111. return(hr);
  112. }
  113. HRESULT
  114. CHsmPhase::CompareTo(
  115. IN IUnknown* pUnknown,
  116. OUT SHORT* pResult
  117. )
  118. /*++
  119. Implements:
  120. IWsbCollectable::CompareTo().
  121. --*/
  122. {
  123. HRESULT hr = S_OK;
  124. CComPtr<IHsmPhase> pPhase;
  125. WsbTraceIn(OLESTR("CHsmPhase::CompareTo"), OLESTR(""));
  126. try {
  127. // Did they give us a valid item to compare to?
  128. WsbAssert(0 != pUnknown, E_POINTER);
  129. // We need the IWsbBool interface to get the value of the object.
  130. WsbAffirmHr(pUnknown->QueryInterface(IID_IHsmPhase, (void**) &pPhase));
  131. // Compare the rules.
  132. hr = CompareToIPhase(pPhase, pResult);
  133. } WsbCatch(hr);
  134. WsbTraceOut(OLESTR("CHsmPhase::CompareTo"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  135. return(hr);
  136. }
  137. HRESULT
  138. CHsmPhase::CompareToPhase(
  139. IN HSM_JOB_PHASE phase,
  140. OUT SHORT* pResult
  141. )
  142. /*++
  143. Implements:
  144. IHsmPhase::CompareToPhase().
  145. --*/
  146. {
  147. HRESULT hr = S_OK;
  148. SHORT aResult = 0;
  149. WsbTraceIn(OLESTR("CHsmPhase::CompareToPhase"), OLESTR(""));
  150. try {
  151. // Compare the guids.
  152. if (m_phase > phase) {
  153. aResult = 1;
  154. }
  155. else if (m_phase < phase) {
  156. aResult = -1;
  157. }
  158. if (0 != aResult) {
  159. hr = S_FALSE;
  160. }
  161. if (0 != pResult) {
  162. *pResult = aResult;
  163. }
  164. } WsbCatch(hr);
  165. WsbTraceOut(OLESTR("CHsmPhase::CompareToPhase"), OLESTR("hr = <%ls>, result = <%d>"), WsbHrAsString(hr), aResult);
  166. return(hr);
  167. }
  168. HRESULT
  169. CHsmPhase::CompareToIPhase(
  170. IN IHsmPhase* pPhase,
  171. OUT SHORT* pResult
  172. )
  173. /*++
  174. Implements:
  175. IHsmPhase::CompareToIPhase().
  176. --*/
  177. {
  178. HRESULT hr = S_OK;
  179. HSM_JOB_PHASE phase;
  180. WsbTraceIn(OLESTR("CHsmPhase::CompareToIPhase"), OLESTR(""));
  181. try {
  182. // Did they give us a valid item to compare to?
  183. WsbAssert(0 != pPhase, E_POINTER);
  184. // Get the identifier.
  185. WsbAffirmHr(pPhase->GetPhase(&phase));
  186. // Compare to the identifier.
  187. hr = CompareToPhase(phase, pResult);
  188. } WsbCatch(hr);
  189. WsbTraceOut(OLESTR("CHsmPhase::CompareToIPhase"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  190. return(hr);
  191. }
  192. HRESULT
  193. CHsmPhase::CopyTo(
  194. IN IHsmPhase* pPhase
  195. )
  196. /*++
  197. Implements:
  198. IHsmPhase::CopyTo().
  199. --*/
  200. {
  201. HRESULT hr = S_OK;
  202. CComPtr<IHsmPhasePriv> pPhasePriv;
  203. WsbTraceIn(OLESTR("CHsmPhase::CopyTo"), OLESTR(""));
  204. try {
  205. // Did they give us a valid item?
  206. WsbAssert(0 != pPhase, E_POINTER);
  207. // Get the private interface for the destination and copy the values.
  208. WsbAffirmHr(pPhase->QueryInterface(IID_IHsmPhasePriv, (void**) &pPhasePriv));
  209. WsbAffirmHr(pPhasePriv->SetInternalStuff(m_mountCount, m_transferCount, m_elapsedTime, m_startTime, m_restartTime, m_stopTime));
  210. WsbAffirmHr(pPhasePriv->SetMediaState(m_mediaState));
  211. WsbAffirmHr(pPhasePriv->SetPhase(m_phase));
  212. WsbAffirmHr(pPhasePriv->SetPriority(m_priority));
  213. WsbAffirmHr(pPhasePriv->SetState(m_state));
  214. WsbAffirmHr(pPhasePriv->SetStats(m_items, m_size, m_skippedItems, m_skippedSize, m_errorItems, m_errorSize));
  215. } WsbCatch(hr);
  216. WsbTraceOut(OLESTR("CHsmPhase::CopyTo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  217. return(hr);
  218. }
  219. HRESULT
  220. CHsmPhase::CopyTo(
  221. IN IHsmPhasePriv* pPhasePriv
  222. )
  223. /*++
  224. Implements:
  225. IHsmPhase::CopyTo().
  226. --*/
  227. {
  228. HRESULT hr = S_OK;
  229. WsbTraceIn(OLESTR("CHsmPhase::CopyTo"), OLESTR(""));
  230. try {
  231. // Did they give us a valid item?
  232. WsbAssert(0 != pPhasePriv, E_POINTER);
  233. // Get the private interface for the destination and copy the values.
  234. WsbAffirmHr(pPhasePriv->SetInternalStuff(m_mountCount, m_transferCount, m_elapsedTime, m_startTime, m_restartTime, m_stopTime));
  235. WsbAffirmHr(pPhasePriv->SetMediaState(m_mediaState));
  236. WsbAffirmHr(pPhasePriv->SetPhase(m_phase));
  237. WsbAffirmHr(pPhasePriv->SetPriority(m_priority));
  238. WsbAffirmHr(pPhasePriv->SetState(m_state));
  239. WsbAffirmHr(pPhasePriv->SetStats(m_items, m_size, m_skippedItems, m_skippedSize, m_errorItems, m_errorSize));
  240. } WsbCatch(hr);
  241. WsbTraceOut(OLESTR("CHsmPhase::CopyTo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  242. return(hr);
  243. }
  244. HRESULT
  245. CHsmPhase::FinalConstruct(
  246. void
  247. )
  248. /*++
  249. Implements:
  250. CComObjectRoot::FinalConstruct().
  251. --*/
  252. {
  253. HRESULT hr = S_OK;
  254. WsbTraceIn(OLESTR("CHsmPhase::FinalConstruct"), OLESTR(""));
  255. try {
  256. WsbAffirmHr(CWsbObject::FinalConstruct());
  257. m_mediaState = HSM_JOB_MEDIA_STATE_IDLE;
  258. m_mountCount = 0;
  259. m_transferCount = 0;
  260. m_phase = HSM_JOB_PHASE_ALL;
  261. m_priority = HSM_JOB_PRIORITY_NORMAL;
  262. m_state = HSM_JOB_STATE_IDLE;
  263. m_items = 0;
  264. m_size = 0;
  265. m_skippedItems = 0;
  266. m_skippedSize = 0;
  267. m_errorItems = 0;
  268. m_errorSize = 0;
  269. m_elapsedTime = 0;
  270. m_startTime.dwLowDateTime = 0;
  271. m_startTime.dwHighDateTime = 0;
  272. m_restartTime.dwLowDateTime = 0;
  273. m_restartTime.dwHighDateTime = 0;
  274. m_stopTime.dwLowDateTime = 0;
  275. m_stopTime.dwHighDateTime = 0;
  276. } WsbCatch(hr);
  277. iCount++;
  278. WsbTraceOut(OLESTR("CHsmPhase::FinalConstruct"), OLESTR("hr = <%ls>, count is <%d>"), WsbHrAsString(hr), iCount);
  279. return(hr);
  280. }
  281. void
  282. CHsmPhase::FinalRelease(
  283. void
  284. )
  285. /*++
  286. Implements:
  287. CHsmPhase::FinalRelease().
  288. --*/
  289. {
  290. WsbTraceIn(OLESTR("CHsmPhase::FinalRelease"), OLESTR(""));
  291. CWsbObject::FinalRelease();
  292. iCount--;
  293. WsbTraceOut(OLESTR("CHsmPhase::FinalRelease"), OLESTR("Count is <%d>"), iCount);
  294. }
  295. HRESULT
  296. CHsmPhase::GetClassID(
  297. OUT CLSID* pClsid
  298. )
  299. /*++
  300. Implements:
  301. IPersist::GetClassID().
  302. --*/
  303. {
  304. HRESULT hr = S_OK;
  305. WsbTraceIn(OLESTR("CHsmPhase::GetClassID"), OLESTR(""));
  306. try {
  307. WsbAssert(0 != pClsid, E_POINTER);
  308. *pClsid = CLSID_CHsmPhase;
  309. } WsbCatch(hr);
  310. WsbTraceOut(OLESTR("CHsmPhase::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  311. return(hr);
  312. }
  313. HRESULT
  314. CHsmPhase::GetElapsedTime(
  315. OUT ULONG* pDays,
  316. OUT USHORT* pHours,
  317. OUT USHORT* pMinutes,
  318. OUT USHORT* pSeconds
  319. )
  320. /*++
  321. Implements:
  322. IHsmPhase::GetElapsedTime().
  323. --*/
  324. {
  325. HRESULT hr = S_OK;
  326. LONGLONG remainingTime = 0;
  327. FILETIME currentTime;
  328. try {
  329. WsbAssert(0 != pDays, E_POINTER);
  330. WsbAssert(0 != pHours, E_POINTER);
  331. WsbAssert(0 != pMinutes, E_POINTER);
  332. WsbAssert(0 != pSeconds, E_POINTER);
  333. // If the phase is still active, then add the time since the last start or restart.
  334. remainingTime = m_elapsedTime;
  335. if (HSM_JOB_STATE_IS_ACTIVE(m_state)) {
  336. WsbAffirmHr(CoFileTimeNow(&currentTime));
  337. if (WsbFTtoLL(m_restartTime) != 0) {
  338. remainingTime += WsbFTtoLL(currentTime) - WsbFTtoLL(m_restartTime);
  339. } else {
  340. remainingTime += WsbFTtoLL(currentTime) - WsbFTtoLL(m_startTime);
  341. }
  342. }
  343. *pDays = (ULONG) (remainingTime / WSB_FT_TICKS_PER_DAY);
  344. remainingTime = remainingTime % WSB_FT_TICKS_PER_DAY;
  345. *pHours = (USHORT) (remainingTime / (WSB_FT_TICKS_PER_HOUR));
  346. remainingTime = remainingTime % WSB_FT_TICKS_PER_HOUR;
  347. *pMinutes = (USHORT) (remainingTime / WSB_FT_TICKS_PER_MINUTE);
  348. *pSeconds = (USHORT) ((remainingTime % WSB_FT_TICKS_PER_MINUTE) / WSB_FT_TICKS_PER_SECOND);
  349. } WsbCatch(hr);
  350. return(hr);
  351. }
  352. HRESULT
  353. CHsmPhase::GetMediaState(
  354. OUT HSM_JOB_MEDIA_STATE* pState
  355. )
  356. /*++
  357. Implements:
  358. IHsmPhase::GetMediaState().
  359. --*/
  360. {
  361. HRESULT hr = S_OK;
  362. try {
  363. WsbAssert(0 != pState, E_POINTER);
  364. *pState = m_mediaState;
  365. } WsbCatch(hr);
  366. return(hr);
  367. }
  368. HRESULT
  369. CHsmPhase::GetMediaStateAsString(
  370. OUT OLECHAR** pName,
  371. IN ULONG bufferSize
  372. )
  373. /*++
  374. Implements:
  375. IHsmPhase::GetMediaStateAsString().
  376. --*/
  377. {
  378. HRESULT hr = S_OK;
  379. CWsbStringPtr tmpString;
  380. try {
  381. WsbAssert(0 != pName, E_POINTER);
  382. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBMEDIASTATEIDLE + m_mediaState));
  383. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  384. } WsbCatch(hr);
  385. return(hr);
  386. }
  387. HRESULT
  388. CHsmPhase::GetName(
  389. OUT OLECHAR** pName,
  390. IN ULONG bufferSize
  391. )
  392. /*++
  393. Implements:
  394. IHsmPhase::GetName().
  395. --*/
  396. {
  397. HRESULT hr = S_OK;
  398. CWsbStringPtr tmpString;
  399. try {
  400. WsbAssert(0 != pName, E_POINTER);
  401. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBPHASEALL + m_phase));
  402. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  403. } WsbCatch(hr);
  404. return(hr);
  405. }
  406. HRESULT
  407. CHsmPhase::GetPhase(
  408. OUT HSM_JOB_PHASE* pPhase
  409. )
  410. /*++
  411. Implements:
  412. IHsmPhase::GetPhase().
  413. --*/
  414. {
  415. HRESULT hr = S_OK;
  416. try {
  417. WsbAssert(0 != pPhase, E_POINTER);
  418. *pPhase = m_phase;
  419. } WsbCatch(hr);
  420. return(hr);
  421. }
  422. HRESULT
  423. CHsmPhase::GetPriority(
  424. OUT HSM_JOB_PRIORITY* pPriority
  425. )
  426. /*++
  427. Implements:
  428. IHsmPhase::GetPriority().
  429. --*/
  430. {
  431. HRESULT hr = S_OK;
  432. try {
  433. WsbAssert(0 != pPriority, E_POINTER);
  434. *pPriority = m_priority;
  435. } WsbCatch(hr);
  436. return(hr);
  437. }
  438. HRESULT
  439. CHsmPhase::GetPriorityAsString(
  440. OUT OLECHAR** pName,
  441. IN ULONG bufferSize
  442. )
  443. /*++
  444. Implements:
  445. IHsmPhase::GetPriorityAsString().
  446. --*/
  447. {
  448. HRESULT hr = S_OK;
  449. CWsbStringPtr tmpString;
  450. try {
  451. WsbAssert(0 != pName, E_POINTER);
  452. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBPRIORITY_IDLE + m_priority));
  453. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  454. } WsbCatch(hr);
  455. return(hr);
  456. }
  457. HRESULT
  458. CHsmPhase::GetSizeMax(
  459. OUT ULARGE_INTEGER* pSize
  460. )
  461. /*++
  462. Implements:
  463. IPersistStream::GetSizeMax().
  464. --*/
  465. {
  466. HRESULT hr = S_OK;
  467. WsbTraceIn(OLESTR("CHsmPhase::GetSizeMax"), OLESTR(""));
  468. try {
  469. WsbAssert(0 != pSize, E_POINTER);
  470. // Determine the size for a rule with no criteria.
  471. pSize->QuadPart = 5 * WsbPersistSizeOf(LONGLONG) + 6 * WsbPersistSizeOf(ULONG) + 3 * WsbPersistSizeOf(FILETIME);
  472. // In theory we should be saving the errorItems and errorSize, but at the
  473. // time this was added, we didn't want to force a reinstall because of
  474. // pSize->QuadPart += 2 * WsbPersistSizeOf(LONGLONG);
  475. } WsbCatch(hr);
  476. WsbTraceOut(OLESTR("CHsmPhase::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pSize));
  477. return(hr);
  478. }
  479. HRESULT
  480. CHsmPhase::GetStartTime(
  481. OUT FILETIME* pTime
  482. )
  483. /*++
  484. Implements:
  485. IHsmPhase::GetStartTime().
  486. --*/
  487. {
  488. HRESULT hr = S_OK;
  489. try {
  490. WsbAssert(0 != pTime, E_POINTER);
  491. *pTime = m_startTime;
  492. } WsbCatch(hr);
  493. return(hr);
  494. }
  495. HRESULT
  496. CHsmPhase::GetState(
  497. OUT HSM_JOB_STATE* pState
  498. )
  499. /*++
  500. Implements:
  501. IHsmPhase::GetState().
  502. --*/
  503. {
  504. HRESULT hr = S_OK;
  505. try {
  506. WsbAssert(0 != pState, E_POINTER);
  507. *pState = m_state;
  508. } WsbCatch(hr);
  509. return(hr);
  510. }
  511. HRESULT
  512. CHsmPhase::GetStateAsString(
  513. OUT OLECHAR** pName,
  514. IN ULONG bufferSize
  515. )
  516. /*++
  517. Implements:
  518. IHsmPhase::GetStateAsString().
  519. --*/
  520. {
  521. HRESULT hr = S_OK;
  522. CWsbStringPtr tmpString;
  523. try {
  524. WsbAssert(0 != pName, E_POINTER);
  525. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBSTATEACTIVE + m_state));
  526. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  527. } WsbCatch(hr);
  528. return(hr);
  529. }
  530. HRESULT
  531. CHsmPhase::GetStats(
  532. OUT LONGLONG* pItems,
  533. OUT LONGLONG* pSize,
  534. OUT LONGLONG* pSkippedItems,
  535. OUT LONGLONG* pSkippedSize,
  536. OUT LONGLONG* pErrorItems,
  537. OUT LONGLONG* pErrorSize
  538. )
  539. /*++
  540. Implements:
  541. IHsmPhase::GetStats().
  542. --*/
  543. {
  544. HRESULT hr = S_OK;
  545. if (0 != pItems) {
  546. *pItems = m_items;
  547. }
  548. if (0 != pSize) {
  549. *pSize = m_size;
  550. }
  551. if (0 != pSkippedItems) {
  552. *pSkippedItems = m_skippedItems;
  553. }
  554. if (0 != pSkippedSize) {
  555. *pSkippedSize = m_skippedSize;
  556. }
  557. if (0 != pErrorItems) {
  558. *pErrorItems = m_errorItems;
  559. }
  560. if (0 != pSize) {
  561. *pErrorSize = m_errorSize;
  562. }
  563. return(hr);
  564. }
  565. HRESULT
  566. CHsmPhase::GetStopTime(
  567. OUT FILETIME* pTime
  568. )
  569. /*++
  570. Implements:
  571. IHsmPhase::GetStopTime().
  572. --*/
  573. {
  574. HRESULT hr = S_OK;
  575. try {
  576. WsbAssert(0 != pTime, E_POINTER);
  577. *pTime = m_stopTime;
  578. } WsbCatch(hr);
  579. return(hr);
  580. }
  581. HRESULT
  582. CHsmPhase::Load(
  583. IN IStream* pStream
  584. )
  585. /*++
  586. Implements:
  587. IPersistStream::Load().
  588. --*/
  589. {
  590. HRESULT hr = S_OK;
  591. WsbTraceIn(OLESTR("CHsmPhase::Load"), OLESTR(""));
  592. try {
  593. ULONG ul_tmp;
  594. WsbAssert(0 != pStream, E_POINTER);
  595. // Do the easy stuff, but make sure that this order matches the order
  596. // in the load method.
  597. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  598. m_mediaState = static_cast<HSM_JOB_MEDIA_STATE>(ul_tmp);
  599. WsbAffirmHr(WsbLoadFromStream(pStream, &m_mountCount));
  600. WsbAffirmHr(WsbLoadFromStream(pStream, &m_transferCount));
  601. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  602. m_phase = static_cast<HSM_JOB_PHASE>(ul_tmp);
  603. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  604. m_priority = static_cast<HSM_JOB_PRIORITY>(ul_tmp);
  605. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  606. m_state = static_cast<HSM_JOB_STATE>(ul_tmp);
  607. WsbAffirmHr(WsbLoadFromStream(pStream, &m_items));
  608. WsbAffirmHr(WsbLoadFromStream(pStream, &m_size));
  609. WsbAffirmHr(WsbLoadFromStream(pStream, &m_skippedItems));
  610. WsbAffirmHr(WsbLoadFromStream(pStream, &m_skippedSize));
  611. WsbAffirmHr(WsbLoadFromStream(pStream, &m_elapsedTime));
  612. WsbAffirmHr(WsbLoadFromStream(pStream, &m_startTime));
  613. WsbAffirmHr(WsbLoadFromStream(pStream, &m_restartTime));
  614. WsbAffirmHr(WsbLoadFromStream(pStream, &m_stopTime));
  615. // In theory we should be saving the errorItems and errorSize, but at the
  616. // time this was added, we didn't want to force a reinstall because of
  617. // changes in the persistant data.
  618. // WsbAffirmHr(WsbLoadFromStream(pStream, &m_errorItems));
  619. // WsbAffirmHr(WsbLoadFromStream(pStream, &m_errorSize));
  620. } WsbCatch(hr);
  621. WsbTraceOut(OLESTR("CHsmPhase::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  622. return(hr);
  623. }
  624. HRESULT
  625. CHsmPhase::Save(
  626. IN IStream* pStream,
  627. IN BOOL clearDirty
  628. )
  629. /*++
  630. Implements:
  631. IPersistStream::Save().
  632. --*/
  633. {
  634. HRESULT hr = S_OK;
  635. WsbTraceIn(OLESTR("CHsmPhase::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  636. try {
  637. WsbAssert(0 != pStream, E_POINTER);
  638. // Do the easy stuff, but make sure that this order matches the order
  639. // in the load method.
  640. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_mediaState)));
  641. WsbAffirmHr(WsbSaveToStream(pStream, m_mountCount));
  642. WsbAffirmHr(WsbSaveToStream(pStream, m_transferCount));
  643. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_phase)));
  644. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_priority)));
  645. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_state)));
  646. WsbAffirmHr(WsbSaveToStream(pStream, m_items));
  647. WsbAffirmHr(WsbSaveToStream(pStream, m_size));
  648. WsbAffirmHr(WsbSaveToStream(pStream, m_skippedItems));
  649. WsbAffirmHr(WsbSaveToStream(pStream, m_skippedSize));
  650. WsbAffirmHr(WsbSaveToStream(pStream, m_elapsedTime));
  651. WsbAffirmHr(WsbSaveToStream(pStream, m_startTime));
  652. WsbAffirmHr(WsbSaveToStream(pStream, m_restartTime));
  653. WsbAffirmHr(WsbSaveToStream(pStream, m_stopTime));
  654. // In theory we should be saving the errorItems and errorSize, but at the
  655. // time this was added, we didn't want to force a reinstall because of
  656. // changes in the persistant data.
  657. // WsbAffirmHr(WsbSaveToStream(pStream, m_errorItems));
  658. // WsbAffirmHr(WsbSaveToStream(pStream, m_errorSize));
  659. // If we got it saved and we were asked to clear the dirty bit, then
  660. // do so now.
  661. if (clearDirty) {
  662. m_isDirty = FALSE;
  663. }
  664. } WsbCatch(hr);
  665. WsbTraceOut(OLESTR("CHsmPhase::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  666. return(hr);
  667. }
  668. HRESULT
  669. CHsmPhase::SetInternalStuff(
  670. IN ULONG mountCount,
  671. IN ULONG transferCount,
  672. IN LONGLONG elapsedTime,
  673. IN FILETIME startTime,
  674. IN FILETIME restartTime,
  675. IN FILETIME stopTime
  676. )
  677. /*++
  678. Implements:
  679. IHsmPhasePriv::SetInternalStuff().
  680. --*/
  681. {
  682. m_mountCount = mountCount;
  683. m_transferCount = transferCount;
  684. m_elapsedTime = elapsedTime;
  685. m_startTime = startTime;
  686. m_restartTime = restartTime;
  687. m_stopTime = stopTime;
  688. return(S_OK);
  689. }
  690. HRESULT
  691. CHsmPhase::SetMediaState(
  692. IN HSM_JOB_MEDIA_STATE state
  693. )
  694. /*++
  695. Implements:
  696. IHsmPhasePriv::SetMediaState().
  697. --*/
  698. {
  699. HRESULT hr = S_OK;
  700. // Determine whether the state being reported will cause the overall state to
  701. // change. The overall state should be mounted/transferring/transferred if any
  702. // media are mounted.
  703. switch (state) {
  704. case HSM_JOB_MEDIA_STATE_BUSY:
  705. case HSM_JOB_MEDIA_STATE_UNAVAILABLE:
  706. if ((HSM_JOB_MEDIA_STATE_IDLE == m_mediaState) ||
  707. (HSM_JOB_MEDIA_STATE_MOUNTING == m_mediaState)) {
  708. m_mediaState = state;
  709. }
  710. break;
  711. case HSM_JOB_MEDIA_STATE_MOUNTING:
  712. if ((HSM_JOB_MEDIA_STATE_MOUNTED != m_mediaState) &&
  713. (HSM_JOB_MEDIA_STATE_TRANSFERRED != m_mediaState) &&
  714. (HSM_JOB_MEDIA_STATE_TRANSFERRING != m_mediaState)) {
  715. m_mediaState = state;
  716. }
  717. break;
  718. case HSM_JOB_MEDIA_STATE_MOUNTED:
  719. if ((HSM_JOB_MEDIA_STATE_MOUNTED != m_mediaState) &&
  720. (HSM_JOB_MEDIA_STATE_TRANSFERRED != m_mediaState) &&
  721. (HSM_JOB_MEDIA_STATE_TRANSFERRING != m_mediaState)) {
  722. m_mediaState = state;
  723. }
  724. m_mountCount++;
  725. break;
  726. case HSM_JOB_MEDIA_STATE_TRANSFERRING:
  727. if ((HSM_JOB_MEDIA_STATE_TRANSFERRING != m_mediaState) &&
  728. (HSM_JOB_MEDIA_STATE_TRANSFERRED != m_mediaState)) {
  729. m_mediaState = state;
  730. }
  731. m_transferCount++;
  732. break;
  733. case HSM_JOB_MEDIA_STATE_TRANSFERRED:
  734. if (m_transferCount <= 1) {
  735. m_mediaState = state;
  736. }
  737. m_transferCount--;
  738. break;
  739. case HSM_JOB_MEDIA_STATE_DISMOUNTING:
  740. if (m_mountCount <= 1) {
  741. m_mediaState = state;
  742. }
  743. break;
  744. case HSM_JOB_MEDIA_STATE_DISMOUNTED:
  745. if (m_mountCount <= 1) {
  746. m_mediaState = state;
  747. }
  748. m_mountCount--;
  749. break;
  750. case HSM_JOB_MEDIA_STATE_FAILED:
  751. m_mediaState = state;
  752. break;
  753. default:
  754. case HSM_JOB_MEDIA_STATE_IDLE:
  755. break;
  756. }
  757. return(hr);
  758. }
  759. HRESULT
  760. CHsmPhase::SetPhase(
  761. IN HSM_JOB_PHASE phase
  762. )
  763. /*++
  764. Implements:
  765. IHsmPhase::SetPhase().
  766. --*/
  767. {
  768. m_phase = phase;
  769. return(S_OK);
  770. }
  771. HRESULT
  772. CHsmPhase::SetPriority(
  773. IN HSM_JOB_PRIORITY priority
  774. )
  775. /*++
  776. Implements:
  777. IHsmPhasePriv::SetPriority().
  778. --*/
  779. {
  780. m_priority = priority;
  781. return(S_OK);
  782. }
  783. HRESULT
  784. CHsmPhase::SetState(
  785. IN HSM_JOB_STATE state
  786. )
  787. /*++
  788. Implements:
  789. IHsmPhasePriv::SetState().
  790. --*/
  791. {
  792. HRESULT hr = S_OK;
  793. FILETIME currentTime;
  794. LONGLONG restartTicks;
  795. LONGLONG stopTicks;
  796. try {
  797. GetSystemTimeAsFileTime(&currentTime);
  798. switch(state) {
  799. case HSM_JOB_STATE_ACTIVE:
  800. // If this is a resume, then update the restartTime not the startTime.
  801. if (HSM_JOB_STATE_RESUMING == m_state) {
  802. m_restartTime = currentTime;
  803. } else {
  804. m_restartTime = WsbLLtoFT(0);
  805. m_startTime = currentTime;
  806. m_elapsedTime = 0;
  807. }
  808. m_state = state;
  809. break;
  810. case HSM_JOB_STATE_CANCELLED:
  811. case HSM_JOB_STATE_DONE:
  812. case HSM_JOB_STATE_FAILED:
  813. case HSM_JOB_STATE_SKIPPED:
  814. case HSM_JOB_STATE_PAUSED:
  815. case HSM_JOB_STATE_SUSPENDED:
  816. // Record the stop time and update the elapsed time.
  817. m_stopTime = currentTime;
  818. restartTicks = WsbFTtoLL(m_restartTime);
  819. stopTicks = WsbFTtoLL(m_stopTime);
  820. if (restartTicks == 0) {
  821. m_elapsedTime = stopTicks - WsbFTtoLL(m_startTime);
  822. } else {
  823. m_elapsedTime += stopTicks - restartTicks;
  824. }
  825. m_state = state;
  826. break;
  827. case HSM_JOB_STATE_CANCELLING:
  828. case HSM_JOB_STATE_IDLE:
  829. case HSM_JOB_STATE_PAUSING:
  830. case HSM_JOB_STATE_RESUMING:
  831. case HSM_JOB_STATE_STARTING:
  832. case HSM_JOB_STATE_SUSPENDING:
  833. // Don't need to do anything for these other than record the state change.
  834. m_state = state;
  835. break;
  836. default:
  837. WsbAssert(FALSE, E_UNEXPECTED);
  838. break;
  839. }
  840. } WsbCatch(hr);
  841. return(hr);
  842. }
  843. HRESULT
  844. CHsmPhase::SetStats(
  845. IN LONGLONG items,
  846. IN LONGLONG size,
  847. IN LONGLONG skippedItems,
  848. IN LONGLONG skippedSize,
  849. IN LONGLONG errorItems,
  850. IN LONGLONG errorSize
  851. )
  852. /*++
  853. Implements:
  854. IHsmPhasePriv::SetStats().
  855. --*/
  856. {
  857. m_items = items;
  858. m_size = size;
  859. m_skippedItems = skippedItems;
  860. m_skippedSize = skippedSize;
  861. m_errorItems = errorItems;
  862. m_errorSize = errorSize;
  863. return(S_OK);
  864. }
  865. HRESULT
  866. CHsmPhase::Test(
  867. USHORT* passed,
  868. USHORT* failed
  869. )
  870. /*++
  871. Implements:
  872. IWsbTestable::Test().
  873. --*/
  874. {
  875. HRESULT hr = S_OK;
  876. try {
  877. WsbAssert(0 != passed, E_POINTER);
  878. WsbAssert(0 != failed, E_POINTER);
  879. *passed = 0;
  880. *failed = 0;
  881. } WsbCatch(hr);
  882. return(hr);
  883. }