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.

399 lines
10 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: DevMgr.h
  6. *
  7. * VERSION: 2.0
  8. *
  9. * DATE: May 18, 1999
  10. *
  11. * DESCRIPTION:
  12. * Declarations and definitions for the WIA device manager object.
  13. *
  14. *******************************************************************************/
  15. //
  16. // Constants used by Event Notifier
  17. //
  18. #ifdef UNICODE
  19. #define REG_PATH_STILL_IMAGE_CLASS \
  20. L"System\\CurrentControlSet\\Control\\Class\\{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}"
  21. #define REG_PATH_STILL_IMAGE_CONTROL \
  22. L"System\\CurrentControlSet\\Control\\StillImage"
  23. #else
  24. #define REG_PATH_STILL_IMAGE_CLASS \
  25. "System\\CurrentControlSet\\Services\\Class\\Image"
  26. #define REG_PATH_STILL_IMAGE_CONTROL \
  27. "System\\CurrentControlSet\\Control\\StillImage"
  28. #endif
  29. #define NAME_VAL TEXT("Name")
  30. #define DESC_VAL TEXT("Desc")
  31. #define ICON_VAL TEXT("Icon")
  32. #define CMDLINE_VAL TEXT("Cmdline")
  33. #define DEFAULT_HANDLER_VAL TEXT("DefaultHandler")
  34. //
  35. // Node used to contain information about a specific callback
  36. //
  37. typedef struct __EventDestNode__
  38. {
  39. //
  40. // Linking elements
  41. //
  42. struct __EventDestNode__ *pPrev;
  43. struct __EventDestNode__ *pNext;
  44. //
  45. // Event callback related fields
  46. //
  47. IWiaEventCallback *pIEventCB;
  48. BSTR bstrDeviceID;
  49. GUID iidEventGUID;
  50. GUID ClsID;
  51. // Never returned to client in enumeration
  52. TCHAR tszCommandline[MAX_PATH];
  53. BSTR bstrName;
  54. BSTR bstrDescription;
  55. BSTR bstrIcon;
  56. FILETIME timeStamp;
  57. BOOL bDeviceDefault;
  58. } EventDestNode, *PEventDestNode;
  59. /**************************************************************************\
  60. * WIA_EVENT_THREAD_INFO
  61. *
  62. * Information for event callback thread
  63. *
  64. * Arguments:
  65. *
  66. *
  67. *
  68. *
  69. * History:
  70. *
  71. * 4/9/1999 Original Version
  72. *
  73. \**************************************************************************/
  74. typedef struct __WIAEventThreadInfo__ {
  75. GUID eventGUID;
  76. BSTR bstrEventDescription;
  77. BSTR bstrDeviceID;
  78. BSTR bstrDeviceDescription;
  79. DWORD dwDeviceType;
  80. BSTR bstrFullItemName;
  81. ULONG ulEventType;
  82. ULONG ulReserved;
  83. IWiaEventCallback *pIEventCB;
  84. } WIAEventThreadInfo, *PWIAEventThreadInfo;
  85. //
  86. // Implementation of IEventNotifier interface
  87. //
  88. // Note : the class factory for CEventNotifier must be on the same
  89. // thread as CWiaDevMgr.
  90. //
  91. //
  92. // Flags to use when searching for callbacks
  93. //
  94. // Ignore STI proxy event matches , look only for exact match
  95. #define FLAG_EN_FINDCB_EXACT_MATCH 0x0001
  96. class CEventNotifier
  97. {
  98. friend class CWiaDevMgr;
  99. friend class CWiaInterfaceEvent;
  100. public :
  101. static HRESULT CreateInstance(const IID& iid, void** ppv);
  102. //
  103. // Constructor and Destructor
  104. //
  105. CEventNotifier();
  106. ~CEventNotifier();
  107. VOID LinkNode(PEventDestNode);
  108. VOID UnlinkNode(PEventDestNode);
  109. //
  110. // Only the WIA device manager is allowed to use this method
  111. //
  112. HRESULT RegisterEventCallback(
  113. LONG lFlags,
  114. BSTR bstrDeviceID,
  115. const GUID *pEventGUID,
  116. IWiaEventCallback *pIWIAEventCallback,
  117. IUnknown **ppIEventObj);
  118. HRESULT RegisterEventCallback(
  119. LONG lFlags,
  120. BSTR bstrDeviceID,
  121. const GUID *pEventGUID,
  122. const GUID *pClsID,
  123. LPCTSTR ptszCommandline,
  124. BSTR bstrName,
  125. BSTR bstrDescription,
  126. BSTR bstrIcon);
  127. //
  128. // Notify a STI event
  129. //
  130. HRESULT NotifySTIEvent(
  131. PWIANOTIFY pWiaNotify,
  132. ULONG ulEventType,
  133. BSTR bstrFullItemName);
  134. HRESULT NotifyVolumeEvent(
  135. PWIANOTIFY_VOLUME pWiaNotifyVolume);
  136. //
  137. // Fire the event
  138. //
  139. HRESULT NotifyEvent(
  140. LONG lReason,
  141. LONG lStatus,
  142. LONG lPercentComplete,
  143. const GUID *pEventGUID,
  144. BSTR bstrDeviceID,
  145. LONG lReserved);
  146. //
  147. // Restore all the persistent Event Callbacks
  148. //
  149. HRESULT RestoreAllPersistentCBs();
  150. //
  151. // Build enumerator for specific device's persistent handler
  152. //
  153. HRESULT CreateEnumEventInfo(
  154. BSTR bstrDeviceID,
  155. const GUID *pEventGUID,
  156. IEnumWIA_DEV_CAPS **ppIEnumDevCap);
  157. //
  158. // Find the total number of persistent handlers and the default one
  159. //
  160. HRESULT GetNumPersistentHandlerAndDefault(
  161. BSTR bstrDeviceID,
  162. const GUID *pEventGUID,
  163. ULONG *pulNumHandlers,
  164. EventDestNode **ppDefaultNode);
  165. //
  166. // Restore specific devices' persistent Event Callbacks
  167. //
  168. HRESULT RestoreDevPersistentCBs(
  169. HKEY hParentOfEventKey);
  170. private :
  171. //
  172. // Utility functions
  173. //
  174. HRESULT RegisterEventCB(
  175. BSTR bstrDeviceID,
  176. const GUID *pEventGUID,
  177. IWiaEventCallback *pIWiaEventCallback,
  178. IUnknown **pEventObj);
  179. HRESULT RegisterEventCB(
  180. BSTR bstrDeviceID,
  181. const GUID *pEventGUID,
  182. const GUID *pClsID,
  183. LPCTSTR ptszCommandline,
  184. BSTR bstrName,
  185. BSTR bstrDescription,
  186. BSTR bstrIcon,
  187. FILETIME &fileTime,
  188. BOOL bIsDefault = FALSE);
  189. HRESULT UnregisterEventCB(PEventDestNode);
  190. HRESULT UnregisterEventCB(
  191. BSTR bstrDeviceID,
  192. const GUID *pEventGUID,
  193. const GUID *pClsID,
  194. BOOL *pbUnRegCOMServer);
  195. PEventDestNode FindEventCBNode(
  196. UINT uiFlags,
  197. BSTR bstrDeviceID,
  198. const GUID *pEventGUID,
  199. IWiaEventCallback *pIWiaEventCallback);
  200. PEventDestNode FindEventCBNode(
  201. UINT uiFlags,
  202. BSTR bstrDeviceID,
  203. const GUID *pEventGUID,
  204. const GUID *pClsID);
  205. HRESULT FindCLSIDForCommandline(
  206. LPCTSTR ptszCommandline,
  207. CLSID *pClsID);
  208. HRESULT SavePersistentEventCB(
  209. BSTR bstrDeviceID,
  210. const GUID *pEventGUID,
  211. const GUID *pClsid,
  212. LPCTSTR ptszCommandline,
  213. BSTR bstrName,
  214. BSTR bstrDescription,
  215. BSTR bstrIcon,
  216. BOOL *pbCreatedKey,
  217. ULONG *pulNumExistingHandlers,
  218. BOOL bMakeDefault = FALSE);
  219. HRESULT DelPersistentEventCB(
  220. BSTR bstrDeviceID,
  221. const GUID *pEventGUID,
  222. const GUID *pClsid,
  223. BOOL bUnRegCOMServer);
  224. HRESULT FindEventByGUID(
  225. BSTR bstrDeviceID,
  226. const GUID *pEventGUID,
  227. HKEY *phEventKey);
  228. //
  229. // Fire an event asynchronously
  230. //
  231. HRESULT FireEventAsync(
  232. PWIAEventThreadInfo pMasterInfo);
  233. //
  234. // Start the callback program
  235. //
  236. HRESULT StartCallbackProgram(
  237. EventDestNode *pCBNode,
  238. PWIAEventThreadInfo pMasterInfo);
  239. private :
  240. ULONG m_ulRef;
  241. //
  242. // Double-linked list containing all the parties interested in Event CB
  243. //
  244. EventDestNode *m_pEventDestNodes;
  245. };
  246. /**************************************************************************\
  247. * CWiaInterfaceEvent
  248. *
  249. * This object is created when an application calls
  250. * RegisterForEventInterface. When this object is released, the
  251. * registered event is unregistered.
  252. *
  253. * History:
  254. *
  255. * 5/18/1999 Original Version
  256. *
  257. \**************************************************************************/
  258. class CWiaInterfaceEvent : public IUnknown
  259. {
  260. //
  261. // IUnknown methods
  262. //
  263. public:
  264. HRESULT _stdcall QueryInterface(const IID& iid, void** ppv);
  265. ULONG _stdcall AddRef();
  266. ULONG _stdcall Release();
  267. //
  268. // private function
  269. //
  270. CWiaInterfaceEvent(PEventDestNode);
  271. ~CWiaInterfaceEvent();
  272. private:
  273. //
  274. // member elements
  275. //
  276. ULONG m_cRef;
  277. PEventDestNode m_pEventDestNode;
  278. };
  279. /**************************************************************************\
  280. * CWiaEventContext
  281. *
  282. * This object is created when an event is queued as scheduler item
  283. *
  284. * History:
  285. *
  286. * 5/18/1999 Original Version
  287. *
  288. \**************************************************************************/
  289. class CWiaEventContext : public IUnknown
  290. {
  291. public:
  292. //
  293. // IUnknown methods
  294. //
  295. HRESULT _stdcall QueryInterface(const IID& iid, void** ppv);
  296. ULONG _stdcall AddRef();
  297. ULONG _stdcall Release();
  298. //
  299. // Constructor /Destructor
  300. //
  301. CWiaEventContext(
  302. BSTR bstrDeviceID,
  303. const GUID *pGuidEvent,
  304. BSTR bstrFullItemName);
  305. ~CWiaEventContext();
  306. public:
  307. //
  308. // Data members
  309. //
  310. ULONG m_cRef;
  311. BSTR m_bstrDeviceId;
  312. GUID m_guidEvent;
  313. BSTR m_bstrFullItemName;
  314. ULONG m_ulEventType;
  315. };
  316. extern CEventNotifier g_eventNotifier;