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.

842 lines
16 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsDrCls.cpp
  5. Abstract:
  6. Implementation of CRmsDriveClass
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsDrCls.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. STDMETHODIMP
  16. CRmsDriveClass::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("CRmsDriveClass::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 RmsFindByDriveClassId:
  35. case RmsFindByObjectId:
  36. default:
  37. // Do CompareTo for object
  38. hr = CRmsComObject::CompareTo( pCollectable, &result );
  39. break;
  40. }
  41. }
  42. WsbCatch(hr);
  43. if ( SUCCEEDED(hr) && (0 != pResult) ){
  44. *pResult = result;
  45. }
  46. WsbTraceOut( OLESTR("CRmsDriveClass::CompareTo"),
  47. OLESTR("hr = <%ls>, result = <%ls>"),
  48. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  49. return hr;
  50. }
  51. HRESULT
  52. CRmsDriveClass::FinalConstruct(
  53. void
  54. )
  55. /*++
  56. Implements:
  57. CComObjectRoot::FinalConstruct
  58. --*/
  59. {
  60. HRESULT hr = S_OK;
  61. try {
  62. WsbAssertHr(CWsbObject::FinalConstruct());
  63. // Initialize values
  64. m_type = RmsMediaUnknown;
  65. m_capability = RmsModeUnknown;
  66. m_idleTime = 0;
  67. m_mountWaitTime = 0;
  68. m_mountLimit = 0;
  69. m_queuedRequests = 0;
  70. m_unloadPauseTime = 0;
  71. m_driveSelectionPolicy = RmsDriveSelectUnknown;
  72. } WsbCatch(hr);
  73. return(hr);
  74. }
  75. STDMETHODIMP
  76. CRmsDriveClass::GetClassID(
  77. OUT CLSID *pClsid
  78. )
  79. /*++
  80. Implements:
  81. IPersist::GetClassId
  82. --*/
  83. {
  84. HRESULT hr = S_OK;
  85. WsbTraceIn(OLESTR("CRmsDriveClass::GetClassID"), OLESTR(""));
  86. try {
  87. WsbAssert(0 != pClsid, E_POINTER);
  88. *pClsid = CLSID_CRmsDriveClass;
  89. } WsbCatch(hr);
  90. WsbTraceOut(OLESTR("CRmsDriveClass::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  91. return(hr);
  92. }
  93. STDMETHODIMP
  94. CRmsDriveClass::GetSizeMax(
  95. OUT ULARGE_INTEGER *pcbSize
  96. )
  97. /*++
  98. Implements:
  99. IPersistStream::GetSizeMax
  100. --*/
  101. {
  102. HRESULT hr = E_NOTIMPL;
  103. // ULONG nameLen;
  104. WsbTraceIn(OLESTR("CRmsDriveClass::GetSizeMax"), OLESTR(""));
  105. // try {
  106. // WsbAssert(0 != pcbSize, E_POINTER);
  107. // nameLen = SysStringByteLen(m_name);
  108. // // Get maximum size
  109. // pcbSize->QuadPart = WsbPersistSizeOf(GUID) + // m_objectId
  110. // WsbPersistSizeOf(LONG) + // length of m_name
  111. // nameLen + // m_name
  112. // WsbPersistSizeOf(LONG) + // m_type
  113. // WsbPersistSizeOf(LONG) + // m_capability
  114. // WsbPersistSizeOf(LONG) + // m_idleTime
  115. // WsbPersistSizeOf(LONG) + // m_mountWaitTime
  116. // WsbPersistSizeOf(LONG) + // m_mountLimit
  117. // WsbPersistSizeOf(LONG) + // m_queuedRequests
  118. // WsbPersistSizeOf(LONG) + // m_unloadPauseTime
  119. // WsbPersistSizeOf(LONG); // m_driveSelectionPolicy
  120. //// get m_pDrives length
  121. // } WsbCatch(hr);
  122. WsbTraceOut(OLESTR("CRmsDriveClass::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  123. return(hr);
  124. }
  125. STDMETHODIMP
  126. CRmsDriveClass::Load(
  127. IN IStream *pStream
  128. )
  129. /*++
  130. Implements:
  131. IPersistStream::Load
  132. --*/
  133. {
  134. HRESULT hr = S_OK;
  135. ULONG ulBytes = 0;
  136. WsbTraceIn(OLESTR("CRmsDriveClass::Load"), OLESTR(""));
  137. try {
  138. ULONG temp;
  139. WsbAssert(0 != pStream, E_POINTER);
  140. WsbAffirmHr(CRmsComObject::Load(pStream));
  141. // Read value
  142. WsbAffirmHr(WsbLoadFromStream(pStream, &m_objectId));
  143. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  144. m_type = (RmsMedia)temp;
  145. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  146. m_capability = (RmsMode)temp;
  147. WsbAffirmHr(WsbLoadFromStream(pStream, &m_idleTime));
  148. WsbAffirmHr(WsbLoadFromStream(pStream, &m_mountWaitTime));
  149. WsbAffirmHr(WsbLoadFromStream(pStream, &m_mountLimit));
  150. WsbAffirmHr(WsbLoadFromStream(pStream, &m_queuedRequests));
  151. WsbAffirmHr(WsbLoadFromStream(pStream, &m_unloadPauseTime));
  152. WsbAffirmHr(WsbLoadFromStream(pStream, &temp));
  153. m_driveSelectionPolicy = (RmsDriveSelect)temp;
  154. // do load of m_pDrives
  155. } WsbCatch(hr);
  156. WsbTraceOut(OLESTR("CRmsDriveClass::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  157. return(hr);
  158. }
  159. STDMETHODIMP
  160. CRmsDriveClass::Save(
  161. IN IStream *pStream,
  162. IN BOOL clearDirty
  163. )
  164. /*++
  165. Implements:
  166. IPersistStream::Save
  167. --*/
  168. {
  169. HRESULT hr = S_OK;
  170. ULONG ulBytes = 0;
  171. WsbTraceIn(OLESTR("CRmsDriveClass::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  172. try {
  173. WsbAssert(0 != pStream, E_POINTER);
  174. WsbAffirmHr(CRmsComObject::Save(pStream, clearDirty));
  175. // Write value
  176. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_type));
  177. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_capability));
  178. WsbAffirmHr(WsbSaveToStream(pStream, m_idleTime));
  179. WsbAffirmHr(WsbSaveToStream(pStream, m_mountWaitTime));
  180. WsbAffirmHr(WsbSaveToStream(pStream, m_mountLimit));
  181. WsbAffirmHr(WsbSaveToStream(pStream, m_queuedRequests));
  182. WsbAffirmHr(WsbSaveToStream(pStream, m_unloadPauseTime));
  183. WsbAffirmHr(WsbSaveToStream(pStream, (ULONG) m_driveSelectionPolicy));
  184. // do load of m_pDrives
  185. // Do we need to clear the dirty bit?
  186. if (clearDirty) {
  187. m_isDirty = FALSE;
  188. }
  189. } WsbCatch(hr);
  190. WsbTraceOut(OLESTR("CRmsDriveClass::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  191. return(hr);
  192. }
  193. STDMETHODIMP
  194. CRmsDriveClass::Test(
  195. OUT USHORT *pPassed,
  196. OUT USHORT *pFailed
  197. )
  198. /*++
  199. Implements:
  200. IWsbTestable::Test
  201. --*/
  202. {
  203. HRESULT hr = S_OK;
  204. CComPtr<IRmsDriveClass> pDriveClass1;
  205. CComPtr<IRmsDriveClass> pDriveClass2;
  206. CComPtr<IPersistFile> pFile1;
  207. CComPtr<IPersistFile> pFile2;
  208. LONG i;
  209. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  210. CWsbBstrPtr bstrVal2 = OLESTR("A5A5A5");
  211. CWsbBstrPtr bstrWork1;
  212. CWsbBstrPtr bstrWork2;
  213. LONG longWork1;
  214. LONG longWork2;
  215. LONG mediaTable [RMSMAXMEDIATYPES] = { RmsMediaUnknown,
  216. RmsMedia8mm,
  217. RmsMedia4mm,
  218. RmsMediaDLT,
  219. RmsMediaOptical,
  220. RmsMediaMO35,
  221. RmsMediaWORM,
  222. RmsMediaCDR,
  223. RmsMediaDVD,
  224. RmsMediaDisk,
  225. RmsMediaFixed,
  226. RmsMediaTape };
  227. WsbTraceIn(OLESTR("CRmsDriveClass::Test"), OLESTR(""));
  228. try {
  229. // Get the DriveClass interface.
  230. hr = S_OK;
  231. try {
  232. WsbAssertHr(((IUnknown*) (IRmsDriveClass*) this)->QueryInterface(IID_IRmsDriveClass, (void**) &pDriveClass1));
  233. // Test SetName & GetName interface
  234. bstrWork1 = bstrVal1;
  235. SetName(bstrWork1);
  236. GetName(&bstrWork2);
  237. if (bstrWork1 == bstrWork2){
  238. (*pPassed)++;
  239. } else {
  240. (*pFailed)++;
  241. }
  242. // Test SetType & GetType
  243. for (i = RmsMediaUnknown; i < RMSMAXMEDIATYPES; i++){
  244. longWork1 = mediaTable[i];
  245. SetType (longWork1);
  246. GetType (&longWork2);
  247. if (longWork1 == longWork2){
  248. (*pPassed)++;
  249. } else {
  250. (*pFailed)++;
  251. }
  252. }
  253. // Test SetCapability & GetCapability
  254. for (i = RmsModeUnknown; i < RmsModeWriteOnly; i++){
  255. longWork1 = i;
  256. SetCapability (longWork1);
  257. GetCapability (&longWork2);
  258. if (longWork1 == longWork2){
  259. (*pPassed)++;
  260. } else {
  261. (*pFailed)++;
  262. }
  263. }
  264. // Test SetIdleTime & GetIdleTime
  265. longWork1 = 99;
  266. SetIdleTime(longWork1);
  267. GetIdleTime(&longWork2);
  268. if(longWork1 == longWork2){
  269. (*pPassed)++;
  270. } else {
  271. (*pFailed)++;
  272. }
  273. // Test SetMountWaitTime & GetMountWaitTime
  274. longWork1 = 99;
  275. SetMountWaitTime(longWork1);
  276. GetMountWaitTime(&longWork2);
  277. if(longWork1 == longWork2){
  278. (*pPassed)++;
  279. } else {
  280. (*pFailed)++;
  281. }
  282. // Test SetMountLimit & GetMountLimit
  283. longWork1 = 99;
  284. SetMountLimit(longWork1);
  285. GetMountLimit(&longWork2);
  286. if(longWork1 == longWork2){
  287. (*pPassed)++;
  288. } else {
  289. (*pFailed)++;
  290. }
  291. // Test SetQueuedRequests & GetQueuedRequests
  292. longWork1 = 99;
  293. SetQueuedRequests(longWork1);
  294. GetQueuedRequests(&longWork2);
  295. if(longWork1 == longWork2){
  296. (*pPassed)++;
  297. } else {
  298. (*pFailed)++;
  299. }
  300. // Test SetUnloadPauseTime & GetUnloadPauseTime
  301. longWork1 = 99;
  302. SetUnloadPauseTime(longWork1);
  303. GetUnloadPauseTime(&longWork2);
  304. if(longWork1 == longWork2){
  305. (*pPassed)++;
  306. } else {
  307. (*pFailed)++;
  308. }
  309. // Test SetDriveSelectionPolicy & GetDriveSelectionPolicy
  310. longWork1 = 99;
  311. SetDriveSelectionPolicy(longWork1);
  312. GetDriveSelectionPolicy(&longWork2);
  313. if(longWork1 == longWork2){
  314. (*pPassed)++;
  315. } else {
  316. (*pFailed)++;
  317. }
  318. } WsbCatch(hr);
  319. // Tally up the results
  320. hr = S_OK;
  321. if (*pFailed) {
  322. hr = S_FALSE;
  323. }
  324. } WsbCatch(hr);
  325. WsbTraceOut(OLESTR("CRmsDriveClass::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  326. return(hr);
  327. }
  328. STDMETHODIMP
  329. CRmsDriveClass::GetDriveClassId(
  330. GUID *pDriveClassId
  331. )
  332. /*++
  333. Implements:
  334. IRmsDriveClass::GetDriveClassId
  335. --*/
  336. {
  337. *pDriveClassId = m_objectId;
  338. return S_OK;
  339. }
  340. STDMETHODIMP
  341. CRmsDriveClass::GetName(
  342. BSTR *pName
  343. )
  344. /*++
  345. Implements:
  346. IRmsDriveClass::GetName
  347. --*/
  348. {
  349. WsbAssertPointer (pName);
  350. m_Name. CopyToBstr (pName);
  351. return S_OK;
  352. }
  353. STDMETHODIMP
  354. CRmsDriveClass::SetName(
  355. BSTR name
  356. )
  357. /*++
  358. Implements:
  359. IRmsDriveClass::SetName
  360. --*/
  361. {
  362. m_Name = name;
  363. m_isDirty = TRUE;
  364. return S_OK;
  365. }
  366. STDMETHODIMP
  367. CRmsDriveClass::GetType(
  368. LONG *pType
  369. )
  370. /*++
  371. Implements:
  372. IRmsDriveClass::GetType
  373. --*/
  374. {
  375. *pType = (LONG) m_type;
  376. return S_OK;
  377. }
  378. STDMETHODIMP
  379. CRmsDriveClass::SetType(
  380. LONG type
  381. )
  382. /*++
  383. Implements:
  384. IRmsDriveClass::SetType
  385. --*/
  386. {
  387. m_type = (RmsMedia) type;
  388. m_isDirty = TRUE;
  389. return S_OK;
  390. }
  391. STDMETHODIMP
  392. CRmsDriveClass::GetCapability(
  393. LONG *pCapability
  394. )
  395. /*++
  396. Implements:
  397. IRmsDriveClass::GetCapability
  398. --*/
  399. {
  400. *pCapability = (LONG) m_capability;
  401. return S_OK;
  402. }
  403. STDMETHODIMP
  404. CRmsDriveClass::SetCapability(
  405. LONG capability
  406. )
  407. /*++
  408. Implements:
  409. IRmsDriveClass::SetCapability
  410. --*/
  411. {
  412. m_capability = (RmsMode) capability;
  413. m_isDirty = TRUE;
  414. return S_OK;
  415. }
  416. STDMETHODIMP
  417. CRmsDriveClass::GetIdleTime(
  418. LONG *pTime
  419. )
  420. /*++
  421. Implements:
  422. IRmsDriveClass::GetIdleTime
  423. --*/
  424. {
  425. *pTime = m_idleTime;
  426. return S_OK;
  427. }
  428. STDMETHODIMP
  429. CRmsDriveClass::SetIdleTime(
  430. LONG time
  431. )
  432. /*++
  433. Implements:
  434. IRmsDriveClass::SetIdleTime
  435. --*/
  436. {
  437. m_idleTime = time;
  438. m_isDirty = TRUE;
  439. return S_OK;
  440. }
  441. STDMETHODIMP
  442. CRmsDriveClass::GetMountWaitTime(
  443. LONG *pTime
  444. )
  445. /*++
  446. Implements:
  447. IRmsDriveClass::GetMountWaittime
  448. --*/
  449. {
  450. *pTime = m_mountWaitTime;
  451. return S_OK;
  452. }
  453. STDMETHODIMP
  454. CRmsDriveClass::SetMountWaitTime(
  455. LONG time
  456. )
  457. /*++
  458. Implements:
  459. IRmsDriveClass::SetMountWaittime
  460. --*/
  461. {
  462. m_mountWaitTime = time;
  463. m_isDirty = TRUE;
  464. return S_OK;
  465. }
  466. STDMETHODIMP
  467. CRmsDriveClass::GetMountLimit(
  468. LONG *pLim
  469. )
  470. /*++
  471. Implements:
  472. IRmsDriveClass::GetMountLimit
  473. --*/
  474. {
  475. *pLim = m_mountLimit;
  476. return S_OK;
  477. }
  478. STDMETHODIMP
  479. CRmsDriveClass::SetMountLimit(
  480. LONG lim
  481. )
  482. /*++
  483. Implements:
  484. IRmsDriveClass::SetMountLimit
  485. --*/
  486. {
  487. m_mountLimit = lim;
  488. m_isDirty = TRUE;
  489. return S_OK;
  490. }
  491. STDMETHODIMP
  492. CRmsDriveClass::GetQueuedRequests(
  493. LONG *pReqs
  494. )
  495. /*++
  496. Implements:
  497. IRmsDriveClass::GetQueuedRequests
  498. --*/
  499. {
  500. *pReqs = m_queuedRequests;
  501. return S_OK;
  502. }
  503. STDMETHODIMP
  504. CRmsDriveClass::SetQueuedRequests(
  505. LONG reqs
  506. )
  507. /*++
  508. Implements:
  509. IRmsDriveClass::SetQueuedRequests
  510. --*/
  511. {
  512. m_queuedRequests = reqs;
  513. m_isDirty = TRUE;
  514. return S_OK;
  515. }
  516. STDMETHODIMP
  517. CRmsDriveClass::GetUnloadPauseTime(
  518. LONG *pTime
  519. )
  520. /*++
  521. Implements:
  522. IRmsDriveClass::GetUnloadPauseTime
  523. --*/
  524. {
  525. *pTime = m_unloadPauseTime;
  526. return S_OK;
  527. }
  528. STDMETHODIMP
  529. CRmsDriveClass::SetUnloadPauseTime(
  530. LONG time
  531. )
  532. /*++
  533. Implements:
  534. IRmsDriveClass::SetUnloadPauseTime
  535. --*/
  536. {
  537. m_unloadPauseTime = time;
  538. m_isDirty = TRUE;
  539. return S_OK;
  540. }
  541. STDMETHODIMP
  542. CRmsDriveClass::GetDriveSelectionPolicy(
  543. LONG *pPolicy
  544. )
  545. /*++
  546. Implements:
  547. IRmsDriveClass::GetDriveSelectionPolicy
  548. --*/
  549. {
  550. *pPolicy = (LONG) m_driveSelectionPolicy;
  551. return S_OK;
  552. }
  553. STDMETHODIMP
  554. CRmsDriveClass::SetDriveSelectionPolicy(
  555. LONG policy
  556. )
  557. /*++
  558. Implements:
  559. IRmsDriveClass::SetDriveSelectionPolicy
  560. --*/
  561. {
  562. m_driveSelectionPolicy = (RmsDriveSelect) policy;
  563. m_isDirty = TRUE;
  564. return S_OK;
  565. }
  566. STDMETHODIMP
  567. CRmsDriveClass::GetDrives(
  568. IWsbIndexedCollection** /*ptr*/
  569. )
  570. /*++
  571. Implements:
  572. IRmsDriveClass::GetDrives
  573. --*/
  574. {
  575. return E_NOTIMPL;
  576. }