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.

238 lines
11 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: wiadevman.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 device manager class.
  15. * It controls the enumeration of devices, the internal device list, adding
  16. * removing of devices from this list (PnP initiated) and implements the
  17. * IWiaDevMgr interface.
  18. *
  19. *******************************************************************************/
  20. //
  21. // Flags used to control refreshing device list
  22. // DEV_MAN_FULL_REFRESH means throw away old infoset and get a new one.
  23. // This is not something that should happen very
  24. // often, in fact, you only really want to do it
  25. // when a device is installed/uninstalled
  26. // DEV_MAN_GEN_EVENTS means generate connect/disconnect events.
  27. // There are 2 cases where we send out CONNECT events:
  28. // 1. If device_object doesn't exist, and we we
  29. // create a new one i.e. we've noticed a new device
  30. // 2. If a device_object exists, and the device
  31. // was unplugged, and is now plugged in.
  32. // DEV_MAN_STATUS_STARTP Update service status with Start Pending
  33. //
  34. #define DEV_MAN_FULL_REFRESH 0x00000001
  35. #define DEV_MAN_GEN_EVENTS 0x00000002
  36. #define DEV_MAN_STATUS_STARTP 0x00000004
  37. //
  38. // Operational flags for ForEachDeviceInList(...)
  39. // DEV_MAN_OP_DEV_SET_FLAGS This operation is to set each ACTIVE_DEVICE's
  40. // flags.
  41. // DEV_MAN_OP_DEV_REMOVE_MATCH This operation is to remove any ACTIVE_DEVICE
  42. // matching the corresponding flags. This is
  43. // usually used to purge the device list of
  44. // devices that have been uninstalled (NOT unplugged!)
  45. //
  46. #define DEV_MAN_OP_DEV_SET_FLAGS 1
  47. #define DEV_MAN_OP_DEV_REMOVE_MATCH 2
  48. #define DEV_MAN_OP_DEV_REREAD 3
  49. #define DEV_MAN_OP_DEV_RESTORE_EVENT 4
  50. //
  51. // Flags for IsInList(...)
  52. // DEV_MAN_IN_LIST_DEV_ID Match should be made on DeviceID
  53. // DEV_MAN_IN_LIST_ALT_ID Match should be made on AlternateID
  54. //
  55. #define DEV_MAN_IN_LIST_DEV_ID 1
  56. #define DEV_MAN_IN_LIST_ALT_ID 2
  57. // NOTE: These flags are mirrored in wiadevdp.h. Any updates should be made in both places.
  58. //
  59. // Flags for enumeration. Used in GetDevInfoStgs(...) to create device lists
  60. // for WIA device enumeration
  61. // DEV_MAN_ENUM_TYPE_VOL Will enumerate our volume devices
  62. // DEV_MAN_ENUM_TYPE_INACTIVE Will enumerate inactive devices (e.g. USB
  63. // device thaat is unplugged)
  64. // DEV_MAN_ENUM_TYPE_STI Will enumerate STI only devices too
  65. // DEV_MAN_ENUM_TYPE_ALL Will enumerate all devices
  66. // DEV_MAN_ENUM_TYPE_LOCAL_ONLY Will exclude remote devices
  67. //
  68. #define DEV_MAN_ENUM_TYPE_VOL 0x00000002
  69. #define DEV_MAN_ENUM_TYPE_INACTIVE 0x00000004
  70. #define DEV_MAN_ENUM_TYPE_STI 0x00000008
  71. #define DEV_MAN_ENUM_TYPE_ALL 0x0000000F
  72. #define DEV_MAN_ENUM_TYPE_LOCAL_ONLY WIA_DEVINFO_ENUM_LOCAL // 0x00000010
  73. //
  74. // This class manages the device list. Generally, our device list works as follows:
  75. // 1. We create an infoset from SetupApis for all StillImage devices on the system.
  76. // This includes devnode and interface type devices, and disabled ones.
  77. // 2. We also enumerate volumes.
  78. // 3. For each device we find in the above two categories, we create an ACTIVE_DEVICE
  79. // object (rename to DEVICE_OBJECT?). This is essentially a place holder for that
  80. // device. It will include a CDrvWrapper object that contains all the information
  81. // we know about that device and anything needed to load the driver.
  82. // 4. Each ACTIVE_DEVICE object will decide whether the driver for its device should
  83. // be loaded on startup or JIT. If the device is not present (i.e. INACTIVE), it
  84. // is not loaded.
  85. // 5. Once we have this device list, we can enumerate active/inactive devices, load
  86. // /unload drivers when a device comes or goes etc.
  87. //
  88. class CWiaDevMan {
  89. public:
  90. //
  91. // Public methods
  92. //
  93. CWiaDevMan();
  94. ~CWiaDevMan();
  95. HRESULT Initialize();
  96. VOID GetRegistrySettings();
  97. HRESULT ReEnumerateDevices(ULONG ulFlags); // Flags indicate: GenEvents, Full Refresh.
  98. HRESULT GenerateEventForDevice(const GUID* event, ACTIVE_DEVICE *pActiveDevice);
  99. HRESULT NotifyRunningDriversOfEvent(const GUID *pEvent);
  100. ACTIVE_DEVICE* IsInList(ULONG ulFlags, const WCHAR *wszID); // Can search on DeviceID, AlternateID
  101. //
  102. // Methods for Device arrival/removal. Note that these are not for device
  103. // installation/uninstallation. When a WIA device is installed/removed, the
  104. // class installer will call us, and we will do a full refresh.
  105. //
  106. HRESULT ProcessDeviceArrival();
  107. // This is not mean device uninstallation - it is for hot-unplugging of devices
  108. HRESULT ProcessDeviceRemoval(WCHAR *wszDeviceId);
  109. // This is not mean device uninstallation
  110. HRESULT ProcessDeviceRemoval(ACTIVE_DEVICE *pActiveDevice, BOOL bGenEvent = TRUE);
  111. //
  112. // Methods for counting and enumeration
  113. //
  114. // Get number of devices. Flags are the DEV_MAN_ENUM_TYPE_XXXXX
  115. ULONG NumDevices(ULONG ulFlags);
  116. // Flags are DEV_MAN_ENUM_TYPE_XXXX
  117. HRESULT GetDevInfoStgs(ULONG ulFlags, ULONG *pulNumDevInfoStream, IWiaPropertyStorage ***pppOutputStorageArray);
  118. VOID WINAPI EnumerateActiveDevicesWithCallback(PFN_ACTIVEDEVICE_CALLBACK pfn, VOID *pContext);
  119. HRESULT ForEachDeviceInList(ULONG ulFLags, ULONG ulParam); // Do some operation for each device in the device list
  120. //
  121. // Methods for getting device information from registry
  122. //
  123. HRESULT GetDeviceValue(ACTIVE_DEVICE *pActiveDevice, WCHAR* pValueName, DWORD *pType, BYTE *pData, DWORD *cbData);
  124. HKEY GetDeviceHKey(WCHAR *wszDeviceID, WCHAR *wszSubKeyName);
  125. HKEY GetDeviceHKey(ACTIVE_DEVICE *pActiveDevice, WCHAR *wszSubKeyName);
  126. HKEY GetHKeyFromMountPoint(WCHAR *wszMountPoint);
  127. HKEY GetHKeyFromDevInfoData(SP_DEVINFO_DATA *pspDevInfoData);
  128. HKEY GetHKeyFromDevInterfaceData(SP_DEVICE_INTERFACE_DATA *pspDevInterfaceData);
  129. //
  130. // Method for setting device information to registry
  131. //
  132. HRESULT UpdateDeviceRegistry(DEVICE_INFO *pDevInfo);
  133. //
  134. // Methods for matching information PnP gives us to our actual device
  135. //
  136. WCHAR *AllocGetInterfaceNameFromDevInfo(DEVICE_INFO *pDevInfo);
  137. BOOL LookupDriverNameFromInterfaceName(LPCTSTR pszInterfaceName, StiCString *pstrDriverName);
  138. ACTIVE_DEVICE *LookDeviceFromPnPHandles(HANDLE hInterfaceHandle, HANDLE hPnPSink);
  139. //
  140. // Methods for unloading/destroying our device list
  141. //
  142. VOID UnloadAllDrivers(BOOL bForceUnload, BOOL bGenEvents);
  143. VOID DestroyDeviceList();
  144. //
  145. // Public fields
  146. //
  147. private:
  148. //
  149. // Private methods
  150. //
  151. //
  152. // Methods to create and destroy our underlying device infoset
  153. //
  154. VOID DestroyInfoSet();
  155. HRESULT CreateInfoSet();
  156. //
  157. // Methods for adding/removing devices from the list
  158. //
  159. //
  160. // AddDevice means create a new device object
  161. //
  162. HRESULT AddDevice(ULONG ulFlags, DEVICE_INFO *pInfo);
  163. //
  164. // Remove device means remove a device object from the list.
  165. // This is not the same as device disconnected - if a device is
  166. // disconnected, the inactive device may still be enumerated, therefore
  167. // it should stay in this list.
  168. //
  169. HRESULT RemoveDevice(ACTIVE_DEVICE *pActiveDevice);
  170. HRESULT RemoveDevice(DEVICE_INFO *pInfo);
  171. //
  172. // Helper methods
  173. //
  174. BOOL VolumesAreEnabled(); // Checks whether we should enable volume devices
  175. // Disabled for IA64 for now.
  176. HRESULT EnumDevNodeDevices(ULONG ulFlags); // Enumerate our devnode devices
  177. HRESULT EnumInterfaceDevices(ULONG ulFlags); // Enumerate our interface devices
  178. HRESULT EnumVolumes(ULONG ulFlags); // Enumerate volumes
  179. //
  180. // Remote device helpers
  181. //
  182. HRESULT FillRemoteDeviceStgs( // Enumerate remote devices and create a dev. info.
  183. IWiaPropertyStorage **ppRemoteDevList, // stg. for each one. Put the dev. info. pointers
  184. ULONG *pulDevices); // into caller allocated array.
  185. ULONG CountRemoteDevices(ULONG ulFlags); // Returns count for number of remote device entries.
  186. BOOL IsCorrectEnumType(ULONG ulEnumType,
  187. DEVICE_INFO *pInfo); // Checks whether a given device falls into device category specified by the enumeration flags
  188. HRESULT GenerateSafeConnectEvent(
  189. ACTIVE_DEVICE *pActiveDevice); // Only generates connect event if it has not already been done
  190. HRESULT GenerateSafeDisconnectEvent(
  191. ACTIVE_DEVICE *pActiveDevice); // Generates disconnect event and clears device's connect event flag set by GenerateSafeConnectEvent
  192. //
  193. // Static function for Shell's HW notification callback.
  194. //
  195. static VOID CALLBACK ShellHWEventAPCProc(ULONG_PTR ulpParam);
  196. //
  197. // Private fields
  198. //
  199. LIST_ENTRY m_leDeviceListHead; // List of DEVICE_OBJECTs. Currently correspond to ACTIVE_DEVICE
  200. HDEVINFO m_DeviceInfoSet; // DeviceInfoSet for real WIA devices, both DevNode type and Interface type
  201. CRIT_SECT m_csDevList; // Critical section for device list access
  202. BOOL m_bMakeVolumesVisible; // Indicates whether volume device should be included in normal device enumeration
  203. BOOL m_bVolumesEnabled; // Indicates whether we enable volumes
  204. DWORD m_dwHWCookie; // Cookie for use in unregistering for volume notifications
  205. };