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.

380 lines
15 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: drvwrap.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ByronC
  10. *
  11. * DATE: 6 Nov, 2000
  12. *
  13. * DESCRIPTION:
  14. * Declarations and definitions for the WIA driver wrapper class.
  15. * It faciliates JIT loading/unloading of drivers and provides an extra layer
  16. * of abstraction for WIA server components - they don't deal directly with
  17. * driver interfaces. This is to make us more robust and implement smart
  18. * driver handling.
  19. *
  20. *******************************************************************************/
  21. //
  22. // Device types, Copied from stipriv.h
  23. //
  24. #define HEL_DEVICE_TYPE_WDM 1
  25. #define HEL_DEVICE_TYPE_PARALLEL 2
  26. #define HEL_DEVICE_TYPE_SERIAL 3
  27. //
  28. // "Internal" device states. This is used to mark what state we think the device
  29. // is in, mainly to tell the difference between active and inactive devices.
  30. // We need to mark this state in case it changes, so we can generate the
  31. // appropriate event (e.g. if state changes from inactive to active, we'd want to
  32. // generate a connect event).
  33. // NOTE: If any flags get added here, be sure to update the
  34. // MapCMStatusToDeviceState(..) function in wiadevman.cpp to carry over any needed
  35. // bits from the old state to the new one.
  36. //
  37. #define DEV_STATE_DISABLED 0x00000001
  38. #define DEV_STATE_REMOVED 0x00000002
  39. #define DEV_STATE_ACTIVE 0x00000004
  40. #define DEV_STATE_CON_EVENT_WAS_THROWN 0x00000008
  41. //
  42. // "Internal" device types. Notice that mass storage cameras are represented
  43. // differently to other mass storage devices. These "normal" mass storage
  44. // devices (like card readers), are marked with the INTERNAL_DEV_TYPE_VOL
  45. // flag, whereas the MSC cameras are marked with INTERNAL_DEV_TYPE_MSC_CAMERA.
  46. //
  47. #define INTERNAL_DEV_TYPE_REAL 0x00000001
  48. #define INTERNAL_DEV_TYPE_VOL 0x00000002
  49. #define INTERNAL_DEV_TYPE_INTERFACE 0x00000004
  50. #define INTERNAL_DEV_TYPE_WIA 0x00000010
  51. #define INTERNAL_DEV_TYPE_LOCAL 0x00000020
  52. #define INTERNAL_DEV_TYPE_MSC_CAMERA 0x00000040
  53. //
  54. // This struct is a member of CDrvWrapper object
  55. //
  56. typedef struct _DEVICE_INFO {
  57. // Indicates whether the information in this struct is valid. For example,
  58. // if we failed to read wszPortName, we would mark this as invalid.
  59. // wszDeviceInternalName is always assumed to be valid.
  60. BOOL bValid;
  61. // PnP ID for this device
  62. //WCHAR* wszPnPId;
  63. // Alternate Device ID, e.g. for volumes, it will be the mount point. For most
  64. // real WIA devices, this will be NULL.
  65. WCHAR* wszAlternateID;
  66. // State of the device to indicate enabled/disabled, plugged in/unplugged etc.
  67. DWORD dwDeviceState;
  68. // Type of the hardware imaging device
  69. STI_DEVICE_TYPE DeviceType;
  70. // Internal Device type
  71. DWORD dwInternalType;
  72. // Lock Holding Time - Only used for those drivers who want "cached" locking
  73. DWORD dwLockHoldingTime;
  74. // Poll Interval
  75. DWORD dwPollTimeout;
  76. // User disable notifications
  77. DWORD dwDisableNotifications;
  78. // Set of capabilities flags
  79. STI_USD_CAPS DeviceCapabilities;
  80. // This includes bus type
  81. DWORD dwHardwareConfiguration;
  82. // Device identifier for reference when creating device object
  83. WCHAR* wszUSDClassId;
  84. // Device identifier for reference when creating device object
  85. WCHAR* wszDeviceInternalName;
  86. // Remote Device identifier for reference when creating remote device object for WIA
  87. WCHAR* wszDeviceRemoteName;
  88. // Vendor description string
  89. WCHAR* wszVendorDescription;
  90. // Device description , provided by vendor
  91. WCHAR* wszDeviceDescription;
  92. // String , representing port on which device is accessible.
  93. WCHAR* wszPortName;
  94. // Control panel propery provider
  95. WCHAR* wszPropProvider;
  96. // Local specific ("friendly") name of the device, mainly used for showing in the UI
  97. WCHAR* wszLocalName;
  98. // Name of server for this device - WIA only entry
  99. WCHAR* wszServer;
  100. // Baud rate - Serial devices only
  101. WCHAR* wszBaudRate;
  102. // UI CLSID
  103. WCHAR* wszUIClassId;
  104. // SP_DEVINFO_DATA which uniquely identifies this device in WIA dev man's info set
  105. // Instead of storing this, we could store interface name instead?
  106. SP_DEVINFO_DATA spDevInfoData;
  107. // SP_DEVICE_INTERFACE_DATA which uniquely identifies this device in WIA dev man's info set
  108. // Same as above, except for interfaces devices instead of devnoe devices
  109. SP_DEVICE_INTERFACE_DATA spDevInterfaceData;
  110. } DEVICE_INFO, *PDEVICE_INFO;
  111. //
  112. // This class is a wrapper for the USD (a similar idea to IStiDevice on STI
  113. // client-side). This provides a layer of abstraction for the higher level
  114. // classes, so that they don't deal with direct USD Insterfaces. There are
  115. // several advantages to this:
  116. // 1. It provides for greater stability. If the driver goes away, we
  117. // cannot always notify components that rely on talking to the USD that
  118. // it is no longer present or valid. However, by making all USD access go
  119. // through this wrapper, we are guaranteed that when the USD is gone,
  120. // all components which attempt to use it will get the appropriate
  121. // error retunred by the wrapper.
  122. // 2. It provides greater flexibility. For example, this class can
  123. // load/unload the corresponding USD on the fly, providing for JIT
  124. // loading. The higher level classes don't worry about such details;
  125. // they simply use the wrapper. The wrapper will then check whether the
  126. // driver is already loaded, and if not, will take the appropriate steps.
  127. //
  128. class CDrvWrap : public IUnknown {
  129. public:
  130. CDrvWrap();
  131. ~CDrvWrap();
  132. HRESULT Initialize();
  133. //
  134. // IUnknown methods. Note: this class is not a real COM object! It does not
  135. // follow any of the COM rules for life-time control (e.g. it will not destroy itself
  136. // if ref count is 0).
  137. //
  138. HRESULT _stdcall QueryInterface(
  139. const IID& iid,
  140. void** ppv);
  141. ULONG _stdcall AddRef(void);
  142. ULONG _stdcall Release(void);
  143. HRESULT LoadInitDriver(HKEY hKeyDeviceParams = NULL); // This will load and initialize the driver
  144. // enabling it for use
  145. HRESULT UnLoadDriver(); // This releases the USD interface pointers
  146. // and unloads the driver
  147. BOOL IsValid(); // Valid means that we call makes calls down to driver.
  148. // This may still be true even if driver is not loaded. It will
  149. // only be false if we know that driver calls will fail even if
  150. // driver was loaded (e.g. USB device was unplugged)
  151. BOOL IsDriverLoaded(); // Indicates whether the driver is loaded and initialized
  152. BOOL IsWiaDevice(); // Indicates whether this driver is WIA capable
  153. BOOL IsWiaDriverLoaded();// Indicates whether this driver's IWiaMiniDrv interface is valid
  154. BOOL IsPlugged(); // Indicates whether the device is currently plugged in
  155. BOOL IsVolumeDevice(); // Indicates whether this is one of our volume devices
  156. BOOL PrepForUse( // This method is called before calling down to the driver. It
  157. BOOL bForWiaCall, // ensures the driver is loaded and initalized appropriately.
  158. IWiaItem *pItem = NULL); // TDB: pItem parameter is no longer needed
  159. //
  160. // Accessor methods
  161. //
  162. WCHAR* getPnPId();
  163. WCHAR* getDeviceId();
  164. DWORD getLockHoldingTime();
  165. DWORD getGenericCaps();
  166. DWORD getPollTimeout();
  167. DWORD getDisableNotificationsValue();
  168. DWORD getHWConfig();
  169. DWORD getDeviceState();
  170. HRESULT setDeviceState(DWORD dwNewState);
  171. DEVICE_INFO* getDevInfo();
  172. HRESULT setDevInfo(
  173. DEVICE_INFO *pInfo);
  174. ULONG getInternalType();
  175. VOID setJITLoading(BOOL bJITLoading);
  176. BOOL getJITLoading();
  177. LONG getWiaClientCount();
  178. BOOL wasConnectEventThrown();
  179. VOID setConnectEventState(BOOL bEventState);
  180. //
  181. // Wrapper methods for IStiUSD
  182. //
  183. HRESULT STI_Initialize(
  184. IStiDeviceControl *pHelDcb,
  185. DWORD dwStiVersion,
  186. HKEY hParametersKey);
  187. HRESULT STI_GetCapabilities(
  188. STI_USD_CAPS *pDevCaps);
  189. HRESULT STI_GetStatus(
  190. STI_DEVICE_STATUS *pDevStatus);
  191. HRESULT STI_GetNotificationData(
  192. STINOTIFY *lpNotify);
  193. HRESULT STI_SetNotificationHandle(
  194. HANDLE hEvent);
  195. HRESULT STI_DeviceReset();
  196. HRESULT STI_Diagnostic(
  197. STI_DIAG *pDiag);
  198. HRESULT STI_LockDevice();
  199. HRESULT STI_UnLockDevice();
  200. HRESULT STI_Escape(
  201. STI_RAW_CONTROL_CODE EscapeFunction,
  202. LPVOID lpInData,
  203. DWORD cbInDataSize,
  204. LPVOID pOutData,
  205. DWORD dwOutDataSize,
  206. LPDWORD pdwActualData);
  207. //
  208. // Wrapper methods for IWiaMiniDrv
  209. //
  210. HRESULT WIA_drvInitializeWia(
  211. BYTE *pWiasContext,
  212. LONG lFlags,
  213. BSTR bstrDeviceID,
  214. BSTR bstrRootFullItemName,
  215. IUnknown *pStiDevice,
  216. IUnknown *pIUnknownOuter,
  217. IWiaDrvItem **ppIDrvItemRoot,
  218. IUnknown **ppIUnknownInner,
  219. LONG *plDevErrVal);
  220. HRESULT WIA_drvGetDeviceErrorStr(
  221. LONG lFlags,
  222. LONG lDevErrVal,
  223. LPOLESTR *ppszDevErrStr,
  224. LONG *plDevErr);
  225. HRESULT WIA_drvDeviceCommand(
  226. BYTE *pWiasContext,
  227. LONG lFlags,
  228. const GUID *plCommand,
  229. IWiaDrvItem **ppWiaDrvItem,
  230. LONG *plDevErrVal);
  231. HRESULT WIA_drvAcquireItemData(
  232. BYTE *pWiasContext,
  233. LONG lFlags,
  234. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  235. LONG *plDevErrVal);
  236. HRESULT WIA_drvInitItemProperties(
  237. BYTE *pWiasContext,
  238. LONG lFlags,
  239. LONG *plDevErrVal);
  240. HRESULT WIA_drvValidateItemProperties(
  241. BYTE *pWiasContext,
  242. LONG lFlags,
  243. ULONG nPropSpec,
  244. const PROPSPEC *pPropSpec,
  245. LONG *plDevErrVal);
  246. HRESULT WIA_drvWriteItemProperties(
  247. BYTE *pWiasContext,
  248. LONG lFlags,
  249. PMINIDRV_TRANSFER_CONTEXT pmdtc,
  250. LONG *plDevErrVal);
  251. HRESULT WIA_drvReadItemProperties(
  252. BYTE *pWiasContext,
  253. LONG lFlags,
  254. ULONG nPropSpec,
  255. const PROPSPEC *pPropSpec,
  256. LONG *plDevErrVal);
  257. HRESULT WIA_drvLockWiaDevice(
  258. BYTE *pWiasContext,
  259. LONG lFlags,
  260. LONG *plDevErrVal);
  261. HRESULT WIA_drvUnLockWiaDevice(
  262. BYTE *pWiasContext,
  263. LONG lFlags,
  264. LONG *plDevErrVal);
  265. HRESULT WIA_drvAnalyzeItem(
  266. BYTE *pWiasContext,
  267. LONG lFlags,
  268. LONG *plDevErrVal);
  269. HRESULT WIA_drvDeleteItem(
  270. BYTE *pWiasContext,
  271. LONG lFlags,
  272. LONG *plDevErrVal);
  273. HRESULT WIA_drvFreeDrvItemContext(
  274. LONG lFlags,
  275. BYTE *pSpecContext,
  276. LONG *plDevErrVal);
  277. HRESULT WIA_drvGetCapabilities(
  278. BYTE *pWiasContext,
  279. LONG ulFlags,
  280. LONG *pcelt,
  281. WIA_DEV_CAP_DRV **ppCapabilities,
  282. LONG *plDevErrVal);
  283. HRESULT WIA_drvGetWiaFormatInfo(
  284. BYTE *pWiasContext,
  285. LONG lFlags,
  286. LONG *pcelt,
  287. WIA_FORMAT_INFO **ppwfi,
  288. LONG *plDevErrVal);
  289. HRESULT WIA_drvNotifyPnpEvent(
  290. const GUID *pEventGUID,
  291. BSTR bstrDeviceID,
  292. ULONG ulReserved);
  293. HRESULT WIA_drvUnInitializeWia(
  294. BYTE *pWiasContext);
  295. private:
  296. HRESULT CreateDeviceControl(); // This method attempts to create a new IStiDevice control to
  297. // hand down to the driver. This object is released in
  298. // UnloadDriver
  299. HRESULT InternalClear(); // This method clears and frees internal data members, so that the
  300. // state of the object is the same as if it was just created and initialized
  301. HRESULT ReportMiniDriverError( // This method translates the a driver error code into an error string
  302. LONG lDevErr, // and writes it to the log.
  303. LPOLESTR pszWhat);
  304. HINSTANCE m_hDriverDLL; // Handle to driver's DLL, so we can manually unload
  305. HANDLE m_hInternalMutex; // Internal sync object - currently unused
  306. DEVICE_INFO *m_pDeviceInfo; // Internal Device information cache
  307. IUnknown *m_pUsdIUnknown; // USD's IUnknown
  308. IStiUSD *m_pIStiUSD; // USD's IStiUSD
  309. IWiaMiniDrv *m_pIWiaMiniDrv; // USD's IWiaMiniDrv
  310. IStiDeviceControl *m_pIStiDeviceControl; // Device control handed down to USD during initialize
  311. BOOL m_bJITLoading; // Indicates whether driver should be loaded JIT
  312. LONG m_lWiaTreeCount; // Keeps track of outstanding App. Item trees (i.e. app.
  313. // connections). Useful for JIT.
  314. BOOL m_bPreparedForUse; // Indicates whether driver is ready for use
  315. BOOL m_bUnload; // Indicates whether driver should be unloaded. Used for JIT,
  316. // and is set when it has been determined that the driver is no
  317. // longer in use (inside WIA_drvUnInitializeWia and is checked
  318. // by WIA_drvUnlockWiaDevice).
  319. };