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.

614 lines
15 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: IStiUSD.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 18 July, 2000
  10. *
  11. * DESCRIPTION:
  12. * Implementation of the WIA sample camera IStiUSD methods.
  13. *
  14. *******************************************************************************/
  15. #include "pch.h"
  16. /**************************************************************************\
  17. * CWiaCameraDevice::CWiaCameraDevice
  18. *
  19. * Device class constructor
  20. *
  21. * Arguments:
  22. *
  23. * None
  24. *
  25. \**************************************************************************/
  26. CWiaCameraDevice::CWiaCameraDevice(LPUNKNOWN punkOuter):
  27. m_cRef(1),
  28. m_punkOuter(NULL),
  29. m_pIStiDevControl(NULL),
  30. m_pStiDevice(NULL),
  31. m_dwLastOperationError(0),
  32. m_bstrDeviceID(NULL),
  33. m_bstrRootFullItemName(NULL),
  34. m_pRootItem(NULL),
  35. m_lNumSupportedCommands(0),
  36. m_lNumSupportedEvents(0),
  37. m_lNumCapabilities(0),
  38. m_pCapabilities(NULL),
  39. m_pDevice(NULL),
  40. m_pDeviceInfo(NULL),
  41. m_iConnectedApps(0)
  42. {
  43. // See if we are aggregated. If we are (almost always the case) save
  44. // pointer to the controlling Unknown , so subsequent calls will be
  45. // delegated. If not, set the same pointer to "this".
  46. if (punkOuter) {
  47. m_punkOuter = punkOuter;
  48. } else {
  49. // Cast below is needed in order to point to right virtual table
  50. m_punkOuter = reinterpret_cast<IUnknown*> (static_cast<INonDelegatingUnknown*> (this));
  51. }
  52. }
  53. /**************************************************************************\
  54. * CWiaCameraDevice::~CWiaCameraDevice
  55. *
  56. * Device class destructor
  57. *
  58. * Arguments:
  59. *
  60. * None
  61. *
  62. \**************************************************************************/
  63. CWiaCameraDevice::~CWiaCameraDevice(void)
  64. {
  65. HRESULT hr = S_OK;
  66. //
  67. // Free all the resources held by the minidriver. Normally this is done by
  68. // drvUnInitializeWia, but there are situations (like WIA service shutdown) when
  69. // just this destructor is called
  70. //
  71. if (m_pDevice)
  72. {
  73. hr = FreeResources();
  74. if (FAILED(hr))
  75. wiauDbgErrorHr(hr, "~CWiaCameraDevice", "FreeResources failed, continuing...");
  76. hr = m_pDevice->UnInit(m_pDeviceInfo);
  77. if (FAILED(hr))
  78. {
  79. wiauDbgErrorHr(hr, "~CWiaCameraDevice", "UnInit failed, continuing...");
  80. }
  81. m_pDeviceInfo = NULL;
  82. delete m_pDevice;
  83. m_pDevice = NULL;
  84. }
  85. // Release the device control interface.
  86. if (m_pIStiDevControl) {
  87. m_pIStiDevControl->Release();
  88. m_pIStiDevControl = NULL;
  89. }
  90. }
  91. /**************************************************************************\
  92. * CWiaCameraDevice::Initialize
  93. *
  94. * Initialize the device object.
  95. *
  96. * Arguments:
  97. *
  98. * pIStiDevControlNone -
  99. * dwStiVersion -
  100. * hParametersKey -
  101. *
  102. \**************************************************************************/
  103. STDMETHODIMP CWiaCameraDevice::Initialize(
  104. PSTIDEVICECONTROL pIStiDevControl,
  105. DWORD dwStiVersion,
  106. HKEY hParametersKey)
  107. {
  108. HRESULT hr = S_OK;
  109. //
  110. // Locals
  111. //
  112. HKEY hkeyDeviceData = NULL;
  113. TCHAR tszMicroName[MAX_PATH];
  114. DWORD dwNameSize = sizeof(tszMicroName);
  115. //
  116. // Initialize logging
  117. //
  118. wiauDbgInit(g_hInst);
  119. //
  120. // Check and cache the pointer to the IStiDeviceControl interface
  121. //
  122. if (!pIStiDevControl) {
  123. wiauDbgError("Initialize", "Invalid device control interface");
  124. return STIERR_INVALID_PARAM;
  125. }
  126. pIStiDevControl->AddRef();
  127. m_pIStiDevControl = pIStiDevControl;
  128. //
  129. // Retrieve the port name from the IStiDeviceControl interface
  130. //
  131. hr = m_pIStiDevControl->GetMyDevicePortName(m_wszPortName, sizeof(m_wszPortName) / sizeof(m_wszPortName[0]));
  132. REQUIRE_SUCCESS(hr, "Initialize", "GetMyDevicePortName failed");
  133. //
  134. // Get the microdriver name from the registry
  135. //
  136. hr = wiauRegOpenData(hParametersKey, &hkeyDeviceData);
  137. REQUIRE_SUCCESS(hr, "Initialize", "wiauRegOpenData failed");
  138. hr = wiauRegGetStr(hkeyDeviceData, TEXT("MicroDriver"), tszMicroName, &dwNameSize);
  139. REQUIRE_SUCCESS(hr, "Initialize", "wiauRegGetStr failed");
  140. //
  141. // Create the device object
  142. //
  143. m_pDevice = new CCamMicro;
  144. REQUIRE_ALLOC(m_pDevice, hr, "Initialize");
  145. hr = m_pDevice->Init(tszMicroName, &m_pDeviceInfo);
  146. REQUIRE_SUCCESS(hr, "Initialize", "Init failed");
  147. //
  148. // Intialize image format converter
  149. //
  150. hr = m_Converter.Init();
  151. REQUIRE_SUCCESS(hr, "Initialize", "Init failed");
  152. Cleanup:
  153. if (hkeyDeviceData)
  154. RegCloseKey(hkeyDeviceData);
  155. return hr;
  156. }
  157. /**************************************************************************\
  158. * CWiaCameraDevice::GetCapabilities
  159. *
  160. * Get the device STI capabilities.
  161. *
  162. * Arguments:
  163. *
  164. * pUsdCaps - Pointer to USD capabilities data.
  165. *
  166. \**************************************************************************/
  167. STDMETHODIMP CWiaCameraDevice::GetCapabilities(PSTI_USD_CAPS pUsdCaps)
  168. {
  169. DBG_FN("CWiaCameraDevice::GetCapabilities");
  170. if (!pUsdCaps)
  171. {
  172. wiauDbgError("GetCapabilities", "invalid arguments");
  173. return E_INVALIDARG;
  174. }
  175. HRESULT hr = S_OK;
  176. memset(pUsdCaps, 0, sizeof(STI_USD_CAPS));
  177. pUsdCaps->dwVersion = STI_VERSION;
  178. pUsdCaps->dwGenericCaps = 0;
  179. return hr;
  180. }
  181. /**************************************************************************\
  182. * CWiaCameraDevice::GetStatus
  183. *
  184. * Query device online and/or event status.
  185. *
  186. * Arguments:
  187. *
  188. * pDevStatus - Pointer to device status data.
  189. *
  190. \**************************************************************************/
  191. STDMETHODIMP CWiaCameraDevice::GetStatus(PSTI_DEVICE_STATUS pDevStatus)
  192. {
  193. DBG_FN("CWiaCameraDevice::GetStatus");
  194. HRESULT hr = S_OK;
  195. //
  196. // Validate parameters
  197. //
  198. REQUIRE_ARGS(!pDevStatus, hr, "GetStatus");
  199. //
  200. // If requested, verify the device is online
  201. //
  202. if (pDevStatus->StatusMask & STI_DEVSTATUS_ONLINE_STATE) {
  203. pDevStatus->dwOnlineState = 0L;
  204. hr = m_pDevice->Status(m_pDeviceInfo);
  205. if (hr == S_OK) {
  206. pDevStatus->dwOnlineState |= STI_ONLINESTATE_OPERATIONAL;
  207. }
  208. else if (hr == S_FALSE) {
  209. hr = S_OK;
  210. }
  211. else {
  212. wiauDbgErrorHr(hr, "GetStatus", "Status failed");
  213. goto Cleanup;
  214. }
  215. }
  216. //
  217. // If requested, see if the device has signaled an event.
  218. // For cameras, there shouldn't be any events.
  219. //
  220. if (pDevStatus->StatusMask & STI_DEVSTATUS_EVENTS_STATE) {
  221. pDevStatus->dwEventHandlingState &= ~STI_EVENTHANDLING_PENDING;
  222. }
  223. Cleanup:
  224. return hr;
  225. }
  226. /**************************************************************************\
  227. * CWiaCameraDevice::DeviceReset
  228. *
  229. * Reset data file pointer to start of file.
  230. *
  231. * Arguments:
  232. *
  233. * None
  234. *
  235. \**************************************************************************/
  236. STDMETHODIMP CWiaCameraDevice::DeviceReset(void)
  237. {
  238. DBG_FN("CWiaCameraDevice::DeviceReset");
  239. HRESULT hr = S_OK;
  240. hr = m_pDevice->Reset(m_pDeviceInfo);
  241. REQUIRE_SUCCESS(hr, "DeviceReset", "Reset failed");
  242. Cleanup:
  243. return hr;
  244. }
  245. /**************************************************************************\
  246. * CWiaCameraDevice::Diagnostic
  247. *
  248. * The test device always passes the diagnostic.
  249. *
  250. * Arguments:
  251. *
  252. * pBuffer - Pointer o diagnostic result data.
  253. *
  254. \**************************************************************************/
  255. STDMETHODIMP CWiaCameraDevice::Diagnostic(LPSTI_DIAG pBuffer)
  256. {
  257. DBG_FN("CWiaCameraDevice::Diagnostic");
  258. if (!pBuffer)
  259. {
  260. wiauDbgError("Diagnostic", "invalid arguments");
  261. return E_INVALIDARG;
  262. }
  263. HRESULT hr = S_OK;
  264. //
  265. // Initialize response buffer
  266. //
  267. memset(&pBuffer->sErrorInfo, 0, sizeof(pBuffer->sErrorInfo));
  268. pBuffer->dwStatusMask = 0;
  269. pBuffer->sErrorInfo.dwGenericError = NOERROR;
  270. pBuffer->sErrorInfo.dwVendorError = 0;
  271. return hr;
  272. }
  273. /**************************************************************************\
  274. * CWiaCameraDevice::SetNotificationHandle
  275. *
  276. * Starts and stops the event notification thread.
  277. *
  278. * Arguments:
  279. *
  280. * hEvent - If not valid start the notification thread otherwise kill
  281. * the notification thread.
  282. *
  283. \**************************************************************************/
  284. STDMETHODIMP CWiaCameraDevice::SetNotificationHandle(HANDLE hEvent)
  285. {
  286. DBG_FN("CWiaCameraDevice::SetNotificationHandle");
  287. HRESULT hr = S_OK;
  288. return hr;
  289. }
  290. /**************************************************************************\
  291. * CWiaCameraDevice::GetNotificationData
  292. *
  293. * Provides data from an event.
  294. *
  295. * Arguments:
  296. *
  297. * pBuffer - Pointer to event data.
  298. *
  299. \**************************************************************************/
  300. STDMETHODIMP CWiaCameraDevice::GetNotificationData( LPSTINOTIFY pBuffer )
  301. {
  302. DBG_FN("CWiaCameraDevice::GetNotificationData");
  303. HRESULT hr = S_OK;
  304. return hr;
  305. }
  306. /**************************************************************************\
  307. * CWiaCameraDevice::Escape
  308. *
  309. * Issue a command to the device.
  310. *
  311. * Arguments:
  312. *
  313. * EscapeFunction - Command to be issued.
  314. * pInData - Input data to be passed with command.
  315. * cbInDataSize - Size of input data.
  316. * pOutData - Output data to be passed back from command.
  317. * cbOutDataSize - Size of output data buffer.
  318. * pcbActualData - Size of output data actually written.
  319. *
  320. \**************************************************************************/
  321. STDMETHODIMP CWiaCameraDevice::Escape(
  322. STI_RAW_CONTROL_CODE EscapeFunction,
  323. LPVOID pInData,
  324. DWORD cbInDataSize,
  325. LPVOID pOutData,
  326. DWORD cbOutDataSize,
  327. LPDWORD pcbActualData)
  328. {
  329. DBG_FN("CWiaCameraDevice::Escape");
  330. HRESULT hr = S_OK;
  331. return hr;
  332. }
  333. /**************************************************************************\
  334. * CWiaCameraDevice::GetLastError
  335. *
  336. * Get the last error from the device.
  337. *
  338. * Arguments:
  339. *
  340. * pdwLastDeviceError - Pointer to last error data.
  341. *
  342. \**************************************************************************/
  343. STDMETHODIMP CWiaCameraDevice::GetLastError(LPDWORD pdwLastDeviceError)
  344. {
  345. DBG_FN("CWiaCameraDevice::GetLastError");
  346. HRESULT hr = S_OK;
  347. REQUIRE_ARGS(!pdwLastDeviceError, hr, "GetLastError");
  348. *pdwLastDeviceError = m_dwLastOperationError;
  349. Cleanup:
  350. return hr;
  351. }
  352. /**************************************************************************\
  353. * CWiaCameraDevice::GetLastErrorInfo
  354. *
  355. * Get extended error information from the device.
  356. *
  357. * Arguments:
  358. *
  359. * pLastErrorInfo - Pointer to extended device error data.
  360. *
  361. \**************************************************************************/
  362. STDMETHODIMP CWiaCameraDevice::GetLastErrorInfo(STI_ERROR_INFO *pLastErrorInfo)
  363. {
  364. DBG_FN("CWiaCameraDevice::GetLastErrorInfo");
  365. HRESULT hr = S_OK;
  366. REQUIRE_ARGS(!pLastErrorInfo, hr, "GetLastErrorInfo");
  367. pLastErrorInfo->dwGenericError = m_dwLastOperationError;
  368. pLastErrorInfo->szExtendedErrorText[0] = '\0';
  369. Cleanup:
  370. return hr;
  371. }
  372. /**************************************************************************\
  373. * CWiaCameraDevice::LockDevice
  374. *
  375. * Lock access to the device.
  376. *
  377. * Arguments:
  378. *
  379. * None
  380. *
  381. \**************************************************************************/
  382. STDMETHODIMP CWiaCameraDevice::LockDevice(void)
  383. {
  384. DBG_FN("CWiaCameraDevice::LockDevice");
  385. HRESULT hr = S_OK;
  386. //
  387. // For devices connected to ports that cannot be shared (e.g. serial),
  388. // open the device and initialize access to the camera
  389. //
  390. if (m_pDeviceInfo->bExclusivePort) {
  391. hr = m_pDevice->Open(m_pDeviceInfo, m_wszPortName);
  392. REQUIRE_SUCCESS(hr, "LockDevice", "Open failed");
  393. }
  394. Cleanup:
  395. return hr;
  396. }
  397. /**************************************************************************\
  398. * CWiaCameraDevice::UnLockDevice
  399. *
  400. * Unlock access to the device.
  401. *
  402. * Arguments:
  403. *
  404. * None
  405. *
  406. \**************************************************************************/
  407. STDMETHODIMP CWiaCameraDevice::UnLockDevice(void)
  408. {
  409. DBG_FN("CWiaCameraDevice::UnLockDevice");
  410. HRESULT hr = S_OK;
  411. //
  412. // For devices connected to ports that cannot be shared (e.g. serial),
  413. // close the device
  414. //
  415. if (m_pDeviceInfo->bExclusivePort) {
  416. hr = m_pDevice->Close(m_pDeviceInfo);
  417. REQUIRE_SUCCESS(hr, "UnLockDevice", "Close failed");
  418. }
  419. Cleanup:
  420. return hr;
  421. }
  422. /**************************************************************************\
  423. * CWiaCameraDevice::RawReadData
  424. *
  425. * Read raw data from the device.
  426. *
  427. * Arguments:
  428. *
  429. * lpBuffer -
  430. * lpdwNumberOfBytes -
  431. * lpOverlapped -
  432. *
  433. \**************************************************************************/
  434. STDMETHODIMP CWiaCameraDevice::RawReadData(
  435. LPVOID lpBuffer,
  436. LPDWORD lpdwNumberOfBytes,
  437. LPOVERLAPPED lpOverlapped)
  438. {
  439. DBG_FN("CWiaCameraDevice::RawReadData");
  440. HRESULT hr = S_OK;
  441. return hr;
  442. }
  443. /**************************************************************************\
  444. * CWiaCameraDevice::RawWriteData
  445. *
  446. * Write raw data to the device.
  447. *
  448. * Arguments:
  449. *
  450. * lpBuffer -
  451. * dwNumberOfBytes -
  452. * lpOverlapped -
  453. *
  454. \**************************************************************************/
  455. STDMETHODIMP CWiaCameraDevice::RawWriteData(
  456. LPVOID lpBuffer,
  457. DWORD dwNumberOfBytes,
  458. LPOVERLAPPED lpOverlapped)
  459. {
  460. DBG_FN("CWiaCameraDevice::RawWriteData");
  461. HRESULT hr = S_OK;
  462. return hr;
  463. }
  464. /**************************************************************************\
  465. * CWiaCameraDevice::RawReadCommand
  466. *
  467. * Read a command from the device.
  468. *
  469. * Arguments:
  470. *
  471. * lpBuffer -
  472. * lpdwNumberOfBytes -
  473. * lpOverlapped -
  474. *
  475. \**************************************************************************/
  476. STDMETHODIMP CWiaCameraDevice::RawReadCommand(
  477. LPVOID lpBuffer,
  478. LPDWORD lpdwNumberOfBytes,
  479. LPOVERLAPPED lpOverlapped)
  480. {
  481. DBG_FN("CWiaCameraDevice::RawReadCommand");
  482. HRESULT hr = S_OK;
  483. return E_NOTIMPL;
  484. }
  485. /**************************************************************************\
  486. * CWiaCameraDevice::RawWriteCommand
  487. *
  488. * Write a command to the device.
  489. *
  490. * Arguments:
  491. *
  492. * lpBuffer -
  493. * nNumberOfBytes -
  494. * lpOverlapped -
  495. *
  496. \**************************************************************************/
  497. STDMETHODIMP CWiaCameraDevice::RawWriteCommand(
  498. LPVOID lpBuffer,
  499. DWORD nNumberOfBytes,
  500. LPOVERLAPPED lpOverlapped)
  501. {
  502. DBG_FN("CWiaCameraDevice::RawWriteCommand");
  503. HRESULT hr = S_OK;
  504. return E_NOTIMPL;
  505. }