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.

638 lines
11 KiB

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