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.

589 lines
12 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. BagHole.cpp
  5. Abstract:
  6. This component is an object representation of the HSM Metadata bag hole record.
  7. Author:
  8. Cat Brant [cbrant] 26-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "metaint.h"
  13. #include "metalib.h"
  14. #include "BagHole.h"
  15. #undef WSB_TRACE_IS
  16. #define WSB_TRACE_IS WSB_TRACE_BIT_META
  17. HRESULT
  18. CBagHole::GetBagHole(
  19. OUT GUID *pBagId,
  20. OUT LONGLONG *pSegStartLoc,
  21. OUT LONGLONG *pSegLen
  22. )
  23. /*++
  24. Routine Description:
  25. See IBagHole::GetBagHole
  26. Arguments:
  27. See IBagHole::GetBagHole
  28. Return Value:
  29. See IBagHole::GetBagHole
  30. --*/
  31. {
  32. HRESULT hr = S_OK;
  33. WsbTraceIn(OLESTR("CBagHole::GetBagHole"),OLESTR(""));
  34. try {
  35. //Make sure we can provide data memebers
  36. WsbAssert(0 != pBagId, E_POINTER);
  37. WsbAssert(0 != pSegStartLoc, E_POINTER);
  38. WsbAssert(0 != pSegLen, E_POINTER);
  39. //Provide the data members
  40. *pBagId = m_BagId;
  41. *pSegStartLoc = m_SegStartLoc;
  42. *pSegLen = m_SegLen;
  43. } WsbCatch(hr);
  44. WsbTraceOut(OLESTR("CBagHole::GetBagHole"),
  45. OLESTR("BagId = <%ls>, SegStartLoc = <%ls>, SegLen = <%ls>"),
  46. WsbPtrToGuidAsString(pBagId),
  47. WsbStringCopy(WsbPtrToLonglongAsString(pSegStartLoc)),
  48. WsbStringCopy(WsbPtrToLonglongAsString(pSegLen)));
  49. return(hr);
  50. }
  51. HRESULT
  52. CBagHole::FinalConstruct(
  53. void
  54. )
  55. /*++
  56. Routine Description:
  57. This method does some initialization of the object that is necessary
  58. after construction.
  59. Arguments:
  60. None.
  61. Return Value:
  62. S_OK
  63. Anything returned by CWsbDbEntity::FinalConstruct().
  64. --*/
  65. {
  66. HRESULT hr = S_OK;
  67. try {
  68. WsbAssertHr(CWsbDbEntity::FinalConstruct());
  69. m_BagId = GUID_NULL;
  70. m_SegStartLoc = 0;
  71. m_SegLen = 0;
  72. } WsbCatch(hr);
  73. return(hr);
  74. }
  75. HRESULT CBagHole::GetClassID
  76. (
  77. OUT LPCLSID pclsid
  78. )
  79. /*++
  80. Routine Description:
  81. See IPerist::GetClassID()
  82. Arguments:
  83. See IPerist::GetClassID()
  84. Return Value:
  85. See IPerist::GetClassID()
  86. --*/
  87. {
  88. HRESULT hr = S_OK;
  89. WsbTraceIn(OLESTR("CBagHole::GetClassID"), OLESTR(""));
  90. try {
  91. WsbAssert(0 != pclsid, E_POINTER);
  92. *pclsid = CLSID_CBagHole;
  93. } WsbCatch(hr);
  94. WsbTraceOut(OLESTR("CBagHole::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pclsid));
  95. return(hr);
  96. }
  97. HRESULT CBagHole::GetSizeMax
  98. (
  99. OUT ULARGE_INTEGER* pcbSize
  100. )
  101. /*++
  102. Routine Description:
  103. See IPersistStream::GetSizeMax().
  104. Arguments:
  105. See IPersistStream::GetSizeMax().
  106. Return Value:
  107. See IPersistStream::GetSizeMax().
  108. --*/
  109. {
  110. HRESULT hr = S_OK;
  111. WsbTraceIn(OLESTR("CBagHole::GetSizeMax"), OLESTR(""));
  112. try {
  113. WsbAssert(0 != pcbSize, E_POINTER);
  114. pcbSize->QuadPart = WsbPersistSizeOf(GUID) + WsbPersistSizeOf(ULONG) + WsbPersistSizeOf(ULONG);
  115. pcbSize->QuadPart = WsbPersistSizeOf(CBagHole); //???????
  116. } WsbCatch(hr);
  117. WsbTraceOut(OLESTR("CBagHole::GetSizeMax"),
  118. OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr),
  119. WsbPtrToUliAsString(pcbSize));
  120. return(hr);
  121. }
  122. HRESULT CBagHole::Load
  123. (
  124. IN IStream* pStream
  125. )
  126. /*++
  127. Routine Description:
  128. See IPersistStream::Load().
  129. Arguments:
  130. See IPersistStream::Load().
  131. Return Value:
  132. See IPersistStream::Load().
  133. --*/
  134. {
  135. HRESULT hr = S_OK;
  136. WsbTraceIn(OLESTR("CBagHole::Load"), OLESTR(""));
  137. try {
  138. WsbAssert(0 != pStream, E_POINTER);
  139. WsbAffirmHr(WsbLoadFromStream(pStream, &m_BagId));
  140. WsbAffirmHr(WsbLoadFromStream(pStream, &m_SegStartLoc));
  141. WsbAffirmHr(WsbLoadFromStream(pStream, &m_SegLen));
  142. } WsbCatch(hr);
  143. WsbTraceOut(OLESTR("CBagHole::Load"),
  144. OLESTR("hr = <%ls>, GUID = <%ls>, SegStartLoc = <%lu>, SegLen = <%lu>"),
  145. WsbHrAsString(hr), WsbGuidAsString(m_BagId),m_SegStartLoc, m_SegLen);
  146. return(hr);
  147. }
  148. HRESULT CBagHole::Print
  149. (
  150. IN IStream* pStream
  151. )
  152. /*++
  153. Implements:
  154. IWsbDbEntity::Print
  155. --*/
  156. {
  157. HRESULT hr = S_OK;
  158. WsbTraceIn(OLESTR("CBagHole::Print"), OLESTR(""));
  159. try {
  160. WsbAssert(0 != pStream, E_POINTER);
  161. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagId = %ls"),
  162. WsbGuidAsString(m_BagId)));
  163. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", StartLoc = %ls"),
  164. WsbLonglongAsString(m_SegStartLoc)));
  165. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", SegLen = %ls"),
  166. WsbLonglongAsString(m_SegLen)));
  167. WsbAffirmHr(CWsbDbEntity::Print(pStream));
  168. } WsbCatch(hr);
  169. WsbTraceOut(OLESTR("CBagHole::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  170. return(hr);
  171. }
  172. HRESULT CBagHole::Save
  173. (
  174. IN IStream* pStream,
  175. IN BOOL clearDirty
  176. )
  177. /*++
  178. Routine Description:
  179. See IPersistStream::Save().
  180. Arguments:
  181. See IPersistStream::Save().
  182. Return Value:
  183. See IPersistStream::Save().
  184. --*/
  185. {
  186. HRESULT hr = S_OK;
  187. WsbTraceIn(OLESTR("CBagHole::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  188. try {
  189. WsbAssert(0 != pStream, E_POINTER);
  190. WsbAffirmHr(WsbSaveToStream(pStream, m_BagId));
  191. WsbAffirmHr(WsbSaveToStream(pStream, m_SegStartLoc));
  192. WsbAffirmHr(WsbSaveToStream(pStream, m_SegLen));
  193. // If we got it saved and we were asked to clear the dirty bit, then
  194. // do so now.
  195. if (clearDirty) {
  196. m_isDirty = FALSE;
  197. }
  198. } WsbCatch(hr);
  199. WsbTraceOut(OLESTR("CBagHole::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  200. return(hr);
  201. }
  202. HRESULT
  203. CBagHole::SetBagHole
  204. (
  205. IN GUID BagId,
  206. IN LONGLONG SegStartLoc,
  207. IN LONGLONG SegLen
  208. )
  209. /*++
  210. Routine Description:
  211. See IBagHole::SetBagHole().
  212. Arguments:
  213. See IBagHole::SetBagHole().
  214. Return Value:
  215. S_OK - Success.
  216. --*/
  217. {
  218. WsbTraceIn(OLESTR("CBagHole::SetBagHole"),
  219. OLESTR("BagId = <%ls>, SegStartLoc = <%ls>, SegLen = <%ls>"), WsbGuidAsString(BagId),
  220. WsbLonglongAsString(SegStartLoc), WsbLonglongAsString(SegLen));
  221. m_isDirty = TRUE;
  222. m_BagId = BagId;
  223. m_SegStartLoc = SegStartLoc;
  224. m_SegLen = SegLen;
  225. WsbTraceOut(OLESTR("CBagHole::SetBagHole"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  226. return(S_OK);
  227. }
  228. HRESULT
  229. CBagHole::Test
  230. (
  231. OUT USHORT *pTestsPassed,
  232. OUT USHORT *pTestsFailed
  233. )
  234. /*++
  235. Routine Description:
  236. See IWsbTestable::Test().
  237. Arguments:
  238. See IWsbTestable::Test().
  239. Return Value:
  240. See IWsbTestable::Test().
  241. --*/
  242. {
  243. #if 0
  244. HRESULT hr = S_OK;
  245. CComPtr<IBagHole> pBagHole1;
  246. CComPtr<IBagHole> pBagHole2;
  247. GUID l_BagId;
  248. LONGLONG l_SegStartLoc;
  249. LONGLONG l_SegLen;
  250. WsbTraceIn(OLESTR("CBagHole::Test"), OLESTR(""));
  251. *pTestsPassed = *pTestsFailed = 0;
  252. try {
  253. // Get the pBagHole interface.
  254. WsbAssertHr(((IUnknown*)(IBagHole*) this)->QueryInterface(IID_IBagHole,
  255. (void**) &pBagHole1));
  256. try {
  257. // Set the BagHole to a value, and see if it is returned.
  258. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CBagHole, 0, 6 ));
  259. WsbAssertHr(pBagHole1->GetBagHole(&l_BagId, &l_SegStartLoc, &l_SegLen));
  260. WsbAssert((l_BagId == CLSID_CBagHole) && (l_SegStartLoc == 0) &&
  261. (l_SegLen == 6), E_FAIL);
  262. } WsbCatch(hr);
  263. if (hr == S_OK) {
  264. (*pTestsPassed)++;
  265. } else {
  266. (*pTestsFailed)++;
  267. }
  268. #ifdef OLD_CODE
  269. hr = S_OK;
  270. try {
  271. //Create another instance and test the comparisson methods:
  272. WsbAssertHr(CoCreateInstance(CLSID_CBagHole, NULL, CLSCTX_ALL, IID_IBagHole, (void**) &pBagHole2));
  273. // Check the default values.
  274. WsbAssertHr(pBagHole2->GetBagHole(&l_BagId, &l_SegStartLoc, &l_SegLen));
  275. WsbAssert(((l_BagId == GUID_NULL) && (l_SegStartLoc == 0) && (l_SegLen == 0)), E_FAIL);
  276. } WsbCatch(hr);
  277. if (hr == S_OK) {
  278. (*pTestsPassed)++;
  279. } else {
  280. (*pTestsFailed)++;
  281. }
  282. hr = S_OK;
  283. try {
  284. // IsEqual()
  285. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 1, 100));
  286. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 1, 100));
  287. WsbAssertHr(pBagHole1->IsEqual(pBagHole2));
  288. } WsbCatch(hr);
  289. if (hr == S_OK) {
  290. (*pTestsPassed)++;
  291. } else {
  292. (*pTestsFailed)++;
  293. }
  294. hr = S_OK;
  295. try {
  296. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 5, 6));
  297. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  298. WsbAssert((pBagHole1->IsEqual(pBagHole2) == S_FALSE), E_FAIL);
  299. } WsbCatch(hr);
  300. if (hr == S_OK) {
  301. (*pTestsPassed)++;
  302. } else {
  303. (*pTestsFailed)++;
  304. }
  305. hr = S_OK;
  306. try {
  307. // CompareTo()
  308. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 1, 100));
  309. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 10, 6));
  310. WsbAssert((pBagHole1->CompareTo(pBagHole2, &result) == S_FALSE) && (result != 0), E_FAIL);
  311. } WsbCatch(hr);
  312. if (hr == S_OK) {
  313. (*pTestsPassed)++;
  314. } else {
  315. (*pTestsFailed)++;
  316. }
  317. hr = S_OK;
  318. try {
  319. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 0, 6));
  320. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  321. WsbAssert(((pBagHole1->CompareTo(pBagHole2, &result) == S_FALSE) && (result > 0)), E_FAIL);
  322. } WsbCatch(hr);
  323. if (hr == S_OK) {
  324. (*pTestsPassed)++;
  325. } else {
  326. (*pTestsFailed)++;
  327. }
  328. hr = S_OK;
  329. try {
  330. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 0, 6));
  331. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 0, 6));
  332. WsbAssert((pBagHole1->CompareTo(pBagHole2, &result) == S_OK), E_FAIL);
  333. } WsbCatch(hr);
  334. if (hr == S_OK) {
  335. (*pTestsPassed)++;
  336. } else {
  337. (*pTestsFailed)++;
  338. }
  339. try {
  340. // Try out the persistence stuff.
  341. CComPtr<IPersistFile> pFile1;
  342. CComPtr<IPersistFile> pFile2;
  343. WsbAssertHr(pBagHole1->QueryInterface(IID_IPersistFile, (void**) &pFile1));
  344. WsbAssertHr(pBagHole2->QueryInterface(IID_IPersistFile, (void**) &pFile2));
  345. LPOLESTR szTmp = NULL;
  346. // The item should be dirty.
  347. try {
  348. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  349. WsbAssertHr(pFile2->IsDirty());
  350. } WsbCatch(hr);
  351. if (hr == S_OK) {
  352. (*pTestsPassed)++;
  353. } else {
  354. (*pTestsFailed)++;
  355. }
  356. hr = S_OK;
  357. try {
  358. // Save the item, and remember.
  359. WsbAssertHr(pFile2->Save(OLESTR("c:\\WsbTests\\BagHole.tst"), TRUE));
  360. } WsbCatch(hr);
  361. if (hr == S_OK) {
  362. (*pTestsPassed)++;
  363. } else {
  364. (*pTestsFailed)++;
  365. }
  366. hr = S_OK;
  367. try {
  368. // It shouldn't be dirty.
  369. WsbAssert((pFile2->IsDirty() == S_FALSE), E_FAIL);
  370. } WsbCatch(hr);
  371. if (hr == S_OK) {
  372. (*pTestsPassed)++;
  373. } else {
  374. (*pTestsFailed)++;
  375. }
  376. hr = S_OK;
  377. try {
  378. // Try reading it in to another object.
  379. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbLong, 0, 6));
  380. WsbAssertHr(pFile1->Load(OLESTR("c:\\WsbTests\\BagHole.tst"), 0));
  381. WsbAssertHr(pBagHole1->CompareToIBagHole(pBagHole2, &result));
  382. }WsbCatch(hr);
  383. if (hr == S_OK) {
  384. (*pTestsPassed)++;
  385. } else {
  386. (*pTestsFailed)++;
  387. }
  388. } WsbCatch(hr);
  389. #endif
  390. } WsbCatch(hr);
  391. WsbTraceOut(OLESTR("CBagHole::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  392. #else
  393. UNREFERENCED_PARAMETER(pTestsPassed);
  394. UNREFERENCED_PARAMETER(pTestsFailed);
  395. #endif
  396. return(S_OK);
  397. }
  398. HRESULT
  399. CBagHole::UpdateKey(
  400. IWsbDbKey *pKey
  401. )
  402. /*++
  403. Implements:
  404. IWsbDbEntity::UpdateKey
  405. --*/
  406. {
  407. HRESULT hr = S_OK;
  408. try {
  409. WsbAffirmHr(pKey->SetToGuid(m_BagId));
  410. WsbAffirmHr(pKey->AppendLonglong(m_SegStartLoc));
  411. } WsbCatch(hr);
  412. return(hr);
  413. }