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.

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