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.

458 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1999, All rights reserved
  4. //
  5. // ircamera.h
  6. //
  7. // Microsoft Confidential
  8. //
  9. // Author: EdwardR 22/July/99 Initial Coding.
  10. //
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef WIN32_LEAN_AND_MEAN
  14. #define WIN32_LEAN_AND_MEAN
  15. #endif
  16. #include <windows.h>
  17. #pragma intrinsic(memcmp,memset)
  18. #include <objbase.h>
  19. #include "sti.h"
  20. #include "stierr.h"
  21. #include "stiusd.h"
  22. #include "wiamindr.h"
  23. //---------------------------------------------------------------------------
  24. // Temp (cached) thumbnail file name extension:
  25. //---------------------------------------------------------------------------
  26. #define SZ_TMB TEXT(".tmb")
  27. //---------------------------------------------------------------------------
  28. // Timeout for sending a reconnect signal to WIA. Currently set to three
  29. // minutes (in milliseconds):
  30. //---------------------------------------------------------------------------
  31. #define RECONNECT_TIMEOUT (3*60*1000)
  32. //---------------------------------------------------------------------------
  33. // GUID's
  34. //---------------------------------------------------------------------------
  35. #if defined( _WIN32 ) && !defined( _NO_COM)
  36. // {26d2e349-10ca-4cc2-881d-3e8025d9b6de}
  37. DEFINE_GUID(CLSID_IrUsd, 0x26d2e349L, 0x10ca, 0x4cc2, 0x88, 0x1d, 0x3e, 0x80, 0x25, 0xd9, 0xb6, 0xde);
  38. // {b62d000a-73b3-4c0c-9a4d-9eb4886d147c}
  39. DEFINE_GUID(guidEventTimeChanged, 0xb62d000aL, 0x73b3, 0x4c0c, 0x9a, 0x4d, 0x9e, 0xb4, 0x88, 0x6d, 0x14, 0x7c);
  40. // {d69b7fbd-9f21-4acf-96b7-86c2aca97ae1}
  41. DEFINE_GUID(guidEventSizeChanged, 0xd69b7fbdL, 0x9f21, 0x4acf, 0x96, 0xb7, 0x86, 0xc2, 0xac, 0xa9, 0x7a, 0xe1);
  42. // {ad89b522-0986-45eb-9ec3-803989197af8}
  43. DEFINE_GUID(guidEventFirstLoaded, 0xad89b522L, 0x0986, 0x45eb, 0x9e, 0xc3, 0x80, 0x39, 0x89, 0x19, 0x7a, 0xf8);
  44. #endif
  45. //---------------------------------------------------------------------------
  46. //---------------------------------------------------------------------------
  47. #define DATASEG_PERINSTANCE ".instance"
  48. #define DATASEG_SHARED ".shared"
  49. #define DATASEG_READONLY ".code"
  50. #define DATASEG_DEFAULT DATASEG_SHARED
  51. #pragma data_seg(DATASEG_PERINSTANCE)
  52. // Set the default data segment
  53. #pragma data_seg(DATASEG_DEFAULT)
  54. //---------------------------------------------------------------------------
  55. //
  56. // Module ref counting
  57. //
  58. //---------------------------------------------------------------------------
  59. extern UINT g_cRefThisDll;
  60. extern UINT g_cLocks;
  61. extern BOOL DllInitializeCOM(void);
  62. extern BOOL DllUnInitializeCOM(void);
  63. extern void DllAddRef(void);
  64. extern void DllRelease(void);
  65. typedef struct _IRCAM_IMAGE_CONTEXT
  66. {
  67. PTCHAR pszCameraImagePath;
  68. } IRCAM_IMAGE_CONTEXT, *PIRCAM_IMAGE_CONTEXT;
  69. typedef struct _CAMERA_PICTURE_INFO
  70. {
  71. LONG PictNumber;
  72. LONG ThumbWidth;
  73. LONG ThumbHeight;
  74. LONG PictWidth;
  75. LONG PictHeight;
  76. LONG PictCompSize;
  77. LONG PictFormat;
  78. LONG PictBitsPerPixel;
  79. LONG PictBytesPerRow;
  80. SYSTEMTIME TimeStamp;
  81. } CAMERA_PICTURE_INFO, *PCAMERA_PICTURE_INFO;
  82. typedef struct _CAMERA_STATUS
  83. {
  84. LONG FirmwareVersion;
  85. LONG NumPictTaken;
  86. LONG NumPictRemaining;
  87. LONG ThumbWidth;
  88. LONG ThumbHeight;
  89. LONG PictWidth;
  90. LONG PictHeight;
  91. SYSTEMTIME CameraTime;
  92. } CAMERA_STATUS, *PCAMERA_STATUS;
  93. #define ALLOC(s) LocalAlloc(0,s)
  94. #define FREE(s) LocalFree(s)
  95. //---------------------------------------------------------------------------
  96. //
  97. // Base class for supporting non-delegating IUnknown for contained objects
  98. //
  99. //---------------------------------------------------------------------------
  100. struct INonDelegatingUnknown
  101. {
  102. // *** IUnknown-like methods ***
  103. STDMETHOD(NonDelegatingQueryInterface)( THIS_ REFIID riid, LPVOID * ppvObj) PURE;
  104. STDMETHOD_(ULONG,NonDelegatingAddRef)(THIS) PURE;
  105. STDMETHOD_(ULONG,NonDelegatingRelease)( THIS) PURE;
  106. };
  107. //---------------------------------------------------------------------------
  108. //
  109. // Class definition for object
  110. //
  111. //---------------------------------------------------------------------------
  112. class IrUsdDevice : public IStiUSD,
  113. public IWiaMiniDrv,
  114. public INonDelegatingUnknown
  115. {
  116. private:
  117. // COM object data
  118. ULONG m_cRef; // Device object reference count.
  119. // STI information
  120. BOOL m_fValid; // Is object initialized?
  121. LPUNKNOWN m_punkOuter; // Pointer to outer unknown.
  122. PSTIDEVICECONTROL m_pIStiDevControl; // Device control interface.
  123. BOOLEAN m_bUsdLoadEvent; // Controls load event.
  124. DWORD m_dwLastOperationError; // Last error.
  125. public:
  126. // Event information
  127. CRITICAL_SECTION m_csShutdown; // Syncronizes shutdown.
  128. HANDLE m_hShutdownEvent; // Shutdown event handle.
  129. HANDLE m_hIrTranPThread; // IrTran-P camera protocol.
  130. HANDLE m_hRegistryEvent;
  131. HANDLE m_hEventMonitorThread;
  132. // WIA information, one time initialization.
  133. IStiDevice *m_pStiDevice; // Sti object.
  134. BSTR m_bstrDeviceID; // WIA unique device ID.
  135. BSTR m_bstrRootFullItemName; // Device name for prop streams.
  136. IWiaEventCallback *m_pIWiaEventCallback; // WIA event sink.
  137. IWiaDrvItem *m_pIDrvItemRoot; // root item
  138. HANDLE m_hSignalEvent; // Signal event handle.
  139. HWND m_hDlg;
  140. GUID m_guidLastEvent; // Last event ID.
  141. DWORD m_dwLastConnectTime; // msec since last connect.
  142. // *** IUnknown-like methods ***
  143. STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, LPVOID * ppvObj);
  144. STDMETHODIMP_(ULONG) NonDelegatingAddRef();
  145. STDMETHODIMP_(ULONG) NonDelegatingRelease();
  146. // *** IUnknown methods ***
  147. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  148. STDMETHODIMP_(ULONG) AddRef( void);
  149. STDMETHODIMP_(ULONG) Release( void);
  150. /*** IStiUSD methods ***/
  151. STDMETHOD(Initialize) (THIS_ PSTIDEVICECONTROL pHelDcb,DWORD dwStiVersion,HKEY hParametersKey) ;
  152. STDMETHOD(GetCapabilities) (THIS_ PSTI_USD_CAPS pDevCaps) ;
  153. STDMETHOD(GetStatus) (THIS_ PSTI_DEVICE_STATUS pDevStatus) ;
  154. STDMETHOD(DeviceReset)(THIS ) ;
  155. STDMETHOD(Diagnostic)(THIS_ LPDIAG pBuffer) ;
  156. STDMETHOD(Escape)(THIS_ STI_RAW_CONTROL_CODE EscapeFunction,LPVOID lpInData,DWORD cbInDataSize,LPVOID pOutData,DWORD dwOutDataSize,LPDWORD pdwActualData) ;
  157. STDMETHOD(GetLastError) (THIS_ LPDWORD pdwLastDeviceError) ;
  158. STDMETHOD(LockDevice) (THIS ) ;
  159. STDMETHOD(UnLockDevice) (THIS ) ;
  160. STDMETHOD(RawReadData)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  161. STDMETHOD(RawWriteData)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  162. STDMETHOD(RawReadCommand)(THIS_ LPVOID lpBuffer,LPDWORD lpdwNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  163. STDMETHOD(RawWriteCommand)(THIS_ LPVOID lpBuffer,DWORD nNumberOfBytes,LPOVERLAPPED lpOverlapped) ;
  164. STDMETHOD(SetNotificationHandle)(THIS_ HANDLE hEvent) ;
  165. STDMETHOD(GetNotificationData)(THIS_ LPSTINOTIFY lpNotify) ;
  166. STDMETHOD(GetLastErrorInfo) (THIS_ STI_ERROR_INFO *pLastErrorInfo);
  167. //
  168. // MiniDrv methods
  169. //
  170. STDMETHOD(drvInitializeWia)(THIS_
  171. BYTE *pWiasContext,
  172. LONG lFlags,
  173. BSTR bstrDeviceID,
  174. BSTR bstrRootFullItemName,
  175. IUnknown *pStiDevice,
  176. IUnknown *pIUnknownOuter,
  177. IWiaDrvItem **ppIDrvItemRoot,
  178. IUnknown **ppIUnknownInner,
  179. LONG *plDevErrVal);
  180. STDMETHOD(drvGetDeviceErrorStr)(THIS_
  181. LONG lFlags,
  182. LONG lDevErrVal,
  183. LPOLESTR *ppszDevErrStr,
  184. LONG *plDevErr);
  185. STDMETHOD(drvDeviceCommand)(THIS_
  186. BYTE *pWiasContext,
  187. LONG lFlags,
  188. const GUID *plCommand,
  189. IWiaDrvItem **ppWiaDrvItem,
  190. LONG *plErr);
  191. STDMETHOD(drvAcquireItemData)(THIS_
  192. BYTE *pWiasContext,
  193. LONG lFlags,
  194. PMINIDRV_TRANSFER_CONTEXT pDataContext,
  195. LONG *plDevErrVal);
  196. STDMETHOD(drvInitItemProperties)(THIS_
  197. BYTE *pWiasContext,
  198. LONG lFlags,
  199. LONG *plDevErrVal);
  200. STDMETHOD(drvValidateItemProperties)(THIS_
  201. BYTE *pWiasContext,
  202. LONG lFlags,
  203. ULONG nPropSpec,
  204. const PROPSPEC *pPropSpec,
  205. LONG *plDevErrVal);
  206. STDMETHOD(drvWriteItemProperties)(THIS_
  207. BYTE *pWiasContext,
  208. LONG lFLags,
  209. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  210. LONG *plDevErrVal);
  211. STDMETHOD(drvReadItemProperties)(THIS_
  212. BYTE *pWiaItem,
  213. LONG lFlags,
  214. ULONG nPropSpec,
  215. const PROPSPEC *pPropSpec,
  216. LONG *plDevErrVal);
  217. STDMETHOD(drvLockWiaDevice)(THIS_
  218. BYTE *pWiasContext,
  219. LONG lFlags,
  220. LONG *plDevErrVal);
  221. STDMETHOD(drvUnLockWiaDevice)(THIS_
  222. BYTE *pWiasContext,
  223. LONG lFlags,
  224. LONG *plDevErrVal );
  225. STDMETHOD(drvAnalyzeItem)(THIS_
  226. BYTE *pWiasContext,
  227. LONG lFlags,
  228. LONG *plDevErrVal);
  229. STDMETHOD(drvDeleteItem)(THIS_
  230. BYTE *pWiasContext,
  231. LONG lFlags,
  232. LONG *plDevErrVal);
  233. STDMETHOD(drvFreeDrvItemContext)(THIS_
  234. LONG lFlags,
  235. BYTE *pSpecContext,
  236. LONG *plDevErrVal);
  237. STDMETHOD(drvGetCapabilities)(THIS_
  238. BYTE *pWiasContext,
  239. LONG ulFlags,
  240. LONG *pcelt,
  241. WIA_DEV_CAP_DRV **ppCapabilities,
  242. LONG *plDevErrVal);
  243. STDMETHOD(drvGetWiaFormatInfo)(THIS_
  244. BYTE *pWiasContext,
  245. LONG ulFlags,
  246. LONG *pcelt,
  247. WIA_FORMAT_INFO **ppwfi,
  248. LONG *plDevErrVal);
  249. STDMETHOD(drvNotifyPnpEvent)(THIS_
  250. const GUID *pEventGUID,
  251. BSTR bstrDeviceID,
  252. ULONG ulReserved );
  253. STDMETHOD(drvUnInitializeWia)(THIS_
  254. BYTE*);
  255. //
  256. // Public helper methods:
  257. //
  258. HRESULT CreateItemFromFileName(
  259. LONG FolderType,
  260. PTCHAR pszPath,
  261. PTCHAR pszName,
  262. IWiaDrvItem **ppNewFolder);
  263. IWiaDrvItem *GetDrvItemRoot(VOID);
  264. BOOL IsInitialized(VOID);
  265. BOOL IsValid(VOID);
  266. private:
  267. //
  268. // Private helper methods:
  269. //
  270. HRESULT InitImageInformation(
  271. BYTE *,
  272. IRCAM_IMAGE_CONTEXT *,
  273. LONG *);
  274. HRESULT EnumDiskImages(
  275. IWiaDrvItem *pRootFile,
  276. TCHAR *pwszPath );
  277. HRESULT CamLoadPicture(
  278. IRCAM_IMAGE_CONTEXT *pCameraImage,
  279. MINIDRV_TRANSFER_CONTEXT *pDataTransCtx,
  280. LONG *plDevErrVal );
  281. HRESULT CamLoadPictureCB(
  282. IRCAM_IMAGE_CONTEXT *pCameraImage,
  283. MINIDRV_TRANSFER_CONTEXT *pDataTransCtx,
  284. LONG *plDevErrVal );
  285. HRESULT CamGetPictureInfo(
  286. IRCAM_IMAGE_CONTEXT *pCameraImage,
  287. CAMERA_PICTURE_INFO *pPictureInfo );
  288. HRESULT CamLoadThumbnail( IN IRCAM_IMAGE_CONTEXT *pIrCamContext,
  289. OUT BYTE **ppThumbnail,
  290. OUT LONG *pThumbSize );
  291. HRESULT CamDeletePicture( IRCAM_IMAGE_CONTEXT *pIrCamContext );
  292. HRESULT CamBuildImageTree(CAMERA_STATUS *,IWiaDrvItem **);
  293. HRESULT CamOpenCamera(CAMERA_STATUS *);
  294. HRESULT BuildDeviceItemTree(LONG *plDevErrVal);
  295. HRESULT DeleteDeviceItemTree(LONG *plDevErrVal);
  296. HRESULT InitDeviceProperties(BYTE *, LONG *plDevErrVal);
  297. void InitializeCapabilities();
  298. public:
  299. DWORD StartEventMonitorThread();
  300. DWORD StartIrTranPThread();
  301. DWORD StopIrTranPThread();
  302. public:
  303. IrUsdDevice(LPUNKNOWN punkOuter);
  304. HRESULT PrivateInitialize();
  305. ~IrUsdDevice();
  306. VOID RunNotifications(VOID);
  307. };
  308. inline IWiaDrvItem *IrUsdDevice::GetDrvItemRoot(VOID)
  309. {
  310. return m_pIDrvItemRoot;
  311. }
  312. inline BOOL IrUsdDevice::IsValid(VOID)
  313. {
  314. return m_fValid;
  315. }
  316. inline BOOL IrUsdDevice::IsInitialized(VOID)
  317. {
  318. return (m_bstrRootFullItemName != NULL);
  319. }
  320. typedef IrUsdDevice *PIrUsdDevice;
  321. HRESULT SetItemSize(BYTE*);
  322. //
  323. // Syncronization mechanisms
  324. //
  325. #define ENTERCRITICAL DllEnterCrit(void);
  326. #define LEAVECRITICAL DllLeaveCrit(void);
  327. // Device constants:
  328. const LEN_INQUIRE_BUTTON = 8;
  329. const BYTE INQUIRE_BUTTON[LEN_INQUIRE_BUTTON + 1] = "INQUIREB";
  330. const LEN_INQUIRE_BUTTON_READ = 10;
  331. const LEN_CLEAR_BUTTON = 5;
  332. const BYTE CLEAR_BUTTON[LEN_CLEAR_BUTTON + 1] = "CLRBT";
  333. const LEN_CURRENT_ERROR = 7;
  334. const BYTE CURRENT_ERROR[LEN_CURRENT_ERROR + 1] = "CURERR";
  335. const LEN_DIAGS = 5;
  336. const BYTE TURN_ON_LAMP[LEN_DIAGS + 1] = "LAMPO";
  337. const BYTE TURN_OFF_LAMP[LEN_DIAGS + 1] = "LAMPF";
  338. const BYTE SELF_TEST[LEN_DIAGS + 1] = "SELFT";
  339. const BYTE STATUS_STRING[LEN_DIAGS + 1] = "STATS";
  340. BOOL
  341. _stdcall CameraEventDlgProc(
  342. HWND hDlg,
  343. unsigned message,
  344. DWORD wParam,
  345. LONG lParam );
  346. typedef struct _CAM_EVENT
  347. {
  348. PTCHAR pszEvent;
  349. const GUID *pguid;
  350. } CAM_EVENT,*PCAM_EVENT;
  351. //
  352. // Useful helper functions:
  353. //
  354. extern int LoadStringResource( IN HINSTANCE hInst,
  355. IN UINT uID,
  356. OUT WCHAR *pwszBuff,
  357. IN int iBuffMax );