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.

579 lines
10 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsIPort.cpp
  5. Abstract:
  6. Implementation of CRmsIEPort
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsIPort.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //
  15. STDMETHODIMP
  16. CRmsIEPort::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("CRmsIEPort::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. CComQIPtr<IRmsIEPort, &IID_IRmsIEPort> pIEPort = pCollectable;
  32. WsbAssertPointer( pIEPort );
  33. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  34. WsbAssertPointer( pObject );
  35. switch ( m_findBy ) {
  36. case RmsFindByDescription:
  37. {
  38. CWsbBstrPtr description;
  39. // Get description to check
  40. WsbAffirmHr( pIEPort->GetDescription( &description ) );
  41. // Compare the names
  42. result = (SHORT)wcscmp( m_description, description );
  43. hr = ( 0 == result ) ? S_OK : S_FALSE;
  44. }
  45. break;
  46. case RmsFindByElementNumber:
  47. case RmsFindByMediaSupported:
  48. // Do CompareTo for changer element
  49. hr = CRmsChangerElement::CompareTo( pCollectable, &result );
  50. break;
  51. default:
  52. // Do CompareTo for object
  53. hr = CRmsComObject::CompareTo( pCollectable, &result );
  54. break;
  55. }
  56. }
  57. WsbCatch( hr );
  58. if ( SUCCEEDED(hr) && (0 != pResult) ){
  59. *pResult = result;
  60. }
  61. WsbTraceOut( OLESTR("CRmsIEPort::CompareTo"),
  62. OLESTR("hr = <%ls>, result = <%ls>"),
  63. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  64. return hr;
  65. }
  66. HRESULT
  67. CRmsIEPort::FinalConstruct(
  68. void
  69. )
  70. /*++
  71. Implements:
  72. CComObjectRoot::FinalConstruct
  73. --*/
  74. {
  75. HRESULT hr = S_OK;
  76. try {
  77. WsbAssertHr(CWsbObject::FinalConstruct());
  78. // Initialize
  79. m_description = RMS_UNDEFINED_STRING;
  80. m_isImport = FALSE;
  81. m_isExport = FALSE;
  82. m_waitTime = 0;
  83. } WsbCatch(hr);
  84. return(hr);
  85. }
  86. STDMETHODIMP
  87. CRmsIEPort::GetClassID(
  88. OUT CLSID* pClsid
  89. )
  90. /*++
  91. Implements:
  92. IPersist::GetClassID
  93. --*/
  94. {
  95. HRESULT hr = S_OK;
  96. WsbTraceIn(OLESTR("CRmsIEPort::GetClassID"), OLESTR(""));
  97. try {
  98. WsbAssert(0 != pClsid, E_POINTER);
  99. *pClsid = CLSID_CRmsIEPort;
  100. } WsbCatch(hr);
  101. WsbTraceOut(OLESTR("CRmsIEPort::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  102. return(hr);
  103. }
  104. STDMETHODIMP
  105. CRmsIEPort::GetSizeMax(
  106. OUT ULARGE_INTEGER* pcbSize
  107. )
  108. /*++
  109. Implements:
  110. IPersistStream::GetSizeMax
  111. --*/
  112. {
  113. HRESULT hr = E_NOTIMPL;
  114. // ULONG descriptionLen;
  115. WsbTraceIn(OLESTR("CRmsIEPort::GetSizeMax"), OLESTR(""));
  116. // try {
  117. // WsbAssert(0 != pcbSize, E_POINTER);
  118. // descriptionLen = SysStringByteLen(m_description);
  119. // // get max size
  120. // pcbSize->QuadPart = WsbPersistSizeOf(LONG) + // length of m_description
  121. // descriptionLen + // m_description
  122. // WsbPersistSizeOf(BOOL) + // m_isImport
  123. // WsbPersistSizeOf(BOOL) + // m_isExport
  124. // WsbPersistSizeOf(LONG); // m_waitTime
  125. // } WsbCatch(hr);
  126. WsbTraceOut(OLESTR("CRmsIEPort::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  127. return(hr);
  128. }
  129. STDMETHODIMP
  130. CRmsIEPort::Load(
  131. IN IStream* pStream
  132. )
  133. /*++
  134. Implements:
  135. IPersistStream::Load
  136. --*/
  137. {
  138. HRESULT hr = S_OK;
  139. ULONG ulBytes = 0;
  140. WsbTraceIn(OLESTR("CRmsIEPort::Load"), OLESTR(""));
  141. try {
  142. WsbAssert(0 != pStream, E_POINTER);
  143. WsbAffirmHr(CRmsChangerElement::Load(pStream));
  144. // Read value
  145. WsbAffirmHr(WsbBstrFromStream(pStream, &m_description));
  146. WsbAffirmHr(WsbLoadFromStream(pStream, &m_isImport));
  147. WsbAffirmHr(WsbLoadFromStream(pStream, &m_isExport));
  148. WsbAffirmHr(WsbLoadFromStream(pStream, &m_waitTime));
  149. } WsbCatch(hr);
  150. WsbTraceOut(OLESTR("CRmsIEPort::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  151. return(hr);
  152. }
  153. STDMETHODIMP
  154. CRmsIEPort::Save(
  155. IN IStream* pStream,
  156. IN BOOL clearDirty
  157. )
  158. /*++
  159. Implements:
  160. IPersistStream::Save
  161. --*/
  162. {
  163. HRESULT hr = S_OK;
  164. ULONG ulBytes = 0;
  165. WsbTraceIn(OLESTR("CRmsIEPort::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  166. try {
  167. WsbAssert(0 != pStream, E_POINTER);
  168. WsbAffirmHr(CRmsChangerElement::Save(pStream, clearDirty));
  169. // Write value
  170. WsbAffirmHr(WsbBstrToStream(pStream, m_description));
  171. WsbAffirmHr(WsbSaveToStream(pStream, m_isImport));
  172. WsbAffirmHr(WsbSaveToStream(pStream, m_isExport));
  173. WsbAffirmHr(WsbSaveToStream(pStream, m_waitTime));
  174. // Do we need to clear the dirty bit?
  175. if (clearDirty) {
  176. m_isDirty = FALSE;
  177. }
  178. } WsbCatch(hr);
  179. WsbTraceOut(OLESTR("CRmsIEPort::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  180. return(hr);
  181. }
  182. STDMETHODIMP
  183. CRmsIEPort::Test(
  184. OUT USHORT *pPassed,
  185. OUT USHORT *pFailed
  186. )
  187. /*++
  188. Implements:
  189. IWsbTestable::Test
  190. --*/
  191. {
  192. HRESULT hr = S_OK;
  193. CComPtr<IRmsIEPort> pIEPort1;
  194. CComPtr<IRmsIEPort> pIEPort2;
  195. CComPtr<IPersistFile> pFile1;
  196. CComPtr<IPersistFile> pFile2;
  197. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  198. CWsbBstrPtr bstrWork1;
  199. CWsbBstrPtr bstrWork2;
  200. LONG longWork1;
  201. LONG longWork2;
  202. WsbTraceIn(OLESTR("CRmsIEPort::Test"), OLESTR(""));
  203. try {
  204. // Get the IEPort interface.
  205. hr = S_OK;
  206. try {
  207. WsbAssertHr(((IUnknown*) (IRmsIEPort*) this)->QueryInterface(IID_IRmsIEPort, (void**) &pIEPort1));
  208. // Test SetDescription & GetDescription interface
  209. bstrWork1 = bstrVal1;
  210. SetDescription(bstrWork1);
  211. GetDescription(&bstrWork2);
  212. if (bstrWork1 == bstrWork2){
  213. (*pPassed)++;
  214. } else {
  215. (*pFailed)++;
  216. }
  217. // Test SetIsImport & IsImport to TRUE
  218. hr = S_OK;
  219. try{
  220. WsbAffirmHr(SetIsImport (TRUE));
  221. WsbAffirmHr(IsImport ());
  222. } WsbCatch (hr);
  223. if (hr == S_OK){
  224. (*pPassed)++;
  225. } else {
  226. (*pFailed)++;
  227. }
  228. // Test SetIsImport & IsImport to FALSE
  229. hr = S_OK;
  230. try{
  231. WsbAffirmHr(SetIsImport (FALSE));
  232. WsbAffirmHr(IsImport ());
  233. } WsbCatch (hr);
  234. if (hr == S_OK){
  235. (*pFailed)++;
  236. } else {
  237. (*pPassed)++;
  238. }
  239. // Test SetIsExport & IsExport to TRUE
  240. hr = S_OK;
  241. try{
  242. WsbAffirmHr(SetIsExport (TRUE));
  243. WsbAffirmHr(IsExport ());
  244. } WsbCatch (hr);
  245. if (hr == S_OK){
  246. (*pPassed)++;
  247. } else {
  248. (*pFailed)++;
  249. }
  250. // Test SetIsExport & IsExport to FALSE
  251. hr = S_OK;
  252. try{
  253. WsbAffirmHr(SetIsExport (FALSE));
  254. WsbAffirmHr(IsExport ());
  255. } WsbCatch (hr);
  256. if (hr == S_OK){
  257. (*pFailed)++;
  258. } else {
  259. (*pPassed)++;
  260. }
  261. // Test SetWaitTime & GetWaitTime
  262. longWork1 = 99;
  263. SetWaitTime(longWork1);
  264. GetWaitTime(&longWork2);
  265. if(longWork1 == longWork2){
  266. (*pPassed)++;
  267. } else {
  268. (*pFailed)++;
  269. }
  270. } WsbCatch(hr);
  271. // Tally up the results
  272. hr = S_OK;
  273. if (*pFailed) {
  274. hr = S_FALSE;
  275. }
  276. } WsbCatch(hr);
  277. WsbTraceOut(OLESTR("CRmsIEPort::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  278. return(hr);
  279. }
  280. STDMETHODIMP
  281. CRmsIEPort::GetDescription(
  282. BSTR *pDesc
  283. )
  284. /*++
  285. Implements:
  286. IRmsIEPort::GetDescription
  287. --*/
  288. {
  289. WsbAssertPointer (pDesc);
  290. m_description. CopyToBstr (pDesc);
  291. return S_OK;
  292. }
  293. STDMETHODIMP
  294. CRmsIEPort::SetDescription(
  295. BSTR desc
  296. )
  297. /*++
  298. Implements:
  299. IRmsIEPort::SetDescription
  300. --*/
  301. {
  302. m_description = desc;
  303. m_isDirty = TRUE;
  304. return S_OK;
  305. }
  306. STDMETHODIMP
  307. CRmsIEPort::SetIsImport(
  308. BOOL flag
  309. )
  310. /*++
  311. Implements:
  312. IRmsIEPort::SetIsImport
  313. --*/
  314. {
  315. m_isImport = flag;
  316. m_isDirty = TRUE;
  317. return S_OK;
  318. }
  319. STDMETHODIMP
  320. CRmsIEPort::IsImport(
  321. void
  322. )
  323. /*++
  324. Implements:
  325. IRmsIEPort::IsImport
  326. --*/
  327. {
  328. HRESULT hr = S_FALSE;
  329. if (m_isImport){
  330. hr = S_OK;
  331. }
  332. return (hr);
  333. }
  334. STDMETHODIMP
  335. CRmsIEPort::SetIsExport(
  336. BOOL flag
  337. )
  338. /*++
  339. Implements:
  340. IRmsIEPort::SetIsExport
  341. --*/
  342. {
  343. m_isExport = flag;
  344. m_isDirty = TRUE;
  345. return S_OK;
  346. }
  347. STDMETHODIMP
  348. CRmsIEPort::IsExport(
  349. void
  350. )
  351. /*++
  352. Implements:
  353. IRmsIEPort::IsExport
  354. --*/
  355. {
  356. HRESULT hr = S_FALSE;
  357. if (m_isExport){
  358. hr = S_OK;
  359. }
  360. return (hr);
  361. }
  362. STDMETHODIMP
  363. CRmsIEPort::GetWaitTime(
  364. LONG *pTime
  365. )
  366. /*++
  367. Implements:
  368. IRmsIEPort::GetWaitTime
  369. --*/
  370. {
  371. *pTime = m_waitTime;
  372. return S_OK;
  373. }
  374. STDMETHODIMP
  375. CRmsIEPort::SetWaitTime(
  376. LONG time
  377. )
  378. /*++
  379. Implements:
  380. IRmsIEPort::SetWaitTime
  381. --*/
  382. {
  383. m_waitTime = time;
  384. m_isDirty = TRUE;
  385. return S_OK;
  386. }