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.

489 lines
11 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsLocat.cpp
  5. Abstract:
  6. Implementation of CRmsLocator
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsLocat.h"
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. CRmsLocator::CRmsLocator(
  16. void
  17. )
  18. /*++
  19. Routine Description:
  20. CRmsLocator constructor
  21. Arguments:
  22. None
  23. Return Value:
  24. None
  25. --*/
  26. {
  27. // Initialize values
  28. m_type = RmsElementUnknown;
  29. m_libraryId = GUID_NULL;
  30. m_mediaSetId = GUID_NULL;
  31. m_position = 0;
  32. m_alternate1 = 0;
  33. m_alternate2 = 0;
  34. m_alternate3 = 0;
  35. m_invert = FALSE;
  36. }
  37. HRESULT
  38. CRmsLocator::CompareTo(
  39. IN IUnknown *pCollectable,
  40. OUT SHORT *pResult
  41. )
  42. /*++
  43. Implements:
  44. CRmsLocator::CompareTo
  45. --*/
  46. {
  47. HRESULT hr = E_FAIL;
  48. SHORT result = 1;
  49. WsbTraceIn( OLESTR("CRmsLocator::CompareTo"), OLESTR("") );
  50. try {
  51. // Validate arguments - Okay if pResult is NULL
  52. WsbAssertPointer( pCollectable );
  53. CRmsLocator pLocator;
  54. RmsElement type;
  55. GUID libraryId;
  56. GUID mediaSetId;
  57. LONG position;
  58. LONG alternate1;
  59. LONG alternate2;
  60. LONG alternate3;
  61. BOOL invert;
  62. // Get Locator to check
  63. GetLocation((LONG *) &type, &libraryId, &mediaSetId, &position,
  64. &alternate1, &alternate2, &alternate3,
  65. &invert);
  66. // See if we have the location requested
  67. if ( (m_type == type ) &&
  68. (m_libraryId == libraryId ) &&
  69. (m_mediaSetId == mediaSetId ) &&
  70. (m_position == position ) &&
  71. (m_alternate1 == alternate1 ) &&
  72. (m_alternate2 == alternate2 ) &&
  73. (m_alternate3 == alternate3 ) &&
  74. (m_invert == invert ) ) {
  75. // Locators match
  76. hr = S_OK;
  77. result = 0;
  78. }
  79. else {
  80. hr = S_FALSE;
  81. result = 1;
  82. }
  83. }
  84. WsbCatch( hr );
  85. if ( SUCCEEDED(hr) && (0 != pResult) ){
  86. *pResult = result;
  87. }
  88. WsbTraceOut( OLESTR("CRmsLocator::CompareTo"),
  89. OLESTR("hr = <%ls>, result = <%ls>"),
  90. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  91. return hr;
  92. }
  93. HRESULT
  94. CRmsLocator::GetSizeMax(
  95. OUT ULARGE_INTEGER* pcbSize
  96. )
  97. /*++
  98. Implements:
  99. IPersistStream::GetSizeMax
  100. --*/
  101. {
  102. HRESULT hr = E_NOTIMPL;
  103. WsbTraceIn(OLESTR("CRmsLocator::GetSizeMax"), OLESTR(""));
  104. // try {
  105. // WsbAssert(0 != pcbSize, E_POINTER);
  106. // // Get max size
  107. // pcbSize->QuadPart = WsbPersistSizeOf(LONG) + // m_type
  108. // WsbPersistSizeOf(GUID) + // m_libraryId
  109. // WsbPersistSizeOf(GUID) + // m_mediaSetId
  110. // WsbPersistSizeOf(LONG) + // m_position
  111. // WsbPersistSizeOf(LONG) + // m_alternate1
  112. // WsbPersistSizeOf(LONG) + // m_alternate2
  113. // WsbPersistSizeOf(LONG) + // m_alternate3
  114. // WsbPersistSizeOf(BOOL); // m_invert
  115. // } WsbCatch(hr);
  116. WsbTraceOut(OLESTR("CRmsLocator::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  117. return(hr);
  118. }
  119. HRESULT
  120. CRmsLocator::Load(
  121. IN IStream* pStream
  122. )
  123. /*++
  124. Implements:
  125. IPersistStream::Load
  126. --*/
  127. {
  128. HRESULT hr = S_OK;
  129. ULONG ulBytes = 0;
  130. WsbTraceIn(OLESTR("CRmsLocator::Load"), OLESTR(""));
  131. try {
  132. ULONG temp;
  133. WsbAssert(0 != pStream, E_POINTER);
  134. // Read value
  135. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  136. m_type = (RmsElement)temp;
  137. WsbAffirmHr(WsbLoadFromStream(pStream, &m_libraryId));
  138. WsbAffirmHr(WsbLoadFromStream(pStream, &m_mediaSetId));
  139. WsbAffirmHr(WsbLoadFromStream(pStream, &m_position));
  140. WsbAffirmHr(WsbLoadFromStream(pStream, &m_alternate1));
  141. WsbAffirmHr(WsbLoadFromStream(pStream, &m_alternate2));
  142. WsbAffirmHr(WsbLoadFromStream(pStream, &m_alternate3));
  143. WsbAffirmHr(WsbLoadFromStream(pStream, &m_invert));
  144. } WsbCatch(hr);
  145. WsbTraceOut(OLESTR("CRmsLocator::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  146. return(hr);
  147. }
  148. HRESULT
  149. CRmsLocator::Save(
  150. IN IStream* pStream,
  151. IN BOOL clearDirty
  152. )
  153. /*++
  154. Implements:
  155. IPersistStream::Save
  156. --*/
  157. {
  158. HRESULT hr = S_OK;
  159. ULONG ulBytes = 0;
  160. WsbTraceIn(OLESTR("CRmsLocator::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  161. try {
  162. WsbAssert(0 != pStream, E_POINTER);
  163. // Write value
  164. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_type));
  165. WsbAffirmHr(WsbSaveToStream(pStream, m_libraryId));
  166. WsbAffirmHr(WsbSaveToStream(pStream, m_mediaSetId));
  167. WsbAffirmHr(WsbSaveToStream(pStream, m_position));
  168. WsbAffirmHr(WsbSaveToStream(pStream, m_alternate1));
  169. WsbAffirmHr(WsbSaveToStream(pStream, m_alternate2));
  170. WsbAffirmHr(WsbSaveToStream(pStream, m_alternate3));
  171. WsbAffirmHr(WsbSaveToStream(pStream, m_invert));
  172. } WsbCatch(hr);
  173. WsbTraceOut(OLESTR("CRmsLocator::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  174. return(hr);
  175. }
  176. HRESULT
  177. CRmsLocator::Test(
  178. OUT USHORT *pPassed,
  179. OUT USHORT *pFailed
  180. )
  181. /*++
  182. Implements:
  183. IWsbTestable::Test
  184. --*/
  185. {
  186. HRESULT hr = S_OK;
  187. CComPtr<IRmsMediaSet> pMediaSet1;
  188. CComPtr<IRmsMediaSet> pMediaSet2;
  189. CComPtr<IPersistFile> pFile1;
  190. CComPtr<IPersistFile> pFile2;
  191. LONG i;
  192. GUID guidVal1 = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
  193. GUID guidVal2 = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
  194. GUID guidWork1;
  195. GUID guidWork2;
  196. LONG longVal1 = 11111111;
  197. LONG longVal2 = 22222222;
  198. LONG longVal3 = 33333333;
  199. LONG longVal4 = 44444444;
  200. LONG longWork0;
  201. LONG longWork1;
  202. LONG longWork2;
  203. LONG longWork3;
  204. LONG longWork4;
  205. BOOL boolWork1;
  206. BOOL boolWork2;
  207. WsbTraceIn(OLESTR("CRmsLocator::Test"), OLESTR(""));
  208. try {
  209. // Get the MediaSet interface.
  210. hr = S_OK;
  211. try {
  212. WsbAssertHr(((IUnknown*) (IRmsMediaSet*) this)->QueryInterface(IID_IRmsMediaSet, (void**) &pMediaSet1));
  213. boolWork1 = FALSE;
  214. // Test SetLocation & GetLocation
  215. for(i = RmsElementUnknown; i < RmsElementIEPort; i++){
  216. SetLocation(i,
  217. guidVal1,
  218. guidVal2,
  219. longVal1,
  220. longVal2,
  221. longVal3,
  222. longVal4,
  223. boolWork1);
  224. GetLocation(&longWork0,
  225. &guidWork1,
  226. &guidWork2,
  227. &longWork1,
  228. &longWork2,
  229. &longWork3,
  230. &longWork4,
  231. &boolWork2);
  232. if((i == longWork0) &&
  233. (guidVal1 == guidWork1) &&
  234. (guidVal2 == guidWork2) &&
  235. (longVal1 == longWork1) &&
  236. (longVal2 == longWork2) &&
  237. (longVal3 == longWork3) &&
  238. (longVal4 == longWork4) &&
  239. (boolWork1 == boolWork2)){
  240. (*pPassed)++;
  241. } else {
  242. (*pFailed)++;
  243. }
  244. if(boolWork1 == TRUE){
  245. boolWork1 = FALSE;
  246. } else {
  247. boolWork1 = TRUE;
  248. }
  249. }
  250. } WsbCatch(hr);
  251. // Tally up the results
  252. hr = S_OK;
  253. if (*pFailed) {
  254. hr = S_FALSE;
  255. }
  256. } WsbCatch(hr);
  257. WsbTraceOut(OLESTR("CRmsLocator::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  258. return(hr);
  259. }
  260. STDMETHODIMP
  261. CRmsLocator::GetLocation(
  262. LONG *pType,
  263. GUID *pLibId,
  264. GUID *pMediaSetId,
  265. LONG *pPos,
  266. LONG *pAlt1,
  267. LONG *pAlt2,
  268. LONG *pAlt3,
  269. BOOL *pInvert)
  270. /*++
  271. Routine Description:
  272. Get location values.
  273. Arguments:
  274. pType - pointer to cartridge type
  275. pLibId - pointer to library id
  276. pMediaSetId - pointer to media set id
  277. pPos - pointer to current position
  278. pAlt1 - pointer to alternate data field 1
  279. pAlt2 - pointer to alternate data field 2
  280. pAlt3 - pointer to alternate data field 3
  281. pInvert - pointer to invert flag
  282. Return Value:
  283. S_OK - successful
  284. --*/
  285. {
  286. if (pType) {
  287. *pType = m_type;
  288. }
  289. if (pLibId) {
  290. *pLibId = m_libraryId;
  291. }
  292. if (pMediaSetId) {
  293. *pMediaSetId = m_mediaSetId;
  294. }
  295. if (pPos) {
  296. *pPos = m_position;
  297. }
  298. if (pAlt1) {
  299. *pAlt1 = m_alternate1;
  300. }
  301. if (pAlt2) {
  302. *pAlt2 = m_alternate2;
  303. }
  304. if (pAlt3) {
  305. *pAlt3 = m_alternate3;
  306. }
  307. if (pInvert) {
  308. *pInvert = m_invert;
  309. }
  310. return S_OK;
  311. }
  312. STDMETHODIMP
  313. CRmsLocator::SetLocation(
  314. LONG type,
  315. GUID libId,
  316. GUID mediaSetId,
  317. LONG pos,
  318. LONG alt1,
  319. LONG alt2,
  320. LONG alt3,
  321. BOOL invert
  322. )
  323. /*++
  324. Routine Description:
  325. Set location values.
  326. Arguments:
  327. type - new value of cartridge type
  328. libId - new value of library id
  329. mediaSetId - new value of media set id
  330. pos - new value of current position
  331. alt1 - new value of alternate data field 1
  332. alt2 - new value of alternate data field 2
  333. alt3 - new value of alternate data field 3
  334. invert - new value of invert flag
  335. Return Value:
  336. S_OK - successful
  337. --*/
  338. {
  339. m_type = (RmsElement) type;
  340. m_libraryId = libId;
  341. m_mediaSetId = mediaSetId;
  342. m_position = pos;
  343. m_alternate1 = alt1;
  344. m_alternate2 = alt2;
  345. m_alternate3 = alt3;
  346. m_invert = invert;
  347. // m_isDirty = TRUE;
  348. return S_OK;
  349. }