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.

1572 lines
44 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmsess.cpp
  5. Abstract:
  6. This module contains the session component. The session is the collator of information for the work being done on
  7. a resource (for a job, demand recall, truncate, ...).
  8. Author:
  9. Chuck Bardeen [cbardeen] 18-Feb-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "wsb.h"
  14. #include "fsa.h"
  15. #include "job.h"
  16. #include "HsmSess.h"
  17. #define WSB_TRACE_IS WSB_TRACE_BIT_JOB
  18. static USHORT iCount = 0;
  19. HRESULT
  20. CHsmSession::AdviseOfEvent(
  21. IN HSM_JOB_PHASE phase,
  22. IN HSM_JOB_EVENT event
  23. )
  24. /*++
  25. --*/
  26. {
  27. HRESULT hr = S_OK;
  28. HRESULT hr2 = S_OK;
  29. CONNECTDATA pConnectData;
  30. CComPtr<IConnectionPoint> pCP;
  31. CComPtr<IConnectionPointContainer> pCPC;
  32. CComPtr<IEnumConnections> pConnection;
  33. CComPtr<IHsmSessionSinkEveryEvent> pSink;
  34. try {
  35. // Tell everyone the new state of the session.
  36. WsbAffirmHr(((IUnknown*)(IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  37. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryEvent, &pCP));
  38. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  39. while(pConnection->Next(1, &pConnectData, 0) == S_OK) {
  40. // We don't care if the sink has problems (it's their problem).
  41. try {
  42. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkEveryEvent, (void**) &pSink));
  43. WsbAffirmHr(pSink->ProcessSessionEvent(((IHsmSession*) this), phase, event));
  44. } WsbCatchAndDo(hr2, ProcessHr(phase, __FILE__, __LINE__, hr2););
  45. WsbAffirmHr((pConnectData.pUnk)->Release());
  46. pSink=0;
  47. }
  48. } WsbCatch(hr);
  49. return(hr);
  50. }
  51. HRESULT
  52. CHsmSession::AdviseOfItem(
  53. IN IHsmPhase* pPhase,
  54. IN IFsaScanItem* pScanItem,
  55. IN HRESULT hrItem,
  56. IN IHsmSessionTotals* pSessionTotals
  57. )
  58. /*++
  59. --*/
  60. {
  61. HRESULT hr = S_OK;
  62. HRESULT hr2 = S_OK;
  63. CONNECTDATA pConnectData;
  64. FILETIME currentTime;
  65. LONGLONG advisedInterval;
  66. CComPtr<IConnectionPoint> pCP;
  67. CComPtr<IConnectionPointContainer> pCPC;
  68. CComPtr<IEnumConnections> pConnection;
  69. CComPtr<IHsmSessionSinkEveryItem> pSink;
  70. CComPtr<IHsmSessionSinkSomeItems> pSink2;
  71. HSM_JOB_PHASE phase;
  72. try {
  73. // For the item there are two ways to tell, so both need to be checked.
  74. // Tell those who want to know about every single file.
  75. WsbAffirmHr(((IUnknown*)(IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  76. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryItem, &pCP));
  77. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  78. while (pConnection->Next(1, &pConnectData, 0) == S_OK) {
  79. // We don't care if the sink has problems (it's their problem).
  80. try {
  81. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkEveryItem, (void**) &pSink));
  82. WsbAffirmHr(pSink->ProcessSessionItem(((IHsmSession*) this), pPhase, pScanItem, hrItem, pSessionTotals));
  83. } WsbCatchAndDo(hr2, pPhase->GetPhase(&phase); ProcessHr(phase, __FILE__, __LINE__, hr2););
  84. WsbAffirmHr((pConnectData.pUnk)->Release());
  85. pSink=0;
  86. }
  87. pCPC = 0;
  88. pCP = 0;
  89. pConnection = 0;
  90. // If we haven't told them withing the interval, then tell those who want to know about some of the files.
  91. GetSystemTimeAsFileTime(&currentTime);
  92. advisedInterval = ((currentTime.dwHighDateTime - m_lastAdviseFile.dwHighDateTime) << 32) + (currentTime.dwLowDateTime - m_lastAdviseFile.dwLowDateTime);
  93. if ((advisedInterval) > m_adviseInterval) {
  94. m_lastAdviseFile = currentTime;
  95. WsbAffirmHr(((IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  96. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkSomeItems, &pCP));
  97. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  98. while(pConnection->Next(1, &pConnectData, 0) == S_OK) {
  99. // We don't care if the sink has problems (it's their problem).
  100. try {
  101. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkSomeItems, (void**) &pSink2));
  102. WsbAffirmHr(pSink2->ProcessSessionItem(((IHsmSession*) this), pPhase, pScanItem, hrItem, pSessionTotals));
  103. } WsbCatchAndDo(hr2, pPhase->GetPhase(&phase); ProcessHr(phase, __FILE__, __LINE__, hr2););
  104. WsbAffirmHr((pConnectData.pUnk)->Release());
  105. pSink2=0;
  106. }
  107. }
  108. } WsbCatch(hr);
  109. return(hr);
  110. }
  111. HRESULT
  112. CHsmSession::AdviseOfMediaState(
  113. IN IHsmPhase* pPhase,
  114. IN HSM_JOB_MEDIA_STATE state,
  115. IN OLECHAR* mediaName,
  116. IN HSM_JOB_MEDIA_TYPE mediaType,
  117. IN ULONG time
  118. )
  119. /*++
  120. --*/
  121. {
  122. HRESULT hr = S_OK;
  123. HRESULT hr2 = S_OK;
  124. CONNECTDATA pConnectData;
  125. CComPtr<IConnectionPoint> pCP;
  126. CComPtr<IConnectionPointContainer> pCPC;
  127. CComPtr<IEnumConnections> pConnection;
  128. CComPtr<IHsmSessionSinkEveryMediaState> pSink;
  129. HSM_JOB_PHASE phase;
  130. try {
  131. // Tell everyone the new media state for the session.
  132. WsbAffirmHr(((IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  133. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryMediaState, &pCP));
  134. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  135. while(pConnection->Next(1, &pConnectData, 0) == S_OK) {
  136. // We don't care if the sink has problems (it's their problem).
  137. try {
  138. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkEveryMediaState, (void**) &pSink));
  139. WsbAffirmHr(pSink->ProcessSessionMediaState(((IHsmSession*) this), pPhase, state, mediaName, mediaType, time));
  140. } WsbCatchAndDo(hr2, pPhase->GetPhase(&phase); ProcessHr(phase, __FILE__, __LINE__, hr2););
  141. WsbAffirmHr((pConnectData.pUnk)->Release());
  142. pSink=0;
  143. }
  144. } WsbCatch(hr);
  145. return(hr);
  146. }
  147. HRESULT
  148. CHsmSession::AdviseOfPriority(
  149. IN IHsmPhase* pPhase
  150. )
  151. /*++
  152. --*/
  153. {
  154. HRESULT hr = S_OK;
  155. HRESULT hr2 = S_OK;
  156. CONNECTDATA pConnectData;
  157. CComPtr<IConnectionPoint> pCP;
  158. CComPtr<IConnectionPointContainer> pCPC;
  159. CComPtr<IEnumConnections> pConnection;
  160. CComPtr<IHsmSessionSinkEveryPriority> pSink;
  161. HSM_JOB_PHASE phase;
  162. try {
  163. // Tell everyone the new priority of a phase of the session.
  164. WsbAffirmHr(((IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  165. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryPriority, &pCP));
  166. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  167. while(pConnection->Next(1, &pConnectData, 0) == S_OK) {
  168. // We don't care if the sink has problems (it's their problem).
  169. try {
  170. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkEveryPriority, (void**) &pSink));
  171. WsbAffirmHr(pSink->ProcessSessionPriority(((IHsmSession*) this), pPhase));
  172. } WsbCatchAndDo(hr2, pPhase->GetPhase(&phase); ProcessHr(phase, __FILE__, __LINE__, hr2););
  173. WsbAffirmHr((pConnectData.pUnk)->Release());
  174. pSink=0;
  175. }
  176. } WsbCatch(hr);
  177. return(hr);
  178. }
  179. HRESULT
  180. CHsmSession::AdviseOfState(
  181. IN IHsmPhase* pPhase,
  182. IN OLECHAR* currentPath
  183. )
  184. /*++
  185. --*/
  186. {
  187. HRESULT hr = S_OK;
  188. HRESULT hr2 = S_OK;
  189. CONNECTDATA pConnectData;
  190. CComPtr<IConnectionPoint> pCP;
  191. CComPtr<IConnectionPointContainer> pCPC;
  192. CComPtr<IEnumConnections> pConnection;
  193. CComPtr<IHsmSessionSinkEveryState> pSink;
  194. HSM_JOB_PHASE phase;
  195. try {
  196. // Tell everyone the new state of the session.
  197. WsbAffirmHr(((IHsmSession*) this)->QueryInterface(IID_IConnectionPointContainer, (void**) &pCPC));
  198. WsbAffirmHr(pCPC->FindConnectionPoint(IID_IHsmSessionSinkEveryState, &pCP));
  199. WsbAffirmHr(pCP->EnumConnections(&pConnection));
  200. while(pConnection->Next(1, &pConnectData, 0) == S_OK) {
  201. // We don't care if the sink has problems (it's their problem).
  202. try {
  203. WsbAffirmHr((pConnectData.pUnk)->QueryInterface(IID_IHsmSessionSinkEveryState, (void**) &pSink));
  204. WsbAffirmHr(pSink->ProcessSessionState(((IHsmSession*) this), pPhase, currentPath));
  205. } WsbCatchAndDo(hr2, pPhase->GetPhase(&phase); ProcessHr(phase, __FILE__, __LINE__, hr2););
  206. WsbAffirmHr((pConnectData.pUnk)->Release());
  207. pSink=0;
  208. }
  209. } WsbCatch(hr);
  210. return(hr);
  211. }
  212. HRESULT
  213. CHsmSession::Cancel(
  214. IN HSM_JOB_PHASE phase
  215. )
  216. /*++
  217. Implements:
  218. IHsmSession::Cancel().
  219. --*/
  220. {
  221. return(AdviseOfEvent(phase, HSM_JOB_EVENT_CANCEL));
  222. }
  223. HRESULT
  224. CHsmSession::EnumPhases(
  225. IN IWsbEnum** ppEnum
  226. )
  227. /*++
  228. Implements:
  229. IHsmSession::EnumPhases().
  230. --*/
  231. {
  232. HRESULT hr = S_OK;
  233. try {
  234. WsbAssert(0 != ppEnum, E_POINTER);
  235. WsbAffirmHr(m_pPhases->Enum(ppEnum));
  236. } WsbCatch(hr);
  237. return(hr);
  238. }
  239. HRESULT
  240. CHsmSession::EnumTotals(
  241. IN IWsbEnum** ppEnum
  242. )
  243. /*++
  244. Implements:
  245. IHsmSession::EnumTotals().
  246. --*/
  247. {
  248. HRESULT hr = S_OK;
  249. try {
  250. WsbAssert(0 != ppEnum, E_POINTER);
  251. WsbAffirmHr(m_pTotals->Enum(ppEnum));
  252. } WsbCatch(hr);
  253. return(hr);
  254. }
  255. HRESULT
  256. CHsmSession::FinalConstruct(
  257. void
  258. )
  259. /*++
  260. Implements:
  261. CComObjectRoot::FinalConstruct().
  262. --*/
  263. {
  264. HRESULT hr = S_OK;
  265. WsbTraceIn(OLESTR("CHsmSession::FinalConstruct"), OLESTR("this = %p"),
  266. this);
  267. try {
  268. WsbAffirmHr(CWsbObject::FinalConstruct());
  269. m_hsmId = GUID_NULL;
  270. m_adviseInterval = 10000;
  271. m_runId = 0;
  272. m_subRunId = 0;
  273. m_state = HSM_JOB_STATE_IDLE;
  274. m_activePhases = 0;
  275. m_lastAdviseFile.dwHighDateTime = 0;
  276. m_lastAdviseFile.dwLowDateTime = 0;
  277. m_logControl = HSM_JOB_LOG_NORMAL;
  278. m_isCanceling = FALSE;
  279. // Each instance should have its own unique identifier.
  280. WsbAffirmHr(CoCreateGuid(&m_id));
  281. // Create the phase and totals collections.
  282. WsbAffirmHr(CoCreateInstance(CLSID_CWsbOrderedCollection, 0, CLSCTX_ALL, IID_IWsbCollection, (void**) &m_pPhases));
  283. WsbAffirmHr(CoCreateInstance(CLSID_CWsbOrderedCollection, 0, CLSCTX_ALL, IID_IWsbCollection, (void**) &m_pTotals));
  284. } WsbCatch(hr);
  285. iCount++;
  286. WsbTraceOut(OLESTR("CHsmSession::FinalConstruct"), OLESTR("hr = <%ls>, count is <%d>"), WsbHrAsString(hr), iCount);
  287. return(hr);
  288. }
  289. void
  290. CHsmSession::FinalRelease(
  291. void
  292. )
  293. /*++
  294. Implements:
  295. CHsmSession::FinalRelease().
  296. --*/
  297. {
  298. WsbTraceIn(OLESTR("CHsmSession::FinalRelease"), OLESTR("this = %p"),
  299. this);
  300. CWsbObject::FinalRelease();
  301. iCount--;
  302. WsbTraceOut(OLESTR("CHsmSession::FinalRelease"), OLESTR("Count is <%d>"), iCount);
  303. }
  304. HRESULT
  305. CHsmSession::GetAdviseInterval(
  306. OUT LONGLONG* pInterval
  307. )
  308. /*++
  309. Implements:
  310. IHsmSession::GetAdviseInterval().
  311. --*/
  312. {
  313. HRESULT hr = S_OK;
  314. try {
  315. WsbAssert(0 != pInterval, E_POINTER);
  316. *pInterval = m_adviseInterval;
  317. } WsbCatch(hr);
  318. return(hr);
  319. }
  320. HRESULT
  321. CHsmSession::GetClassID(
  322. OUT CLSID* pClsid
  323. )
  324. /*++
  325. Implements:
  326. IPersist::GetClassID().
  327. --*/
  328. {
  329. HRESULT hr = S_OK;
  330. WsbTraceIn(OLESTR("CHsmSession::GetClassID"), OLESTR(""));
  331. try {
  332. WsbAssert(0 != pClsid, E_POINTER);
  333. *pClsid = CLSID_CHsmSession;
  334. } WsbCatch(hr);
  335. WsbTraceOut(OLESTR("CHsmSession::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  336. return(hr);
  337. }
  338. HRESULT
  339. CHsmSession::GetHsmId(
  340. OUT GUID* pId
  341. )
  342. /*++
  343. Implements:
  344. IHsmSession::GetHsmId().
  345. --*/
  346. {
  347. HRESULT hr = S_OK;
  348. try {
  349. WsbAssert(0 != pId, E_POINTER);
  350. *pId = m_hsmId;
  351. } WsbCatch(hr);
  352. return(hr);
  353. }
  354. HRESULT
  355. CHsmSession::GetIdentifier(
  356. OUT GUID* pId
  357. )
  358. /*++
  359. Implements:
  360. IHsmSession::GetIdentifier().
  361. --*/
  362. {
  363. HRESULT hr = S_OK;
  364. try {
  365. WsbAssert(0 != pId, E_POINTER);
  366. *pId = m_id;
  367. } WsbCatch(hr);
  368. return(hr);
  369. }
  370. HRESULT
  371. CHsmSession::GetJob(
  372. OUT IHsmJob** ppJob
  373. )
  374. /*++
  375. Implements:
  376. IHsmSession::GetJob().
  377. --*/
  378. {
  379. HRESULT hr = S_OK;
  380. try {
  381. WsbAssert(0 != ppJob, E_POINTER);
  382. *ppJob = m_pJob;
  383. if (m_pJob != 0) {
  384. m_pJob.p->AddRef();
  385. }
  386. } WsbCatch(hr);
  387. return(hr);
  388. }
  389. HRESULT
  390. CHsmSession::GetName(
  391. OLECHAR** pName,
  392. ULONG bufferSize
  393. )
  394. /*++
  395. Implements:
  396. IHsmSession::GetName().
  397. --*/
  398. {
  399. HRESULT hr = S_OK;
  400. try {
  401. WsbAssert(0 != pName, E_POINTER);
  402. WsbAffirmHr(m_name.CopyTo(pName, bufferSize));
  403. } WsbCatch(hr);
  404. return(hr);
  405. }
  406. HRESULT
  407. CHsmSession::GetResource(
  408. OUT IFsaResource** ppResource
  409. )
  410. /*++
  411. Implements:
  412. IHsmSession::GetResource().
  413. --*/
  414. {
  415. HRESULT hr = S_OK;
  416. try {
  417. WsbAssert(0 != ppResource, E_POINTER);
  418. *ppResource = m_pResource;
  419. if (m_pResource != 0) {
  420. m_pResource.p->AddRef();
  421. }
  422. } WsbCatch(hr);
  423. return(hr);
  424. }
  425. HRESULT
  426. CHsmSession::GetRunId(
  427. OUT ULONG* pId
  428. )
  429. /*++
  430. Implements:
  431. IHsmSession::GetRunId().
  432. --*/
  433. {
  434. HRESULT hr = S_OK;
  435. try {
  436. WsbAssert(0 != pId, E_POINTER);
  437. *pId = m_runId;
  438. } WsbCatch(hr);
  439. return(hr);
  440. }
  441. HRESULT
  442. CHsmSession::GetSubRunId(
  443. OUT ULONG* pId
  444. )
  445. /*++
  446. Implements:
  447. IHsmSession::GetSubRunId().
  448. --*/
  449. {
  450. HRESULT hr = S_OK;
  451. try {
  452. WsbAssert(0 != pId, E_POINTER);
  453. *pId = m_subRunId;
  454. } WsbCatch(hr);
  455. return(hr);
  456. }
  457. HRESULT
  458. CHsmSession::GetSizeMax(
  459. OUT ULARGE_INTEGER* pSize
  460. )
  461. /*++
  462. Implements:
  463. IPersistStream::GetSizeMax().
  464. --*/
  465. {
  466. HRESULT hr = S_OK;
  467. WsbTraceIn(OLESTR("CHsmSession::GetSizeMax"), OLESTR(""));
  468. pSize->QuadPart = 0;
  469. hr = E_NOTIMPL;
  470. WsbTraceOut(OLESTR("CHsmSession::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pSize));
  471. return(hr);
  472. }
  473. HRESULT
  474. CHsmSession::Load(
  475. IN IStream* pStream
  476. )
  477. /*++
  478. Implements:
  479. IPersistStream::Load().
  480. --*/
  481. {
  482. HRESULT hr = S_OK;
  483. WsbTraceIn(OLESTR("CHsmSession::Load"), OLESTR(""));
  484. try {
  485. WsbAssert(0 != pStream, E_POINTER);
  486. hr = E_NOTIMPL;
  487. } WsbCatch(hr);
  488. WsbTraceOut(OLESTR("CHsmSession::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  489. return(hr);
  490. }
  491. HRESULT
  492. CHsmSession::Pause(
  493. IN HSM_JOB_PHASE phase
  494. )
  495. /*++
  496. Implements:
  497. IHsmSession::Pause().
  498. --*/
  499. {
  500. return(AdviseOfEvent(phase, HSM_JOB_EVENT_PAUSE));
  501. }
  502. HRESULT
  503. CHsmSession::ProcessEvent(
  504. IN HSM_JOB_PHASE phase,
  505. IN HSM_JOB_EVENT event
  506. )
  507. /*++
  508. Implements:
  509. IHsmSession::ProcessEvent().
  510. --*/
  511. {
  512. HRESULT hr = S_OK;
  513. HRESULT hr2 = S_OK;
  514. try {
  515. // Tell everyone about the new event, but don't return an error if this fails.
  516. try {
  517. WsbAffirmHr(AdviseOfEvent(phase, event));
  518. } WsbCatchAndDo(hr2, ProcessHr(phase, __FILE__, __LINE__, hr2););
  519. } WsbCatch(hr);
  520. return(hr);
  521. }
  522. HRESULT
  523. CHsmSession::ProcessHr(
  524. IN HSM_JOB_PHASE phase,
  525. IN CHAR* file,
  526. IN ULONG line,
  527. IN HRESULT inHr
  528. )
  529. /*++
  530. Implements:
  531. IHsmSession::ProcessHr().
  532. --*/
  533. {
  534. HRESULT hr = S_OK;
  535. CComPtr<IWsbEnum> pEnum;
  536. CComPtr<IHsmPhasePriv> pPhasePriv;
  537. CComPtr<IHsmPhasePriv> pFoundPhasePriv;
  538. CWsbStringPtr phaseName;
  539. CWsbStringPtr resourceName;
  540. CWsbStringPtr fileName = file;
  541. UNREFERENCED_PARAMETER(line);
  542. try {
  543. if ((m_logControl & HSM_JOB_LOG_HR) != 0) {
  544. WsbAffirmHr(EnumPhases(&pEnum));
  545. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  546. WsbAffirmHr(pPhasePriv->SetPhase(phase));
  547. WsbAffirmHr(pEnum->Find(pPhasePriv, IID_IHsmPhasePriv, (void**) &pFoundPhasePriv));
  548. WsbAffirmHr(pFoundPhasePriv->GetName(&phaseName, 0));
  549. WsbAffirmHr(m_pResource->GetLogicalName(&resourceName, 0));
  550. // If no file was specified, then don't display the file and line number.
  551. if ((0 == file) || (0 == *file)) {
  552. WsbLogEvent(JOB_MESSAGE_SESSION_ERROR, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, WsbHrAsString(inHr), NULL);
  553. } else {
  554. #ifdef DBG
  555. WsbLogEvent(JOB_MESSAGE_SESSION_INTERNALERROR, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, (OLECHAR*) fileName, WsbLongAsString(line), WsbHrAsString(inHr), NULL);
  556. #else
  557. WsbLogEvent(JOB_MESSAGE_SESSION_ERROR, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, WsbHrAsString(inHr), NULL);
  558. #endif
  559. }
  560. }
  561. } WsbCatch(hr);
  562. return(hr);
  563. }
  564. HRESULT
  565. CHsmSession::ProcessItem(
  566. IN HSM_JOB_PHASE phase,
  567. IN HSM_JOB_ACTION action,
  568. IN IFsaScanItem* pScanItem,
  569. IN HRESULT hrItem
  570. )
  571. /*++
  572. Implements:
  573. IHsmSession::ProcessItem().
  574. --*/
  575. {
  576. HRESULT hr = S_OK;
  577. HRESULT hr2 = S_OK;
  578. CWsbStringPtr itemPath;
  579. CWsbStringPtr phaseName;
  580. CWsbStringPtr resourceName;
  581. CComPtr<IWsbEnum> pEnum;
  582. CComPtr<IHsmPhasePriv> pPhasePriv;
  583. CComPtr<IHsmPhasePriv> pFoundPhasePriv;
  584. CComPtr<IHsmPhase> pFoundPhase;
  585. CComPtr<IHsmSessionTotalsPriv> pTotalsPriv;
  586. CComPtr<IHsmSessionTotalsPriv> pFoundTotalsPriv;
  587. CComPtr<IHsmSessionTotals> pFoundTotals;
  588. try {
  589. // Update the phase.
  590. WsbAffirmHr(EnumPhases(&pEnum));
  591. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  592. WsbAffirmHr(pPhasePriv->SetPhase(phase));
  593. hr = pEnum->Find(pPhasePriv, IID_IHsmPhasePriv, (void**) &pFoundPhasePriv);
  594. // If one wasn't found then add it, otherwise, just update the state.
  595. if (hr == WSB_E_NOTFOUND) {
  596. hr = S_OK;
  597. WsbAffirmHr(pPhasePriv->AddItem(pScanItem, hrItem));
  598. WsbAffirmHr(m_pPhases->Add(pPhasePriv));
  599. pFoundPhasePriv = pPhasePriv;
  600. } else if (SUCCEEDED(hr)) {
  601. WsbAffirmHr(pFoundPhasePriv->AddItem(pScanItem, hrItem));
  602. }
  603. pEnum = 0;
  604. // Update the session totals.
  605. WsbAffirmHr(EnumTotals(&pEnum));
  606. WsbAffirmHr(CoCreateInstance(CLSID_CHsmSessionTotals, 0, CLSCTX_ALL, IID_IHsmSessionTotalsPriv, (void**) &pTotalsPriv));
  607. WsbAffirmHr(pTotalsPriv->SetAction(action));
  608. hr = pEnum->Find(pTotalsPriv, IID_IHsmSessionTotalsPriv, (void**) &pFoundTotalsPriv);
  609. // If one wasn't found then add it, otherwise, just update the state.
  610. if (hr == WSB_E_NOTFOUND) {
  611. hr = S_OK;
  612. WsbAffirmHr(pTotalsPriv->AddItem(pScanItem, hrItem));
  613. WsbAffirmHr(m_pTotals->Add(pTotalsPriv));
  614. pFoundTotalsPriv = pTotalsPriv;
  615. } else if (SUCCEEDED(hr)) {
  616. WsbAffirmHr(pFoundTotalsPriv->AddItem(pScanItem, hrItem));
  617. }
  618. // If we had a error (other than just some information ones from the scanner), then
  619. // log it.
  620. if (((m_logControl & HSM_JOB_LOG_ITEMALL) != 0) ||
  621. (((m_logControl & HSM_JOB_LOG_ITEMALLFAIL) != 0) && FAILED(hrItem)) ||
  622. (((m_logControl & HSM_JOB_LOG_ITEMMOSTFAIL) != 0) &&
  623. (FAILED(hrItem) && (hrItem != JOB_E_FILEEXCLUDED) && (hrItem != JOB_E_DOESNTMATCH)))) {
  624. WsbAffirmHr(pFoundPhasePriv->GetName(&phaseName, 0));
  625. WsbAffirmHr(m_pResource->GetLogicalName(&resourceName, 0));
  626. WsbAffirmHr(pScanItem->GetPathAndName(0, &itemPath, 0));
  627. WsbLogEvent(JOB_MESSAGE_SESSION_ITEM_SKIPPED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, WsbAbbreviatePath(itemPath, 120), WsbHrAsString(hrItem), NULL);
  628. }
  629. // Tell everyone about the item.
  630. //
  631. // NOTE: We might want to clone the phase and session totals so that the don't get
  632. // updated before the called method gets a chance to look at them.
  633. try {
  634. WsbAffirmHr(pFoundPhasePriv->QueryInterface(IID_IHsmPhase, (void**) &pFoundPhase));
  635. WsbAffirmHr(pFoundTotalsPriv->QueryInterface(IID_IHsmSessionTotals, (void**) &pFoundTotals));
  636. WsbAffirmHr(AdviseOfItem(pFoundPhase, pScanItem, hrItem, pFoundTotals));
  637. } WsbCatchAndDo(hr2, ((IHsmSession*) this)->ProcessHr(phase, __FILE__, __LINE__, hr2););
  638. } WsbCatch(hr);
  639. return(hr);
  640. }
  641. HRESULT
  642. CHsmSession::ProcessMediaState(
  643. IN HSM_JOB_PHASE phase,
  644. IN HSM_JOB_MEDIA_STATE state,
  645. IN OLECHAR* mediaName,
  646. IN HSM_JOB_MEDIA_TYPE mediaType,
  647. IN ULONG time
  648. )
  649. /*++
  650. Implements:
  651. IHsmSession::ProcessMediaState().
  652. --*/
  653. {
  654. HRESULT hr = S_OK;
  655. HRESULT hr2 = S_OK;
  656. CComPtr<IWsbEnum> pEnum;
  657. CComPtr<IHsmPhasePriv> pPhasePriv;
  658. CComPtr<IHsmPhasePriv> pFoundPhasePriv;
  659. CComPtr<IHsmPhase> pFoundPhase;
  660. try {
  661. // Record the state change in the phase object.
  662. WsbAffirmHr(EnumPhases(&pEnum));
  663. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  664. WsbAffirmHr(pPhasePriv->SetPhase(phase));
  665. hr = pEnum->Find(pPhasePriv, IID_IHsmPhasePriv, (void**) &pFoundPhasePriv);
  666. // If one wasn't found then add it, otherwise, just update the state.
  667. if (hr == WSB_E_NOTFOUND) {
  668. hr = S_OK;
  669. WsbAffirmHr(pPhasePriv->SetMediaState(state));
  670. WsbAffirmHr(m_pPhases->Add(pPhasePriv));
  671. pFoundPhasePriv = pPhasePriv;
  672. } else {
  673. WsbAffirmHr(pFoundPhasePriv->SetMediaState(state));
  674. }
  675. // Tell everyone about the new state, but don't return an error if this fails.
  676. try {
  677. WsbAffirmHr(pFoundPhasePriv->QueryInterface(IID_IHsmPhase, (void**) &pFoundPhase));
  678. WsbAffirmHr(AdviseOfMediaState(pFoundPhase, state, mediaName, mediaType, time));
  679. } WsbCatchAndDo(hr2, ((IHsmSession*) this)->ProcessHr(phase, __FILE__, __LINE__, hr2););
  680. } WsbCatch(hr);
  681. return(hr);
  682. }
  683. HRESULT
  684. CHsmSession::ProcessPriority(
  685. IN HSM_JOB_PHASE phase,
  686. IN HSM_JOB_PRIORITY priority
  687. )
  688. /*++
  689. Implements:
  690. IHsmSession::ProcessPriority().
  691. --*/
  692. {
  693. HRESULT hr = S_OK;
  694. HRESULT hr2 = S_OK;
  695. CComPtr<IWsbEnum> pEnum;
  696. CComPtr<IHsmPhasePriv> pPhasePriv;
  697. CComPtr<IHsmPhasePriv> pFoundPhasePriv;
  698. CComPtr<IHsmPhase> pFoundPhase;
  699. try {
  700. // Record the state change in the phase object.
  701. WsbAffirmHr(EnumPhases(&pEnum));
  702. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  703. WsbAffirmHr(pPhasePriv->SetPhase(phase));
  704. hr = pEnum->Find(pPhasePriv, IID_IHsmPhasePriv, (void**) &pFoundPhasePriv);
  705. // If one wasn't found then add it, otherwise, just update the state.
  706. if (hr == WSB_E_NOTFOUND) {
  707. hr = S_OK;
  708. WsbAffirmHr(pPhasePriv->SetPriority(priority));
  709. WsbAffirmHr(m_pPhases->Add(pPhasePriv));
  710. pFoundPhasePriv = pPhasePriv;
  711. } else {
  712. WsbAffirmHr(pFoundPhasePriv->SetPriority(priority));
  713. }
  714. // Tell everyone about the new state, but don't return an error if this fails.
  715. try {
  716. WsbAffirmHr(pFoundPhasePriv->QueryInterface(IID_IHsmPhase, (void**) &pFoundPhase));
  717. WsbAffirmHr(AdviseOfPriority(pFoundPhase));
  718. } WsbCatchAndDo(hr2, ((IHsmSession*) this)->ProcessHr(phase, __FILE__, __LINE__, hr2););
  719. } WsbCatch(hr);
  720. return(hr);
  721. }
  722. HRESULT
  723. CHsmSession::ProcessState(
  724. IN HSM_JOB_PHASE phase,
  725. IN HSM_JOB_STATE state,
  726. IN OLECHAR* currentPath,
  727. IN BOOL bLog
  728. )
  729. /*++
  730. Implements:
  731. IHsmSession::ProcessState().
  732. --*/
  733. {
  734. HRESULT hr = S_OK;
  735. HRESULT hr2 = S_OK;
  736. CComPtr<IWsbEnum> pEnum;
  737. CComPtr<IHsmPhase> pPhase;
  738. CComPtr<IHsmPhasePriv> pPhasePriv;
  739. CComPtr<IHsmPhase> pFoundPhase;
  740. CComPtr<IHsmPhasePriv> pFoundPhasePriv;
  741. CComPtr<IHsmPhase> pClonedPhase;
  742. CComPtr<IHsmPhasePriv> pClonedPhasePriv;
  743. HSM_JOB_STATE oldState;
  744. HSM_JOB_STATE otherState;
  745. HSM_JOB_STATE setState;
  746. BOOL shouldSet;
  747. LONGLONG items;
  748. LONGLONG skippedItems;
  749. LONGLONG errorItems;
  750. LONGLONG size;
  751. LONGLONG skippedSize;
  752. LONGLONG errorSize;
  753. ULONG days;
  754. USHORT hours;
  755. USHORT minutes;
  756. USHORT seconds;
  757. LONGLONG elapsedTime;
  758. OLECHAR itemsString[40];
  759. OLECHAR sizeString[40];
  760. OLECHAR skippedItemsString[40];
  761. OLECHAR skippedSizeString[40];
  762. OLECHAR errorItemsString[40];
  763. OLECHAR errorSizeString[40];
  764. OLECHAR durationString[40];
  765. OLECHAR itemRateString[40];
  766. OLECHAR byteRateString[40];
  767. CWsbStringPtr resourceName;
  768. CWsbStringPtr phaseName;
  769. WsbTraceIn(OLESTR("CHsmSession::ProcessState"), OLESTR("Phase = <%d>, State = <%d>, Path = <%ls>, pLog = <%s>"),
  770. phase, state, WsbAbbreviatePath(currentPath, (WSB_TRACE_BUFF_SIZE - 100)), WsbBoolAsString(bLog));
  771. try {
  772. // Record the state change in the phase object.
  773. WsbAffirmHr(EnumPhases(&pEnum));
  774. WsbAffirmHr(CoCreateInstance(CLSID_CHsmPhase, 0, CLSCTX_ALL, IID_IHsmPhasePriv, (void**) &pPhasePriv));
  775. WsbAffirmHr(pPhasePriv->SetPhase(phase));
  776. hr = pEnum->Find(pPhasePriv, IID_IHsmPhasePriv, (void**) &pFoundPhasePriv);
  777. // If one wasn't found then add it, otherwise, just update the state.
  778. if (hr == WSB_E_NOTFOUND) {
  779. hr = S_OK;
  780. WsbAffirmHr(pPhasePriv->SetState(state));
  781. WsbAffirmHr(m_pPhases->Add(pPhasePriv));
  782. pFoundPhasePriv = pPhasePriv;
  783. } else {
  784. WsbAffirmHr(pFoundPhasePriv->SetState(state));
  785. }
  786. // Put something in the event log that indicates when is happening with the session.
  787. if (((m_logControl & HSM_JOB_LOG_STATE) != 0) && (bLog)) {
  788. WsbAffirmHr(m_pResource->GetLogicalName(&resourceName, 0));
  789. WsbAffirmHr(pFoundPhasePriv->GetName(&phaseName, 0));
  790. WsbAffirmHr(pFoundPhasePriv->GetStats(&items, &size, &skippedItems, &skippedSize, &errorItems, &errorSize));
  791. WsbAffirmHr(pFoundPhasePriv->GetElapsedTime(&days, &hours, &minutes, &seconds));
  792. elapsedTime = max(1, ((LONGLONG) seconds) + 60 * (((LONGLONG) minutes) + 60 * (((LONGLONG) hours) + (24 * ((LONGLONG) days)))));
  793. swprintf(itemsString, OLESTR("%I64u"), items);
  794. swprintf(sizeString, OLESTR("%I64u"), size);
  795. swprintf(skippedItemsString, OLESTR("%I64u"), skippedItems);
  796. swprintf(skippedSizeString, OLESTR("%I64u"), skippedSize);
  797. swprintf(errorItemsString, OLESTR("%I64u"), errorItems);
  798. swprintf(errorSizeString, OLESTR("%I64u"), errorSize);
  799. swprintf(durationString, OLESTR("%2.2u:%2.2u:%2.2u"), hours + (24 * days), minutes, seconds);
  800. swprintf(itemRateString, OLESTR("%I64u"), items / elapsedTime);
  801. swprintf(byteRateString, OLESTR("%I64u"), size / elapsedTime);
  802. switch (state) {
  803. case HSM_JOB_STATE_STARTING:
  804. WsbLogEvent(JOB_MESSAGE_SESSION_STARTING, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  805. break;
  806. case HSM_JOB_STATE_RESUMING:
  807. WsbLogEvent(JOB_MESSAGE_SESSION_RESUMING, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  808. break;
  809. // If one hits this state, then change the overall state to this value
  810. case HSM_JOB_STATE_ACTIVE:
  811. WsbLogEvent(JOB_MESSAGE_SESSION_ACTIVE, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  812. break;
  813. case HSM_JOB_STATE_CANCELLING:
  814. WsbLogEvent(JOB_MESSAGE_SESSION_CANCELLING, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  815. break;
  816. case HSM_JOB_STATE_PAUSING:
  817. WsbLogEvent(JOB_MESSAGE_SESSION_PAUSING, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  818. break;
  819. case HSM_JOB_STATE_SUSPENDING:
  820. WsbLogEvent(JOB_MESSAGE_SESSION_SUSPENDING, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  821. break;
  822. case HSM_JOB_STATE_CANCELLED:
  823. WsbLogEvent(JOB_MESSAGE_SESSION_CANCELLED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, itemsString, sizeString, skippedItemsString, skippedSizeString, errorItemsString, errorSizeString, durationString, itemRateString, byteRateString, NULL);
  824. break;
  825. case HSM_JOB_STATE_DONE:
  826. WsbLogEvent(JOB_MESSAGE_SESSION_DONE, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, itemsString, sizeString, skippedItemsString, skippedSizeString, errorItemsString, errorSizeString, durationString, itemRateString, byteRateString, NULL);
  827. break;
  828. case HSM_JOB_STATE_FAILED:
  829. WsbLogEvent(JOB_MESSAGE_SESSION_FAILED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, itemsString, sizeString, skippedItemsString, skippedSizeString, errorItemsString, errorSizeString, durationString, itemRateString, byteRateString, NULL);
  830. break;
  831. case HSM_JOB_STATE_IDLE:
  832. WsbLogEvent(JOB_MESSAGE_SESSION_IDLE, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  833. break;
  834. case HSM_JOB_STATE_PAUSED:
  835. WsbLogEvent(JOB_MESSAGE_SESSION_PAUSED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, itemsString, sizeString, skippedItemsString, skippedSizeString, errorItemsString, errorSizeString, durationString, itemRateString, byteRateString, NULL);
  836. break;
  837. case HSM_JOB_STATE_SUSPENDED:
  838. WsbLogEvent(JOB_MESSAGE_SESSION_SUSPENDED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, itemsString, sizeString, skippedItemsString, skippedSizeString, errorItemsString, errorSizeString, durationString, itemRateString, byteRateString, NULL);
  839. break;
  840. case HSM_JOB_STATE_SKIPPED:
  841. WsbLogEvent(JOB_MESSAGE_SESSION_SKIPPED, 0, NULL, (OLECHAR*) m_name, (OLECHAR*) phaseName, (OLECHAR*) resourceName, NULL);
  842. break;
  843. default:
  844. break;
  845. }
  846. }
  847. // Tell everyone about the new state, but don't return an error if this fails.
  848. try {
  849. WsbAffirmHr(pFoundPhasePriv->QueryInterface(IID_IHsmPhase, (void**) &pFoundPhase));
  850. WsbAffirmHr(AdviseOfState(pFoundPhase, currentPath));
  851. } WsbCatchAndDo(hr2, ((IHsmSession*) this)->ProcessHr(phase, __FILE__, __LINE__, hr2););
  852. // We may need to generate the "HSM_JOB_PHASE_ALL" messages. This is the session
  853. // summary for all the phases.
  854. // Remember the state, and only send a message if the state changes. We also need some strings to
  855. // log messages.
  856. oldState = m_state;
  857. switch (state) {
  858. // If one hits this state, then change the overall state to this value.
  859. // Also increment the activePhases count.
  860. case HSM_JOB_STATE_STARTING:
  861. if (0 == m_activePhases) {
  862. m_state = state;
  863. }
  864. m_activePhases++;
  865. break;
  866. case HSM_JOB_STATE_RESUMING:
  867. if (0 == m_activePhases) {
  868. m_state = state;
  869. }
  870. m_activePhases++;
  871. break;
  872. // If one hits this state, then change the overall state to this value
  873. case HSM_JOB_STATE_ACTIVE:
  874. if ((HSM_JOB_STATE_STARTING == m_state) || (HSM_JOB_STATE_RESUMING == m_state)) {
  875. m_state = state;
  876. }
  877. break;
  878. // If all change to this state, then change to this value.
  879. case HSM_JOB_STATE_CANCELLING:
  880. case HSM_JOB_STATE_PAUSING:
  881. case HSM_JOB_STATE_SUSPENDING:
  882. shouldSet = TRUE;
  883. for (hr2 = pEnum->First(IID_IHsmPhase, (void**) &pPhase);
  884. SUCCEEDED(hr2) && shouldSet;
  885. hr2 = pEnum->Next(IID_IHsmPhase, (void**) &pPhase)) {
  886. WsbAffirmHr(pPhase->GetState(&otherState));
  887. if ((state != otherState) && (HSM_JOB_STATE_SKIPPED != otherState)) {
  888. shouldSet = FALSE;
  889. }
  890. pPhase = 0;
  891. }
  892. if (state == HSM_JOB_STATE_CANCELLING) {
  893. // Some jobs might need to know that a phase is canceling
  894. m_isCanceling = TRUE;
  895. }
  896. if (shouldSet) {
  897. m_state = state;
  898. }
  899. break;
  900. // Decrement the the activePhases count. If all phases are in one of these states
  901. // (i.e. activeSessions count goes to 0), then change it to the "worst" state (first
  902. // in the follwing list) :
  903. // 1) Cancelled
  904. // 2) Failed
  905. // 3) Suspended
  906. // 4) Paused
  907. // 5) Idle
  908. // 6) Done
  909. case HSM_JOB_STATE_CANCELLED:
  910. case HSM_JOB_STATE_DONE:
  911. case HSM_JOB_STATE_FAILED:
  912. case HSM_JOB_STATE_IDLE:
  913. case HSM_JOB_STATE_PAUSED:
  914. case HSM_JOB_STATE_SUSPENDED:
  915. if (m_activePhases > 0) {
  916. m_activePhases--;
  917. if (m_activePhases == 0) {
  918. shouldSet = FALSE;
  919. setState = state;
  920. for (hr2 = pEnum->First(IID_IHsmPhase, (void**) &pPhase);
  921. SUCCEEDED(hr2);
  922. hr2 = pEnum->Next(IID_IHsmPhase, (void**) &pPhase)) {
  923. WsbAffirmHr(pPhase->GetState(&otherState));
  924. switch (otherState) {
  925. case HSM_JOB_STATE_CANCELLED:
  926. shouldSet = TRUE;
  927. setState = otherState;
  928. break;
  929. case HSM_JOB_STATE_FAILED:
  930. if (HSM_JOB_STATE_CANCELLED != setState) {
  931. shouldSet = TRUE;
  932. setState = otherState;
  933. }
  934. break;
  935. case HSM_JOB_STATE_SUSPENDED:
  936. if ((HSM_JOB_STATE_CANCELLED != setState) &&
  937. (HSM_JOB_STATE_FAILED != setState)) {
  938. shouldSet = TRUE;
  939. setState = otherState;
  940. }
  941. break;
  942. case HSM_JOB_STATE_IDLE:
  943. if ((HSM_JOB_STATE_CANCELLED != setState) &&
  944. (HSM_JOB_STATE_FAILED != setState) &&
  945. (HSM_JOB_STATE_SUSPENDED != setState)) {
  946. shouldSet = TRUE;
  947. setState = otherState;
  948. }
  949. break;
  950. case HSM_JOB_STATE_PAUSED:
  951. if (HSM_JOB_STATE_DONE == setState) {
  952. shouldSet = TRUE;
  953. setState = otherState;
  954. }
  955. break;
  956. case HSM_JOB_STATE_DONE:
  957. if (HSM_JOB_STATE_DONE == setState) {
  958. shouldSet = TRUE;
  959. }
  960. break;
  961. case HSM_JOB_STATE_ACTIVE:
  962. case HSM_JOB_STATE_CANCELLING:
  963. case HSM_JOB_STATE_PAUSING:
  964. case HSM_JOB_STATE_RESUMING:
  965. case HSM_JOB_STATE_SKIPPED:
  966. case HSM_JOB_STATE_STARTING:
  967. case HSM_JOB_STATE_SUSPENDING:
  968. default:
  969. break;
  970. }
  971. pPhase = 0;
  972. }
  973. if (shouldSet) {
  974. m_state = setState;
  975. }
  976. }
  977. }
  978. break;
  979. case HSM_JOB_STATE_SKIPPED:
  980. break;
  981. default:
  982. break;
  983. }
  984. if (oldState != m_state) {
  985. try {
  986. WsbAffirmHr(pFoundPhasePriv->Clone(&pClonedPhasePriv));
  987. WsbAffirmHr(pClonedPhasePriv->SetPhase(HSM_JOB_PHASE_ALL));
  988. WsbAffirmHr(pClonedPhasePriv->QueryInterface(IID_IHsmPhase, (void**) &pClonedPhase));
  989. WsbAffirmHr(AdviseOfState(pClonedPhase, currentPath));
  990. } WsbCatchAndDo(hr2, ((IHsmSession*) this)->ProcessHr(phase, __FILE__, __LINE__, hr2););
  991. }
  992. } WsbCatch(hr);
  993. WsbTraceOut(OLESTR("CHsmSession::ProcessState"), OLESTR("hr = <%ls>, State = <%d>, ActivePhases = <%lu>"), WsbHrAsString(hr), m_state, m_activePhases);
  994. return(hr);
  995. }
  996. HRESULT
  997. CHsmSession::ProcessString(
  998. IN HSM_JOB_PHASE /*phase*/,
  999. IN OLECHAR* string
  1000. )
  1001. /*++
  1002. Implements:
  1003. IHsmSession::ProcessString().
  1004. --*/
  1005. {
  1006. HRESULT hr = S_OK;
  1007. try {
  1008. // Don't know what to really do with it, but for now just print it.
  1009. _putts(string);
  1010. } WsbCatch(hr);
  1011. return(hr);
  1012. }
  1013. HRESULT
  1014. CHsmSession::Resume(
  1015. IN HSM_JOB_PHASE phase
  1016. )
  1017. /*++
  1018. Implements:
  1019. IHsmSession::Resume().
  1020. --*/
  1021. {
  1022. return(AdviseOfEvent(phase, HSM_JOB_EVENT_RESUME));
  1023. }
  1024. HRESULT
  1025. CHsmSession::Save(
  1026. IN IStream* pStream,
  1027. IN BOOL clearDirty
  1028. )
  1029. /*++
  1030. Implements:
  1031. IPersistStream::Save().
  1032. --*/
  1033. {
  1034. HRESULT hr = S_OK;
  1035. CComPtr<IPersistStream> pPersistStream;
  1036. WsbTraceIn(OLESTR("CHsmSession::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  1037. try {
  1038. WsbAssert(0 != pStream, E_POINTER);
  1039. hr = E_NOTIMPL;
  1040. } WsbCatch(hr);
  1041. WsbTraceOut(OLESTR("CHsmSession::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  1042. return(hr);
  1043. }
  1044. HRESULT
  1045. CHsmSession::SetAdviseInterval(
  1046. IN LONGLONG interval
  1047. )
  1048. /*++
  1049. Implements:
  1050. IHsmSession::SetAdviseInterval
  1051. --*/
  1052. {
  1053. m_adviseInterval = interval;
  1054. m_isDirty = TRUE;
  1055. return(S_OK);
  1056. }
  1057. HRESULT
  1058. CHsmSession::Start(
  1059. IN OLECHAR* name,
  1060. IN ULONG logControl,
  1061. IN GUID hsmId,
  1062. IN IHsmJob* pJob,
  1063. IN IFsaResource* pResource,
  1064. IN ULONG runId,
  1065. IN ULONG subRunId
  1066. )
  1067. /*++
  1068. Implements:
  1069. IHsmSession::Start().
  1070. --*/
  1071. {
  1072. HRESULT hr = S_OK;
  1073. try {
  1074. WsbAssert(0 != pResource, E_POINTER);
  1075. // You can only use a session once (i.e. no restart).
  1076. WsbAssert(m_pResource == 0, E_UNEXPECTED);
  1077. // Store the information that has been provided.
  1078. m_logControl = logControl;
  1079. m_name = name;
  1080. m_hsmId = hsmId;
  1081. m_runId = runId;
  1082. m_subRunId = subRunId;
  1083. m_pJob = pJob;
  1084. m_pResource = pResource;
  1085. m_isDirty = TRUE;
  1086. } WsbCatch(hr);
  1087. return(hr);
  1088. }
  1089. HRESULT
  1090. CHsmSession::Suspend(
  1091. IN HSM_JOB_PHASE phase
  1092. )
  1093. /*++
  1094. Implements:
  1095. IHsmSession::Suspend().
  1096. --*/
  1097. {
  1098. return(AdviseOfEvent(phase, HSM_JOB_EVENT_SUSPEND));
  1099. }
  1100. HRESULT
  1101. CHsmSession::Test(
  1102. OUT USHORT* passed,
  1103. OUT USHORT* failed
  1104. )
  1105. /*++
  1106. Implements:
  1107. IWsbTestable::Test().
  1108. --*/
  1109. {
  1110. HRESULT hr = S_OK;
  1111. try {
  1112. WsbAssert(0 != passed, E_POINTER);
  1113. WsbAssert(0 != failed, E_POINTER);
  1114. *passed = 0;
  1115. *failed = 0;
  1116. } WsbCatch(hr);
  1117. return(hr);
  1118. }
  1119. HRESULT
  1120. CHsmSession::IsCanceling(
  1121. void
  1122. )
  1123. /*++
  1124. Implements:
  1125. IHsmSession::IsCanceling().
  1126. --*/
  1127. {
  1128. HRESULT hr = S_FALSE;
  1129. if (m_isCanceling) {
  1130. hr = S_OK;
  1131. }
  1132. return(hr);
  1133. }