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.

488 lines
8.1 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsPartn.cpp
  5. Abstract:
  6. Implementation of CRmsPartition
  7. Author:
  8. Brian Dodd [brian] 19-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsPartn.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. STDMETHODIMP
  16. CRmsPartition::CompareTo(
  17. IN IUnknown *pCollectable,
  18. OUT SHORT *pResult
  19. )
  20. /*++
  21. Implements:
  22. IWsbCollectable::CompareTo
  23. --*/
  24. {
  25. HRESULT hr = E_FAIL;
  26. SHORT result = 1;
  27. WsbTraceIn( OLESTR("CRmsPartition::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. // We need the IRmsPartition interface to get the value of the object.
  32. CComQIPtr<IRmsPartition, &IID_IRmsPartition> pPartition = pCollectable;
  33. WsbAssertPointer( pPartition );
  34. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  35. WsbAssertPointer( pObject );
  36. switch ( m_findBy ) {
  37. case RmsFindByPartitionNumber:
  38. {
  39. LONG partNo;
  40. WsbAffirmHr( pPartition->GetPartNo( &partNo ) );
  41. if( m_partNo == partNo ) {
  42. // partition numbers match
  43. hr = S_OK;
  44. result = 0;
  45. }
  46. else {
  47. hr = S_FALSE;
  48. result = 1;
  49. }
  50. break;
  51. }
  52. default:
  53. // Do CompareTo for object
  54. hr = CRmsComObject::CompareTo( pCollectable, &result );
  55. break;
  56. }
  57. }
  58. WsbCatch( hr );
  59. if ( SUCCEEDED(hr) && (0 != pResult) ){
  60. *pResult = result;
  61. }
  62. WsbTraceOut( OLESTR("CRmsPartition::CompareTo"),
  63. OLESTR("hr = <%ls>, result = <%ls>"),
  64. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  65. return hr;
  66. }
  67. HRESULT
  68. CRmsPartition::FinalConstruct(
  69. void
  70. )
  71. /*++
  72. Implements:
  73. CComObjectRoot::FinalConstruct
  74. --*/
  75. {
  76. HRESULT hr = S_OK;
  77. try {
  78. WsbAssertHr(CWsbObject::FinalConstruct());
  79. // Initialize values
  80. m_partNo = 0;
  81. m_attributes = RmsAttributesUnknown;
  82. m_sizeofIdentifier = 0;
  83. } WsbCatch(hr);
  84. return(hr);
  85. }
  86. STDMETHODIMP
  87. CRmsPartition::GetClassID(
  88. OUT CLSID* pClsid
  89. )
  90. /*++
  91. Implements:
  92. IPersist::GetClassID
  93. --*/
  94. {
  95. HRESULT hr = S_OK;
  96. WsbTraceIn(OLESTR("CRmsPartition::GetClassID"), OLESTR(""));
  97. try {
  98. WsbAssert(0 != pClsid, E_POINTER);
  99. *pClsid = CLSID_CRmsPartition;
  100. } WsbCatch(hr);
  101. WsbTraceOut(OLESTR("CRmsPartition::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  102. return(hr);
  103. }
  104. STDMETHODIMP
  105. CRmsPartition::GetSizeMax(
  106. OUT ULARGE_INTEGER* pcbSize
  107. )
  108. /*++
  109. Implements:
  110. IPersistStream::GetSizeMax
  111. --*/
  112. {
  113. HRESULT hr = E_NOTIMPL;
  114. WsbTraceIn(OLESTR("CRmsPartition::GetSizeMax"), OLESTR(""));
  115. // try {
  116. // WsbAssert(0 != pcbSize, E_POINTER);
  117. // // Get max size
  118. // pcbSize->QuadPart = WsbPersistSizeOf(LONG) + // m_partNo
  119. // WsbPersistSizeOf(LONG) + // m_attributes
  120. // WsbPersistSizeOf(SHORT); // m_sizeofIdentifier
  121. //// MaxId; // m_pIdentifier
  122. // } WsbCatch(hr);
  123. WsbTraceOut(OLESTR("CRmsPartition::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  124. return(hr);
  125. }
  126. STDMETHODIMP
  127. CRmsPartition::Load(
  128. IN IStream* pStream
  129. )
  130. /*++
  131. Implements:
  132. IPersistStream::Load
  133. --*/
  134. {
  135. HRESULT hr = S_OK;
  136. ULONG ulBytes = 0;
  137. WsbTraceIn(OLESTR("CRmsPartition::Load"), OLESTR(""));
  138. try {
  139. ULONG temp;
  140. WsbAssert(0 != pStream, E_POINTER);
  141. WsbAffirmHr(CRmsStorageInfo::Load(pStream));
  142. // Read value
  143. WsbAffirmHr(WsbLoadFromStream(pStream, &m_partNo));
  144. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  145. m_attributes = (RmsAttribute)temp;
  146. WsbAffirmHr(WsbLoadFromStream(pStream, &m_sizeofIdentifier));
  147. } WsbCatch(hr);
  148. WsbTraceOut(OLESTR("CRmsPartition::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  149. return(hr);
  150. }
  151. STDMETHODIMP
  152. CRmsPartition::Save(
  153. IN IStream* pStream,
  154. IN BOOL clearDirty
  155. )
  156. /*++
  157. Implements:
  158. IPersistStream::Save
  159. --*/
  160. {
  161. HRESULT hr = S_OK;
  162. ULONG ulBytes = 0;
  163. WsbTraceIn(OLESTR("CRmsPartition::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  164. try {
  165. WsbAssert(0 != pStream, E_POINTER);
  166. WsbAffirmHr(CRmsStorageInfo::Save(pStream, clearDirty));
  167. // Write value
  168. WsbAffirmHr(WsbSaveToStream(pStream, m_partNo));
  169. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_attributes));
  170. WsbAffirmHr(WsbSaveToStream(pStream, m_sizeofIdentifier));
  171. // Do we need to clear the dirty bit?
  172. if (clearDirty) {
  173. m_isDirty = FALSE;
  174. }
  175. } WsbCatch(hr);
  176. WsbTraceOut(OLESTR("CRmsPartition::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  177. return(hr);
  178. }
  179. STDMETHODIMP
  180. CRmsPartition::Test(
  181. OUT USHORT *pPassed,
  182. OUT USHORT *pFailed
  183. )
  184. /*++
  185. Implements:
  186. IWsbTestable::Test
  187. --*/
  188. {
  189. HRESULT hr = S_OK;
  190. CComPtr<IRmsPartition> pPartition1;
  191. CComPtr<IRmsPartition> pPartition2;
  192. CComPtr<IPersistFile> pFile1;
  193. CComPtr<IPersistFile> pFile2;
  194. LONG i;
  195. LONG longWork1;
  196. LONG longWork2;
  197. WsbTraceIn(OLESTR("CRmsPartition::Test"), OLESTR(""));
  198. try {
  199. // Get the Partition interface.
  200. hr = S_OK;
  201. try {
  202. WsbAssertHr(((IUnknown*) (IRmsPartition*) this)->QueryInterface(IID_IRmsPartition, (void**) &pPartition1));
  203. // Test SetAttributes & GetAttributes
  204. for (i = RmsAttributesUnknown; i < RmsAttributesVerify; i++){
  205. longWork1 = i;
  206. SetAttributes(longWork1);
  207. GetAttributes(&longWork2);
  208. if (longWork1 == longWork2){
  209. (*pPassed)++;
  210. } else {
  211. (*pFailed)++;
  212. }
  213. }
  214. } WsbCatch(hr);
  215. // Tally up the results
  216. hr = S_OK;
  217. if (*pFailed) {
  218. hr = S_FALSE;
  219. }
  220. } WsbCatch(hr);
  221. WsbTraceOut(OLESTR("CRmsPartition::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  222. return(hr);
  223. }
  224. STDMETHODIMP
  225. CRmsPartition::GetPartNo(
  226. LONG *pPartNo
  227. )
  228. /*++
  229. Implements:
  230. IRmsPartition::GetPartNo
  231. --*/
  232. {
  233. *pPartNo = m_partNo;
  234. return S_OK;
  235. }
  236. STDMETHODIMP
  237. CRmsPartition::GetAttributes (
  238. LONG *pAttr
  239. )
  240. /*++
  241. Implements:
  242. IRmsPartition::GetAttributes
  243. --*/
  244. {
  245. *pAttr = (LONG) m_attributes;
  246. return S_OK;
  247. }
  248. STDMETHODIMP
  249. CRmsPartition::SetAttributes (
  250. LONG attr
  251. )
  252. /*++
  253. Implements:
  254. IRmsPartition::SetAttributes
  255. --*/
  256. {
  257. m_attributes = (RmsAttribute) attr;
  258. m_isDirty = TRUE;
  259. return S_OK;
  260. }
  261. STDMETHODIMP
  262. CRmsPartition::GetIdentifier (
  263. UCHAR *pIdent,
  264. SHORT *pSize
  265. )
  266. /*++
  267. Implements:
  268. IRmsPartition::GetIdentifier
  269. --*/
  270. {
  271. *pSize = m_sizeofIdentifier;
  272. memmove (pIdent, m_pIdentifier, m_sizeofIdentifier);
  273. return S_OK;
  274. }
  275. STDMETHODIMP
  276. CRmsPartition::SetIdentifier (
  277. UCHAR *pIdent,
  278. SHORT size
  279. )
  280. /*++
  281. Implements:
  282. IRmsPartition::SetIdentifier
  283. --*/
  284. {
  285. m_sizeofIdentifier = size;
  286. memmove (m_pIdentifier, pIdent, size);
  287. m_isDirty = TRUE;
  288. return S_OK;
  289. }
  290. STDMETHODIMP
  291. CRmsPartition::GetStorageInfo(
  292. IRmsStorageInfo** /*ptr*/
  293. )
  294. /*++
  295. Implements:
  296. IRmsPartition::GetStorageInfo
  297. --*/
  298. {
  299. return S_OK;
  300. }
  301. STDMETHODIMP
  302. CRmsPartition::VerifyIdentifier(
  303. void
  304. )
  305. /*++
  306. Implements:
  307. IRmsPartition::VerifyIdentifier
  308. --*/
  309. {
  310. return S_OK;
  311. }
  312. STDMETHODIMP
  313. CRmsPartition::ReadOnMediaId(
  314. UCHAR* /*pid*/,
  315. LONG* /*pSize*/
  316. )
  317. /*++
  318. Implements:
  319. IRmsPartition::ReadOnMediaId
  320. --*/
  321. {
  322. return S_OK;
  323. }