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.

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