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.

661 lines
18 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2001
  4. *
  5. * TITLE: IStiUSD.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 15 Nov, 2000
  10. *
  11. * DESCRIPTION:
  12. * Implementation of the WIA File System Device driver 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_NumSupportedCommands(0),
  36. m_NumSupportedEvents(0),
  37. m_NumCapabilities(0),
  38. m_pCapabilities(NULL),
  39. m_pDevice(NULL),
  40. m_ConnectedApps(0),
  41. m_pIWiaLog(NULL),
  42. m_FormatInfo(NULL),
  43. m_NumFormatInfo(0)
  44. {
  45. // See if we are aggregated. If we are (almost always the case) save
  46. // pointer to the controlling Unknown , so subsequent calls will be
  47. // delegated. If not, set the same pointer to "this".
  48. if (punkOuter) {
  49. m_punkOuter = punkOuter;
  50. } else {
  51. // Cast below is needed in order to point to right virtual table
  52. m_punkOuter = reinterpret_cast<IUnknown*>
  53. (static_cast<INonDelegatingUnknown*>
  54. (this));
  55. }
  56. }
  57. /**************************************************************************\
  58. * CWiaCameraDevice::~CWiaCameraDevice
  59. *
  60. * Device class destructor
  61. *
  62. * Arguments:
  63. *
  64. * None
  65. *
  66. \**************************************************************************/
  67. CWiaCameraDevice::~CWiaCameraDevice(void)
  68. {
  69. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL2,("~CWiaCameraDevice, executing ~CWiaCameraDevice destructor"));
  70. // Close the connection with the camera and delete it
  71. if( m_pDevice )
  72. {
  73. m_pDevice->Close();
  74. delete m_pDevice;
  75. m_pDevice = NULL;
  76. }
  77. // Release the device control interface.
  78. if (m_pIStiDevControl) {
  79. m_pIStiDevControl->Release();
  80. m_pIStiDevControl = NULL;
  81. }
  82. if(m_pIWiaLog)
  83. m_pIWiaLog->Release();
  84. }
  85. /**************************************************************************\
  86. * CWiaCameraDevice::Initialize
  87. *
  88. * Initialize the device object.
  89. *
  90. * Arguments:
  91. *
  92. * pIStiDevControlNone -
  93. * dwStiVersion -
  94. * hParametersKey -
  95. *
  96. \**************************************************************************/
  97. STDMETHODIMP CWiaCameraDevice::Initialize(
  98. PSTIDEVICECONTROL pIStiDevControl,
  99. DWORD dwStiVersion,
  100. HKEY hParametersKey)
  101. {
  102. HRESULT hr = S_OK;
  103. //
  104. // Create logging object
  105. //
  106. hr = CoCreateInstance(CLSID_WiaLog, NULL, CLSCTX_INPROC,
  107. IID_IWiaLog, (void**)&m_pIWiaLog);
  108. if (SUCCEEDED(hr) &&
  109. (m_pIWiaLog != NULL))
  110. {
  111. //
  112. // This will not really work on 64 bit!!!
  113. //
  114. hr = m_pIWiaLog->InitializeLog((LONG)(LONG_PTR) g_hInst);
  115. if (SUCCEEDED(hr))
  116. {
  117. WIAS_LTRACE(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,WIALOG_LEVEL1,("CWiaCameraDevice::Initialize, logging initialized"));
  118. }
  119. else
  120. OutputDebugString(TEXT("Failed to initialize log for fsusd.dll\n"));
  121. }
  122. else
  123. {
  124. OutputDebugString(TEXT("Failed to CoCreateInstance on WiaLog for fsusd.dll\n"));
  125. }
  126. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  127. WIALOG_NO_RESOURCE_ID,
  128. WIALOG_LEVEL1,
  129. "CWiaCameraDevice::Initialize");
  130. //
  131. // Check and cache the pointer to the IStiDeviceControl interface
  132. //
  133. if (!pIStiDevControl) {
  134. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CWiaCameraDevice::Initialize, invalid device control interface"));
  135. return STIERR_INVALID_PARAM;
  136. }
  137. pIStiDevControl->AddRef();
  138. m_pIStiDevControl = pIStiDevControl;
  139. //
  140. // Retrieve the port name from the IStiDeviceControl interface
  141. //
  142. hr = m_pIStiDevControl->GetMyDevicePortName(m_pPortName, sizeof(m_pPortName) / sizeof(m_pPortName[0]));
  143. if (FAILED(hr))
  144. {
  145. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Initialize, GetMyDevicePortName failed"));
  146. WIAS_LHRESULT(m_pIWiaLog, hr);
  147. return hr;
  148. }
  149. //
  150. // Create the device
  151. //
  152. m_pDevice = new FakeCamera;
  153. if (!m_pDevice)
  154. {
  155. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Initialize, memory allocation failed"));
  156. return E_OUTOFMEMORY;
  157. }
  158. #if 1
  159. // DBG_TRC(("IStiPortName=%S [%d]", m_pPortName, wcslen(m_pPortName)));
  160. WIAS_LTRACE(m_pIWiaLog, WIALOG_NO_RESOURCE_ID, WIALOG_LEVEL1, ("IStiPortName=%S [%d]", m_pPortName, wcslen(m_pPortName)));
  161. #endif
  162. m_pIWiaLog->AddRef();
  163. m_pDevice->SetWiaLog(&m_pIWiaLog);
  164. //
  165. // Initialize access to the camera
  166. //
  167. // ISSUE-10/17/2000-davepar Also need to pass in event callback
  168. //
  169. hr = m_pDevice->Open(m_pPortName);
  170. if (FAILED(hr))
  171. {
  172. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Initialize, Init failed"));
  173. goto Cleanup;
  174. }
  175. if( !m_pCapabilities )
  176. {
  177. hr = BuildCapabilities();
  178. if( hr != S_OK )
  179. {
  180. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Initialize, BuildCapabilities failed"));
  181. goto Cleanup;
  182. }
  183. }
  184. //
  185. // Intialize image format converter
  186. //
  187. hr = m_Converter.Init();
  188. if (FAILED(hr))
  189. {
  190. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("Initialize, Init converter failed"));
  191. goto Cleanup;
  192. }
  193. Cleanup:
  194. if( hr != S_OK )
  195. {
  196. if( m_pDevice )
  197. {
  198. delete m_pDevice;
  199. m_pDevice = NULL;
  200. }
  201. }
  202. return hr;
  203. }
  204. /**************************************************************************\
  205. * CWiaCameraDevice::GetCapabilities
  206. *
  207. * Get the device STI capabilities.
  208. *
  209. * Arguments:
  210. *
  211. * pUsdCaps - Pointer to USD capabilities data.
  212. *
  213. \**************************************************************************/
  214. STDMETHODIMP CWiaCameraDevice::GetCapabilities(PSTI_USD_CAPS pUsdCaps)
  215. {
  216. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  217. WIALOG_NO_RESOURCE_ID,
  218. WIALOG_LEVEL3,
  219. "CWiaCameraDevice::GetCapabilities");
  220. HRESULT hr = S_OK;
  221. memset(pUsdCaps, 0, sizeof(*pUsdCaps));
  222. pUsdCaps->dwVersion = STI_VERSION;
  223. pUsdCaps->dwGenericCaps = 0;
  224. return hr;
  225. }
  226. /**************************************************************************\
  227. * CWiaCameraDevice::GetStatus
  228. *
  229. * Query device online and/or event status.
  230. *
  231. * Arguments:
  232. *
  233. * pDevStatus - Pointer to device status data.
  234. *
  235. \**************************************************************************/
  236. STDMETHODIMP CWiaCameraDevice::GetStatus(PSTI_DEVICE_STATUS pDevStatus)
  237. {
  238. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  239. WIALOG_NO_RESOURCE_ID,
  240. WIALOG_LEVEL3,
  241. "CWiaCameraDevice::GetStatus");
  242. HRESULT hr = S_OK;
  243. // Validate parameters.
  244. if (!pDevStatus) {
  245. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("CWiaCameraDevice::GetStatus, NULL parameter"));
  246. return E_INVALIDARG;
  247. }
  248. // If asked, verify the device is online
  249. if (pDevStatus->StatusMask & STI_DEVSTATUS_ONLINE_STATE) {
  250. pDevStatus->dwOnlineState = 0L;
  251. hr = m_pDevice->Status();
  252. if (hr == S_OK) {
  253. pDevStatus->dwOnlineState |= STI_ONLINESTATE_OPERATIONAL;
  254. }
  255. else if (hr == S_FALSE) {
  256. hr = S_OK;
  257. }
  258. else {
  259. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("GetStatus, Status failed"));
  260. return hr;
  261. }
  262. }
  263. // If asked, verify state of event
  264. if (pDevStatus->StatusMask & STI_DEVSTATUS_EVENTS_STATE) {
  265. pDevStatus->dwEventHandlingState &= ~STI_EVENTHANDLING_PENDING;
  266. // ISSUE-10/17/2000-davepar See if camera wants polling, and then poll for events
  267. }
  268. return hr;
  269. }
  270. /**************************************************************************\
  271. * CWiaCameraDevice::DeviceReset
  272. *
  273. * Reset data file pointer to start of file.
  274. *
  275. * Arguments:
  276. *
  277. * None
  278. *
  279. \**************************************************************************/
  280. STDMETHODIMP CWiaCameraDevice::DeviceReset(void)
  281. {
  282. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  283. WIALOG_NO_RESOURCE_ID,
  284. WIALOG_LEVEL3,
  285. "CWiaCameraDevice::DeviceReset");
  286. HRESULT hr = S_OK;
  287. hr = m_pDevice->Reset();
  288. if (FAILED(hr))
  289. {
  290. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("DeviceReset, Reset failed"));
  291. }
  292. return hr;
  293. }
  294. /**************************************************************************\
  295. * CWiaCameraDevice::Diagnostic
  296. *
  297. * The test device always passes the diagnostic.
  298. *
  299. * Arguments:
  300. *
  301. * pBuffer - Pointer o diagnostic result data.
  302. *
  303. \**************************************************************************/
  304. STDMETHODIMP CWiaCameraDevice::Diagnostic(LPSTI_DIAG pBuffer)
  305. {
  306. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  307. WIALOG_NO_RESOURCE_ID,
  308. WIALOG_LEVEL3,
  309. "CWiaCameraDevice::Diagnostic");
  310. HRESULT hr = S_OK;
  311. // ISSUE-10/17/2000-davepar Should call m_pDevice->Diagnostic
  312. // Initialize response buffer
  313. memset(&pBuffer->sErrorInfo, 0, sizeof(pBuffer->sErrorInfo));
  314. pBuffer->dwStatusMask = 0;
  315. pBuffer->sErrorInfo.dwGenericError = NOERROR;
  316. pBuffer->sErrorInfo.dwVendorError = 0;
  317. return hr;
  318. }
  319. /**************************************************************************\
  320. * CWiaCameraDevice::SetNotificationHandle
  321. *
  322. * Starts and stops the event notification thread.
  323. *
  324. * Arguments:
  325. *
  326. * hEvent - If not valid start the notification thread otherwise kill
  327. * the notification thread.
  328. *
  329. \**************************************************************************/
  330. STDMETHODIMP CWiaCameraDevice::SetNotificationHandle(HANDLE hEvent)
  331. {
  332. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  333. WIALOG_NO_RESOURCE_ID,
  334. WIALOG_LEVEL3,
  335. "CWiaCameraDevice::SetNotificationHandle");
  336. HRESULT hr = S_OK;
  337. return hr;
  338. }
  339. /**************************************************************************\
  340. * CWiaCameraDevice::GetNotificationData
  341. *
  342. * Provides data from an event.
  343. *
  344. * Arguments:
  345. *
  346. * pBuffer - Pointer to event data.
  347. *
  348. \**************************************************************************/
  349. STDMETHODIMP CWiaCameraDevice::GetNotificationData( LPSTINOTIFY pBuffer )
  350. {
  351. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  352. WIALOG_NO_RESOURCE_ID,
  353. WIALOG_LEVEL3,
  354. "CWiaCameraDevice::GetNotificationData");
  355. HRESULT hr = S_OK;
  356. return hr;
  357. }
  358. /**************************************************************************\
  359. * CWiaCameraDevice::Escape
  360. *
  361. * Issue a command to the device.
  362. *
  363. * Arguments:
  364. *
  365. * EscapeFunction - Command to be issued.
  366. * pInData - Input data to be passed with command.
  367. * cbInDataSize - Size of input data.
  368. * pOutData - Output data to be passed back from command.
  369. * cbOutDataSize - Size of output data buffer.
  370. * pcbActualData - Size of output data actually written.
  371. *
  372. \**************************************************************************/
  373. STDMETHODIMP CWiaCameraDevice::Escape(
  374. STI_RAW_CONTROL_CODE EscapeFunction,
  375. LPVOID pInData,
  376. DWORD cbInDataSize,
  377. LPVOID pOutData,
  378. DWORD cbOutDataSize,
  379. LPDWORD pcbActualData)
  380. {
  381. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  382. WIALOG_NO_RESOURCE_ID,
  383. WIALOG_LEVEL3,
  384. "CWiaCameraDevice::Escape");
  385. HRESULT hr = S_OK;
  386. return hr;
  387. }
  388. /**************************************************************************\
  389. * CWiaCameraDevice::GetLastError
  390. *
  391. * Get the last error from the device.
  392. *
  393. * Arguments:
  394. *
  395. * pdwLastDeviceError - Pointer to last error data.
  396. *
  397. \**************************************************************************/
  398. STDMETHODIMP CWiaCameraDevice::GetLastError(LPDWORD pdwLastDeviceError)
  399. {
  400. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  401. WIALOG_NO_RESOURCE_ID,
  402. WIALOG_LEVEL3,
  403. "CWiaCameraDevice::GetLastError");
  404. HRESULT hr = S_OK;
  405. if (!pdwLastDeviceError) {
  406. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("GetLastError, invalid arg"));
  407. return E_INVALIDARG;
  408. }
  409. *pdwLastDeviceError = m_dwLastOperationError;
  410. return hr;
  411. }
  412. /**************************************************************************\
  413. * CWiaCameraDevice::GetLastErrorInfo
  414. *
  415. * Get extended error information from the device.
  416. *
  417. * Arguments:
  418. *
  419. * pLastErrorInfo - Pointer to extended device error data.
  420. *
  421. \**************************************************************************/
  422. STDMETHODIMP CWiaCameraDevice::GetLastErrorInfo(STI_ERROR_INFO *pLastErrorInfo)
  423. {
  424. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  425. WIALOG_NO_RESOURCE_ID,
  426. WIALOG_LEVEL3,
  427. "CWiaCameraDevice::GetLastErrorInfo");
  428. HRESULT hr = S_OK;
  429. if (!pLastErrorInfo) {
  430. WIAS_LERROR(m_pIWiaLog,WIALOG_NO_RESOURCE_ID,("GetLastErrorInfo, invalid arg"));
  431. return E_INVALIDARG;
  432. }
  433. pLastErrorInfo->dwGenericError = m_dwLastOperationError;
  434. pLastErrorInfo->szExtendedErrorText[0] = '\0';
  435. return hr;
  436. }
  437. /**************************************************************************\
  438. * CWiaCameraDevice::LockDevice
  439. *
  440. * Lock access to the device.
  441. *
  442. * Arguments:
  443. *
  444. * None
  445. *
  446. \**************************************************************************/
  447. STDMETHODIMP CWiaCameraDevice::LockDevice(void)
  448. {
  449. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  450. WIALOG_NO_RESOURCE_ID,
  451. WIALOG_LEVEL3,
  452. "CWiaCameraDevice::LockDevice");
  453. HRESULT hr = S_OK;
  454. return hr;
  455. }
  456. /**************************************************************************\
  457. * CWiaCameraDevice::UnLockDevice
  458. *
  459. * Unlock access to the device.
  460. *
  461. * Arguments:
  462. *
  463. * None
  464. *
  465. \**************************************************************************/
  466. STDMETHODIMP CWiaCameraDevice::UnLockDevice(void)
  467. {
  468. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  469. WIALOG_NO_RESOURCE_ID,
  470. WIALOG_LEVEL3,
  471. "CWiaCameraDevice::UnLockDevice");
  472. HRESULT hr = S_OK;
  473. return hr;
  474. }
  475. /**************************************************************************\
  476. * CWiaCameraDevice::RawReadData
  477. *
  478. * Read raw data from the device.
  479. *
  480. * Arguments:
  481. *
  482. * lpBuffer -
  483. * lpdwNumberOfBytes -
  484. * lpOverlapped -
  485. *
  486. \**************************************************************************/
  487. STDMETHODIMP CWiaCameraDevice::RawReadData(
  488. LPVOID lpBuffer,
  489. LPDWORD lpdwNumberOfBytes,
  490. LPOVERLAPPED lpOverlapped)
  491. {
  492. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  493. WIALOG_NO_RESOURCE_ID,
  494. WIALOG_LEVEL3,
  495. "CWiaCameraDevice::RawReadData");
  496. HRESULT hr = S_OK;
  497. return hr;
  498. }
  499. /**************************************************************************\
  500. * CWiaCameraDevice::RawWriteData
  501. *
  502. * Write raw data to the device.
  503. *
  504. * Arguments:
  505. *
  506. * lpBuffer -
  507. * dwNumberOfBytes -
  508. * lpOverlapped -
  509. *
  510. \**************************************************************************/
  511. STDMETHODIMP CWiaCameraDevice::RawWriteData(
  512. LPVOID lpBuffer,
  513. DWORD dwNumberOfBytes,
  514. LPOVERLAPPED lpOverlapped)
  515. {
  516. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  517. WIALOG_NO_RESOURCE_ID,
  518. WIALOG_LEVEL3,
  519. "CWiaCameraDevice::RawWriteData");
  520. HRESULT hr = S_OK;
  521. return hr;
  522. }
  523. /**************************************************************************\
  524. * CWiaCameraDevice::RawReadCommand
  525. *
  526. * Read a command from the device.
  527. *
  528. * Arguments:
  529. *
  530. * lpBuffer -
  531. * lpdwNumberOfBytes -
  532. * lpOverlapped -
  533. *
  534. \**************************************************************************/
  535. STDMETHODIMP CWiaCameraDevice::RawReadCommand(
  536. LPVOID lpBuffer,
  537. LPDWORD lpdwNumberOfBytes,
  538. LPOVERLAPPED lpOverlapped)
  539. {
  540. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  541. WIALOG_NO_RESOURCE_ID,
  542. WIALOG_LEVEL3,
  543. "CWiaCameraDevice::RawReadCommand");
  544. HRESULT hr = S_OK;
  545. return E_NOTIMPL;
  546. }
  547. /**************************************************************************\
  548. * CWiaCameraDevice::RawWriteCommand
  549. *
  550. * Write a command to the device.
  551. *
  552. * Arguments:
  553. *
  554. * lpBuffer -
  555. * nNumberOfBytes -
  556. * lpOverlapped -
  557. *
  558. \**************************************************************************/
  559. STDMETHODIMP CWiaCameraDevice::RawWriteCommand(
  560. LPVOID lpBuffer,
  561. DWORD nNumberOfBytes,
  562. LPOVERLAPPED lpOverlapped)
  563. {
  564. CWiaLogProc WIAS_LOGPROC(m_pIWiaLog,
  565. WIALOG_NO_RESOURCE_ID,
  566. WIALOG_LEVEL3,
  567. "CWiaCameraDevice::RawWriteCommand");
  568. HRESULT hr = S_OK;
  569. return E_NOTIMPL;
  570. }