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.

349 lines
14 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT 2001, MICROSOFT CORP.
  4. *
  5. * TITLE: Root.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 15 Nov, 2000
  10. *
  11. * DESCRIPTION:
  12. * This file implements the helper methods for IWiaMiniDrv for the root item.
  13. *
  14. *******************************************************************************/
  15. #include "pch.h"
  16. /**************************************************************************\
  17. * BuildRootItemProperties
  18. *
  19. * Create the properties for the root item.
  20. *
  21. * Arguments:
  22. *
  23. * pWiasContext - WIA service context
  24. *
  25. \**************************************************************************/
  26. HRESULT
  27. CWiaCameraDevice::BuildRootItemProperties(
  28. BYTE *pWiasContext
  29. )
  30. {
  31. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  32. WIALOG_NO_RESOURCE_ID,
  33. WIALOG_LEVEL1,
  34. "CWiaCameraDevice::BuildRootItemProperties");
  35. HRESULT hr = S_OK;
  36. //
  37. // Create a WIA property list and allocate enough space for all
  38. // the properties created below
  39. //
  40. CWiauPropertyList RootProps;
  41. hr = RootProps.Init(50);
  42. if (FAILED(hr))
  43. {
  44. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildRootItemProperties, initializing property list failed"));
  45. return hr;
  46. }
  47. //
  48. // These are the WHQL required properties for cameras:
  49. //
  50. INT index;
  51. hr = RootProps.DefineProperty(&index, WIA_IPA_ACCESS_RIGHTS, WIA_IPA_ACCESS_RIGHTS_STR,
  52. WIA_PROP_READ, WIA_PROP_NONE);
  53. if (FAILED(hr)) goto failure;
  54. RootProps.SetCurrentValue(index, (LONG) WIA_ITEM_READ | WIA_ITEM_WRITE);
  55. hr = RootProps.DefineProperty(&index, WIA_DPA_FIRMWARE_VERSION, WIA_DPA_FIRMWARE_VERSION_STR,
  56. WIA_PROP_READ, WIA_PROP_NONE);
  57. if (FAILED(hr)) goto failure;
  58. RootProps.SetCurrentValue(index, m_DeviceInfo.FirmwareVersion);
  59. hr = RootProps.DefineProperty(&index, WIA_DPC_PICTURES_TAKEN, WIA_DPC_PICTURES_TAKEN_STR,
  60. WIA_PROP_READ, WIA_PROP_NONE);
  61. if (FAILED(hr)) goto failure;
  62. RootProps.SetCurrentValue(index, m_DeviceInfo.PicturesTaken);
  63. #ifdef COUNT_PIC_REMAINING
  64. hr = RootProps.DefineProperty(&index, WIA_DPC_PICTURES_REMAINING, WIA_DPC_PICTURES_REMAINING_STR,
  65. WIA_PROP_READ, WIA_PROP_NONE);
  66. if (FAILED(hr)) goto failure;
  67. RootProps.SetCurrentValue(index, m_DeviceInfo.PicturesRemaining);
  68. #endif
  69. //
  70. // These are WHQL optional properties
  71. //
  72. #if DEADCODE
  73. hr = RootProps.DefineProperty(&index, WIA_DPA_DEVICE_TIME, WIA_DPA_DEVICE_TIME_STR,
  74. WIA_PROP_RW, WIA_PROP_NONE);
  75. if (FAILED(hr)) goto failure;
  76. RootProps.SetCurrentValue(index, &m_DeviceInfo.Time);
  77. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_MODE, WIA_DPC_EXPOSURE_MODE_STR,
  78. WIA_PROP_RW, WIA_PROP_NONE);
  79. if (FAILED(hr)) goto failure;
  80. RootProps.SetCurrentValue(index, CameraStats.ExposureMode);
  81. FakeCamera_SetValidValues(index, pRootProperties);
  82. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_COMP, WIA_DPC_EXPOSURE_COMP_STR,
  83. WIA_PROP_RW, WIA_PROP_NONE);
  84. if (FAILED(hr)) goto failure;
  85. RootProps.SetCurrentValue(index, CameraStats.ExposureComp);
  86. FakeCamera_SetValidValues(index, pRootProperties);
  87. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_TIME, WIA_DPC_EXPOSURE_TIME_STR,
  88. WIA_PROP_RW, WIA_PROP_NONE);
  89. if (FAILED(hr)) goto failure;
  90. RootProps.SetCurrentValue(index, CameraStats.ExposureTime);
  91. hr = RootProps.DefineProperty(&index, WIA_DPC_FNUMBER, WIA_DPC_FNUMBER_STR,
  92. WIA_PROP_RW, WIA_PROP_NONE);
  93. if (FAILED(hr)) goto failure;
  94. RootProps.SetCurrentValue(index, CameraStats.FNumber);
  95. hr = RootProps.DefineProperty(&index, WIA_DPC_FLASH_MODE, WIA_DPC_FLASH_MODE_STR,
  96. WIA_PROP_RW, WIA_PROP_NONE);
  97. if (FAILED(hr)) goto failure;
  98. RootProps.SetCurrentValue(index, CameraStats.FlashMode);
  99. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_MODE, WIA_DPC_FOCUS_MODE_STR,
  100. WIA_PROP_RW, WIA_PROP_NONE);
  101. if (FAILED(hr)) goto failure;
  102. RootProps.SetCurrentValue(index, CameraStats.FocusMode);
  103. hr = RootProps.DefineProperty(&index, WIA_DPC_PAN_POSITION, WIA_DPC_PAN_POSITION_STR,
  104. WIA_PROP_RW, WIA_PROP_NONE);
  105. if (FAILED(hr)) goto failure;
  106. RootProps.SetCurrentValue(index, CameraStats.PanPosition);
  107. hr = RootProps.DefineProperty(&index, WIA_DPC_TILT_POSITION, WIA_DPC_TILT_POSITION_STR,
  108. WIA_PROP_RW, WIA_PROP_NONE);
  109. if (FAILED(hr)) goto failure;
  110. RootProps.SetCurrentValue(index, CameraStats.TiltPosition);
  111. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMER_MODE, WIA_DPC_TIMER_MODE_STR,
  112. WIA_PROP_RW, WIA_PROP_NONE);
  113. if (FAILED(hr)) goto failure;
  114. RootProps.SetCurrentValue(index, CameraStats.TimerMode);
  115. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMER_VALUE, WIA_DPC_TIMER_VALUE_STR,
  116. WIA_PROP_RW, WIA_PROP_NONE);
  117. if (FAILED(hr)) goto failure;
  118. RootProps.SetCurrentValue(index, CameraStats.TimerValue);
  119. hr = RootProps.DefineProperty(&index, WIA_DPC_POWER_MODE, WIA_DPC_POWER_MODE_STR,
  120. WIA_PROP_READ, WIA_PROP_NONE);
  121. if (FAILED(hr)) goto failure;
  122. RootProps.SetCurrentValue(index, CameraStats.PowerMode);
  123. hr = RootProps.DefineProperty(&index, WIA_DPC_BATTERY_STATUS, WIA_DPC_BATTERY_STATUS_STR,
  124. WIA_PROP_READ, WIA_PROP_NONE);
  125. if (FAILED(hr)) goto failure;
  126. RootProps.SetCurrentValue(index, CameraStats.BatteryStatus);
  127. hr = RootProps.DefineProperty(&index, WIA_DPC_THUMB_WIDTH, WIA_DPC_THUMB_WIDTH_STR,
  128. WIA_PROP_RW, WIA_PROP_NONE);
  129. if (FAILED(hr)) goto failure;
  130. RootProps.SetCurrentValue(index, CameraStats.ThumbWidth);
  131. hr = RootProps.DefineProperty(&index, WIA_DPC_THUMB_HEIGHT, WIA_DPC_THUMB_HEIGHT_STR,
  132. WIA_PROP_RW, WIA_PROP_NONE);
  133. if (FAILED(hr)) goto failure;
  134. RootProps.SetCurrentValue(index, CameraStats.ThumbHeight);
  135. hr = RootProps.DefineProperty(&index, WIA_DPC_PICT_WIDTH, WIA_DPC_PICT_WIDTH_STR,
  136. WIA_PROP_RW, WIA_PROP_NONE);
  137. if (FAILED(hr)) goto failure;
  138. RootProps.SetCurrentValue(index, CameraStats.PictWidth);
  139. hr = RootProps.DefineProperty(&index, WIA_DPC_PICT_HEIGHT, WIA_DPC_PICT_HEIGHT_STR,
  140. WIA_PROP_RW, WIA_PROP_NONE);
  141. if (FAILED(hr)) goto failure;
  142. RootProps.SetCurrentValue(index, CameraStats.PictHeight);
  143. hr = RootProps.DefineProperty(&index, WIA_DPC_COMPRESSION_SETTING, WIA_DPC_COMPRESSION_SETTING_STR,
  144. WIA_PROP_RW, WIA_PROP_NONE);
  145. if (FAILED(hr)) goto failure;
  146. RootProps.SetCurrentValue(index, CameraStats.CompressionSetting);
  147. hr = RootProps.DefineProperty(&index, WIA_DPC_TIMELAPSE_INTERVAL, WIA_DPC_TIMELAPSE_INTERVAL_STR,
  148. WIA_PROP_RW, WIA_PROP_NONE);
  149. if (FAILED(hr)) goto failure;
  150. RootProps.SetCurrentValue(index, CameraStats.TimelapseInterval);
  151. hr = RootProps.DefineProperty(&index, WIA_DPC_BURST_INTERVAL, WIA_DPC_BURST_INTERVAL_STR,
  152. WIA_PROP_RW, WIA_PROP_NONE);
  153. if (FAILED(hr)) goto failure;
  154. RootProps.SetCurrentValue(index, CameraStats.BurstInterval);
  155. hr = RootProps.DefineProperty(&index, WIA_DPC_BURST_NUMBER, WIA_DPC_BURST_NUMBER_STR,
  156. WIA_PROP_RW, WIA_PROP_NONE);
  157. if (FAILED(hr)) goto failure;
  158. RootProps.SetCurrentValue(index, CameraStats.BurstNumber);
  159. hr = RootProps.DefineProperty(&index, WIA_DPC_EFFECT_MODE, WIA_DPC_EFFECT_MODE_STR,
  160. WIA_PROP_RW, WIA_PROP_NONE);
  161. if (FAILED(hr)) goto failure;
  162. RootProps.SetCurrentValue(index, CameraStats.EffectMode);
  163. hr = RootProps.DefineProperty(&index, WIA_DPC_DIGITAL_ZOOM, WIA_DPC_DIGITAL_ZOOM_STR,
  164. WIA_PROP_RW, WIA_PROP_NONE);
  165. if (FAILED(hr)) goto failure;
  166. RootProps.SetCurrentValue(index, CameraStats.DigitalZoom);
  167. hr = RootProps.DefineProperty(&index, WIA_DPC_SHARPNESS, WIA_DPC_SHARPNESS_STR,
  168. WIA_PROP_RW, WIA_PROP_NONE);
  169. if (FAILED(hr)) goto failure;
  170. RootProps.SetCurrentValue(index, CameraStats.Sharpness);
  171. hr = RootProps.DefineProperty(&index, WIA_DPC_CONTRAST, WIA_DPC_CONTRAST_STR,
  172. WIA_PROP_RW, WIA_PROP_NONE);
  173. if (FAILED(hr)) goto failure;
  174. RootProps.SetCurrentValue(index, CameraStats.Constrast);
  175. hr = RootProps.DefineProperty(&index, WIA_DPC_CAPTURE_MODE, WIA_DPC_CAPTURE_MODE_STR,
  176. WIA_PROP_RW, WIA_PROP_NONE);
  177. if (FAILED(hr)) goto failure;
  178. RootProps.SetCurrentValue(index, CameraStats.CaptureMode);
  179. hr = RootProps.DefineProperty(&index, WIA_DPC_CAPTURE_DELAY, WIA_DPC_CAPTURE_DELAY_STR,
  180. WIA_PROP_RW, WIA_PROP_NONE);
  181. if (FAILED(hr)) goto failure;
  182. RootProps.SetCurrentValue(index, CameraStats.CaptureDelay);
  183. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_INDEX, WIA_DPC_EXPOSURE_INDEX_STR,
  184. WIA_PROP_RW, WIA_PROP_NONE);
  185. if (FAILED(hr)) goto failure;
  186. RootProps.SetCurrentValue(index, CameraStats.ExposureIndex);
  187. hr = RootProps.DefineProperty(&index, WIA_DPC_EXPOSURE_METERING_MODE, WIA_DPC_EXPOSURE_METERING_MODE_STR,
  188. WIA_PROP_RW, WIA_PROP_NONE);
  189. if (FAILED(hr)) goto failure;
  190. RootProps.SetCurrentValue(index, CameraStats.ExposureMeteringMode);
  191. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_METERING_MODE, WIA_DPC_FOCUS_METERING_MODE_STR,
  192. WIA_PROP_RW, WIA_PROP_NONE);
  193. if (FAILED(hr)) goto failure;
  194. RootProps.SetCurrentValue(index, CameraStats.FocusMeteringMode);
  195. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCUS_DISTANCE, WIA_DPC_FOCUS_DISTANCE_STR,
  196. WIA_PROP_RW, WIA_PROP_NONE);
  197. if (FAILED(hr)) goto failure;
  198. RootProps.SetCurrentValue(index, CameraStats.FocusDistance);
  199. hr = RootProps.DefineProperty(&index, WIA_DPC_FOCAL_LENGTH, WIA_DPC_FOCAL_LENGTH_STR,
  200. WIA_PROP_RW, WIA_PROP_NONE);
  201. if (FAILED(hr)) goto failure;
  202. RootProps.SetCurrentValue(index, CameraStats.FocalLength);
  203. hr = RootProps.DefineProperty(&index, WIA_DPC_RGBGAIN, WIA_DPC_RGBGAIN_STR,
  204. WIA_PROP_RW, WIA_PROP_NONE);
  205. if (FAILED(hr)) goto failure;
  206. RootProps.SetCurrentValue(index, CameraStats.RGBGain);
  207. hr = RootProps.DefineProperty(&index, WIA_DPC_WHITE_BALANCE, WIA_DPC_WHITE_BALANCE_STR,
  208. WIA_PROP_RW, WIA_PROP_NONE);
  209. if (FAILED(hr)) goto failure;
  210. RootProps.SetCurrentValue(index, CameraStats.WhiteBalance);
  211. #endif // DEADCODE
  212. //
  213. // TODO: Add other optional properties that your device supports here
  214. //
  215. // Last step: send all the properties to WIA
  216. hr = RootProps.SendToWia(pWiasContext);
  217. if (FAILED(hr))
  218. {
  219. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildRootItemProperties, SendToWia failed"));
  220. }
  221. return hr;
  222. //
  223. // Any failures from DefineProperty will end up here
  224. //
  225. failure:
  226. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("BuildRootItemProperties, DefineProperty failed"));
  227. return hr;
  228. }
  229. /**************************************************************************\
  230. * ReadRootItemProperties
  231. *
  232. * Update the properties for the root item.
  233. *
  234. * Arguments:
  235. *
  236. * pWiasContext - WIA service context
  237. *
  238. \**************************************************************************/
  239. HRESULT
  240. CWiaCameraDevice::ReadRootItemProperties(
  241. BYTE *pWiasContext,
  242. LONG NumPropSpecs,
  243. const PROPSPEC *pPropSpecs
  244. )
  245. {
  246. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  247. WIALOG_NO_RESOURCE_ID,
  248. WIALOG_LEVEL1,
  249. "CWiaCameraDevice::ReadRootItemProperties");
  250. HRESULT hr = S_OK;
  251. if (!NumPropSpecs || !pPropSpecs)
  252. {
  253. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ReadRootItemProperties, invalid arg"));
  254. return E_INVALIDARG;
  255. }
  256. //
  257. // Loop through all of the PropSpecs
  258. //
  259. for (int count = 0; count < NumPropSpecs; count++)
  260. {
  261. PROPID propId = pPropSpecs[count].propid;
  262. switch (propId)
  263. {
  264. case WIA_DPC_PICTURES_TAKEN:
  265. hr = wiasWritePropLong(pWiasContext, WIA_DPC_PICTURES_TAKEN, m_DeviceInfo.PicturesTaken);
  266. break;
  267. #ifdef COUNT_PIC_REMAINING
  268. case WIA_DPC_PICTURES_REMAINING:
  269. hr = wiasWritePropLong(pWiasContext, WIA_DPC_PICTURES_REMAINING, m_DeviceInfo.PicturesRemaining);
  270. break;
  271. #endif
  272. default:
  273. break;
  274. }
  275. if (FAILED(hr))
  276. {
  277. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("ReadRootItemProperties, wiasWritePropLong failed 0x%08x", propId));
  278. WIAS_LHRESULT(m_pIWiaLog, hr);
  279. return hr;
  280. }
  281. }
  282. return hr;
  283. }