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.

432 lines
7.7 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsSSlot.cpp
  5. Abstract:
  6. Implementation of CRmsStorageSlot
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsSSlot.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. STDMETHODIMP
  16. CRmsStorageSlot::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("CRmsStorageSlot::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  32. WsbAssertPointer( pObject );
  33. switch ( m_findBy ) {
  34. case RmsFindByElementNumber:
  35. case RmsFindByMediaSupported:
  36. // Do CompareTo for changer element
  37. hr = CRmsChangerElement::CompareTo( pCollectable, &result );
  38. break;
  39. case RmsFindByObjectId:
  40. default:
  41. // Do CompareTo for object
  42. hr = CRmsComObject::CompareTo( pCollectable, &result );
  43. break;
  44. }
  45. }
  46. WsbCatch( hr );
  47. if ( SUCCEEDED(hr) && (0 != pResult) ){
  48. *pResult = result;
  49. }
  50. WsbTraceOut( OLESTR("CRmsStorageSlot::CompareTo"),
  51. OLESTR("hr = <%ls>, result = <%ls>"),
  52. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  53. return hr;
  54. }
  55. HRESULT
  56. CRmsStorageSlot::FinalConstruct(
  57. void
  58. )
  59. /*++
  60. Implements:
  61. CComObjectRoot::FinalConstruct
  62. --*/
  63. {
  64. HRESULT hr = S_OK;
  65. try {
  66. WsbAssertHr(CWsbObject::FinalConstruct());
  67. // Initialize values
  68. m_isInMagazine = FALSE;
  69. m_magazineNo = 0;
  70. m_cellNo = 0;
  71. } WsbCatch(hr);
  72. return(hr);
  73. }
  74. STDMETHODIMP
  75. CRmsStorageSlot::GetClassID(
  76. OUT CLSID* pClsid
  77. )
  78. /*++
  79. Implements:
  80. IPersist::GetClassID
  81. --*/
  82. {
  83. HRESULT hr = S_OK;
  84. WsbTraceIn(OLESTR("CRmsStorageSlot::GetClassID"), OLESTR(""));
  85. try {
  86. WsbAssert(0 != pClsid, E_POINTER);
  87. *pClsid = CLSID_CRmsStorageSlot;
  88. } WsbCatch(hr);
  89. WsbTraceOut(OLESTR("CRmsStorageSlot::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  90. return(hr);
  91. }
  92. STDMETHODIMP
  93. CRmsStorageSlot::GetSizeMax(
  94. OUT ULARGE_INTEGER* pcbSize
  95. )
  96. /*++
  97. Implements:
  98. IPersistStream::GetSizeMax
  99. --*/
  100. {
  101. HRESULT hr = E_NOTIMPL;
  102. WsbTraceIn(OLESTR("CRmsStorageSlot::GetSizeMax"), OLESTR(""));
  103. // try {
  104. // WsbAssert(0 != pcbSize, E_POINTER);
  105. // // Get max size
  106. // pcbSize->QuadPart = WsbPersistSizeOf(BOOL) + // m_isInMagazine
  107. // WsbPersistSizeOf(LONG) + // m_magazineNo
  108. // WsbPersistSizeOf(LONG); // m_cellNo
  109. // } WsbCatch(hr);
  110. WsbTraceOut(OLESTR("CRmsStorageSlot::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  111. return(hr);
  112. }
  113. STDMETHODIMP
  114. CRmsStorageSlot::Load(
  115. IN IStream* pStream
  116. )
  117. /*++
  118. Implements:
  119. IPersistStream::Load
  120. --*/
  121. {
  122. HRESULT hr = S_OK;
  123. ULONG ulBytes = 0;
  124. WsbTraceIn(OLESTR("CRmsStorageSlot::Load"), OLESTR(""));
  125. try {
  126. WsbAssert(0 != pStream, E_POINTER);
  127. WsbAffirmHr(CRmsChangerElement::Load(pStream));
  128. // Read value
  129. WsbAffirmHr(WsbLoadFromStream(pStream, &m_isInMagazine));
  130. WsbAffirmHr(WsbLoadFromStream(pStream, &m_magazineNo));
  131. WsbAffirmHr(WsbLoadFromStream(pStream, &m_cellNo));
  132. } WsbCatch(hr);
  133. WsbTraceOut(OLESTR("CRmsStorageSlot::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  134. return(hr);
  135. }
  136. STDMETHODIMP
  137. CRmsStorageSlot::Save(
  138. IN IStream* pStream,
  139. IN BOOL clearDirty
  140. )
  141. /*++
  142. Implements:
  143. IPersistStream::Save
  144. --*/
  145. {
  146. HRESULT hr = S_OK;
  147. ULONG ulBytes = 0;
  148. WsbTraceIn(OLESTR("CRmsStorageSlot::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  149. try {
  150. WsbAssert(0 != pStream, E_POINTER);
  151. WsbAffirmHr(CRmsChangerElement::Save(pStream, clearDirty));
  152. // Write value
  153. WsbAffirmHr(WsbSaveToStream(pStream, m_isInMagazine));
  154. WsbAffirmHr(WsbSaveToStream(pStream, m_magazineNo));
  155. WsbAffirmHr(WsbSaveToStream(pStream, m_cellNo));
  156. // Do we need to clear the dirty bit?
  157. if (clearDirty) {
  158. m_isDirty = FALSE;
  159. }
  160. } WsbCatch(hr);
  161. WsbTraceOut(OLESTR("CRmsStorageSlot::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  162. return(hr);
  163. }
  164. STDMETHODIMP
  165. CRmsStorageSlot::Test(
  166. OUT USHORT *pPassed,
  167. OUT USHORT *pFailed
  168. )
  169. /*++
  170. Implements:
  171. IWsbTestable::Test
  172. --*/
  173. {
  174. HRESULT hr = S_OK;
  175. CComPtr<IRmsStorageSlot> pStorageSlot1;
  176. CComPtr<IRmsStorageSlot> pStorageSlot2;
  177. CComPtr<IPersistFile> pFile1;
  178. CComPtr<IPersistFile> pFile2;
  179. LONG longWork1;
  180. LONG longWork2;
  181. LONG longWork3;
  182. LONG longWork4;
  183. WsbTraceIn(OLESTR("CRmsStorageSlot::Test"), OLESTR(""));
  184. try {
  185. // Get the StorageSlot interface.
  186. hr = S_OK;
  187. try {
  188. WsbAssertHr(((IUnknown*) (IRmsStorageSlot*) this)->QueryInterface(IID_IRmsStorageSlot, (void**) &pStorageSlot1));
  189. // Test SetIsInMagazine & IsInMagazine to TRUE
  190. hr = S_OK;
  191. try{
  192. WsbAffirmHr(SetIsInMagazine (TRUE));
  193. WsbAffirmHr(IsInMagazine ());
  194. } WsbCatch (hr);
  195. if (hr == S_OK){
  196. (*pPassed)++;
  197. } else {
  198. (*pFailed)++;
  199. }
  200. // Test SetIsInMagazine & IsInMagazine to FALSE
  201. hr = S_OK;
  202. try{
  203. WsbAffirmHr(SetIsInMagazine (FALSE));
  204. WsbAffirmHr(IsInMagazine ());
  205. } WsbCatch (hr);
  206. if (hr == S_OK){
  207. (*pFailed)++;
  208. } else {
  209. (*pPassed)++;
  210. }
  211. // Test SetMagazineAndCell & GetMagazineAndCell
  212. longWork1 = 99;
  213. longWork2 = 11;
  214. SetMagazineAndCell(longWork1, longWork2);
  215. GetMagazineAndCell(&longWork3, &longWork4);
  216. if((longWork1 == longWork3) && (longWork2 == longWork4)){
  217. (*pPassed)++;
  218. } else {
  219. (*pFailed)++;
  220. }
  221. } WsbCatch(hr);
  222. // Tally up the results
  223. hr = S_OK;
  224. if (*pFailed) {
  225. hr = S_FALSE;
  226. }
  227. } WsbCatch(hr);
  228. WsbTraceOut(OLESTR("CRmsStorageSlot::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  229. return(hr);
  230. }
  231. STDMETHODIMP
  232. CRmsStorageSlot::SetIsInMagazine(
  233. BOOL flag
  234. )
  235. /*++
  236. Implements:
  237. IRmsStorageSlot::SetIsInMagazine
  238. --*/
  239. {
  240. m_isInMagazine = flag;
  241. m_isDirty = TRUE;
  242. return S_OK;
  243. }
  244. STDMETHODIMP
  245. CRmsStorageSlot::IsInMagazine(
  246. void
  247. )
  248. /*++
  249. Implements:
  250. IRmsStorageSlot::IsInMagazine
  251. --*/
  252. {
  253. HRESULT hr = S_FALSE;
  254. if (m_isInMagazine){
  255. hr = S_OK;
  256. }
  257. return (hr);
  258. }
  259. STDMETHODIMP
  260. CRmsStorageSlot::GetMagazineAndCell(
  261. LONG *pMag,
  262. LONG *pCell
  263. )
  264. /*++
  265. Implements:
  266. IRmsStorageSlot::GetMagazineAndCell
  267. --*/
  268. {
  269. *pMag = m_magazineNo;
  270. *pCell = m_cellNo;
  271. return S_OK;
  272. }
  273. STDMETHODIMP
  274. CRmsStorageSlot::SetMagazineAndCell(
  275. LONG mag,
  276. LONG cell
  277. )
  278. /*++
  279. Implements:
  280. IRmsStorageSlot::SetMagazineAndCell
  281. --*/
  282. {
  283. m_magazineNo = mag;
  284. m_cellNo = cell;
  285. m_isDirty = TRUE;
  286. return S_OK;
  287. }