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.

611 lines
21 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: validate.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 17 July, 2000
  10. *
  11. * DESCRIPTION:
  12. *
  13. *******************************************************************************/
  14. #include "pch.h"
  15. extern HINSTANCE g_hInst; // used for WIAS_LOGPROC macro
  16. /**************************************************************************\
  17. * ValidateDataTransferContext
  18. *
  19. * Checks the data transfer context to ensure it's valid.
  20. *
  21. * Arguments:
  22. *
  23. * pDataTransferContext - Pointer the data transfer context.
  24. *
  25. * Return Value:
  26. *
  27. * Status
  28. *
  29. * History:
  30. *
  31. * 7/18/2000 Original Version
  32. *
  33. \**************************************************************************/
  34. HRESULT CWIAScannerDevice::ValidateDataTransferContext(
  35. PMINIDRV_TRANSFER_CONTEXT pDataTransferContext)
  36. {
  37. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  38. WIALOG_NO_RESOURCE_ID,
  39. WIALOG_LEVEL3,
  40. "::ValidateDataTransferContext");
  41. if (pDataTransferContext->lSize != sizeof(MINIDRV_TRANSFER_CONTEXT)) {
  42. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ValidateDataTransferContext, invalid data transfer context"));
  43. return E_INVALIDARG;;
  44. }
  45. return S_OK;
  46. }
  47. /**************************************************************************\
  48. * UpdateValidDepth
  49. *
  50. * Helper that updates the valid value for depth based on the data type.
  51. *
  52. * Arguments:
  53. *
  54. * pWiasContext - a pointer to the WiaItem context
  55. * lDataType - the value of the DataType property.
  56. * lDepth - the address of the variable where the Depth's new value
  57. * will be returned.
  58. *
  59. * Return Value:
  60. *
  61. * Status - S_OK if successful
  62. * E_INVALIDARG if lDataType is unknown
  63. * Errors are those returned by wiasReadPropLong,
  64. * and wiasWritePropLong.
  65. *
  66. * History:
  67. *
  68. * 7/18/2000 Original Version
  69. *
  70. \**************************************************************************/
  71. HRESULT CWIAScannerDevice::UpdateValidDepth(
  72. BYTE *pWiasContext,
  73. LONG lDataType,
  74. LONG *lDepth)
  75. {
  76. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  77. WIALOG_NO_RESOURCE_ID,
  78. WIALOG_LEVEL3,
  79. "CWIAScannerDevice::UpdateValidDepth");
  80. HRESULT hr = S_OK;
  81. LONG pValidDepth[1];
  82. switch (lDataType) {
  83. case WIA_DATA_THRESHOLD:
  84. pValidDepth[0] = 1;
  85. break;
  86. case WIA_DATA_GRAYSCALE:
  87. pValidDepth[0] = 8;
  88. break;
  89. case WIA_DATA_COLOR:
  90. pValidDepth[0] = 24;
  91. break;
  92. default:
  93. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("UpdateValidDepth, unknown data type"));
  94. return E_INVALIDARG;
  95. }
  96. if (lDepth) {
  97. *lDepth = pValidDepth[0];
  98. }
  99. return hr;
  100. }
  101. /**************************************************************************\
  102. * CheckDataType
  103. *
  104. * This helper method is called to check whether WIA_IPA_DATATYPE
  105. * property is changed. When this property changes, other dependant
  106. * properties and their valid values must also be changed.
  107. *
  108. * Arguments:
  109. *
  110. * pWiasContext - a pointer to the item context whose properties have
  111. * changed.
  112. * pContext - a pointer to the property context (which indicates
  113. * which properties are being written).
  114. *
  115. * Return Value:
  116. *
  117. * Status
  118. *
  119. * History:
  120. *
  121. * 7/18/2000 Original Version
  122. *
  123. \**************************************************************************/
  124. HRESULT CWIAScannerDevice::CheckDataType(
  125. BYTE *pWiasContext,
  126. WIA_PROPERTY_CONTEXT *pContext)
  127. {
  128. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  129. WIALOG_NO_RESOURCE_ID,
  130. WIALOG_LEVEL3,
  131. "CWIAScannerDevice::CheckDataType");
  132. WIAS_CHANGED_VALUE_INFO cviDataType, cviDepth;
  133. HRESULT hr = S_OK;
  134. //
  135. // Call wiasGetChangedValue for DataType. It is checked first since it's
  136. // not dependant on any other property. All properties in this method
  137. // that follow are dependant properties of DataType.
  138. //
  139. // The call to wiasGetChangedValue specifies that validation should not be
  140. // skipped (since valid values for DataType never change). Also,
  141. // the address of a variable for the old value is NULL, since the old
  142. // value is not needed. The address of bDataTypeChanged is passed
  143. // so that dependant properties will know whether the DataType is being
  144. // changed or not. This is important since dependant properties may need
  145. // their valid values updated and may need to be folded to new valid
  146. // values.
  147. //
  148. hr = wiasGetChangedValueLong(pWiasContext,
  149. pContext,
  150. FALSE,
  151. WIA_IPA_DATATYPE,
  152. &cviDataType);
  153. if (FAILED(hr)) {
  154. return hr;
  155. }
  156. //
  157. // Call wiasGetChangedValue for Depth. Depth is a dependant property of
  158. // DataType whose valid value changes according to what the current
  159. // value of DataType is.
  160. //
  161. // The call to wiasGetChangedValue specifies that validation should only
  162. // be skipped if the DataType has changed. This is because the valid
  163. // values for Depth will change according to the new value for
  164. // DataType. The address of a variable for the old value is NULL, since
  165. // the old value is not needed. The address of bDepthChanged is passed
  166. // so that dependant properties will know whether the Depth is being
  167. // changed or not. This is important since dependant properties may need
  168. // their valid values updated and may need to be folded to new valid
  169. // values.
  170. //
  171. hr = wiasGetChangedValueLong(pWiasContext,
  172. pContext,
  173. cviDataType.bChanged,
  174. WIA_IPA_DEPTH,
  175. &cviDepth);
  176. if (FAILED(hr)) {
  177. return hr;
  178. }
  179. if (cviDataType.bChanged) {
  180. //
  181. // DataType changed so update valid value for Depth
  182. //
  183. hr = UpdateValidDepth(pWiasContext, cviDataType.Current.lVal, &cviDepth.Current.lVal);
  184. if (SUCCEEDED(hr)) {
  185. //
  186. // Check whether we must fold. Depth will only be folded if it
  187. // is not one of the properties that the app is changing.
  188. //
  189. if (!cviDepth.bChanged) {
  190. hr = wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, cviDepth.Current.lVal);
  191. }
  192. }
  193. }
  194. //
  195. // Update properties dependant on DataType and Depth.
  196. // Here, ChannelsPerPixel and BitsPerChannel are updated.
  197. //
  198. if (cviDataType.bChanged || cviDepth.bChanged) {
  199. if (SUCCEEDED(hr)) {
  200. #define NUM_PROPS_TO_SET 2
  201. PROPSPEC ps[NUM_PROPS_TO_SET] = {
  202. {PRSPEC_PROPID, WIA_IPA_CHANNELS_PER_PIXEL},
  203. {PRSPEC_PROPID, WIA_IPA_BITS_PER_CHANNEL}};
  204. PROPVARIANT pv[NUM_PROPS_TO_SET];
  205. for (LONG index = 0; index < NUM_PROPS_TO_SET; index++) {
  206. PropVariantInit(&pv[index]);
  207. pv[index].vt = VT_I4;
  208. }
  209. switch (cviDataType.Current.lVal) {
  210. case WIA_DATA_THRESHOLD:
  211. pv[0].lVal = 1;
  212. pv[1].lVal = 1;
  213. break;
  214. case WIA_DATA_GRAYSCALE:
  215. pv[0].lVal = 1;
  216. pv[1].lVal = 8;
  217. break;
  218. case WIA_DATA_COLOR:
  219. pv[0].lVal = 3;
  220. pv[1].lVal = 8;
  221. break;
  222. default:
  223. pv[0].lVal = 1;
  224. pv[1].lVal = 8;
  225. break;
  226. }
  227. hr = wiasWriteMultiple(pWiasContext, NUM_PROPS_TO_SET, ps, pv);
  228. }
  229. }
  230. return hr;
  231. }
  232. /**************************************************************************\
  233. * CheckIntent
  234. *
  235. * This helper method is called to make the relevant changes if the
  236. * Current Intent property changes.
  237. *
  238. * Arguments:
  239. *
  240. * pWiasContext - a pointer to the item context whose properties have
  241. * changed.
  242. * pContext - a pointer to the property context (which indicates
  243. * which properties are being written).
  244. *
  245. * Return Value:
  246. *
  247. * Status
  248. *
  249. * History:
  250. *
  251. * 7/18/2000 Original Version
  252. *
  253. \**************************************************************************/
  254. HRESULT CWIAScannerDevice::CheckIntent(
  255. BYTE *pWiasContext,
  256. WIA_PROPERTY_CONTEXT *pContext)
  257. {
  258. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  259. WIALOG_NO_RESOURCE_ID,
  260. WIALOG_LEVEL3,
  261. "CWIAScannerDevice::CheckIntent");
  262. HRESULT hr;
  263. WIAS_CHANGED_VALUE_INFO cviIntent;
  264. //
  265. // Call wiasGetChangedValue for CurrentIntent. CurrentIntent is checked first
  266. // since it's not dependant on any other property. All properties in
  267. // this method that follow are dependant properties of CurrentIntent.
  268. //
  269. // The call to wiasGetChangedValue specifies that validation should not be
  270. // skipped (since valid values for CurrentIntent never change). The
  271. // address of the old value is specified as NULL, since it is not used.
  272. // The address of bIntentChanged is passed so that dependant properties
  273. // will know whether the YResolution is being changed or not. This is
  274. // important since dependant properties will need their valid values
  275. // updated and may need to be folded to new valid values.
  276. //
  277. hr = wiasGetChangedValueLong(pWiasContext,
  278. pContext,
  279. FALSE,
  280. WIA_IPS_CUR_INTENT,
  281. &cviIntent);
  282. if (SUCCEEDED(hr)) {
  283. if (cviIntent.bChanged) {
  284. LONG lImageSizeIntent = (cviIntent.Current.lVal & WIA_INTENT_SIZE_MASK);
  285. LONG lImageTypeIntent = (cviIntent.Current.lVal & WIA_INTENT_IMAGE_TYPE_MASK);
  286. switch (lImageTypeIntent) {
  287. case WIA_INTENT_NONE:
  288. break;
  289. case WIA_INTENT_IMAGE_TYPE_GRAYSCALE:
  290. wiasWritePropLong(pWiasContext, WIA_IPA_DATATYPE, WIA_DATA_GRAYSCALE);
  291. UpdateValidDepth (pWiasContext, WIA_DATA_GRAYSCALE, NULL);
  292. wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, 8);
  293. break;
  294. case WIA_INTENT_IMAGE_TYPE_TEXT:
  295. wiasWritePropLong(pWiasContext, WIA_IPA_DATATYPE, WIA_DATA_THRESHOLD);
  296. UpdateValidDepth (pWiasContext, WIA_DATA_THRESHOLD, NULL);
  297. wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, 1);
  298. break;
  299. case WIA_INTENT_IMAGE_TYPE_COLOR:
  300. wiasWritePropLong(pWiasContext, WIA_IPA_DATATYPE, WIA_DATA_COLOR);
  301. UpdateValidDepth(pWiasContext, WIA_DATA_COLOR, NULL);
  302. wiasWritePropLong(pWiasContext, WIA_IPA_DEPTH, 24);
  303. break;
  304. default:
  305. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, unknown intent (TYPE) = %d",lImageTypeIntent));
  306. return E_INVALIDARG;
  307. }
  308. switch (lImageSizeIntent) {
  309. case WIA_INTENT_NONE:
  310. break;
  311. case WIA_INTENT_MINIMIZE_SIZE:
  312. case WIA_INTENT_MAXIMIZE_QUALITY:
  313. {
  314. //
  315. // Set the X and Y Resolutions.
  316. //
  317. wiasWritePropLong(pWiasContext, WIA_IPS_XRES, lImageSizeIntent & WIA_INTENT_MINIMIZE_SIZE ? 150 : 300);
  318. wiasWritePropLong(pWiasContext, WIA_IPS_YRES, lImageSizeIntent & WIA_INTENT_MINIMIZE_SIZE ? 150 : 300);
  319. //
  320. // The Resolutions and DataType were set, so update the property
  321. // context to indicate that they have changed.
  322. //
  323. wiasSetPropChanged(WIA_IPS_XRES, pContext, TRUE);
  324. wiasSetPropChanged(WIA_IPS_YRES, pContext, TRUE);
  325. wiasSetPropChanged(WIA_IPA_DATATYPE, pContext, TRUE);
  326. //
  327. // Reset any device item properties which may have changed due to validation.
  328. //
  329. //
  330. // update IPA_NUMBER_OF_LINES property
  331. //
  332. LONG lLength = 0;
  333. hr = wiasReadPropLong(pWiasContext, WIA_IPS_YEXTENT, &lLength, NULL, TRUE);
  334. if (SUCCEEDED(hr)) {
  335. hr = wiasWritePropLong(pWiasContext, WIA_IPA_NUMBER_OF_LINES, lLength);
  336. if (FAILED(hr)) {
  337. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not write WIA_IPA_NUMBER_OF_LINES"));
  338. return hr;
  339. }
  340. } else {
  341. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPS_YEXTENT"));
  342. return hr;
  343. }
  344. //
  345. // update IPA_PIXEL_PER_LINE property
  346. //
  347. LONG lWidth = 0;
  348. hr = wiasReadPropLong(pWiasContext, WIA_IPS_XEXTENT, &lWidth, NULL, TRUE);
  349. if (SUCCEEDED(hr)) {
  350. hr = wiasWritePropLong(pWiasContext, WIA_IPA_PIXELS_PER_LINE, lWidth);
  351. if (FAILED(hr)) {
  352. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not write WIA_IPA_PIXELS_PER_LINE"));
  353. return hr;
  354. }
  355. } else {
  356. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPS_XEXTENT"));
  357. return hr;
  358. }
  359. }
  360. break;
  361. default:
  362. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, unknown intent (SIZE) = %d",lImageSizeIntent));
  363. return E_INVALIDARG;
  364. }
  365. }
  366. } else {
  367. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, wiasGetChangedValue (intent) failed"));
  368. }
  369. return hr;
  370. }
  371. /**************************************************************************\
  372. * CheckPreferredFormat
  373. *
  374. * This helper method is called to make the relevant changes if the
  375. * Format property changes.
  376. *
  377. * Arguments:
  378. *
  379. * pWiasContext - a pointer to the item context whose properties have
  380. * changed.
  381. * pContext - a pointer to the property context (which indicates
  382. * which properties are being written).
  383. *
  384. * Return Value:
  385. *
  386. * Status
  387. *
  388. * History:
  389. *
  390. * 7/18/2000 Original Version
  391. *
  392. \**************************************************************************/
  393. HRESULT CWIAScannerDevice::CheckPreferredFormat(
  394. BYTE *pWiasContext,
  395. WIA_PROPERTY_CONTEXT *pContext)
  396. {
  397. HRESULT hr = S_OK;
  398. //
  399. // update WIA_IPA_PREFERRED_FORMAT property
  400. //
  401. GUID FormatGUID;
  402. hr = wiasReadPropGuid(pWiasContext, WIA_IPA_FORMAT, &FormatGUID, NULL, TRUE);
  403. if (SUCCEEDED(hr)) {
  404. hr = wiasWritePropGuid(pWiasContext, WIA_IPA_PREFERRED_FORMAT, FormatGUID);
  405. if (FAILED(hr)) {
  406. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckPreferredFormat, could not write WIA_IPA_PREFERRED_FORMAT"));
  407. return hr;
  408. }
  409. } else {
  410. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckIntent, could not read WIA_IPA_FORMAT"));
  411. }
  412. return hr;
  413. }
  414. /**************************************************************************\
  415. * CheckADFStatus
  416. *
  417. *
  418. * Arguments:
  419. *
  420. * pWiasContext - pointer to an Item.
  421. *
  422. * Return Value:
  423. *
  424. * Byte count.
  425. *
  426. * History:
  427. *
  428. * 7/18/2000 Original Version
  429. *
  430. \**************************************************************************/
  431. HRESULT CWIAScannerDevice::CheckADFStatus(BYTE *pWiasContext,
  432. WIA_PROPERTY_CONTEXT *pContext)
  433. {
  434. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  435. WIALOG_NO_RESOURCE_ID,
  436. WIALOG_LEVEL3,
  437. "CWIAScannerDevice::CheckADFStatus");
  438. if(!m_bADFAttached)
  439. return S_OK;
  440. HRESULT hr = S_OK;
  441. BYTE *pRootItemCtx = NULL;
  442. LONG lDocHandlingSelect = FLATBED;
  443. //
  444. // get root item
  445. //
  446. hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  447. if (SUCCEEDED(hr)) {
  448. //
  449. // read document handling select for validation
  450. //
  451. hr = wiasReadPropLong(pRootItemCtx,WIA_DPS_DOCUMENT_HANDLING_SELECT,&lDocHandlingSelect,NULL,FALSE);
  452. if (SUCCEEDED(hr)) {
  453. if (S_FALSE == hr) {
  454. lDocHandlingSelect = FLATBED; // default setting
  455. }
  456. if (lDocHandlingSelect & FEEDER) {
  457. // set to FEEDER, check hardware for status
  458. hr = m_pScanAPI->ADFAvailable();
  459. if (S_OK == hr) {
  460. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,FEED_READY);
  461. } else {
  462. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,PAPER_JAM);
  463. }
  464. } else if (lDocHandlingSelect & FLATBED) {
  465. // set to FLATBED
  466. hr = wiasWritePropLong(pWiasContext, WIA_DPS_DOCUMENT_HANDLING_STATUS,FLAT_READY);
  467. } else {
  468. // set to an invalid value
  469. hr = E_INVALIDARG;
  470. }
  471. } else {
  472. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckADFStatus, wiasReadPropLong (WIA_DPS_DOCUMENT_HANDLING_SELECT) Failed"));
  473. WIAS_LHRESULT(m_pIWiaLog,hr);
  474. }
  475. } else {
  476. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CheckADFStatus, wiasGetRootItem Failed"));
  477. WIAS_LHRESULT(m_pIWiaLog,hr);
  478. }
  479. return hr;
  480. }
  481. /**************************************************************************\
  482. * CheckPreview
  483. *
  484. *
  485. * Arguments:
  486. *
  487. * pWiasContext - pointer to an Item.
  488. *
  489. * Return Value:
  490. *
  491. * Byte count.
  492. *
  493. * History:
  494. *
  495. * 8/21/2000 Original Version
  496. *
  497. \**************************************************************************/
  498. HRESULT CWIAScannerDevice::CheckPreview(BYTE *pWiasContext,
  499. WIA_PROPERTY_CONTEXT *pContext)
  500. {
  501. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  502. WIALOG_NO_RESOURCE_ID,
  503. WIALOG_LEVEL3,
  504. "CWIAScannerDevice::CheckPreview");
  505. HRESULT hr = S_OK;
  506. BYTE *pRootItemCtx = NULL;
  507. LONG lPreview = 0;
  508. hr = wiasGetRootItem(pWiasContext, &pRootItemCtx);
  509. if (FAILED(hr)) {
  510. return E_FAIL;
  511. }
  512. hr = wiasReadPropLong(pRootItemCtx,
  513. WIA_DPS_PREVIEW,
  514. &lPreview,
  515. NULL,
  516. FALSE);
  517. if(hr == S_FALSE){
  518. // property does not exist...so return S_OK
  519. return S_OK;
  520. }
  521. if (SUCCEEDED(hr)) {
  522. switch (lPreview) {
  523. case WIA_FINAL_SCAN:
  524. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to WIA_FINAL_SCAN"));
  525. hr = S_OK;
  526. break;
  527. case WIA_PREVIEW_SCAN:
  528. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to WIA_PREVIEW_SCAN"));
  529. hr = S_OK;
  530. break;
  531. default:
  532. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("CheckPreview, Set to invalid argument (%d)",lPreview));
  533. hr = E_INVALIDARG;
  534. break;
  535. }
  536. }
  537. return hr;
  538. }