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.

1522 lines
31 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsLibry.cpp
  5. Abstract:
  6. Implementation of CRmsLibrary
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsLibry.h"
  13. #include "RmsServr.h"
  14. //////////////////////////////////////////////////////////////////////////////////
  15. STDMETHODIMP
  16. CRmsLibrary::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("CRmsLibrary::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. // We need the IRmsLibrary interface to get the value of the object.
  32. CComQIPtr<IRmsLibrary, &IID_IRmsLibrary> pLibrary = pCollectable;
  33. WsbAssertPointer( pLibrary );
  34. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  35. WsbAssertPointer( pObject );
  36. switch ( m_findBy ) {
  37. case RmsFindByName:
  38. {
  39. CWsbBstrPtr name;
  40. // Get the target device name
  41. pLibrary->GetName( &name );
  42. // Compare the names
  43. result = (SHORT)wcscmp( m_Name, name );
  44. hr = ( 0 == result ) ? S_OK : S_FALSE;
  45. }
  46. break;
  47. case RmsFindByMediaSupported:
  48. {
  49. RmsMedia mediaSupported;
  50. WsbAffirmHr(pLibrary->GetMediaSupported((LONG*) &mediaSupported));
  51. if( m_mediaSupported == mediaSupported ){
  52. // media types supported match
  53. hr = S_OK;
  54. result = 0;
  55. }
  56. else{
  57. hr = S_FALSE;
  58. result = 1;
  59. }
  60. }
  61. break;
  62. case RmsFindByDeviceInfo:
  63. {
  64. //
  65. // We're looking for a device in a library.
  66. // The template has one changer device OR one drive device.
  67. //
  68. try {
  69. WsbAssertHr( E_UNEXPECTED ); // Dead code now
  70. if ( m_maxDrives > 0 ) {
  71. CComPtr<IWsbEnum> pEnumDrives;
  72. CComPtr<IWsbIndexedCollection> pFindDrives;
  73. CComPtr<IRmsMediumChanger> pFindDrive;
  74. CComPtr<IWsbIndexedCollection> pDrives;
  75. WsbAffirmHr( pLibrary->GetDrives( &pDrives ) );
  76. WsbAssertPointer( pDrives );
  77. WsbAffirmHr( m_pDrives->Enum( &pEnumDrives ) );
  78. WsbAssertPointer( pEnumDrives );
  79. WsbAssertHr( pEnumDrives->First( IID_IRmsDrive, (void **)&pFindDrive ) );
  80. WsbAssertPointer( pFindDrive );
  81. hr = pDrives->Contains( pFindDrive );
  82. result = (SHORT) ( ( S_OK == hr ) ? 0 : 1 );
  83. }
  84. else if ( m_maxChangers > 0 ) {
  85. CComPtr<IWsbEnum> pEnumChangers;
  86. CComPtr<IWsbIndexedCollection> pFindChangers;
  87. CComPtr<IRmsMediumChanger> pFindChanger;
  88. CComPtr<IWsbIndexedCollection> pChangers;
  89. WsbAffirmHr( pLibrary->GetChangers( &pChangers ) );
  90. WsbAssertPointer( pChangers );
  91. WsbAffirmHr( m_pChangers->Enum( &pEnumChangers ) );
  92. WsbAssertPointer( pEnumChangers );
  93. WsbAssertHr( pEnumChangers->First( IID_IRmsMediumChanger, (void **)&pFindChanger ) );
  94. WsbAssertPointer( pFindChanger );
  95. hr = pChangers->Contains( pFindChanger );
  96. result = (SHORT)( ( S_OK == hr ) ? 0 : 1 );
  97. }
  98. else {
  99. // has to be one or the other
  100. WsbAssertHr( E_UNEXPECTED );
  101. }
  102. }
  103. WsbCatch( hr );
  104. }
  105. break;
  106. default:
  107. // Do CompareTo for object
  108. hr = CRmsComObject::CompareTo( pCollectable, &result );
  109. break;
  110. }
  111. }
  112. WsbCatch( hr );
  113. if ( SUCCEEDED(hr) && (0 != pResult) ){
  114. *pResult = result;
  115. }
  116. WsbTraceOut( OLESTR("CRmsLibrary::CompareTo"),
  117. OLESTR("hr = <%ls>, result = <%ls>"),
  118. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  119. return hr;
  120. }
  121. HRESULT
  122. CRmsLibrary::FinalConstruct(
  123. void
  124. )
  125. /*++
  126. Implements:
  127. CComObjectRoot::FinalConstruct
  128. --*/
  129. {
  130. HRESULT hr = S_OK;
  131. try {
  132. WsbAssertHr(CWsbObject::FinalConstruct());
  133. m_mediaSupported = RmsMediaUnknown;
  134. m_maxChangers = 0;
  135. m_maxDrives = 0;
  136. m_maxPorts = 0;
  137. m_maxSlots = 0;
  138. m_NumUsedSlots = 0;
  139. m_NumStagingSlots = 0;
  140. m_NumScratchCarts = 0;
  141. m_NumUnknownCarts = 0;
  142. m_isMagazineSupported = FALSE;
  143. m_maxCleaningMounts = 0;
  144. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  145. 0,
  146. CLSCTX_SERVER,
  147. IID_IWsbIndexedCollection,
  148. (void **)&m_pChangers ));
  149. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  150. 0,
  151. CLSCTX_SERVER,
  152. IID_IWsbIndexedCollection,
  153. (void **)&m_pDriveClasses ));
  154. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  155. 0,
  156. CLSCTX_SERVER,
  157. IID_IWsbIndexedCollection,
  158. (void **)&m_pDrives ));
  159. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  160. 0,
  161. CLSCTX_SERVER,
  162. IID_IWsbIndexedCollection,
  163. (void **)&m_pStorageSlots ));
  164. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  165. 0,
  166. CLSCTX_SERVER,
  167. IID_IWsbIndexedCollection,
  168. (void **)&m_pStagingSlots ));
  169. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  170. 0,
  171. CLSCTX_SERVER,
  172. IID_IWsbIndexedCollection,
  173. (void **)&m_pPorts ));
  174. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  175. 0,
  176. CLSCTX_SERVER,
  177. IID_IWsbIndexedCollection,
  178. (void **)&m_pCleaningCartridges ));
  179. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  180. 0,
  181. CLSCTX_SERVER,
  182. IID_IWsbIndexedCollection,
  183. (void **)&m_pScratchCartridges ));
  184. WsbAssertHr(CoCreateInstance( CLSID_CWsbOrderedCollection,
  185. 0,
  186. CLSCTX_SERVER,
  187. IID_IWsbIndexedCollection,
  188. (void **)&m_pMediaSets ));
  189. } WsbCatch(hr);
  190. return(hr);
  191. }
  192. STDMETHODIMP
  193. CRmsLibrary::GetClassID(
  194. OUT CLSID* pClsid
  195. )
  196. /*++
  197. Implements:
  198. IPersist::GetClassId
  199. --*/
  200. {
  201. HRESULT hr = S_OK;
  202. WsbTraceIn(OLESTR("CRmsLibrary::GetClassID"), OLESTR(""));
  203. try {
  204. WsbAssert(0 != pClsid, E_POINTER);
  205. *pClsid = CLSID_CRmsLibrary;
  206. } WsbCatch(hr);
  207. WsbTraceOut(OLESTR("CRmsLibrary::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  208. return(hr);
  209. }
  210. STDMETHODIMP
  211. CRmsLibrary::GetSizeMax(
  212. OUT ULARGE_INTEGER* pcbSize
  213. )
  214. /*++
  215. Implements:
  216. IPersistStream::GetSizeMax
  217. --*/
  218. {
  219. HRESULT hr = E_NOTIMPL;
  220. // ULONG nameLen;
  221. WsbTraceIn(OLESTR("CRmsLibrary::GetSizeMax"), OLESTR(""));
  222. // try {
  223. // WsbAssert(0 != pcbSize, E_POINTER);
  224. // // Get max size
  225. // nameLen = SysStringByteLen(m_name);
  226. // pcbSize->QuadPart = WsbPersistSizeOf(GUID) + // m_objectId
  227. // WsbPersistSizeOf(LONG) + // m_name length
  228. // nameLen + // m_name data
  229. // WsbPersistSizeOf(LONG) + // m_mediaSupported
  230. // WsbPersistSizeOf(LONG) + // m_maxChangers
  231. // WsbPersistSizeOf(LONG) + // m_maxDrives
  232. // WsbPersistSizeOf(LONG) + // m_maxPorts
  233. // WsbPersistSizeOf(LONG) + // m_maxSlots
  234. // WsbPersistSizeOf(LONG) + // m_NumUsedSlots
  235. // WsbPersistSizeOf(LONG) + // m_NumStagingSlots
  236. // WsbPersistSizeOf(LONG) + // m_NumScratchCarts
  237. // WsbPersistSizeOf(LONG) + // m_NumUnknownCarts
  238. // WsbPersistSizeOf(LONG) + // m_isMagazineSupported
  239. // WsbPersistSizeOf(LONG) + // m_maxCleaningMounts
  240. // WsbPersistSizeOf(LONG); // m_slotSelectionPolicy
  241. // } WsbCatch(hr);
  242. WsbTraceOut(OLESTR("CRmsLibrary::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  243. return(hr);
  244. }
  245. STDMETHODIMP
  246. CRmsLibrary::Load(
  247. IN IStream* pStream
  248. )
  249. /*++
  250. Implements:
  251. IPersistStream::Load
  252. --*/
  253. {
  254. HRESULT hr = S_OK;
  255. WsbTraceIn(OLESTR("CRmsLibrary::Load"), OLESTR(""));
  256. try {
  257. CComPtr<IPersistStream> pPersistStream;
  258. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  259. ULONG temp;
  260. WsbAssert(0 != pStream, E_POINTER);
  261. WsbAffirmHr(CRmsComObject::Load(pStream));
  262. WsbAffirmHr(WsbLoadFromStream(pStream, &m_objectId));
  263. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  264. m_mediaSupported = (RmsMedia)temp;
  265. WsbAffirmHr(WsbLoadFromStream(pStream, &m_maxChangers));
  266. WsbAffirmHr(WsbLoadFromStream(pStream, &m_maxDrives));
  267. WsbAffirmHr(WsbLoadFromStream(pStream, &m_maxPorts));
  268. WsbAffirmHr(WsbLoadFromStream(pStream, &m_maxSlots));
  269. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumUsedSlots));
  270. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumStagingSlots));
  271. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumScratchCarts));
  272. WsbAffirmHr(WsbLoadFromStream(pStream, &m_NumUnknownCarts));
  273. WsbAffirmHr(WsbLoadFromStream(pStream, &m_isMagazineSupported));
  274. WsbAffirmHr(WsbLoadFromStream(pStream, &m_maxCleaningMounts));
  275. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  276. m_slotSelectionPolicy = (RmsSlotSelect)temp;
  277. WsbAffirmHr(m_pChangers->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  278. WsbAffirmHr(pPersistStream->Load(pStream));
  279. pPersistStream = 0;
  280. WsbAffirmHr(m_pDriveClasses->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  281. WsbAffirmHr(pPersistStream->Load(pStream));
  282. pPersistStream = 0;
  283. WsbAffirmHr(m_pDrives->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  284. WsbAffirmHr(pPersistStream->Load(pStream));
  285. pPersistStream = 0;
  286. WsbAffirmHr(m_pStorageSlots->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  287. WsbAffirmHr(pPersistStream->Load(pStream));
  288. pPersistStream = 0;
  289. WsbAffirmHr(m_pStagingSlots->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  290. WsbAffirmHr(pPersistStream->Load(pStream));
  291. pPersistStream = 0;
  292. WsbAffirmHr(m_pPorts->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  293. WsbAffirmHr(pPersistStream->Load(pStream));
  294. pPersistStream = 0;
  295. WsbAffirmHr(m_pCleaningCartridges->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  296. WsbAffirmHr(pPersistStream->Load(pStream));
  297. pPersistStream = 0;
  298. WsbAffirmHr(m_pScratchCartridges->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  299. WsbAffirmHr(pPersistStream->Load(pStream));
  300. pPersistStream = 0;
  301. GUID mediaSetId;
  302. CComPtr<IRmsMediaSet> pMediaSet;
  303. WsbAffirmHr( WsbLoadFromStream(pStream, &mediaSetId) );
  304. while ( 0 != memcmp(&GUID_NULL, &mediaSetId, sizeof(GUID))) {
  305. hr = pServer->CreateObject( mediaSetId, CLSID_CRmsMediaSet, IID_IRmsMediaSet, RmsOpenExisting, (void **)&pMediaSet );
  306. if (S_OK == hr) {
  307. WsbAffirmHr( m_pMediaSets->Add( pMediaSet ) );
  308. } else if (RMS_E_NOT_FOUND == hr) {
  309. WsbThrow(hr);
  310. } else {
  311. WsbThrow(hr);
  312. }
  313. WsbAffirmHr( WsbLoadFromStream(pStream, &mediaSetId) );
  314. }
  315. }
  316. WsbCatch(hr);
  317. WsbTraceOut(OLESTR("CRmsLibrary::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  318. return hr;
  319. }
  320. STDMETHODIMP
  321. CRmsLibrary::Save(
  322. IN IStream* pStream,
  323. IN BOOL clearDirty
  324. )
  325. /*++
  326. Implements:
  327. IPersistStream::Save
  328. --*/
  329. {
  330. HRESULT hr = S_OK;
  331. WsbTraceIn(OLESTR("CRmsLibrary::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  332. try {
  333. CComPtr<IPersistStream> pPersistStream;
  334. WsbAssertPointer( pStream );
  335. WsbAffirmHr(CRmsComObject::Save(pStream, clearDirty));
  336. WsbAffirmHr(WsbSaveToStream(pStream, m_objectId));
  337. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_mediaSupported));
  338. WsbAffirmHr(WsbSaveToStream(pStream, m_maxChangers));
  339. WsbAffirmHr(WsbSaveToStream(pStream, m_maxDrives));
  340. WsbAffirmHr(WsbSaveToStream(pStream, m_maxPorts));
  341. WsbAffirmHr(WsbSaveToStream(pStream, m_maxSlots));
  342. WsbAffirmHr(WsbSaveToStream(pStream, m_NumUsedSlots));
  343. WsbAffirmHr(WsbSaveToStream(pStream, m_NumStagingSlots));
  344. WsbAffirmHr(WsbSaveToStream(pStream, m_NumScratchCarts));
  345. WsbAffirmHr(WsbSaveToStream(pStream, m_NumUnknownCarts));
  346. WsbAffirmHr(WsbSaveToStream(pStream, m_isMagazineSupported));
  347. WsbAffirmHr(WsbSaveToStream(pStream, m_maxCleaningMounts));
  348. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_slotSelectionPolicy));
  349. WsbAffirmHr(m_pChangers->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  350. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  351. pPersistStream = 0;
  352. WsbAffirmHr(m_pDriveClasses->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  353. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  354. pPersistStream = 0;
  355. WsbAffirmHr(m_pDrives->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  356. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  357. pPersistStream = 0;
  358. WsbAffirmHr(m_pStorageSlots->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  359. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  360. pPersistStream = 0;
  361. WsbAffirmHr(m_pStagingSlots->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  362. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  363. pPersistStream = 0;
  364. WsbAffirmHr(m_pPorts->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  365. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  366. pPersistStream = 0;
  367. WsbAffirmHr(m_pCleaningCartridges->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  368. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  369. pPersistStream = 0;
  370. WsbAffirmHr(m_pScratchCartridges->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  371. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  372. pPersistStream = 0;
  373. // Save the ID (GUID) for the media sets.
  374. GUID objectId;
  375. CComPtr<IRmsComObject> pMediaSet;
  376. CComPtr<IWsbEnum> pEnum;
  377. WsbAffirmHr( m_pMediaSets->Enum( &pEnum ) );
  378. hr = pEnum->First( IID_IRmsComObject, (void **)&pMediaSet );
  379. while ( S_OK == hr ) {
  380. WsbAffirmHr( pMediaSet->GetObjectId( &objectId ) );
  381. WsbAffirmHr( WsbSaveToStream(pStream, objectId) );
  382. pMediaSet = 0;
  383. hr = pEnum->Next( IID_IRmsComObject, (void **)&pMediaSet );
  384. }
  385. objectId = GUID_NULL;
  386. WsbAffirmHr( WsbSaveToStream(pStream, objectId) ); // This marks the last one!
  387. // Do we need to clear the dirty bit?
  388. if (clearDirty) {
  389. m_isDirty = FALSE;
  390. }
  391. }
  392. WsbCatch(hr);
  393. WsbTraceOut(OLESTR("CRmsLibrary::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  394. return hr;
  395. }
  396. STDMETHODIMP
  397. CRmsLibrary::Test(
  398. OUT USHORT *pPassed,
  399. OUT USHORT *pFailed
  400. )
  401. /*++
  402. Implements:
  403. IWsbTestable::Test
  404. --*/
  405. {
  406. HRESULT hr = S_OK;
  407. CComPtr<IRmsLibrary> pLibrary1;
  408. CComPtr<IRmsLibrary> pLibrary2;
  409. CComPtr<IPersistFile> pFile1;
  410. CComPtr<IPersistFile> pFile2;
  411. LONG i;
  412. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  413. CWsbBstrPtr bstrWork1;
  414. CWsbBstrPtr bstrWork2;
  415. LONG longWork1;
  416. LONG longWork2;
  417. LONG mediaTable [RMSMAXMEDIATYPES] = { RmsMediaUnknown,
  418. RmsMedia8mm,
  419. RmsMedia4mm,
  420. RmsMediaDLT,
  421. RmsMediaOptical,
  422. RmsMediaMO35,
  423. RmsMediaWORM,
  424. RmsMediaCDR,
  425. RmsMediaDVD,
  426. RmsMediaDisk,
  427. RmsMediaFixed,
  428. RmsMediaTape };
  429. WsbTraceIn(OLESTR("CRmsLibrary::Test"), OLESTR(""));
  430. try {
  431. // Get the Library interface.
  432. hr = S_OK;
  433. try {
  434. WsbAssertHr(((IUnknown*) (IRmsLibrary*) this)->QueryInterface(IID_IRmsLibrary, (void**) &pLibrary1));
  435. // Test SetName & GetName interface
  436. bstrWork1 = bstrVal1;
  437. SetName(bstrWork1);
  438. GetName(&bstrWork2);
  439. if (bstrWork1 == bstrWork2){
  440. (*pPassed)++;
  441. } else {
  442. (*pFailed)++;
  443. }
  444. // Test SetMediaSupported & GetMediaSupported
  445. for (i = 0; i < RMSMAXMEDIATYPES; i++){
  446. longWork1 = mediaTable[i];
  447. SetMediaSupported (longWork1);
  448. GetMediaSupported (&longWork2);
  449. if (longWork1 == longWork2){
  450. (*pPassed)++;
  451. } else {
  452. (*pFailed)++;
  453. }
  454. }
  455. // Test SetMaxChangers & GetMaxChangers
  456. longWork1 = 99;
  457. SetMaxChangers(longWork1);
  458. GetMaxChangers(&longWork2);
  459. if(longWork1 == longWork2){
  460. (*pPassed)++;
  461. } else {
  462. (*pFailed)++;
  463. }
  464. // Test SetMaxDrives & GetMaxDrives
  465. longWork1 = 99;
  466. SetMaxDrives(longWork1);
  467. GetMaxDrives(&longWork2);
  468. if(longWork1 == longWork2){
  469. (*pPassed)++;
  470. } else {
  471. (*pFailed)++;
  472. }
  473. // Test SetMaxPorts & GetMaxPorts
  474. longWork1 = 99;
  475. SetMaxPorts(longWork1);
  476. GetMaxPorts(&longWork2);
  477. if(longWork1 == longWork2){
  478. (*pPassed)++;
  479. } else {
  480. (*pFailed)++;
  481. }
  482. // Test SetMaxSlots & GetMaxSlots
  483. longWork1 = 99;
  484. SetMaxSlots(longWork1);
  485. GetMaxSlots(&longWork2);
  486. if(longWork1 == longWork2){
  487. (*pPassed)++;
  488. } else {
  489. (*pFailed)++;
  490. }
  491. // Test GetNumUsedSlots
  492. m_NumUsedSlots = 99;
  493. longWork1 = m_NumUsedSlots;
  494. GetNumUsedSlots(&longWork2);
  495. if(longWork1 == longWork2){
  496. (*pPassed)++;
  497. } else {
  498. (*pFailed)++;
  499. }
  500. // Test SetNumStagingSlots & GetNumStagingSlots
  501. longWork1 = 99;
  502. SetNumStagingSlots(longWork1);
  503. GetNumStagingSlots(&longWork2);
  504. if(longWork1 == longWork2){
  505. (*pPassed)++;
  506. } else {
  507. (*pFailed)++;
  508. }
  509. // Test SetNumScratchCarts & GetNumScratchCarts
  510. longWork1 = 99;
  511. SetNumScratchCarts(longWork1);
  512. GetNumScratchCarts(&longWork2);
  513. if(longWork1 == longWork2){
  514. (*pPassed)++;
  515. } else {
  516. (*pFailed)++;
  517. }
  518. // Test SetNumUnknownCarts & GetNumUnknownCarts
  519. longWork1 = 99;
  520. SetNumUnknownCarts(longWork1);
  521. GetNumUnknownCarts(&longWork2);
  522. if(longWork1 == longWork2){
  523. (*pPassed)++;
  524. } else {
  525. (*pFailed)++;
  526. }
  527. // Test SetIsMagazineSupported & IsMagazineSupported to TRUE
  528. hr = S_OK;
  529. try{
  530. WsbAffirmHr(SetIsMagazineSupported (TRUE));
  531. WsbAffirmHr(IsMagazineSupported ());
  532. } WsbCatch (hr);
  533. if (hr == S_OK){
  534. (*pPassed)++;
  535. } else {
  536. (*pFailed)++;
  537. }
  538. // Test SetIsMagazineSupported & IsMagazineSupported to FALSE
  539. hr = S_OK;
  540. try{
  541. WsbAffirmHr(SetIsMagazineSupported (FALSE));
  542. WsbAffirmHr(IsMagazineSupported ());
  543. } WsbCatch (hr);
  544. if (hr == S_OK){
  545. (*pFailed)++;
  546. } else {
  547. (*pPassed)++;
  548. }
  549. // Test SetMaxCleaningMounts & GetMaxCleaningMounts
  550. longWork1 = 99;
  551. SetMaxCleaningMounts(longWork1);
  552. GetMaxCleaningMounts(&longWork2);
  553. if(longWork1 == longWork2){
  554. (*pPassed)++;
  555. } else {
  556. (*pFailed)++;
  557. }
  558. // Test SetSlotSelectionPolicy & GetSlotSelectionPolicy
  559. for (i = RmsSlotSelectUnknown; i < RmsSlotSelectSortLabel; i++){
  560. longWork1 = i;
  561. SetSlotSelectionPolicy (longWork1);
  562. GetSlotSelectionPolicy (&longWork2);
  563. if (longWork1 == longWork2){
  564. (*pPassed)++;
  565. } else {
  566. (*pFailed)++;
  567. }
  568. }
  569. } WsbCatch(hr);
  570. // Tally up the results
  571. hr = S_OK;
  572. if (*pFailed) {
  573. hr = S_FALSE;
  574. }
  575. } WsbCatch(hr);
  576. WsbTraceOut(OLESTR("CRmsLibrary::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  577. return(hr);
  578. }
  579. ////////////////////////////////////////////////////////////////////////////////
  580. //
  581. // IRmsLibrary
  582. //
  583. STDMETHODIMP
  584. CRmsLibrary::GetLibraryId(
  585. GUID *pLibraryId
  586. )
  587. /*++
  588. Implements:
  589. IRmsLibrary::GetLibraryId
  590. --*/
  591. {
  592. *pLibraryId = m_objectId;
  593. return (S_OK);
  594. }
  595. STDMETHODIMP
  596. CRmsLibrary::SetLibraryId(
  597. GUID objectId
  598. )
  599. /*++
  600. Implements:
  601. IRmsLibrary::SetLibraryId
  602. --*/
  603. {
  604. m_objectId = objectId;
  605. m_isDirty = TRUE;
  606. return (S_OK);
  607. }
  608. STDMETHODIMP
  609. CRmsLibrary::GetName(
  610. BSTR *pName
  611. )
  612. /*++
  613. Implements:
  614. IRmsLibrary::GetName
  615. --*/
  616. {
  617. WsbAssertPointer (pName);
  618. m_Name. CopyToBstr (pName);
  619. return S_OK;
  620. }
  621. STDMETHODIMP
  622. CRmsLibrary::SetName(
  623. BSTR name
  624. )
  625. /*++
  626. Implements:
  627. IRmsLibrary::SetName
  628. --*/
  629. {
  630. m_Name = name;
  631. m_isDirty = TRUE;
  632. return S_OK;
  633. }
  634. STDMETHODIMP
  635. CRmsLibrary::GetMediaSupported(
  636. LONG *pType
  637. )
  638. /*++
  639. Implements:
  640. IRmsLibrary::GetMediaSupported
  641. --*/
  642. {
  643. *pType = m_mediaSupported;
  644. return S_OK;
  645. }
  646. STDMETHODIMP
  647. CRmsLibrary::SetMediaSupported(
  648. LONG type
  649. )
  650. /*++
  651. Implements:
  652. IRmsLibrary::SetMediaSupported
  653. --*/
  654. {
  655. m_mediaSupported = (RmsMedia) type;
  656. m_isDirty = TRUE;
  657. return S_OK;
  658. }
  659. STDMETHODIMP
  660. CRmsLibrary::GetMaxChangers(
  661. LONG *pNum
  662. )
  663. /*++
  664. Implements:
  665. IRmsLibrary::GetMaxChangers
  666. --*/
  667. {
  668. *pNum = m_maxChangers;
  669. return S_OK;
  670. }
  671. STDMETHODIMP
  672. CRmsLibrary::SetMaxChangers(
  673. LONG num
  674. )
  675. /*++
  676. Implements:
  677. IRmsLibrary::SetMaxChangers
  678. --*/
  679. {
  680. m_maxChangers = num;
  681. m_isDirty = TRUE;
  682. return S_OK;
  683. }
  684. STDMETHODIMP
  685. CRmsLibrary::GetMaxDrives(
  686. LONG *pNum
  687. )
  688. /*++
  689. Implements:
  690. IRmsLibrary::GetMaxDrives
  691. --*/
  692. {
  693. *pNum = m_maxDrives;
  694. return S_OK;
  695. }
  696. STDMETHODIMP
  697. CRmsLibrary::SetMaxDrives(
  698. LONG num
  699. )
  700. /*++
  701. Implements:
  702. IRmsLibrary::SetMaxDrives
  703. --*/
  704. {
  705. m_maxDrives = num;
  706. m_isDirty = TRUE;
  707. return S_OK;
  708. }
  709. STDMETHODIMP
  710. CRmsLibrary::GetMaxPorts(
  711. LONG *pNum
  712. )
  713. /*++
  714. Implements:
  715. IRmsLibrary::GetMaxPorts
  716. --*/
  717. {
  718. *pNum = m_maxPorts;
  719. return S_OK;
  720. }
  721. STDMETHODIMP
  722. CRmsLibrary::SetMaxPorts(
  723. LONG num
  724. )
  725. /*++
  726. Implements:
  727. IRmsLibrary::SetMaxPorts
  728. --*/
  729. {
  730. m_maxPorts = num;
  731. m_isDirty = TRUE;
  732. return S_OK;
  733. }
  734. STDMETHODIMP
  735. CRmsLibrary::GetMaxSlots(
  736. LONG *pNum
  737. )
  738. /*++
  739. Implements:
  740. IRmsLibrary::GetMaxSlots
  741. --*/
  742. {
  743. *pNum = m_maxSlots;
  744. return S_OK;
  745. }
  746. STDMETHODIMP
  747. CRmsLibrary::SetMaxSlots(
  748. LONG num
  749. )
  750. /*++
  751. Implements:
  752. IRmsLibrary::SetMaxSlots
  753. --*/
  754. {
  755. m_maxSlots = num;
  756. m_isDirty = TRUE;
  757. return S_OK;
  758. }
  759. STDMETHODIMP
  760. CRmsLibrary::GetNumUsedSlots(
  761. LONG *pNum
  762. )
  763. /*++
  764. Implements:
  765. IRmsLibrary::GetNumUsedSlots
  766. --*/
  767. {
  768. *pNum = m_NumUsedSlots;
  769. return S_OK;
  770. }
  771. STDMETHODIMP
  772. CRmsLibrary::GetNumStagingSlots(
  773. LONG *pNum
  774. )
  775. /*++
  776. Implements:
  777. IRmsLibrary::GetNumStagingSlots
  778. --*/
  779. {
  780. *pNum = m_NumStagingSlots;
  781. return S_OK;
  782. }
  783. STDMETHODIMP
  784. CRmsLibrary::SetNumStagingSlots(
  785. LONG num
  786. )
  787. /*++
  788. Implements:
  789. IRmsLibrary::SetNumStagingSlots
  790. --*/
  791. {
  792. m_NumStagingSlots = num;
  793. m_isDirty = TRUE;
  794. return S_OK;
  795. }
  796. STDMETHODIMP
  797. CRmsLibrary::GetNumScratchCarts(
  798. LONG *pNum
  799. )
  800. /*++
  801. Implements:
  802. IRmsLibrary::SetNumScratchCarts
  803. --*/
  804. {
  805. *pNum = m_NumScratchCarts;
  806. m_isDirty = TRUE;
  807. return S_OK;
  808. }
  809. STDMETHODIMP
  810. CRmsLibrary::SetNumScratchCarts(
  811. LONG num
  812. )
  813. /*++
  814. Implements:
  815. IRmsLibrary::SetNumScratchCarts
  816. --*/
  817. {
  818. m_NumScratchCarts = num;
  819. m_isDirty = TRUE;
  820. return S_OK;
  821. }
  822. STDMETHODIMP
  823. CRmsLibrary::GetNumUnknownCarts(
  824. LONG *pNum
  825. )
  826. /*++
  827. Implements:
  828. IRmsLibrary::GetNumUnknownCarts
  829. --*/
  830. {
  831. *pNum = m_NumUnknownCarts;
  832. return S_OK;
  833. }
  834. STDMETHODIMP
  835. CRmsLibrary::SetNumUnknownCarts(
  836. LONG num
  837. )
  838. /*++
  839. Implements:
  840. IRmsLibrary::SetNumUnknownCarts
  841. --*/
  842. {
  843. m_NumUnknownCarts = num;
  844. m_isDirty = TRUE;
  845. return S_OK;
  846. }
  847. STDMETHODIMP
  848. CRmsLibrary::SetIsMagazineSupported(
  849. BOOL flag
  850. )
  851. /*++
  852. Implements:
  853. IRmsLibrary::SetIsMagazineSupported
  854. --*/
  855. {
  856. m_isMagazineSupported = flag;
  857. m_isDirty = TRUE;
  858. return S_OK;
  859. }
  860. STDMETHODIMP
  861. CRmsLibrary::IsMagazineSupported(
  862. void
  863. )
  864. /*++
  865. Implements:
  866. IRmsLibrary::IsMagazineSupported
  867. --*/
  868. {
  869. HRESULT hr = S_FALSE;
  870. if (m_isMagazineSupported){
  871. hr = S_OK;
  872. }
  873. return (hr);
  874. }
  875. STDMETHODIMP
  876. CRmsLibrary::GetMaxCleaningMounts(
  877. LONG *pNum
  878. )
  879. /*++
  880. Implements:
  881. IRmsLibrary::GetMaxCleaningMounts
  882. --*/
  883. {
  884. *pNum = m_maxCleaningMounts;
  885. return S_OK;
  886. }
  887. STDMETHODIMP
  888. CRmsLibrary::SetMaxCleaningMounts(
  889. LONG num
  890. )
  891. /*++
  892. Implements:
  893. IRmsLibrary::SetMaxCleanMounts
  894. --*/
  895. {
  896. m_maxCleaningMounts = num;
  897. m_isDirty = TRUE;
  898. return S_OK;
  899. }
  900. STDMETHODIMP
  901. CRmsLibrary::GetSlotSelectionPolicy(
  902. LONG *pNum
  903. )
  904. /*++
  905. Implements:
  906. IRmsLibrary::GetSlotSelectionPolicy
  907. --*/
  908. {
  909. *pNum = m_slotSelectionPolicy;
  910. return S_OK;
  911. }
  912. STDMETHODIMP
  913. CRmsLibrary::SetSlotSelectionPolicy(
  914. LONG num
  915. )
  916. /*++
  917. Implements:
  918. IRmsLibrary::SetSlotSelectionPolicy
  919. --*/
  920. {
  921. m_slotSelectionPolicy = (RmsSlotSelect) num;
  922. m_isDirty = TRUE;
  923. return S_OK;
  924. }
  925. STDMETHODIMP
  926. CRmsLibrary::GetChangers(
  927. IWsbIndexedCollection **ptr
  928. )
  929. /*++
  930. Implements:
  931. IRmsLibrary::GetChangers
  932. --*/
  933. {
  934. *ptr = m_pChangers;
  935. m_pChangers->AddRef();
  936. return S_OK;
  937. }
  938. STDMETHODIMP
  939. CRmsLibrary::GetDriveClasses(
  940. IWsbIndexedCollection **ptr
  941. )
  942. /*++
  943. Implements:
  944. IRmsLibrary::GetDriveClasses
  945. --*/
  946. {
  947. *ptr = m_pDriveClasses;
  948. m_pDriveClasses->AddRef();
  949. return S_OK;
  950. }
  951. STDMETHODIMP
  952. CRmsLibrary::GetDrives(
  953. IWsbIndexedCollection **ptr
  954. )
  955. /*++
  956. Implements:
  957. IRmsLibrary::GetDrives
  958. --*/
  959. {
  960. *ptr = m_pDrives;
  961. m_pDrives->AddRef();
  962. return S_OK;
  963. }
  964. STDMETHODIMP
  965. CRmsLibrary::GetStorageSlots(
  966. IWsbIndexedCollection **ptr
  967. )
  968. /*++
  969. Implements:
  970. IRmsLibrary::GetStorageSlots
  971. --*/
  972. {
  973. *ptr = m_pStorageSlots;
  974. m_pStorageSlots->AddRef();
  975. return S_OK;
  976. }
  977. STDMETHODIMP
  978. CRmsLibrary::GetStagingSlots(
  979. IWsbIndexedCollection **ptr
  980. )
  981. /*++
  982. Implements:
  983. IRmsLibrary::GetStagingSlots
  984. --*/
  985. {
  986. *ptr = m_pStagingSlots;
  987. m_pStagingSlots->AddRef();
  988. return S_OK;
  989. }
  990. STDMETHODIMP
  991. CRmsLibrary::GetPorts(
  992. IWsbIndexedCollection **ptr
  993. )
  994. /*++
  995. Implements:
  996. IRmsLibrary::GetPorts
  997. --*/
  998. {
  999. *ptr = m_pPorts;
  1000. m_pPorts->AddRef();
  1001. return S_OK;
  1002. }
  1003. STDMETHODIMP
  1004. CRmsLibrary::GetCleaningCartridges(
  1005. IWsbIndexedCollection **ptr
  1006. )
  1007. /*++
  1008. Implements:
  1009. IRmsLibrary::GetCleaningCartridges
  1010. --*/
  1011. {
  1012. *ptr = m_pCleaningCartridges;
  1013. m_pCleaningCartridges->AddRef();
  1014. return S_OK;
  1015. }
  1016. STDMETHODIMP
  1017. CRmsLibrary::GetScratchCartridges(
  1018. IWsbIndexedCollection **ptr
  1019. )
  1020. /*++
  1021. Implements:
  1022. IRmsLibrary::GetScratchCartridges
  1023. --*/
  1024. {
  1025. *ptr = m_pScratchCartridges;
  1026. m_pScratchCartridges->AddRef();
  1027. return S_OK;
  1028. }
  1029. STDMETHODIMP
  1030. CRmsLibrary::GetMediaSets(
  1031. IWsbIndexedCollection **ptr
  1032. )
  1033. /*++
  1034. Implements:
  1035. IRmsLibrary::GetMediaSets
  1036. --*/
  1037. {
  1038. *ptr = m_pMediaSets;
  1039. m_pMediaSets->AddRef();
  1040. m_isDirty = TRUE;
  1041. return S_OK;
  1042. }
  1043. STDMETHODIMP
  1044. CRmsLibrary::Audit(
  1045. LONG /*start*/,
  1046. LONG /*count*/,
  1047. BOOL /*verify*/,
  1048. BOOL /*unknownOnly*/,
  1049. BOOL /*mountWait*/,
  1050. LPOVERLAPPED /*pOverlapped*/,
  1051. LONG* /*pRequest*/
  1052. )
  1053. /*++
  1054. Implements:
  1055. IRmsLibrary::Audit
  1056. --*/
  1057. {
  1058. return E_NOTIMPL;
  1059. }