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.

222 lines
6.5 KiB

  1. // DeviceConsole.h : Declaration of the CDeviceConsole
  2. #ifndef __DEVICECONSOLE_H_
  3. #define __DEVICECONSOLE_H_
  4. #include "resource.h" // main symbols
  5. #define UM_POSTEVENTS (WM_USER+101)
  6. #define UM_POSTGLOBALEVENT (WM_USER+102)
  7. class CEventsDispEntry;
  8. class CEventsMap;
  9. class CDispHandlerEvent;
  10. class CDispHandlerCallback;
  11. class CDispInterfaceHandlers;
  12. class CDeviceConsole;
  13. class CEventsDispPtr
  14. {
  15. private:
  16. CComQIPtr<IDispatch> m_Dispatch;
  17. public:
  18. //
  19. // I have to use const due to way STL works
  20. // however I need to cast away const for ref-counting
  21. // *sigh*
  22. //
  23. CEventsDispPtr(const IDispatch*p) {
  24. m_Dispatch = (IDispatch*)p;
  25. }
  26. CEventsDispPtr(const CEventsDispPtr & p) {
  27. m_Dispatch = (IDispatch*)p.m_Dispatch;
  28. }
  29. bool operator==(const CEventsDispPtr & p) const {
  30. return m_Dispatch == p.m_Dispatch;
  31. }
  32. HRESULT Invoke(UINT argc,VARIANT * argv) {
  33. if(!m_Dispatch) {
  34. return S_FALSE;
  35. }
  36. DISPPARAMS DispParams;
  37. UINT Err;
  38. HRESULT hr;
  39. DispParams.cArgs = argc;
  40. DispParams.cNamedArgs = 0;
  41. DispParams.rgdispidNamedArgs = NULL;
  42. DispParams.rgvarg = argv;
  43. hr = m_Dispatch->Invoke(0,IID_NULL,0,DISPATCH_METHOD,&DispParams,NULL,NULL,&Err);
  44. return hr;
  45. }
  46. };
  47. //
  48. // attachEvent detachEvent operation
  49. //
  50. class CEventsDispEntry : public std::list<CEventsDispPtr>
  51. {
  52. public:
  53. HRESULT AttachEvent(LPDISPATCH pDisp,VARIANT_BOOL *pStatus);
  54. HRESULT DetachEvent(LPDISPATCH pDisp,VARIANT_BOOL *pStatus);
  55. HRESULT Invoke(UINT argc,VARIANT *argv);
  56. };
  57. class CEventsMap : public std::map<std::wstring,CEventsDispEntry>
  58. {
  59. public:
  60. HRESULT AttachEvent(LPWSTR Name,LPDISPATCH pDisp,VARIANT_BOOL *pStatus);
  61. HRESULT DetachEvent(LPWSTR Name,LPDISPATCH pDisp,VARIANT_BOOL *pStatus);
  62. HRESULT Invoke(LPWSTR Name,UINT argc,VARIANT *argv);
  63. CEventsDispEntry & LookupNc(LPWSTR Name) throw(std::bad_alloc);
  64. };
  65. //
  66. // map of interface/handle and callbacks
  67. //
  68. class CDispInterfaceHandlers
  69. {
  70. public:
  71. CDispInterfaceHandlers *m_pPrev;
  72. CDispInterfaceHandlers *m_pNext;
  73. GUID m_InterfaceClass;
  74. HDEVNOTIFY m_hNotify;
  75. CDispHandlerCallback *m_pFirstCallback;
  76. CDispHandlerCallback *m_pLastCallback;
  77. CDispHandlerEvent *m_pFirstEvent;
  78. CDispHandlerEvent *m_pLastEvent;
  79. public:
  80. CDispInterfaceHandlers() {
  81. }
  82. ~CDispInterfaceHandlers() {
  83. }
  84. };
  85. class CDispHandlerCallback
  86. {
  87. public:
  88. CDispHandlerCallback *m_pPrev;
  89. CDispHandlerCallback *m_pNext;
  90. public:
  91. CDispHandlerCallback() {
  92. }
  93. ~CDispHandlerCallback() {
  94. }
  95. virtual void DeviceEvent(CDispHandlerEvent * pEvent) = 0;
  96. };
  97. class CDispHandlerEvent
  98. {
  99. public:
  100. CDispHandlerEvent *m_pNext;
  101. BSTR m_Device;
  102. WPARAM m_Event;
  103. CDispHandlerEvent() {
  104. }
  105. ~CDispHandlerEvent() {
  106. }
  107. };
  108. typedef CWinTraits<WS_POPUP,0> CPopupWinTraits;
  109. class CDevConNotifyWindow :
  110. public CWindowImpl<CDevConNotifyWindow,CWindow,CPopupWinTraits>
  111. {
  112. public:
  113. CDeviceConsole *m_pDevCon;
  114. public:
  115. CDevConNotifyWindow() {
  116. m_pDevCon = NULL;
  117. }
  118. BEGIN_MSG_MAP(CDevConNotifyWindow)
  119. MESSAGE_HANDLER(WM_DEVICECHANGE, OnDeviceChange)
  120. MESSAGE_HANDLER(UM_POSTEVENTS, OnPostEvents)
  121. MESSAGE_HANDLER(UM_POSTGLOBALEVENT, OnPostGlobalEvent)
  122. END_MSG_MAP()
  123. LRESULT OnDeviceChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  124. LRESULT OnPostEvents(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  125. LRESULT OnPostGlobalEvent(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  126. };
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CDeviceConsole
  129. class ATL_NO_VTABLE CDeviceConsole :
  130. public CComObjectRootEx<CComSingleThreadModel>,
  131. public CComCoClass<CDeviceConsole, &CLSID_DeviceConsole>,
  132. public IDispatchImpl<IDeviceConsole, &IID_IDeviceConsole, &LIBID_DEVCON2Lib>
  133. {
  134. public:
  135. VARIANT_BOOL RebootRequired;
  136. CEventsMap m_Events;
  137. CDevConNotifyWindow *m_pNotifyWindow;
  138. CDispInterfaceHandlers *m_pFirstWatch;
  139. CDispInterfaceHandlers *m_pLastWatch;
  140. CDeviceConsole()
  141. {
  142. m_pNotifyWindow = NULL;
  143. m_pFirstWatch = NULL;
  144. m_pLastWatch = NULL;
  145. RebootRequired = VARIANT_FALSE;
  146. }
  147. ~CDeviceConsole()
  148. {
  149. if(m_pNotifyWindow) {
  150. m_pNotifyWindow->DestroyWindow();
  151. delete m_pNotifyWindow;
  152. }
  153. }
  154. CDevConNotifyWindow *NotifyWindow();
  155. DECLARE_REGISTRY_RESOURCEID(IDR_DEVICECONSOLE)
  156. DECLARE_PROTECT_FINAL_CONSTRUCT()
  157. BEGIN_COM_MAP(CDeviceConsole)
  158. COM_INTERFACE_ENTRY(IDeviceConsole)
  159. COM_INTERFACE_ENTRY(IDispatch)
  160. END_COM_MAP()
  161. // IDeviceConsole
  162. public:
  163. void FireGlobalEvent(WPARAM wParam);
  164. STDMETHOD(AttachEvent)(/*[in]*/ BSTR eventName,/*[in]*/ LPDISPATCH handler,/*[out, retval]*/ VARIANT_BOOL *pOk);
  165. STDMETHOD(DetachEvent)(/*[in]*/ BSTR eventName,/*[in]*/ LPDISPATCH handler,/*[out, retval]*/ VARIANT_BOOL *pOk);
  166. STDMETHOD(StringList)(/*[in]*/ VARIANT from,/*[out,retval]*/ LPDISPATCH *pDest);
  167. STDMETHOD(DevicesByInstanceIds)(/*[in]*/ VARIANT InstanceIdList,/*[in,optional]*/ VARIANT machine,/*[out,retval]*/ LPDISPATCH *pDevList);
  168. STDMETHOD(DevicesByInterfaceClasses)(/*[in]*/ VARIANT InterfaceClasses,/*[in,optional]*/ VARIANT machine,/*[out,retval]*/ LPDISPATCH * pDevices);
  169. STDMETHOD(DevicesBySetupClasses)(/*[in]*/ VARIANT SetupClasses,/*[in,optional]*/ VARIANT flags,/*[in,optional]*/ VARIANT machine,/*[out,retval]*/ LPDISPATCH * pDevices);
  170. STDMETHOD(CreateEmptySetupClassList)(/*[in,optional]*/ VARIANT machine,/*[out,retval]*/ LPDISPATCH * pResult);
  171. STDMETHOD(SetupClasses)(/*[in,optional]*/ VARIANT match,/*[in,optional]*/ VARIANT machine,/*[retval,out]*/ LPDISPATCH *pDevices);
  172. STDMETHOD(get_RebootRequired)(/*[out, retval]*/ VARIANT_BOOL *pVal);
  173. STDMETHOD(put_RebootRequired)(/*[in]*/ VARIANT_BOOL newVal);
  174. STDMETHOD(RebootReasonHardware)();
  175. STDMETHOD(CheckReboot)();
  176. STDMETHOD(UpdateDriver)(/*[in]*/ BSTR infname,/*[in]*/ BSTR hwid,/*[in,optional]*/ VARIANT flags);
  177. STDMETHOD(CreateEmptyDeviceList)(/*[in,optional]*/ VARIANT machine,/*[retval,out]*/ LPDISPATCH *pDevices);
  178. STDMETHOD(AllDevices)(/*[in]*/ VARIANT flags,/*[in]*/ VARIANT machine,/*[retval,out]*/ LPDISPATCH *pDevices);
  179. //
  180. // helpers
  181. //
  182. HRESULT BuildDeviceList(HDEVINFO hDevInfo, LPDISPATCH *pDevices);
  183. };
  184. #endif //__DEVICECONSOLE_H_