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.

1049 lines
20 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsMdSet.cpp
  5. Abstract:
  6. Implementation of CRmsMediaSet
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsServr.h"
  13. #include "RmsMdSet.h"
  14. ////////////////////////////////////////////////////////////////////////////////
  15. //
  16. STDMETHODIMP
  17. CRmsMediaSet::CompareTo(
  18. IN IUnknown *pCollectable,
  19. OUT SHORT *pResult)
  20. /*++
  21. Implements:
  22. IWsbCollectable::CompareTo
  23. --*/
  24. {
  25. HRESULT hr = E_FAIL;
  26. SHORT result = 1;
  27. WsbTraceIn( OLESTR("CRmsMediaSet::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. // We need the IRmsMediaSet interface to get the value of the object.
  32. CComQIPtr<IRmsMediaSet, &IID_IRmsMediaSet> pMediaSet = pCollectable;
  33. WsbAssertPointer( pMediaSet );
  34. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  35. WsbAssertPointer( pObject );
  36. switch ( m_findBy ) {
  37. case RmsFindByName:
  38. {
  39. CWsbBstrPtr name;
  40. WsbAffirmHr( pMediaSet->GetName( &name ) );
  41. // Compare the names
  42. result = (SHORT)wcscmp( m_Name, name );
  43. hr = ( 0 == result ) ? S_OK : S_FALSE;
  44. }
  45. break;
  46. case RmsFindByMediaSupported:
  47. {
  48. RmsMedia mediaSupported;
  49. WsbAffirmHr(pMediaSet->GetMediaSupported( (LONG*) &mediaSupported ) );
  50. if ( m_MediaSupported == mediaSupported ) {
  51. // media types supported match
  52. hr = S_OK;
  53. result = 0;
  54. }
  55. else {
  56. hr = S_FALSE;
  57. result = 1;
  58. }
  59. }
  60. break;
  61. case RmsFindByMediaSetId:
  62. default:
  63. // Do CompareTo for object
  64. hr = CRmsComObject::CompareTo( pCollectable, &result );
  65. break;
  66. }
  67. }
  68. WsbCatch( hr );
  69. if ( SUCCEEDED(hr) && (0 != pResult) ){
  70. *pResult = result;
  71. }
  72. WsbTraceOut( OLESTR("CRmsMediaSet::CompareTo"),
  73. OLESTR("hr = <%ls>, result = <%ls>"),
  74. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  75. return hr;
  76. }
  77. HRESULT
  78. CRmsMediaSet::FinalConstruct(void)
  79. /*++
  80. Implements:
  81. CComObjectRoot::FinalConstruct
  82. --*/
  83. {
  84. HRESULT hr = S_OK;
  85. try {
  86. WsbAssertHr(CWsbObject::FinalConstruct());
  87. // Initialize values
  88. m_Name = RMS_UNDEFINED_STRING;
  89. m_MediaSupported = RmsMediaUnknown;
  90. m_SizeOfInfo = 0;
  91. memset(m_Info, 0, MaxInfo);
  92. m_OwnerId = CLSID_NULL;
  93. m_MediaSetType = RmsMediaSetUnknown;
  94. m_MaxCartridges = 0;
  95. m_Occupancy = 0;
  96. m_IsMediaCopySupported = FALSE;
  97. } WsbCatch(hr);
  98. return hr;
  99. }
  100. STDMETHODIMP
  101. CRmsMediaSet::GetClassID(
  102. OUT CLSID* pClsid)
  103. /*++
  104. Implements:
  105. IPersist::GetClassID
  106. --*/
  107. {
  108. HRESULT hr = S_OK;
  109. WsbTraceIn(OLESTR("CRmsMediaSet::GetClassID"), OLESTR(""));
  110. try {
  111. WsbAssertPointer(pClsid);
  112. *pClsid = CLSID_CRmsMediaSet;
  113. } WsbCatch(hr);
  114. WsbTraceOut(OLESTR("CRmsMediaSet::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  115. return hr;
  116. }
  117. STDMETHODIMP
  118. CRmsMediaSet::GetSizeMax(
  119. OUT ULARGE_INTEGER* pcbSize)
  120. /*++
  121. Implements:
  122. IPersistStream::GetSizeMax
  123. --*/
  124. {
  125. HRESULT hr = E_NOTIMPL;
  126. // ULONG nameLen;
  127. WsbTraceIn(OLESTR("CRmsMediaSet::GetSizeMax"), OLESTR(""));
  128. // try {
  129. // WsbAssert(0 != pcbSize, E_POINTER);
  130. // nameLen = SysStringByteLen(m_name);
  131. // // Get max size
  132. // pcbSize->QuadPart = WsbPersistSizeOf(LONG) + // m_objectId
  133. // WsbPersistSizeOf(LONG) + // length of m_name
  134. // nameLen + // m_name
  135. // WsbPersistSizeOf(LONG) + // m_mediaSupported
  136. // WsbPersistSizeOf(SHORT) + // m_sizeofInfo
  137. // MaxInfo + // m_info
  138. // WsbPersistSizeOf(CLSID) + // m_ownerId
  139. // WsbPersistSizeOf(LONG) + // m_mediaSetType
  140. // WsbPersistSizeOf(LONG) + // m_maxCartridges
  141. // WsbPersistSizeOf(LONG); // m_occupancy
  142. // } WsbCatch(hr);
  143. WsbTraceOut(OLESTR("CRmsMediaSet::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  144. return hr;
  145. }
  146. STDMETHODIMP
  147. CRmsMediaSet::Load(
  148. IN IStream* pStream)
  149. /*++
  150. Implements:
  151. IPersistStream::Load
  152. --*/
  153. {
  154. HRESULT hr = S_OK;
  155. ULONG ulBytes = 0;
  156. WsbTraceIn(OLESTR("CRmsMediaSet::Load"), OLESTR(""));
  157. try {
  158. ULONG temp;
  159. WsbAssertPointer(pStream);
  160. WsbAffirmHr(CRmsStorageInfo::Load(pStream));
  161. // Read value
  162. WsbAffirmHr(WsbLoadFromStream(pStream, &m_objectId));
  163. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  164. m_MediaSupported = (RmsMedia)temp;
  165. WsbAffirmHr(WsbLoadFromStream(pStream, &m_SizeOfInfo));
  166. WsbAffirmHr(WsbLoadFromStream(pStream, &(m_Info [0]), MaxInfo));
  167. WsbAffirmHr(WsbLoadFromStream(pStream, &m_OwnerId));
  168. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  169. m_MediaSetType = (RmsMediaSet)temp;
  170. WsbAffirmHr(WsbLoadFromStream(pStream, &m_MaxCartridges));
  171. WsbAffirmHr(WsbLoadFromStream(pStream, &m_Occupancy));
  172. WsbAffirmHr(WsbLoadFromStream(pStream, &m_IsMediaCopySupported));
  173. } WsbCatch(hr);
  174. WsbTraceOut(OLESTR("CRmsMediaSet::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  175. return hr;
  176. }
  177. STDMETHODIMP
  178. CRmsMediaSet::Save(
  179. IN IStream* pStream,
  180. IN BOOL clearDirty)
  181. /*++
  182. Implements:
  183. IPersistStream::Save
  184. --*/
  185. {
  186. HRESULT hr = S_OK;
  187. ULONG ulBytes = 0;
  188. WsbTraceIn(OLESTR("CRmsMediaSet::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  189. try {
  190. WsbAssertPointer(pStream);
  191. WsbAffirmHr(CRmsStorageInfo::Save(pStream, clearDirty));
  192. // Write value
  193. WsbAffirmHr(WsbSaveToStream(pStream, m_objectId));
  194. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_MediaSupported));
  195. WsbAffirmHr(WsbSaveToStream(pStream, m_SizeOfInfo));
  196. WsbAffirmHr(WsbSaveToStream(pStream, &(m_Info [0]), MaxInfo));
  197. WsbAffirmHr(WsbSaveToStream(pStream, m_OwnerId));
  198. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_MediaSetType));
  199. WsbAffirmHr(WsbSaveToStream(pStream, m_MaxCartridges));
  200. WsbAffirmHr(WsbSaveToStream(pStream, m_Occupancy));
  201. WsbAffirmHr(WsbSaveToStream(pStream, m_IsMediaCopySupported));
  202. // Do we need to clear the dirty bit?
  203. if (clearDirty) {
  204. m_isDirty = FALSE;
  205. }
  206. } WsbCatch(hr);
  207. WsbTraceOut(OLESTR("CRmsMediaSet::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  208. return hr;
  209. }
  210. STDMETHODIMP
  211. CRmsMediaSet::Test(
  212. OUT USHORT *pPassed,
  213. OUT USHORT *pFailed)
  214. /*++
  215. Implements:
  216. IWsbTestable::Test
  217. --*/
  218. {
  219. HRESULT hr = S_OK;
  220. CComPtr<IRmsMediaSet> pMediaSet1;
  221. CComPtr<IRmsMediaSet> pMediaSet2;
  222. CComPtr<IPersistFile> pFile1;
  223. CComPtr<IPersistFile> pFile2;
  224. GUID guidVal1 = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
  225. GUID guidWork1;
  226. GUID guidWork2;
  227. CLSID clsidWork1;
  228. CLSID clsidWork2;
  229. LONG i;
  230. LONG longWork1;
  231. LONG longWork2;
  232. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  233. CWsbBstrPtr bstrWork1;
  234. CWsbBstrPtr bstrWork2;
  235. LONG mediaTable [RMSMAXMEDIATYPES] = { RmsMediaUnknown,
  236. RmsMedia8mm,
  237. RmsMedia4mm,
  238. RmsMediaDLT,
  239. RmsMediaOptical,
  240. RmsMediaMO35,
  241. RmsMediaWORM,
  242. RmsMediaCDR,
  243. RmsMediaDVD,
  244. RmsMediaDisk,
  245. RmsMediaFixed,
  246. RmsMediaTape };
  247. WsbTraceIn(OLESTR("CRmsMediaSet::Test"), OLESTR(""));
  248. try {
  249. // Get the MediaSet interface.
  250. hr = S_OK;
  251. try {
  252. WsbAssertHr(((IUnknown*) (IRmsMediaSet*) this)->QueryInterface(IID_IRmsMediaSet, (void**) &pMediaSet1));
  253. // Test SetMediaSetId & GetMediaSetId
  254. m_objectId = guidVal1;
  255. guidWork1 = m_objectId;
  256. GetMediaSetId(&guidWork2);
  257. if(guidWork1 == guidWork2){
  258. (*pPassed)++;
  259. } else {
  260. (*pFailed)++;
  261. }
  262. // Test SetName & GetName interface
  263. bstrWork1 = bstrVal1;
  264. SetName(bstrWork1);
  265. GetName(&bstrWork2);
  266. if (bstrWork1 == bstrWork2){
  267. (*pPassed)++;
  268. } else {
  269. (*pFailed)++;
  270. }
  271. // Test SetMediaSupported & GetMediaSupported
  272. for (i = RmsMediaUnknown; i < RMSMAXMEDIATYPES; i++){
  273. longWork1 = mediaTable[i];
  274. SetMediaSupported (longWork1);
  275. GetMediaSupported (&longWork2);
  276. if (longWork1 == longWork2){
  277. (*pPassed)++;
  278. } else {
  279. (*pFailed)++;
  280. }
  281. }
  282. // Test SetInfo & GetInfo
  283. // Test SetOwnerClassId & GetOwnerClassId
  284. clsidWork1 = CLSID_NULL;
  285. SetOwnerClassId(clsidWork1);
  286. GetOwnerClassId(&clsidWork2);
  287. if(clsidWork1 == clsidWork2){
  288. (*pPassed)++;
  289. } else {
  290. (*pFailed)++;
  291. }
  292. // Test SetMediaSetType & GetMediaSetType
  293. for (i = RmsMediaSetUnknown; i < RmsMediaSetNTMS; i++){
  294. longWork1 = i;
  295. SetMediaSetType (longWork1);
  296. GetMediaSetType (&longWork2);
  297. if (longWork1 == longWork2){
  298. (*pPassed)++;
  299. } else {
  300. (*pFailed)++;
  301. }
  302. }
  303. // Test SetMaxCartridges & GetMaxCartridges
  304. longWork1 = 99;
  305. SetMaxCartridges(longWork1);
  306. GetMaxCartridges(&longWork2);
  307. if(longWork1 == longWork2){
  308. (*pPassed)++;
  309. } else {
  310. (*pFailed)++;
  311. }
  312. // Test SetOccupancy & GetOccupancy
  313. longWork1 = 99;
  314. SetOccupancy(longWork1);
  315. GetOccupancy(&longWork2);
  316. if(longWork1 == longWork2){
  317. (*pPassed)++;
  318. } else {
  319. (*pFailed)++;
  320. }
  321. } WsbCatch(hr);
  322. // Tally up the results
  323. hr = S_OK;
  324. if (*pFailed) {
  325. hr = S_FALSE;
  326. }
  327. } WsbCatch(hr);
  328. WsbTraceOut(OLESTR("CRmsMediaSet::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  329. return hr;
  330. }
  331. STDMETHODIMP
  332. CRmsMediaSet::GetMediaSetId(
  333. OUT GUID *pMediaSetId)
  334. /*++
  335. Implements:
  336. IRmsMediaSet::GetMediaSetId
  337. --*/
  338. {
  339. HRESULT hr = S_OK;
  340. try {
  341. WsbAssertPointer (pMediaSetId);
  342. *pMediaSetId = m_objectId;
  343. } WsbCatch(hr);
  344. return hr;
  345. }
  346. STDMETHODIMP
  347. CRmsMediaSet::GetName(
  348. OUT BSTR *pName)
  349. /*++
  350. Implements:
  351. IRmsMediaSet::GetName
  352. --*/
  353. {
  354. HRESULT hr = S_OK;
  355. try {
  356. WsbAssertPointer (pName);
  357. m_Name. CopyToBstr (pName);
  358. } WsbCatch(hr);
  359. return hr;
  360. }
  361. STDMETHODIMP
  362. CRmsMediaSet::SetName(
  363. IN BSTR name)
  364. /*++
  365. Implements:
  366. IRmsMediaSet::SetName
  367. --*/
  368. {
  369. m_Name = name;
  370. m_isDirty = TRUE;
  371. return S_OK;
  372. }
  373. STDMETHODIMP
  374. CRmsMediaSet::GetMediaSupported(
  375. OUT LONG *pType)
  376. /*++
  377. Implements:
  378. IRmsMediaSet::GetMediaSupported
  379. --*/
  380. {
  381. HRESULT hr = S_OK;
  382. try {
  383. WsbAssertPointer (pType);
  384. *pType = m_MediaSupported;
  385. } WsbCatch(hr);
  386. return hr;
  387. }
  388. STDMETHODIMP
  389. CRmsMediaSet::SetMediaSupported(
  390. IN LONG type)
  391. /*++
  392. Implements:
  393. IRmsMediaSet::SetMediaSupported
  394. --*/
  395. {
  396. m_MediaSupported = (RmsMedia) type;
  397. m_isDirty = TRUE;
  398. return S_OK;
  399. }
  400. STDMETHODIMP
  401. CRmsMediaSet::GetInfo(
  402. OUT UCHAR *pInfo,
  403. OUT SHORT *pSize)
  404. /*++
  405. Implements:
  406. IRmsMediaSet::GetInfo
  407. --*/
  408. {
  409. HRESULT hr = S_OK;
  410. try {
  411. WsbAssertPointer (pInfo);
  412. WsbAssertPointer (pSize);
  413. memmove (pInfo, m_Info, m_SizeOfInfo );
  414. *pSize = m_SizeOfInfo;
  415. } WsbCatch(hr);
  416. return hr;
  417. }
  418. STDMETHODIMP
  419. CRmsMediaSet::SetInfo(
  420. IN UCHAR *pInfo,
  421. IN SHORT size)
  422. /*++
  423. Implements:
  424. IRmsMediaSet::SetInfo
  425. --*/
  426. {
  427. HRESULT hr = S_OK;
  428. try {
  429. WsbAssertPointer (pInfo);
  430. memmove (m_Info, pInfo, size);
  431. m_SizeOfInfo = size;
  432. m_isDirty = TRUE;
  433. } WsbCatch(hr);
  434. return hr;
  435. }
  436. STDMETHODIMP
  437. CRmsMediaSet::GetOwnerClassId(
  438. OUT CLSID *pClassId)
  439. /*++
  440. Implements:
  441. IRmsMediaSet::GetOwnerClassId
  442. --*/
  443. {
  444. HRESULT hr = S_OK;
  445. try {
  446. WsbAssertPointer (pClassId);
  447. *pClassId = m_OwnerId;
  448. } WsbCatch(hr);
  449. return hr;
  450. }
  451. STDMETHODIMP
  452. CRmsMediaSet::SetOwnerClassId(
  453. IN CLSID classId)
  454. /*++
  455. Implements:
  456. IRmsMediaSet::SetOwnerClassId
  457. --*/
  458. {
  459. m_OwnerId = classId;
  460. m_isDirty = TRUE;
  461. return S_OK;
  462. }
  463. STDMETHODIMP
  464. CRmsMediaSet::GetMediaSetType(
  465. OUT LONG *pType)
  466. /*++
  467. Implements:
  468. IRmsMediaSet::GetMediaSetType
  469. --*/
  470. {
  471. HRESULT hr = S_OK;
  472. try {
  473. WsbAssertPointer (pType);
  474. *pType = m_MediaSetType;
  475. } WsbCatch(hr);
  476. return hr;
  477. }
  478. STDMETHODIMP
  479. CRmsMediaSet::SetMediaSetType(
  480. IN LONG type)
  481. /*++
  482. Implements:
  483. IRmsMediaSet::SetMediaSetType
  484. --*/
  485. {
  486. m_MediaSetType = (RmsMediaSet) type;
  487. m_isDirty = TRUE;
  488. return S_OK;
  489. }
  490. STDMETHODIMP
  491. CRmsMediaSet::GetMaxCartridges(
  492. OUT LONG *pNum)
  493. /*++
  494. Implements:
  495. IRmsMediaSet::GetMaxCartridges
  496. --*/
  497. {
  498. HRESULT hr = S_OK;
  499. try {
  500. WsbAssertPointer (pNum);
  501. *pNum = m_MaxCartridges;
  502. } WsbCatch(hr);
  503. return hr;
  504. }
  505. STDMETHODIMP
  506. CRmsMediaSet::SetMaxCartridges(
  507. IN LONG num)
  508. /*++
  509. Implements:
  510. IRmsMediaSet::SetMaxCartridges
  511. --*/
  512. {
  513. m_MaxCartridges = num;
  514. m_isDirty = TRUE;
  515. return S_OK;
  516. }
  517. STDMETHODIMP
  518. CRmsMediaSet::GetOccupancy(
  519. OUT LONG *pNum)
  520. /*++
  521. Implements:
  522. IRmsMediaSet::GetOccupancy
  523. --*/
  524. {
  525. HRESULT hr = S_OK;
  526. try {
  527. WsbAssertPointer (pNum);
  528. *pNum = m_Occupancy;
  529. } WsbCatch(hr);
  530. return hr;
  531. }
  532. STDMETHODIMP
  533. CRmsMediaSet::SetOccupancy(
  534. IN LONG num)
  535. /*++
  536. Implements:
  537. IRmsMediaSet::SetOccupancy
  538. --*/
  539. {
  540. m_Occupancy = num;
  541. m_isDirty = TRUE;
  542. return S_OK;
  543. }
  544. STDMETHODIMP
  545. CRmsMediaSet::IsMediaCopySupported(void)
  546. /*++
  547. Implements:
  548. IRmsMediaSet::IsMediaCopySupported
  549. --*/
  550. {
  551. HRESULT hr = S_OK;
  552. WsbTraceIn(OLESTR("CRmsMediaSet::IsMediaCopySupported"), OLESTR(""));
  553. try {
  554. if (RmsMediaSetNTMS == m_MediaSetType) {
  555. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  556. CComPtr<IRmsNTMS> pNtms;
  557. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  558. WsbAffirmPointer(pNtms);
  559. m_IsMediaCopySupported = (S_OK == pNtms->IsMediaCopySupported(m_objectId)) ? TRUE : FALSE;
  560. }
  561. hr = ( m_IsMediaCopySupported ) ? S_OK : S_FALSE;
  562. } WsbCatch(hr)
  563. WsbTraceOut(OLESTR("CRmsMediaSet::IsMediaCopySupported"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  564. return hr;
  565. }
  566. STDMETHODIMP
  567. CRmsMediaSet::SetIsMediaCopySupported(
  568. IN BOOL flag)
  569. /*++
  570. Implements:
  571. IRmsMediaSet::SetIsMediaCopySupported
  572. --*/
  573. {
  574. m_IsMediaCopySupported = flag;
  575. m_isDirty = TRUE;
  576. return S_OK;
  577. }
  578. STDMETHODIMP
  579. CRmsMediaSet::Allocate(
  580. IN REFGUID prevSideId,
  581. IN OUT LONGLONG *pFreeSpace,
  582. IN BSTR displayName,
  583. IN DWORD dwOptions,
  584. OUT IRmsCartridge **ppCart)
  585. /*++
  586. Implements:
  587. IRmsMediaSet::Allocate
  588. --*/
  589. {
  590. HRESULT hr = S_OK;
  591. WsbTraceIn(OLESTR("CRmsMediaSet::Allocate"), OLESTR("<%ls> <%ls> <0x%08x>"),
  592. WsbQuickString(WsbPtrToStringAsString((WCHAR **)&displayName)),
  593. WsbQuickString(WsbPtrToLonglongAsString(pFreeSpace)),
  594. dwOptions );
  595. try {
  596. WsbAssertPointer(ppCart);
  597. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  598. switch (m_MediaSetType) {
  599. case RmsMediaSetLibrary:
  600. {
  601. CComPtr<IWsbIndexedCollection> pCarts;
  602. CComPtr<IRmsCartridge> pFindCart;
  603. // Get the cartridge collection
  604. WsbAffirmHr(pServer->GetCartridges(&pCarts));
  605. // Create a cartridge template
  606. WsbAffirmHr(CoCreateInstance(CLSID_CRmsCartridge, 0, CLSCTX_SERVER, IID_IRmsCartridge, (void **)&pFindCart));
  607. // Fill in the find template
  608. // Using FindByScratchMediaCriteria
  609. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pFindCart;
  610. WsbAssertHr(pObject->SetFindBy(RmsFindByScratchMediaCriteria));
  611. // Scratch selection criteria
  612. WsbAssertHr(pFindCart->SetStatus(RmsStatusScratch));
  613. WsbAssertHr(pFindCart->SetLocation(RmsElementUnknown, GUID_NULL, m_objectId, 0, 0, 0, 0, FALSE));
  614. // Now find the cartridge
  615. hr = pCarts->Find(pFindCart, IID_IRmsCartridge, (void **)ppCart);
  616. if (WSB_E_NOTFOUND == hr) {
  617. WsbThrow(RMS_E_SCRATCH_NOT_FOUND_FINAL);
  618. }
  619. WsbAffirmHr(hr);
  620. // Set media name and description to display name
  621. WsbAffirmPointer(*ppCart);
  622. WsbAffirmHr((*ppCart)->SetName(displayName));
  623. WsbAffirmHr((*ppCart)->SetDescription(displayName));
  624. }
  625. break;
  626. case RmsMediaSetNTMS:
  627. {
  628. CComPtr<IRmsNTMS> pNtms;
  629. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  630. WsbAffirmHr(pNtms->Allocate(m_objectId, prevSideId, pFreeSpace, displayName, dwOptions, ppCart));
  631. }
  632. break;
  633. case RmsMediaSetShelf:
  634. case RmsMediaSetOffSite:
  635. case RmsMediaSetFolder:
  636. case RmsMediaSetUnknown:
  637. default:
  638. WsbThrow(E_UNEXPECTED);
  639. break;
  640. }
  641. (void) InterlockedIncrement(&m_Occupancy);
  642. } WsbCatch(hr)
  643. WsbTraceOut(OLESTR("CRmsMediaSet::Allocate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  644. return hr;
  645. }
  646. STDMETHODIMP
  647. CRmsMediaSet::Deallocate(
  648. IN IRmsCartridge *pCart)
  649. /*++
  650. Implements:
  651. IRmsMediaSet::Deallocate
  652. --*/
  653. {
  654. HRESULT hr = S_OK;
  655. WsbTraceIn(OLESTR("CRmsMediaSet::Deallocate"), OLESTR(""));
  656. try {
  657. WsbAssertPointer (pCart);
  658. CComQIPtr<IRmsServer, &IID_IRmsServer> pServer = g_pServer;
  659. switch (m_MediaSetType) {
  660. case RmsMediaSetLibrary:
  661. {
  662. WsbAffirmHr(pCart->SetStatus(RmsStatusScratch));
  663. }
  664. break;
  665. case RmsMediaSetNTMS:
  666. {
  667. CComPtr<IRmsNTMS> pNtms;
  668. WsbAffirmHr(pServer->GetNTMS(&pNtms));
  669. WsbAffirmHr(pNtms->Deallocate(pCart));
  670. }
  671. break;
  672. case RmsMediaSetShelf:
  673. case RmsMediaSetOffSite:
  674. case RmsMediaSetFolder:
  675. case RmsMediaSetUnknown:
  676. default:
  677. WsbThrow(E_UNEXPECTED);
  678. break;
  679. }
  680. (void) InterlockedDecrement(&m_Occupancy);
  681. } WsbCatch(hr);
  682. WsbTraceOut(OLESTR("CRmsMediaSet::Deallocate"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  683. return hr;
  684. }