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.

591 lines
13 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. CWsbStringPtr strGuid;
  162. WsbAffirmHr(WsbSafeGuidAsString(m_BagId, strGuid));
  163. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(" BagId = %ls"),
  164. (WCHAR *)strGuid));
  165. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", StartLoc = %ls"),
  166. WsbLonglongAsString(m_SegStartLoc)));
  167. WsbAffirmHr(WsbPrintfToStream(pStream, OLESTR(", SegLen = %ls"),
  168. WsbLonglongAsString(m_SegLen)));
  169. WsbAffirmHr(CWsbDbEntity::Print(pStream));
  170. } WsbCatch(hr);
  171. WsbTraceOut(OLESTR("CBagHole::Print"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  172. return(hr);
  173. }
  174. HRESULT CBagHole::Save
  175. (
  176. IN IStream* pStream,
  177. IN BOOL clearDirty
  178. )
  179. /*++
  180. Routine Description:
  181. See IPersistStream::Save().
  182. Arguments:
  183. See IPersistStream::Save().
  184. Return Value:
  185. See IPersistStream::Save().
  186. --*/
  187. {
  188. HRESULT hr = S_OK;
  189. WsbTraceIn(OLESTR("CBagHole::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  190. try {
  191. WsbAssert(0 != pStream, E_POINTER);
  192. WsbAffirmHr(WsbSaveToStream(pStream, m_BagId));
  193. WsbAffirmHr(WsbSaveToStream(pStream, m_SegStartLoc));
  194. WsbAffirmHr(WsbSaveToStream(pStream, m_SegLen));
  195. // If we got it saved and we were asked to clear the dirty bit, then
  196. // do so now.
  197. if (clearDirty) {
  198. m_isDirty = FALSE;
  199. }
  200. } WsbCatch(hr);
  201. WsbTraceOut(OLESTR("CBagHole::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  202. return(hr);
  203. }
  204. HRESULT
  205. CBagHole::SetBagHole
  206. (
  207. IN GUID BagId,
  208. IN LONGLONG SegStartLoc,
  209. IN LONGLONG SegLen
  210. )
  211. /*++
  212. Routine Description:
  213. See IBagHole::SetBagHole().
  214. Arguments:
  215. See IBagHole::SetBagHole().
  216. Return Value:
  217. S_OK - Success.
  218. --*/
  219. {
  220. WsbTraceIn(OLESTR("CBagHole::SetBagHole"),
  221. OLESTR("BagId = <%ls>, SegStartLoc = <%ls>, SegLen = <%ls>"), WsbGuidAsString(BagId),
  222. WsbLonglongAsString(SegStartLoc), WsbLonglongAsString(SegLen));
  223. m_isDirty = TRUE;
  224. m_BagId = BagId;
  225. m_SegStartLoc = SegStartLoc;
  226. m_SegLen = SegLen;
  227. WsbTraceOut(OLESTR("CBagHole::SetBagHole"), OLESTR("hr = <%ls>"),WsbHrAsString(S_OK));
  228. return(S_OK);
  229. }
  230. HRESULT
  231. CBagHole::Test
  232. (
  233. OUT USHORT *pTestsPassed,
  234. OUT USHORT *pTestsFailed
  235. )
  236. /*++
  237. Routine Description:
  238. See IWsbTestable::Test().
  239. Arguments:
  240. See IWsbTestable::Test().
  241. Return Value:
  242. See IWsbTestable::Test().
  243. --*/
  244. {
  245. #if 0
  246. HRESULT hr = S_OK;
  247. CComPtr<IBagHole> pBagHole1;
  248. CComPtr<IBagHole> pBagHole2;
  249. GUID l_BagId;
  250. LONGLONG l_SegStartLoc;
  251. LONGLONG l_SegLen;
  252. WsbTraceIn(OLESTR("CBagHole::Test"), OLESTR(""));
  253. *pTestsPassed = *pTestsFailed = 0;
  254. try {
  255. // Get the pBagHole interface.
  256. WsbAssertHr(((IUnknown*)(IBagHole*) this)->QueryInterface(IID_IBagHole,
  257. (void**) &pBagHole1));
  258. try {
  259. // Set the BagHole to a value, and see if it is returned.
  260. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CBagHole, 0, 6 ));
  261. WsbAssertHr(pBagHole1->GetBagHole(&l_BagId, &l_SegStartLoc, &l_SegLen));
  262. WsbAssert((l_BagId == CLSID_CBagHole) && (l_SegStartLoc == 0) &&
  263. (l_SegLen == 6), E_FAIL);
  264. } WsbCatch(hr);
  265. if (hr == S_OK) {
  266. (*pTestsPassed)++;
  267. } else {
  268. (*pTestsFailed)++;
  269. }
  270. #ifdef OLD_CODE
  271. hr = S_OK;
  272. try {
  273. //Create another instance and test the comparisson methods:
  274. WsbAssertHr(CoCreateInstance(CLSID_CBagHole, NULL, CLSCTX_ALL, IID_IBagHole, (void**) &pBagHole2));
  275. // Check the default values.
  276. WsbAssertHr(pBagHole2->GetBagHole(&l_BagId, &l_SegStartLoc, &l_SegLen));
  277. WsbAssert(((l_BagId == GUID_NULL) && (l_SegStartLoc == 0) && (l_SegLen == 0)), E_FAIL);
  278. } WsbCatch(hr);
  279. if (hr == S_OK) {
  280. (*pTestsPassed)++;
  281. } else {
  282. (*pTestsFailed)++;
  283. }
  284. hr = S_OK;
  285. try {
  286. // IsEqual()
  287. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 1, 100));
  288. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 1, 100));
  289. WsbAssertHr(pBagHole1->IsEqual(pBagHole2));
  290. } WsbCatch(hr);
  291. if (hr == S_OK) {
  292. (*pTestsPassed)++;
  293. } else {
  294. (*pTestsFailed)++;
  295. }
  296. hr = S_OK;
  297. try {
  298. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 5, 6));
  299. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  300. WsbAssert((pBagHole1->IsEqual(pBagHole2) == S_FALSE), E_FAIL);
  301. } WsbCatch(hr);
  302. if (hr == S_OK) {
  303. (*pTestsPassed)++;
  304. } else {
  305. (*pTestsFailed)++;
  306. }
  307. hr = S_OK;
  308. try {
  309. // CompareTo()
  310. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 1, 100));
  311. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 10, 6));
  312. WsbAssert((pBagHole1->CompareTo(pBagHole2, &result) == S_FALSE) && (result != 0), E_FAIL);
  313. } WsbCatch(hr);
  314. if (hr == S_OK) {
  315. (*pTestsPassed)++;
  316. } else {
  317. (*pTestsFailed)++;
  318. }
  319. hr = S_OK;
  320. try {
  321. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 0, 6));
  322. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  323. WsbAssert(((pBagHole1->CompareTo(pBagHole2, &result) == S_FALSE) && (result > 0)), E_FAIL);
  324. } WsbCatch(hr);
  325. if (hr == S_OK) {
  326. (*pTestsPassed)++;
  327. } else {
  328. (*pTestsFailed)++;
  329. }
  330. hr = S_OK;
  331. try {
  332. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbBool, 0, 6));
  333. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbBool, 0, 6));
  334. WsbAssert((pBagHole1->CompareTo(pBagHole2, &result) == S_OK), E_FAIL);
  335. } WsbCatch(hr);
  336. if (hr == S_OK) {
  337. (*pTestsPassed)++;
  338. } else {
  339. (*pTestsFailed)++;
  340. }
  341. try {
  342. // Try out the persistence stuff.
  343. CComPtr<IPersistFile> pFile1;
  344. CComPtr<IPersistFile> pFile2;
  345. WsbAssertHr(pBagHole1->QueryInterface(IID_IPersistFile, (void**) &pFile1));
  346. WsbAssertHr(pBagHole2->QueryInterface(IID_IPersistFile, (void**) &pFile2));
  347. LPOLESTR szTmp = NULL;
  348. // The item should be dirty.
  349. try {
  350. WsbAssertHr(pBagHole2->SetBagHole(CLSID_CWsbLong, 0, 6));
  351. WsbAssertHr(pFile2->IsDirty());
  352. } WsbCatch(hr);
  353. if (hr == S_OK) {
  354. (*pTestsPassed)++;
  355. } else {
  356. (*pTestsFailed)++;
  357. }
  358. hr = S_OK;
  359. try {
  360. // Save the item, and remember.
  361. WsbAssertHr(pFile2->Save(OLESTR("c:\\WsbTests\\BagHole.tst"), TRUE));
  362. } WsbCatch(hr);
  363. if (hr == S_OK) {
  364. (*pTestsPassed)++;
  365. } else {
  366. (*pTestsFailed)++;
  367. }
  368. hr = S_OK;
  369. try {
  370. // It shouldn't be dirty.
  371. WsbAssert((pFile2->IsDirty() == S_FALSE), E_FAIL);
  372. } WsbCatch(hr);
  373. if (hr == S_OK) {
  374. (*pTestsPassed)++;
  375. } else {
  376. (*pTestsFailed)++;
  377. }
  378. hr = S_OK;
  379. try {
  380. // Try reading it in to another object.
  381. WsbAssertHr(pBagHole1->SetBagHole(CLSID_CWsbLong, 0, 6));
  382. WsbAssertHr(pFile1->Load(OLESTR("c:\\WsbTests\\BagHole.tst"), 0));
  383. WsbAssertHr(pBagHole1->CompareToIBagHole(pBagHole2, &result));
  384. }WsbCatch(hr);
  385. if (hr == S_OK) {
  386. (*pTestsPassed)++;
  387. } else {
  388. (*pTestsFailed)++;
  389. }
  390. } WsbCatch(hr);
  391. #endif
  392. } WsbCatch(hr);
  393. WsbTraceOut(OLESTR("CBagHole::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  394. #else
  395. UNREFERENCED_PARAMETER(pTestsPassed);
  396. UNREFERENCED_PARAMETER(pTestsFailed);
  397. #endif
  398. return(S_OK);
  399. }
  400. HRESULT
  401. CBagHole::UpdateKey(
  402. IWsbDbKey *pKey
  403. )
  404. /*++
  405. Implements:
  406. IWsbDbEntity::UpdateKey
  407. --*/
  408. {
  409. HRESULT hr = S_OK;
  410. try {
  411. WsbAffirmHr(pKey->SetToGuid(m_BagId));
  412. WsbAffirmHr(pKey->AppendLonglong(m_SegStartLoc));
  413. } WsbCatch(hr);
  414. return(hr);
  415. }