Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

759 lines
15 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmsesst.cpp
  5. Abstract:
  6. This class is the session totals component, which keeps track of totals for a session
  7. on a per action basis.
  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 "hsmsesst.h"
  16. #define WSB_TRACE_IS WSB_TRACE_BIT_JOB
  17. static USHORT iCount = 0;
  18. HRESULT
  19. CHsmSessionTotals::AddItem(
  20. IN IFsaScanItem* pItem,
  21. IN HRESULT hrItem
  22. )
  23. /*++
  24. Implements:
  25. IHsmSessionTotalsPriv::AddItem().
  26. --*/
  27. {
  28. HRESULT hr = S_OK;
  29. LONGLONG size;
  30. WsbTraceIn(OLESTR("CHsmSessionTotals::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 statistics.
  37. switch (hrItem) {
  38. case S_OK:
  39. m_items++;
  40. m_size += size;
  41. break;
  42. case S_FALSE:
  43. case JOB_E_FILEEXCLUDED:
  44. case JOB_E_DOESNTMATCH:
  45. case FSA_E_REPARSE_NOT_WRITTEN_FILE_CHANGED:
  46. case HSM_E_FILE_CHANGED:
  47. m_skippedItems++;
  48. m_skippedSize += size;
  49. break;
  50. default:
  51. m_errorItems++;
  52. m_errorSize += size;
  53. break;
  54. }
  55. } WsbCatch(hr);
  56. WsbTraceOut(OLESTR("CHsmSessionTotals::AddItem"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  57. return(hr);
  58. }
  59. HRESULT
  60. CHsmSessionTotals::Clone(
  61. OUT IHsmSessionTotals** ppSessionTotals
  62. )
  63. /*++
  64. Implements:
  65. IHsmSessionTotals::Clone().
  66. --*/
  67. {
  68. HRESULT hr = S_OK;
  69. CComPtr<IHsmSessionTotals> pSessionTotals;
  70. WsbTraceIn(OLESTR("CHsmSessionTotals::Clone"), OLESTR(""));
  71. try {
  72. // Did they give us a valid item?
  73. WsbAssert(0 != ppSessionTotals, E_POINTER);
  74. *ppSessionTotals = 0;
  75. // Create the new instance.
  76. WsbAffirmHr(CoCreateInstance(CLSID_CHsmSessionTotals, 0, CLSCTX_ALL, IID_IHsmSessionTotals, (void**) &pSessionTotals));
  77. // Fill it in with the new values.
  78. WsbAffirmHr(CopyTo(pSessionTotals));
  79. // Return it to the caller.
  80. *ppSessionTotals = pSessionTotals;
  81. pSessionTotals->AddRef();
  82. } WsbCatch(hr);
  83. WsbTraceOut(OLESTR("CHsmSessionTotals::Clone"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  84. return(hr);
  85. }
  86. HRESULT
  87. CHsmSessionTotals::Clone(
  88. OUT IHsmSessionTotalsPriv** ppSessionTotalsPriv
  89. )
  90. /*++
  91. Implements:
  92. IHsmSessionTotalsPriv::Clone().
  93. --*/
  94. {
  95. HRESULT hr = S_OK;
  96. CComPtr<IHsmSessionTotalsPriv> pSessionTotalsPriv;
  97. WsbTraceIn(OLESTR("CHsmSessionTotals::Clone"), OLESTR(""));
  98. try {
  99. // Did they give us a valid item?
  100. WsbAssert(0 != ppSessionTotalsPriv, E_POINTER);
  101. *ppSessionTotalsPriv = 0;
  102. // Create the new instance.
  103. WsbAffirmHr(CoCreateInstance(CLSID_CHsmSessionTotals, 0, CLSCTX_ALL, IID_IHsmSessionTotalsPriv, (void**) &pSessionTotalsPriv));
  104. // Fill it in with the new values.
  105. WsbAffirmHr(CopyTo(pSessionTotalsPriv));
  106. // Return it to the caller.
  107. *ppSessionTotalsPriv = pSessionTotalsPriv;
  108. pSessionTotalsPriv->AddRef();
  109. } WsbCatch(hr);
  110. WsbTraceOut(OLESTR("CHsmSessionTotals::Clone"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  111. return(hr);
  112. }
  113. HRESULT
  114. CHsmSessionTotals::CompareTo(
  115. IN IUnknown* pUnknown,
  116. OUT SHORT* pResult
  117. )
  118. /*++
  119. Implements:
  120. IWsbCollectable::CompareTo().
  121. --*/
  122. {
  123. HRESULT hr = S_OK;
  124. CComPtr<IHsmSessionTotals> pSessionTotals;
  125. WsbTraceIn(OLESTR("CHsmSessionTotals::CompareTo"), OLESTR(""));
  126. try {
  127. // Did they give us a valid item to compare to?
  128. WsbAssert(0 != pUnknown, E_POINTER);
  129. // We need the IWsbBool interface to get the value of the object.
  130. WsbAffirmHr(pUnknown->QueryInterface(IID_IHsmSessionTotals, (void**) &pSessionTotals));
  131. // Compare the rules.
  132. hr = CompareToISessionTotals(pSessionTotals, pResult);
  133. } WsbCatch(hr);
  134. WsbTraceOut(OLESTR("CHsmSessionTotals::CompareTo"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  135. return(hr);
  136. }
  137. HRESULT
  138. CHsmSessionTotals::CompareToAction(
  139. IN HSM_JOB_ACTION action,
  140. OUT SHORT* pResult
  141. )
  142. /*++
  143. Implements:
  144. IHsmSessionTotals::CompareToAction().
  145. --*/
  146. {
  147. HRESULT hr = S_OK;
  148. SHORT aResult = 0;
  149. WsbTraceIn(OLESTR("CHsmSessionTotals::CompareToAction"), OLESTR(""));
  150. try {
  151. // Compare the guids.
  152. if (m_action > action) {
  153. aResult = 1;
  154. }
  155. else if (m_action < action) {
  156. aResult = -1;
  157. }
  158. if (0 != aResult) {
  159. hr = S_FALSE;
  160. }
  161. if (0 != pResult) {
  162. *pResult = aResult;
  163. }
  164. } WsbCatch(hr);
  165. WsbTraceOut(OLESTR("CHsmSessionTotals::CompareToAction"), OLESTR("hr = <%ls>, result = <%d>"), WsbHrAsString(hr), aResult);
  166. return(hr);
  167. }
  168. HRESULT
  169. CHsmSessionTotals::CompareToISessionTotals(
  170. IN IHsmSessionTotals* pTotals,
  171. OUT SHORT* pResult
  172. )
  173. /*++
  174. Implements:
  175. IHsmSessionTotals::CompareToISessionTotals().
  176. --*/
  177. {
  178. HRESULT hr = S_OK;
  179. HSM_JOB_ACTION action;
  180. WsbTraceIn(OLESTR("CHsmSessionTotals::CompareToISessionTotals"), OLESTR(""));
  181. try {
  182. // Did they give us a valid item to compare to?
  183. WsbAssert(0 != pTotals, E_POINTER);
  184. // Get the identifier.
  185. WsbAffirmHr(pTotals->GetAction(&action));
  186. // Compare to the identifier.
  187. hr = CompareToAction(action, pResult);
  188. } WsbCatch(hr);
  189. WsbTraceOut(OLESTR("CHsmSessionTotals::CompareToISessionTotals"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  190. return(hr);
  191. }
  192. HRESULT
  193. CHsmSessionTotals::CopyTo(
  194. IN IHsmSessionTotals* pSessionTotals
  195. )
  196. /*++
  197. Implements:
  198. IHsmSessionTotals::CopyTo().
  199. --*/
  200. {
  201. HRESULT hr = S_OK;
  202. CComPtr<IHsmSessionTotalsPriv> pSessionTotalsPriv;
  203. WsbTraceIn(OLESTR("CHsmSessionTotals::CopyTo"), OLESTR(""));
  204. try {
  205. // Did they give us a valid item?
  206. WsbAssert(0 != pSessionTotals, E_POINTER);
  207. // Get the private interface for the destination and copy the values.
  208. WsbAffirmHr(pSessionTotals->QueryInterface(IID_IHsmSessionTotalsPriv, (void**) &pSessionTotalsPriv));
  209. WsbAffirmHr(pSessionTotalsPriv->SetAction(m_action));
  210. WsbAffirmHr(pSessionTotalsPriv->SetStats(m_items, m_size, m_skippedItems, m_skippedSize, m_errorItems, m_errorSize));
  211. } WsbCatch(hr);
  212. WsbTraceOut(OLESTR("CHsmSessionTotals::CopyTo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  213. return(hr);
  214. }
  215. HRESULT
  216. CHsmSessionTotals::CopyTo(
  217. IN IHsmSessionTotalsPriv* pSessionTotalsPriv
  218. )
  219. /*++
  220. Implements:
  221. IHsmSessionTotals::CopyTo().
  222. --*/
  223. {
  224. HRESULT hr = S_OK;
  225. WsbTraceIn(OLESTR("CHsmSessionTotals::CopyTo"), OLESTR(""));
  226. try {
  227. // Did they give us a valid item?
  228. WsbAssert(0 != pSessionTotalsPriv, E_POINTER);
  229. // Get the private interface for the destination and copy the values.
  230. WsbAffirmHr(pSessionTotalsPriv->SetAction(m_action));
  231. WsbAffirmHr(pSessionTotalsPriv->SetStats(m_items, m_size, m_skippedItems, m_skippedSize, m_errorItems, m_errorSize));
  232. } WsbCatch(hr);
  233. WsbTraceOut(OLESTR("CHsmSessionTotals::CopyTo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  234. return(hr);
  235. }
  236. HRESULT
  237. CHsmSessionTotals::FinalConstruct(
  238. void
  239. )
  240. /*++
  241. Implements:
  242. CComObjectRoot::FinalConstruct().
  243. --*/
  244. {
  245. HRESULT hr = S_OK;
  246. WsbTraceIn(OLESTR("CHsmSessionTotals::FinalConstruct"), OLESTR(""));
  247. try {
  248. WsbAffirmHr(CWsbObject::FinalConstruct());
  249. m_action = HSM_JOB_ACTION_UNKNOWN;
  250. m_items = 0;
  251. m_size = 0;
  252. m_skippedItems = 0;
  253. m_skippedSize = 0;
  254. m_errorItems = 0;
  255. m_errorSize = 0;
  256. } WsbCatch(hr);
  257. iCount++;
  258. WsbTraceOut(OLESTR("CHsmSessionTotals::FinalConstruct"), OLESTR("hr = <%ls>, Count is <%d>"),
  259. WsbHrAsString(hr), iCount);
  260. return(hr);
  261. }
  262. void
  263. CHsmSessionTotals::FinalRelease(
  264. void
  265. )
  266. /*++
  267. Implements:
  268. CHsmSessionTotals::FinalRelease().
  269. --*/
  270. {
  271. WsbTraceIn(OLESTR("CHsmSessionTotals::FinalRelease"), OLESTR(""));
  272. CWsbObject::FinalRelease();
  273. iCount--;
  274. WsbTraceOut(OLESTR("CHsmSessionTotals:FinalRelease"), OLESTR("Count is <%d>"), iCount);
  275. }
  276. HRESULT
  277. CHsmSessionTotals::GetAction(
  278. OUT HSM_JOB_ACTION* pAction
  279. )
  280. /*++
  281. Implements:
  282. IHsmSessionTotals::GetAction().
  283. --*/
  284. {
  285. HRESULT hr = S_OK;
  286. try {
  287. WsbAssert(0 != pAction, E_POINTER);
  288. *pAction = m_action;
  289. } WsbCatch(hr);
  290. return(hr);
  291. }
  292. HRESULT
  293. CHsmSessionTotals::GetClassID(
  294. OUT CLSID* pClsid
  295. )
  296. /*++
  297. Implements:
  298. IPersist::GetClassID().
  299. --*/
  300. {
  301. HRESULT hr = S_OK;
  302. WsbTraceIn(OLESTR("CHsmSessionTotals::GetClassID"), OLESTR(""));
  303. try {
  304. WsbAssert(0 != pClsid, E_POINTER);
  305. *pClsid = CLSID_CHsmSessionTotals;
  306. } WsbCatch(hr);
  307. WsbTraceOut(OLESTR("CHsmSessionTotals::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  308. return(hr);
  309. }
  310. HRESULT
  311. CHsmSessionTotals::GetName(
  312. OUT OLECHAR** pName,
  313. IN ULONG bufferSize
  314. )
  315. /*++
  316. Implements:
  317. IHsmSessionTotals::GetName().
  318. --*/
  319. {
  320. HRESULT hr = S_OK;
  321. CWsbStringPtr tmpString;
  322. try {
  323. WsbAssert(0 != pName, E_POINTER);
  324. WsbAffirmHr(tmpString.LoadFromRsc(_Module.m_hInst, IDS_HSMJOBACTION_UNKNOWN + m_action));
  325. WsbAffirmHr(tmpString.CopyTo(pName, bufferSize));
  326. } WsbCatch(hr);
  327. return(hr);
  328. }
  329. HRESULT
  330. CHsmSessionTotals::GetSizeMax(
  331. OUT ULARGE_INTEGER* pSize
  332. )
  333. /*++
  334. Implements:
  335. IPersistStream::GetSizeMax().
  336. --*/
  337. {
  338. HRESULT hr = S_OK;
  339. WsbTraceIn(OLESTR("CHsmSessionTotals::GetSizeMax"), OLESTR(""));
  340. try {
  341. WsbAssert(0 != pSize, E_POINTER);
  342. // Determine the size for a rule with no criteria.
  343. pSize->QuadPart = 4 * WsbPersistSizeOf(LONGLONG) + WsbPersistSizeOf(ULONG);
  344. // In theory we should be saving the errorItems and errorSize, but at the
  345. // time this was added, we didn't want to force a reinstall because of
  346. // pSize->QuadPart += 2 * WsbPersistSizeOf(LONGLONG);
  347. } WsbCatch(hr);
  348. WsbTraceOut(OLESTR("CHsmSessionTotals::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pSize));
  349. return(hr);
  350. }
  351. HRESULT
  352. CHsmSessionTotals::GetStats(
  353. OUT LONGLONG* pItems,
  354. OUT LONGLONG* pSize,
  355. OUT LONGLONG* pSkippedItems,
  356. OUT LONGLONG* pSkippedSize,
  357. OUT LONGLONG* pErrorItems,
  358. OUT LONGLONG* pErrorSize
  359. )
  360. /*++
  361. Implements:
  362. IHsmSessionTotals::GetStats().
  363. --*/
  364. {
  365. HRESULT hr = S_OK;
  366. if (0 != pItems) {
  367. *pItems = m_items;
  368. }
  369. if (0 != pSize) {
  370. *pSize = m_size;
  371. }
  372. if (0 != pSkippedItems) {
  373. *pSkippedItems = m_skippedItems;
  374. }
  375. if (0 != pSkippedSize) {
  376. *pSkippedSize = m_skippedSize;
  377. }
  378. if (0 != pErrorItems) {
  379. *pErrorItems = m_errorItems;
  380. }
  381. if (0 != pSize) {
  382. *pErrorSize = m_errorSize;
  383. }
  384. return(hr);
  385. }
  386. HRESULT
  387. CHsmSessionTotals::Load(
  388. IN IStream* pStream
  389. )
  390. /*++
  391. Implements:
  392. IPersistStream::Load().
  393. --*/
  394. {
  395. HRESULT hr = S_OK;
  396. WsbTraceIn(OLESTR("CHsmSessionTotals::Load"), OLESTR(""));
  397. try {
  398. ULONG ul_tmp;
  399. WsbAssert(0 != pStream, E_POINTER);
  400. // Do the easy stuff, but make sure that this order matches the order
  401. // in the load method.
  402. WsbAffirmHr(WsbLoadFromStream(pStream, &ul_tmp));
  403. m_action = static_cast<HSM_JOB_ACTION>(ul_tmp);
  404. WsbAffirmHr(WsbLoadFromStream(pStream, &m_items));
  405. WsbAffirmHr(WsbLoadFromStream(pStream, &m_size));
  406. WsbAffirmHr(WsbLoadFromStream(pStream, &m_skippedItems));
  407. WsbAffirmHr(WsbLoadFromStream(pStream, &m_skippedSize));
  408. // In theory we should be saving the errorItems and errorSize, but at the
  409. // time this was added, we didn't want to force a reinstall because of
  410. // changes in the persistant data.
  411. // WsbAffirmHr(WsbLoadFromStream(pStream, &m_errorItems));
  412. // WsbAffirmHr(WsbLoadFromStream(pStream, &m_errorSize));
  413. } WsbCatch(hr);
  414. WsbTraceOut(OLESTR("CHsmSessionTotals::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  415. return(hr);
  416. }
  417. HRESULT
  418. CHsmSessionTotals::Save(
  419. IN IStream* pStream,
  420. IN BOOL clearDirty
  421. )
  422. /*++
  423. Implements:
  424. IPersistStream::Save().
  425. --*/
  426. {
  427. HRESULT hr = S_OK;
  428. WsbTraceIn(OLESTR("CHsmSessionTotals::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  429. try {
  430. WsbAssert(0 != pStream, E_POINTER);
  431. // Do the easy stuff, but make sure that this order matches the order
  432. // in the load method.
  433. WsbAffirmHr(WsbSaveToStream(pStream, static_cast<ULONG>(m_action)));
  434. WsbAffirmHr(WsbSaveToStream(pStream, m_items));
  435. WsbAffirmHr(WsbSaveToStream(pStream, m_size));
  436. WsbAffirmHr(WsbSaveToStream(pStream, m_skippedItems));
  437. WsbAffirmHr(WsbSaveToStream(pStream, m_skippedSize));
  438. // In theory we should be saving the errorItems and errorSize, but at the
  439. // time this was added, we didn't want to force a reinstall because of
  440. // changes in the persistant data.
  441. // WsbAffirmHr(WsbSaveToStream(pStream, m_errorItems));
  442. // WsbAffirmHr(WsbSaveToStream(pStream, m_errorSize));
  443. // If we got it saved and we were asked to clear the dirty bit, then
  444. // do so now.
  445. if (clearDirty) {
  446. m_isDirty = FALSE;
  447. }
  448. } WsbCatch(hr);
  449. WsbTraceOut(OLESTR("CHsmSessionTotals::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  450. return(hr);
  451. }
  452. HRESULT
  453. CHsmSessionTotals::SetAction(
  454. IN HSM_JOB_ACTION action
  455. )
  456. /*++
  457. Implements:
  458. IHsmSessionTotals::SetAction().
  459. --*/
  460. {
  461. m_action = action;
  462. return(S_OK);
  463. }
  464. HRESULT
  465. CHsmSessionTotals::SetStats(
  466. IN LONGLONG items,
  467. IN LONGLONG size,
  468. IN LONGLONG skippedItems,
  469. IN LONGLONG skippedSize,
  470. IN LONGLONG errorItems,
  471. IN LONGLONG errorSize
  472. )
  473. /*++
  474. Implements:
  475. IHsmSessionTotals::SetStats().
  476. --*/
  477. {
  478. m_items = items;
  479. m_size = size;
  480. m_skippedItems = skippedItems;
  481. m_skippedSize = skippedSize;
  482. m_errorItems = errorItems;
  483. m_errorSize = errorSize;
  484. return(S_OK);
  485. }
  486. HRESULT
  487. CHsmSessionTotals::Test(
  488. USHORT* passed,
  489. USHORT* failed
  490. )
  491. /*++
  492. Implements:
  493. IWsbTestable::Test().
  494. --*/
  495. {
  496. HRESULT hr = S_OK;
  497. try {
  498. WsbAssert(0 != passed, E_POINTER);
  499. WsbAssert(0 != failed, E_POINTER);
  500. *passed = 0;
  501. *failed = 0;
  502. } WsbCatch(hr);
  503. return(hr);
  504. }