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.

1249 lines
25 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmjobwi.cpp
  5. Abstract:
  6. This component represents a resource that will is/was operated on by a job.
  7. Author:
  8. Chuck Bardeen [cbardeen] 09-Feb-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "wsb.h"
  13. #include "fsa.h"
  14. #include "job.h"
  15. #include "hsmjobwi.h"
  16. #define WSB_TRACE_IS WSB_TRACE_BIT_JOB
  17. static USHORT iCountJobwi = 0;
  18. HRESULT
  19. CHsmJobWorkItem::CompareTo(
  20. IN IUnknown* pUnknown,
  21. OUT SHORT* pResult
  22. )
  23. /*++
  24. Implements:
  25. IWsbCollectable::CompareTo().
  26. --*/
  27. {
  28. HRESULT hr = S_OK;
  29. CComPtr<IHsmJobWorkItem> pWorkItem;
  30. WsbTraceIn(OLESTR("CHsmJobWorkItem::CompareTo"), OLESTR(""));
  31. try {
  32. // Did they give us a valid item to compare to?
  33. WsbAssert(0 != pUnknown, E_POINTER);
  34. // We need the IWsbBool interface to get the value of the object.
  35. WsbAffirmHr(pUnknown->QueryInterface(IID_IHsmJobWorkItem, (void**) &pWorkItem));
  36. // Compare the rules.
  37. hr = CompareToIWorkItem(pWorkItem, pResult);
  38. } WsbCatch(hr);
  39. WsbTraceOut(OLESTR("CHsmJobWorkItem::CompareTo"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  40. return(hr);
  41. }
  42. HRESULT
  43. CHsmJobWorkItem::CompareToIWorkItem(
  44. IN IHsmJobWorkItem* pWorkItem,
  45. OUT SHORT* pResult
  46. )
  47. /*++
  48. Implements:
  49. IHsmJobWorkItem::CompareToIWorkItem().
  50. --*/
  51. {
  52. HRESULT hr = S_OK;
  53. GUID id;
  54. WsbTraceIn(OLESTR("CHsmJobWorkItem::CompareToIWorkItem"), OLESTR(""));
  55. try {
  56. // Did they give us a valid item to compare to?
  57. WsbAssert(0 != pWorkItem, E_POINTER);
  58. // Get the identifier.
  59. WsbAffirmHr(pWorkItem->GetResourceId(&id));
  60. // Compare to the identifier.
  61. hr = CompareToResourceId(id, pResult);
  62. } WsbCatch(hr);
  63. WsbTraceOut(OLESTR("CHsmJobWorkItem::CompareToIWorkItem"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  64. return(hr);
  65. }
  66. HRESULT
  67. CHsmJobWorkItem::CompareToResourceId(
  68. IN GUID id,
  69. OUT SHORT* pResult
  70. )
  71. /*++
  72. Implements:
  73. IHsmJobWorkItem::CompareToResourceId().
  74. --*/
  75. {
  76. HRESULT hr = S_OK;
  77. SHORT aResult = 0;
  78. WsbTraceIn(OLESTR("CHsmJobWorkItem::CompareToResourceId"), OLESTR("resource id = <%ls>"), WsbGuidAsString(id));
  79. try {
  80. // Compare the guids.
  81. aResult = WsbSign( memcmp(&m_resourceId, &id, sizeof(GUID)) );
  82. if (0 != aResult) {
  83. hr = S_FALSE;
  84. }
  85. if (0 != pResult) {
  86. *pResult = aResult;
  87. }
  88. } WsbCatch(hr);
  89. WsbTraceOut(OLESTR("CHsmJobWorkItem::CompareToResourceId"), OLESTR("hr = <%ls>, result = <%d>"), WsbHrAsString(hr), aResult);
  90. return(hr);
  91. }
  92. HRESULT
  93. CHsmJobWorkItem::DoPostScan(
  94. void
  95. )
  96. /*++
  97. Implements:
  98. IPersist::DoPostScan().
  99. --*/
  100. {
  101. HRESULT hr = S_OK;
  102. WsbTraceIn(OLESTR("CHsmJobWorkItem::DoPostScan"), OLESTR(""));
  103. try {
  104. CComPtr<IHsmActionOnResourcePost> pActionPost;
  105. CComPtr<IHsmJobDef> pJobDef;
  106. // Execute any post-scan action
  107. WsbAffirmHr(m_pJob->GetDef(&pJobDef));
  108. WsbAffirmHr(pJobDef->GetPostActionOnResource(&pActionPost));
  109. if (pActionPost) {
  110. WsbTrace(OLESTR("CHsmJobWorkItem::DoPostScan, doing post-scan action\n"), (void*)pJobDef);
  111. WsbAffirmHr(pActionPost->Do(static_cast<IHsmJobWorkItem*>(this), m_state));
  112. }
  113. } WsbCatch(hr);
  114. WsbTraceOut(OLESTR("CHsmJobWorkItem::DoPostScan"), OLESTR("hr = <%ls>"),
  115. WsbHrAsString(hr));
  116. return(hr);
  117. }
  118. HRESULT
  119. CHsmJobWorkItem::DoPreScan(
  120. void
  121. )
  122. /*++
  123. Implements:
  124. IPersist::DoPreScan().
  125. --*/
  126. {
  127. HRESULT hr = S_OK;
  128. WsbTraceIn(OLESTR("CHsmJobWorkItem::DoPreScan"), OLESTR(""));
  129. try {
  130. CComPtr<IHsmActionOnResourcePre> pActionPre;
  131. CComPtr<IHsmJobDef> pJobDef;
  132. // Execute any pre-scan action
  133. WsbAffirmHr(m_pJob->GetDef(&pJobDef));
  134. WsbTrace(OLESTR("CHsmJobWorkItem::DoPreScan, pJobDef = %lx\n"), (void*)pJobDef);
  135. WsbAffirmHr(pJobDef->GetPreActionOnResource(&pActionPre));
  136. if (pActionPre) {
  137. WsbTrace(OLESTR("CHsmJobWorkItem::DoPreScan, doing pre-scan action\n"));
  138. WsbAffirmHr(pActionPre->Do(static_cast<IHsmJobWorkItem*>(this), pJobDef));
  139. }
  140. } WsbCatch(hr);
  141. WsbTraceOut(OLESTR("CHsmJobWorkItem::DoPreScan"), OLESTR("hr = <%ls>"),
  142. WsbHrAsString(hr));
  143. return(hr);
  144. }
  145. HRESULT
  146. CHsmJobWorkItem::EnumPhases(
  147. IN IWsbEnum** ppEnum
  148. )
  149. /*++
  150. Implements:
  151. IHsmSession::EnumPhases().
  152. --*/
  153. {
  154. HRESULT hr = S_OK;
  155. try {
  156. WsbAssert(0 != ppEnum, E_POINTER);
  157. WsbAffirmHr(m_pPhases->Enum(ppEnum));
  158. } WsbCatch(hr);
  159. return(hr);
  160. }
  161. HRESULT
  162. CHsmJobWorkItem::EnumTotals(
  163. IN IWsbEnum** ppEnum
  164. )
  165. /*++
  166. Implements:
  167. IHsmSession::EnumTotals().
  168. --*/
  169. {
  170. HRESULT hr = S_OK;
  171. try {
  172. WsbAssert(0 != ppEnum, E_POINTER);
  173. WsbAffirmHr(m_pTotals->Enum(ppEnum));
  174. } WsbCatch(hr);
  175. return(hr);
  176. }
  177. HRESULT
  178. CHsmJobWorkItem::FinalConstruct(
  179. void
  180. )
  181. /*++
  182. Implements:
  183. CComObjectRoot::FinalConstruct().
  184. --*/
  185. {
  186. HRESULT hr = S_OK;
  187. WsbTraceIn(OLESTR("CHsmJobWorkItem::FinalConstruct"), OLESTR(""));
  188. try {
  189. WsbAffirmHr(CWsbObject::FinalConstruct());
  190. m_cookie = 0;
  191. m_resourceId = GUID_NULL;
  192. m_state = HSM_JOB_STATE_IDLE;
  193. m_subRunId = 0;
  194. m_bActive = FALSE;
  195. // Create the phase and totals collections.
  196. WsbAffirmHr(CoCreateInstance(CLSID_CWsbOrderedCollection, 0, CLSCTX_ALL, IID_IWsbCollection, (void**) &m_pPhases));
  197. WsbAffirmHr(CoCreateInstance(CLSID_CWsbOrderedCollection, 0, CLSCTX_ALL, IID_IWsbCollection, (void**) &m_pTotals));
  198. } WsbCatch(hr);
  199. iCountJobwi++;
  200. WsbTraceOut(OLESTR("CHsmJobWorkItem::FinalConstruct"), OLESTR("hr = <%ls>, count is <%d>"), WsbHrAsString(hr), iCountJobwi);
  201. return(hr);
  202. }
  203. void
  204. CHsmJobWorkItem::FinalRelease(
  205. void
  206. )
  207. /*++
  208. Implements:
  209. CHsmJobWorkItem::FinalRelease().
  210. --*/
  211. {
  212. WsbTraceIn(OLESTR("CHsmJobWorkItem::FinalRelease"), OLESTR(""));
  213. CWsbObject::FinalRelease();
  214. iCountJobwi--;
  215. WsbTraceOut(OLESTR("CHsmJobWorkItem:FinalRelease"), OLESTR("Count is <%d>"), iCountJobwi);
  216. }
  217. HRESULT
  218. CHsmJobWorkItem::GetClassID(
  219. OUT CLSID* pClsid
  220. )
  221. /*++
  222. Implements:
  223. IPersist::GetClassID().
  224. --*/
  225. {
  226. HRESULT hr = S_OK;
  227. WsbTraceIn(OLESTR("CHsmJobWorkItem::GetClassID"), OLESTR(""));
  228. try {
  229. WsbAssert(0 != pClsid, E_POINTER);
  230. *pClsid = CLSID_CHsmJobWorkItem;
  231. } WsbCatch(hr);
  232. WsbTraceOut(OLESTR("CHsmJobWorkItem::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  233. return(hr);
  234. }
  235. HRESULT
  236. CHsmJobWorkItem::GetCookie(
  237. OUT DWORD* pCookie
  238. )
  239. /*++
  240. Implements:
  241. IHsmJobWorkItem::GetCookie().
  242. --*/
  243. {
  244. HRESULT hr = S_OK;
  245. try {
  246. WsbAssert(0 != pCookie, E_POINTER);
  247. *pCookie = m_cookie;
  248. } WsbCatch(hr);
  249. return(hr);
  250. }
  251. HRESULT
  252. CHsmJobWorkItem::GetCurrentPath(
  253. OUT OLECHAR** pPath,
  254. IN ULONG bufferSize
  255. )
  256. /*++
  257. Implements:
  258. IHsmJobWorkItem::GetCurrentPath().
  259. --*/
  260. {
  261. HRESULT hr = S_OK;
  262. try {
  263. WsbAssert(0 != pPath, E_POINTER);
  264. WsbAffirmHr(m_currentPath.CopyTo(pPath, bufferSize));
  265. } WsbCatch(hr);
  266. return(hr);
  267. }
  268. HRESULT
  269. CHsmJobWorkItem::GetFinishTime(
  270. OUT FILETIME* pTime
  271. )
  272. /*++
  273. Implements:
  274. IHsmJobWorkItem::GetFinishTime().
  275. --*/
  276. {
  277. HRESULT hr = S_OK;
  278. try {
  279. WsbAssert(0 != pTime, E_POINTER);
  280. *pTime = m_finishTime;
  281. } WsbCatch(hr);
  282. return(hr);
  283. }
  284. HRESULT
  285. CHsmJobWorkItem::GetPhases(
  286. IN IWsbCollection** ppCollection
  287. )
  288. /*++
  289. Implements:
  290. IHsmJobWorkItemPriv::GetPhases().
  291. --*/
  292. {
  293. HRESULT hr = S_OK;
  294. try {
  295. WsbAssert(0 != ppCollection, E_POINTER);
  296. *ppCollection = m_pPhases;
  297. if (m_pPhases != 0) {
  298. m_pPhases.p->AddRef();
  299. }
  300. } WsbCatch(hr);
  301. return(hr);
  302. }
  303. HRESULT
  304. CHsmJobWorkItem::GetResourceId(
  305. OUT GUID* pId
  306. )
  307. /*++
  308. Implements:
  309. IHsmJobWorkItem::GetResourceId().
  310. --*/
  311. {
  312. HRESULT hr = S_OK;
  313. try {
  314. WsbAssert(0 != pId, E_POINTER);
  315. *pId = m_resourceId;
  316. } WsbCatch(hr);
  317. return(hr);
  318. }
  319. HRESULT
  320. CHsmJobWorkItem::GetSession(
  321. OUT IHsmSession** ppSession
  322. )
  323. /*++
  324. Implements:
  325. IHsmJobWorkItem::GetSession().
  326. --*/
  327. {
  328. HRESULT hr = S_OK;
  329. try {
  330. WsbAssert(0 != ppSession, E_POINTER);
  331. *ppSession = m_pSession;
  332. if (m_pSession != 0) {
  333. m_pSession.p->AddRef();
  334. } else {
  335. WsbTrace(OLESTR("CHsmJobWorkItem::GetSession - session pointer is null. \n"));
  336. }
  337. } WsbCatch(hr);
  338. return(hr);
  339. }
  340. HRESULT
  341. CHsmJobWorkItem::GetStartingPath(
  342. OUT OLECHAR** pPath,
  343. IN ULONG bufferSize
  344. )
  345. /*++
  346. Implements:
  347. IHsmJobWorkItem::GetStartingPath().
  348. --*/
  349. {
  350. HRESULT hr = S_OK;
  351. try {
  352. WsbAssert(0 != pPath, E_POINTER);
  353. WsbAffirmHr(m_startingPath.CopyTo(pPath, bufferSize));
  354. } WsbCatch(hr);
  355. return(hr);
  356. }
  357. HRESULT
  358. CHsmJobWorkItem::GetSizeMax(
  359. OUT ULARGE_INTEGER* pSize
  360. )
  361. /*++
  362. Implements:
  363. IPersistStream::GetSizeMax().
  364. --*/
  365. {
  366. HRESULT hr = S_OK;
  367. CComPtr<IPersistStream> pPersistStream;
  368. ULARGE_INTEGER entrySize;
  369. WsbTraceIn(OLESTR("CHsmJobWorkItem::GetSizeMax"), OLESTR(""));
  370. try {
  371. WsbAssert(0 != pSize, E_POINTER);
  372. // Determine the size for a rule with no criteria.
  373. pSize->QuadPart = 4 * WsbPersistSizeOf(ULONG) + WsbPersistSize((wcslen(m_currentPath) + 1) * sizeof(OLECHAR)) + WsbPersistSize((wcslen(m_startingPath) + 1) * sizeof(OLECHAR)) + 2 * WsbPersistSizeOf(FILETIME) + WsbPersistSizeOf(GUID);
  374. // Now allocate space for the phase and totals.
  375. WsbAffirmHr(m_pPhases->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  376. WsbAffirmHr(pPersistStream->GetSizeMax(&entrySize));
  377. pSize->QuadPart += entrySize.QuadPart;
  378. pPersistStream = 0;
  379. WsbAffirmHr(m_pTotals->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  380. WsbAffirmHr(pPersistStream->GetSizeMax(&entrySize));
  381. pSize->QuadPart += entrySize.QuadPart;
  382. pPersistStream = 0;
  383. } WsbCatch(hr);
  384. WsbTraceOut(OLESTR("CHsmJobWorkItem::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pSize));
  385. return(hr);
  386. }
  387. HRESULT
  388. CHsmJobWorkItem::GetStartTime(
  389. OUT FILETIME* pTime
  390. )
  391. /*++
  392. Implements:
  393. IHsmJobWorkItem::GetStartTime().
  394. --*/
  395. {
  396. HRESULT hr = S_OK;
  397. try {
  398. WsbAssert(0 != pTime, E_POINTER);
  399. *pTime = m_startTime;
  400. } WsbCatch(hr);
  401. return(hr);
  402. }
  403. HRESULT
  404. CHsmJobWorkItem::GetState(
  405. OUT HSM_JOB_STATE* pState
  406. )
  407. /*++
  408. Implements:
  409. IHsmJobWorkItem::GetState().
  410. --*/
  411. {
  412. HRESULT hr = S_OK;
  413. try {
  414. WsbAssert(0 != pState, E_POINTER);
  415. *pState = m_state;
  416. } WsbCatch(hr);
  417. return(hr);
  418. }
  419. HRESULT
  420. CHsmJobWorkItem::GetStateAsString(
  421. OUT OLECHAR** pName,
  422. IN ULONG bufferSize
  423. )
  424. /*++
  425. Implements:
  426. IHsmJobWorkItem::GetStateAsString().
  427. --*/
  428. {
  429. HRESULT hr = S_OK;
  430. CWsbStringPtr tmpString;
  431. try {
  432. WsbAssert(0 != pName, E_POINTER);
  433. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBSTATEACTIVE + m_state));
  434. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  435. } WsbCatch(hr);
  436. return(hr);
  437. }
  438. HRESULT
  439. CHsmJobWorkItem::GetSubRunId(
  440. OUT ULONG* pId
  441. )
  442. /*++
  443. Implements:
  444. IHsmJobWorkItem::GetSubRunId().
  445. --*/
  446. {
  447. HRESULT hr = S_OK;
  448. try {
  449. WsbAssert(0 != pId, E_POINTER);
  450. *pId = m_subRunId;
  451. } WsbCatch(hr);
  452. return(hr);
  453. }
  454. HRESULT
  455. CHsmJobWorkItem::GetTotals(
  456. IN IWsbCollection** ppCollection
  457. )
  458. /*++
  459. Implements:
  460. IHsmSessionPriv::GetTotals().
  461. --*/
  462. {
  463. HRESULT hr = S_OK;
  464. try {
  465. WsbAssert(0 != ppCollection, E_POINTER);
  466. *ppCollection = m_pTotals;
  467. if (m_pTotals != 0 ) {
  468. m_pTotals.p->AddRef();
  469. }
  470. } WsbCatch(hr);
  471. return(hr);
  472. }
  473. HRESULT
  474. CHsmJobWorkItem::Init(
  475. IN IHsmJob* pJob
  476. )
  477. /*++
  478. Implements:
  479. IHsmSessionPriv::Init().
  480. --*/
  481. {
  482. m_pJob = pJob;
  483. return(S_OK);
  484. }
  485. HRESULT
  486. CHsmJobWorkItem::Load(
  487. IN IStream* pStream
  488. )
  489. /*++
  490. Implements:
  491. IPersistStream::Load().
  492. --*/
  493. {
  494. HRESULT hr = S_OK;
  495. CComPtr<IPersistStream> pPersistStream;
  496. WsbTraceIn(OLESTR("CHsmJobWorkItem::Load"), OLESTR(""));
  497. try {
  498. ULONG ul_tmp;
  499. WsbAssert(0 != pStream, E_POINTER);
  500. // Do the easy stuff, but make sure that this order matches the order
  501. // in the load method.
  502. WsbAffirmHr(WsbLoadFromStream(pStream, &m_currentPath, 0));
  503. WsbAffirmHr(WsbLoadFromStream(pStream, &m_finishTime));
  504. WsbAffirmHr(WsbLoadFromStream(pStream, &m_resourceId));
  505. WsbAffirmHr(WsbLoadFromStream(pStream, &m_startingPath, 0));
  506. WsbAffirmHr(WsbLoadFromStream(pStream, &m_startTime));
  507. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  508. m_state = static_cast<HSM_JOB_STATE>(ul_tmp);
  509. WsbAffirmHr(WsbLoadFromStream(pStream, &m_subRunId));
  510. WsbAffirmHr(m_pPhases->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  511. WsbAffirmHr(pPersistStream->Load(pStream));
  512. pPersistStream = 0;
  513. WsbAffirmHr(m_pTotals->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  514. WsbAffirmHr(pPersistStream->Load(pStream));
  515. pPersistStream = 0;
  516. // The session and cookie are not saved, since it is not likely to be alive on the load.
  517. m_pSession = 0;
  518. m_cookie = 0;
  519. } WsbCatch(hr);
  520. WsbTraceOut(OLESTR("CHsmJobWorkItem::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  521. return(hr);
  522. }
  523. HRESULT
  524. CHsmJobWorkItem::ProcessSessionState(
  525. IN IHsmSession* pSession,
  526. IN IHsmPhase* pPhase,
  527. IN OLECHAR* currentPath
  528. )
  529. /*++
  530. Implements:
  531. IHsmSessionSinkEveryState::ProcessSessionState().
  532. --*/
  533. {
  534. HRESULT hr = S_OK;
  535. HRESULT hrPhase = S_OK;
  536. CWsbStringPtr tmpString;
  537. CWsbStringPtr tmpString2;
  538. CComPtr<IConnectionPointContainer> pCPC;
  539. CComPtr<IConnectionPoint> pCP;
  540. CComPtr<IHsmPhase> pFoundPhase;
  541. CComPtr<IHsmPhase> pClonedPhase;
  542. CComPtr<IHsmSessionTotals> pSessionTotals;
  543. CComPtr<IHsmSessionTotals> pClonedTotals;
  544. CComPtr<IWsbCollection> pPhases;
  545. CComPtr<IWsbEnum> pEnum;
  546. CComPtr<IHsmJobPriv> pJobPriv;
  547. HSM_JOB_PHASE phase;
  548. HSM_JOB_STATE state;
  549. WsbTraceIn(OLESTR("CHsmJobWorkItem::ProcessSessionState"), OLESTR(""));
  550. try {
  551. WsbAssert(0 != pSession, E_POINTER);
  552. // Tell everyone the new state of the session.
  553. try {
  554. WsbAffirmHr(m_pJob->QueryInterface(IID_IHsmJobPriv, (void**) &pJobPriv));
  555. WsbAffirmHr(pJobPriv->AdviseOfSessionState(pSession, pPhase, currentPath));
  556. } WsbCatch(hr);
  557. // We only keep track of the ones that are for the session as a whole.
  558. WsbAffirmHr(pPhase->GetPhase(&phase));
  559. WsbAffirmHr(pPhase->GetState(&state));
  560. WsbAffirmHr(pPhase->GetName(&tmpString, 0));
  561. WsbAffirmHr(pPhase->GetStateAsString(&tmpString2, 0));
  562. WsbTrace(OLESTR("CHsmJobWorkItem::ProcessSessionState - Phase = <%ls>, State = <%ls>\n"), (OLECHAR *)tmpString, (OLECHAR *)tmpString2);
  563. if (HSM_JOB_PHASE_ALL == phase) {
  564. m_currentPath = currentPath;
  565. m_state = state;
  566. // If the session has finished, then we have some cleanup to do so that it can go
  567. // away.
  568. if (HSM_JOB_STATE_IS_DONE(state)) {
  569. // Do the post-scan action, if any
  570. WsbAffirmHr(DoPostScan());
  571. WsbAffirmHr(CoFileTimeNow(&m_finishTime));
  572. // Collect all the phase and session totals information so that it can be
  573. // persistsed for later use.
  574. try {
  575. WsbAffirmHr(pSession->EnumPhases(&pEnum));
  576. for (hrPhase = pEnum->First(IID_IHsmPhase, (void**) &pFoundPhase);
  577. SUCCEEDED(hrPhase);
  578. hrPhase = pEnum->Next(IID_IHsmPhase, (void**) &pFoundPhase)) {
  579. // Create the new instance.
  580. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhase, (void**) &pClonedPhase));
  581. // Fill it in with the new values.
  582. WsbAffirmHr(pFoundPhase->CopyTo(pClonedPhase));
  583. WsbAffirmHr(m_pPhases->Add(pClonedPhase));
  584. pFoundPhase = 0;
  585. pClonedPhase = 0;
  586. }
  587. WsbAssert(hrPhase == WSB_E_NOTFOUND, hrPhase);
  588. pEnum = 0;
  589. WsbAffirmHr(pSession->EnumTotals(&pEnum));
  590. for (hrPhase = pEnum->First(IID_IHsmSessionTotals, (void**) &pSessionTotals);
  591. SUCCEEDED(hrPhase);
  592. hrPhase = pEnum->Next(IID_IHsmSessionTotals, (void**) &pSessionTotals)) {
  593. WsbAffirmHr(pSessionTotals->GetName(&tmpString, 0));
  594. WsbTrace(OLESTR("CHsmJobWorkItem::ProcessSessionState - Copying session totals <%ls>\n"), (OLECHAR *)tmpString);
  595. // Create the new instance.
  596. WsbAffirmHr(CoCreateInstance(CLSID_CHsmSessionTotals, 0, CLSCTX_ALL, IID_IHsmSessionTotals, (void**) &pClonedTotals));
  597. // Fill it in with the new values.
  598. WsbAffirmHr(pSessionTotals->CopyTo(pClonedTotals));
  599. WsbAffirmHr(m_pTotals->Add(pClonedTotals));
  600. pSessionTotals = 0;
  601. pClonedTotals = 0;
  602. }
  603. WsbAssert(hrPhase == WSB_E_NOTFOUND, hrPhase);
  604. pEnum = 0;
  605. } WsbCatch(hr)
  606. if (0 != m_cookie) {
  607. // Tell the session that we don't want to be advised anymore.
  608. WsbAffirmHr(pSession->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  609. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryState, &pCP));
  610. WsbAffirmHr(pCP->Unadvise(m_cookie));
  611. } else {
  612. WsbTrace(OLESTR("CHsmJobWorkItem::ProcessSessionState - cookie was 0 so didn't unadvise.\n"));
  613. }
  614. // Let the session object go away.
  615. m_pSession = 0;
  616. m_cookie = 0;
  617. m_bActive = FALSE;
  618. // See if there is anymore work to do for this job.
  619. WsbAffirmHr(pJobPriv->DoNext());
  620. }
  621. }
  622. } WsbCatch(hr);
  623. WsbTraceOut(OLESTR("CHsmJobWorkItem::ProcessSessionState"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  624. return(hr);
  625. }
  626. HRESULT
  627. CHsmJobWorkItem::Save(
  628. IN IStream* pStream,
  629. IN BOOL clearDirty
  630. )
  631. /*++
  632. Implements:
  633. IPersistStream::Save().
  634. --*/
  635. {
  636. HRESULT hr = S_OK;
  637. CComPtr<IWsbEnum> pEnum;
  638. CComPtr<IPersistStream> pPersistStream;
  639. WsbTraceIn(OLESTR("CHsmJobWorkItem::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  640. try {
  641. WsbAssert(0 != pStream, E_POINTER);
  642. // Do the easy stuff, but make sure that this order matches the order
  643. // in the load method.
  644. WsbAffirmHr(WsbSaveToStream(pStream, m_currentPath));
  645. WsbAffirmHr(WsbSaveToStream(pStream, m_finishTime));
  646. WsbAffirmHr(WsbSaveToStream(pStream, m_resourceId));
  647. WsbAffirmHr(WsbSaveToStream(pStream, m_startingPath));
  648. WsbAffirmHr(WsbSaveToStream(pStream, m_startTime));
  649. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_state)));
  650. WsbAffirmHr(WsbSaveToStream(pStream, m_subRunId));
  651. WsbAffirmHr(m_pPhases->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  652. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  653. pPersistStream = 0;
  654. WsbAffirmHr(m_pTotals->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  655. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  656. pPersistStream = 0;
  657. // The session and cookie are not saved, since it is not likely to be alive on the load.
  658. // If we got it saved and we were asked to clear the dirty bit, then
  659. // do so now.
  660. if (clearDirty) {
  661. m_isDirty = FALSE;
  662. }
  663. } WsbCatch(hr);
  664. WsbTraceOut(OLESTR("CHsmJobWorkItem::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  665. return(hr);
  666. }
  667. HRESULT
  668. CHsmJobWorkItem::Test(
  669. USHORT* passed,
  670. USHORT* failed
  671. )
  672. /*++
  673. Implements:
  674. IWsbTestable::Test().
  675. --*/
  676. {
  677. HRESULT hr = S_OK;
  678. try {
  679. WsbAssert(0 != passed, E_POINTER);
  680. WsbAssert(0 != failed, E_POINTER);
  681. *passed = 0;
  682. *failed = 0;
  683. } WsbCatch(hr);
  684. return(hr);
  685. }
  686. HRESULT
  687. CHsmJobWorkItem::SetCookie(
  688. IN DWORD cookie
  689. )
  690. /*++
  691. Implements:
  692. IHsmJobWorkItem::SetCookie().
  693. --*/
  694. {
  695. WsbTraceIn(OLESTR("CHsmJobWorkItem::SetCookie"), OLESTR(""));
  696. HRESULT hr = S_OK;
  697. m_cookie = cookie;
  698. WsbTraceOut(OLESTR("CHsmJobWorkItem::SetCookie"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  699. return(hr);
  700. }
  701. HRESULT
  702. CHsmJobWorkItem::SetCurrentPath(
  703. IN OLECHAR* path
  704. )
  705. /*++
  706. Implements:
  707. IHsmJobWorkItem::SetCurrentPath().
  708. --*/
  709. {
  710. m_currentPath = path;
  711. return(S_OK);
  712. }
  713. HRESULT
  714. CHsmJobWorkItem::SetFinishTime(
  715. IN FILETIME time
  716. )
  717. /*++
  718. Implements:
  719. IHsmJobWorkItem::SetFinishTime().
  720. --*/
  721. {
  722. m_finishTime = time;
  723. return(S_OK);
  724. }
  725. HRESULT
  726. CHsmJobWorkItem::SetResourceId(
  727. IN GUID id
  728. )
  729. /*++
  730. Implements:
  731. IHsmJobWorkItem::SetResourceId().
  732. --*/
  733. {
  734. m_resourceId = id;
  735. return(S_OK);
  736. }
  737. HRESULT
  738. CHsmJobWorkItem::SetSession(
  739. IN IHsmSession* pSession
  740. )
  741. /*++
  742. Implements:
  743. IHsmJobWorkItem::SetSession().
  744. --*/
  745. {
  746. HRESULT hr = S_OK;
  747. if (m_pSession != 0) {
  748. m_pSession = 0;
  749. }
  750. m_pSession = pSession;
  751. return(hr);
  752. }
  753. HRESULT
  754. CHsmJobWorkItem::SetStartingPath(
  755. IN OLECHAR* path
  756. )
  757. /*++
  758. Implements:
  759. IHsmJobWorkItem::SetStartingPath().
  760. --*/
  761. {
  762. m_startingPath = path;
  763. return(S_OK);
  764. }
  765. HRESULT
  766. CHsmJobWorkItem::SetStartTime(
  767. IN FILETIME time
  768. )
  769. /*++
  770. Implements:
  771. IHsmJobWorkItem::SetStartTime().
  772. --*/
  773. {
  774. m_startTime = time;
  775. return(S_OK);
  776. }
  777. HRESULT
  778. CHsmJobWorkItem::SetState(
  779. IN HSM_JOB_STATE state
  780. )
  781. /*++
  782. Implements:
  783. IHsmJobWorkItem::SetState().
  784. --*/
  785. {
  786. m_state = state;
  787. return(S_OK);
  788. }
  789. HRESULT
  790. CHsmJobWorkItem::SetSubRunId(
  791. IN ULONG id
  792. )
  793. /*++
  794. Implements:
  795. IHsmJobWorkItem::SetSubRunId().
  796. --*/
  797. {
  798. m_subRunId = id;
  799. return(S_OK);
  800. }
  801. HRESULT
  802. CHsmJobWorkItem::IsActiveItem(
  803. void
  804. )
  805. /*++
  806. Implements:
  807. IHsmJobWorkItemPriv::IsActiveItem().
  808. --*/
  809. {
  810. HRESULT hr = S_OK;
  811. WsbTraceIn(OLESTR("CHsmJobWorkItem::IsActiveItem"), OLESTR(""));
  812. hr = (m_bActive ? S_OK : S_FALSE);
  813. WsbTraceOut(OLESTR("CHsmJobWorkItem::IsActiveItem"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  814. return hr;
  815. }
  816. HRESULT
  817. CHsmJobWorkItem::SetActiveItem(
  818. BOOL bActive
  819. )
  820. /*++
  821. Implements:
  822. IHsmJobWorkItemPriv::SetActiveItem().
  823. --*/
  824. {
  825. HRESULT hr = S_OK;
  826. WsbTraceIn( OLESTR("CHsmJobWorkItem::SetActiveItem"), OLESTR("bActive = %ls"),
  827. WsbBoolAsString(bActive) );
  828. m_bActive = bActive;
  829. WsbTraceOut(OLESTR("CHsmJobWorkItem::SetActiveItem"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  830. return hr;
  831. }