ReactOS  0.4.15-dev-2720-g5ee0925
fxmessagedispatchum.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft. All rights reserved.
4 
5 Module Name:
6 
7  FxMessageDispatchUm.cpp
8 
9 Abstract:
10 
11  Implements the host process dispatcher object. See header file for
12  details.
13 
14 Author:
15 
16 
17 
18 Environment:
19 
20  User mode only
21 
22 Revision History:
23 
24 
25 
26 --*/
27 
28 #include "fxmin.hpp"
29 #include "fxldrum.h"
30 
31 extern "C"
32 {
33 #include "FxMessageDispatchUm.tmh"
34 }
35 
36 // {cba20727-0910-4a8a-aada-c31d5cf5bf20}
37 extern const GUID IID_FxMessageDispatch =
38 {0xcba20727, 0x0910, 0x4a8a, { 0xaa, 0xda, 0xc3, 0x1d, 0x5c, 0xf5, 0xbf, 0x20 }};
39 
40 //
41 // Manager functions.
42 //
47  _Out_ FxMessageDispatch ** ppWudfDispatcher
48  )
49 {
50  HRESULT hr = S_OK;
51  FxMessageDispatch * pWudfDispatcher = NULL;
53 
54  *ppWudfDispatcher = NULL;
55 
56  pWudfDispatcher = new (DriverGlobals) FxMessageDispatch(Device);
57  if (NULL == pWudfDispatcher) {
58  hr = E_OUTOFMEMORY;
60  "Memory allocation failure. Cannot create Dispatcher object.\n");
61  goto Done;
62  }
63 
64  *ppWudfDispatcher = pWudfDispatcher;
65 
66 Done:
67 
68  if (FAILED(hr)) {
69  status = Device->NtStatusFromHr(hr);
70  }
71  else {
73  }
74 
75  return status;
76 }
77 
78 //
79 // IUnknown
80 //
81 ULONG
83 {
84  LONG cRefs = InterlockedIncrement( &m_cRefs );
85 
86  //
87  // This allows host to manage the lifetime of FxDevice.
88  //
89  m_Device->ADDREF(this);
90 
91  return cRefs;
92 }
93 
94 
95 ULONG
97 {
98  LONG cRefs = InterlockedDecrement( &m_cRefs );
99 
100  if (0 == cRefs) {
101  //
102  // The lifetime of this object is controlled by FxDevice
103  // object (the container object), and not by this ref count. FxDevice
104  // will delete this object in its destructior.
105  //
106  DO_NOTHING();
107  }
108 
109  //
110  // This allows host to manage the lifetime of FxDevice. If this is the last
111  // release on FxDevice, FxDevice will e deleted and this object will be
112  // deleted as part of FxDevice destructor.
113  //
114  m_Device->RELEASE(this);
115 
116  return cRefs;
117 }
118 
119 HRESULT
121  _In_ const IID& iid,
122  _Out_ void ** ppv
123  )
124 {
125  if ( NULL == ppv ) {
126  return E_INVALIDARG;
127  }
128 
129  if ( iid == IID_IUnknown) {
130  *ppv = static_cast<IUnknown *> (this);
131  }
132  else if ( iid == IID_IFxMessageDispatch ) {
133  *ppv = static_cast<IFxMessageDispatch *> (this);
134  }
135  else if ( iid == IID_IFxMessageDispatch2 ) {
136  *ppv = static_cast<IFxMessageDispatch2 *> (this);
137  }
138  else if ( iid == IID_FxMessageDispatch ) {
139  *ppv = this;
140  }
141  else {
142  *ppv = NULL;
143  return E_NOINTERFACE;
144  }
145 
146  this->AddRef();
147  return S_OK;
148 }
149 
150 //
151 // IFxMessageDispatch
152 //
153 void
155  _In_ IWudfIrp * pIrp
156  )
157 {
158  IWudfPnpIrp * pIPnpIrp = NULL;
159 
160  HRESULT hrQI = pIrp->QueryInterface(IID_IWudfPnpIrp, (PVOID*)&pIPnpIrp);
161  FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pIPnpIrp));
162 
163  if (IRP_MJ_POWER == pIPnpIrp->GetMajorFunction()) {
165  pIrp,
166  NULL);
167  }
168  else {
170  pIrp,
171  NULL);
172  }
173 
174  SAFE_RELEASE(pIPnpIrp);
175 }
176 
177 void
179  _In_ IWudfIoIrp * pCreateIrp
180  )
181 {
183  pCreateIrp,
184  NULL);
185 }
186 
187 void
189  _In_ IWudfIoIrp * pIrp,
190  _In_opt_ IUnknown * pFxContext
191  )
192 {
194  pIrp,
195  pFxContext);
196 }
197 
198 void
200  _In_ IWudfIoIrp * pIrp,
201  _In_opt_ IUnknown * pFxContext
202  )
203 {
205 }
206 
207 void
209  _In_ IWudfIoIrp * pIrp,
210  _In_opt_ IUnknown * pFxContext
211  )
212 {
214 }
215 
216 void
218  _In_ IWudfIoIrp * pIrp,
219  _In_ IUnknown * pFxContext
220  )
221 {
223 }
224 
225 void
227  _In_ IWudfIoIrp * pIrp,
228  _In_ IUnknown * pFxContext
229  )
230 {
232 }
233 
234 void
236  _In_ IWudfIoIrp * pIrp,
237  _In_opt_ IUnknown * pFxContext
238  )
239 {
241  pIrp,
242  pFxContext);
243 }
244 
245 void
247  _In_ IWudfIoIrp * pIrp,
248  _In_opt_ IUnknown * pFxContext
249  )
250 {
252  GetDeviceObject(),
253  pIrp,
254  pFxContext
255  );
256 }
257 
258 void
260  _In_ IWudfIoIrp * pIrp,
261  _In_opt_ IUnknown * pFxContext
262  )
263 {
265  pIrp,
266  pFxContext);
267 }
268 
269 VOID
272  _Out_ UMINT::WDF_DEVICE_IO_TYPE *RWPreference,
273  _Out_ UMINT::WDF_DEVICE_IO_TYPE *IoctlPreference
274  )
275 {
277  RetrievalMode,
278  (WDF_DEVICE_IO_TYPE*)RWPreference,
279  (WDF_DEVICE_IO_TYPE*)IoctlPreference);
280 }
281 
282 ULONG
284  VOID
285  )
286 {
288 }
289 
290 NTSTATUS
292  _In_ RdWmiPowerAction Action,
293  _Out_ BOOLEAN *QueryResult
294  )
295 {
296  return m_Device->ProcessWmiPowerQueryOrSetData(Action, QueryResult);
297 }
298 
301  _In_ LPCGUID pDeviceInterfaceGuid,
302  _In_ PCWSTR pSymbolicLink
303  )
304 {
306  pDeviceInterfaceGuid,
307  pSymbolicLink);
308 }
309 
310 void
312  _In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID
313  )
314 {
316  RemoteInterfaceID);
317 }
318 
319 BOOL
321  _In_ DWORD Id,
322  _In_ PVOID DataBuffer,
323  _In_ SIZE_T cbDataBufferSize
324  )
325 {
327  Id,
328  DataBuffer,
329  cbDataBufferSize);
330 }
331 
332 void
334  void
335  )
336 {
338 }
339 
340 void
342  void
343  )
344 {
346 }
347 
348 //
349 // Additional public functions.
350 //
351 
352 //
353 // Returns the Dispatcher object from the given interface without
354 // incrementing the refcount.
355 //
358  _In_ IFxMessageDispatch* pIFxMessageDispatch
359  )
360 {
361  FxMessageDispatch * pWudfDispatcher = NULL;
362  HRESULT hrQI = pIFxMessageDispatch->QueryInterface(
364  reinterpret_cast<void**>(&pWudfDispatcher)
365  );
366  FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pWudfDispatcher));
367  pWudfDispatcher->Release(); //release the reference taken by QI
368  return pWudfDispatcher;
369 }
370 
371 //
372 // Returns the specified interface from the given object without
373 // incrementing the refcount.
374 //
375 IFxMessageDispatch*
377  _In_ FxMessageDispatch* pWudfDispatcher
378  )
379 {
380  IFxMessageDispatch * pIFxMessageDispatch = NULL;
381  HRESULT hrQI = pWudfDispatcher->QueryInterface(IID_IFxMessageDispatch,
382  (PVOID*)&pIFxMessageDispatch);
383  FX_VERIFY(INTERNAL, CHECK_QI(hrQI, pIFxMessageDispatch));
384  pIFxMessageDispatch->Release(); //release the reference taken by QI
385  return pIFxMessageDispatch;
386 }
virtual void __stdcall DispatchPnP(_In_ IWudfIrp *pIrp)
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define E_NOINTERFACE
Definition: winerror.h:2364
ULONG __stdcall Release()
virtual void __stdcall SetInformationFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
#define IRP_MJ_FLUSH_BUFFERS
HRESULT hr
Definition: shlfolder.c:183
virtual void __stdcall WriteFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
enum _WDF_DEVICE_IO_TYPE WDF_DEVICE_IO_TYPE
static void PoFxDevicePowerNotRequired(_In_ MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:817
REFIID LPVOID * ppv
Definition: atlbase.h:39
virtual void __stdcall QueryInformationFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual void __stdcall FlushBuffers(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
DriverGlobals
FxIrp * pIrp
#define _In_opt_
Definition: no_sal2.h:212
virtual void __stdcall CreateFile(_In_ IWudfIoIrp *pCreateIrp)
DWORD Id
virtual void __stdcall CloseFile(_In_ IWudfIoIrp *pIrp, _In_ IUnknown *pFxContext)
__inline ULONG GetDirectTransferThreshold(VOID)
Definition: fxdevice.hpp:1986
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
const GUID IID_FxMessageDispatch
static NTSTATUS _CreateAndInitialize(_In_ PFX_DRIVER_GLOBALS DriverGlobals, _In_ FxDevice *Device, _Out_ FxMessageDispatch **ppWudfDispatcher)
#define E_INVALIDARG
Definition: ddrawi.h:101
virtual void __stdcall RemoteInterfaceRemoval(_In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID)
unsigned char BOOLEAN
static WUDF_INTERFACE_CONTEXT RemoteInterfaceArrival(_In_ IWudfDevice *DeviceObject, _In_ LPCGUID DeviceInterfaceGuid, _In_ PCWSTR SymbolicLink)
Definition: fxdeviceum.cpp:762
#define _Out_
Definition: no_sal2.h:160
#define SAFE_RELEASE(p)
PDRIVER_OBJECT_UM GetDriverObject(VOID)
FxMessageDispatch(_In_ FxDevice *Device)
HRESULT hrQI
Definition: framework.cpp:106
virtual void __stdcall CleanupFile(_In_ IWudfIoIrp *pIrp, _In_ IUnknown *pFxContext)
virtual void __stdcall PoFxDevicePowerNotRequired(VOID)
#define TRACINGDEVICE
Definition: dbgtrace.h:58
virtual void __stdcall PoFxDevicePowerRequired(VOID)
static void RemoteInterfaceRemoval(_In_ IWudfDevice *DeviceObject, _In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID)
Definition: fxdeviceum.cpp:778
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
LONG HRESULT
Definition: typedefs.h:79
enum _WDF_DEVICE_IO_BUFFER_RETRIEVAL WDF_DEVICE_IO_BUFFER_RETRIEVAL
Definition: mxum.h:117
const GUID IID_IUnknown
virtual NTSTATUS __stdcall ProcessWmiPowerQueryOrSetData(_In_ RdWmiPowerAction Action, _Out_ BOOLEAN *QueryResult)
static BOOL TransportQueryId(_In_ IWudfDevice *DeviceObject, _In_ DWORD Id, _In_ PVOID DataBuffer, _In_ SIZE_T cbDataBufferSize)
Definition: fxdeviceum.cpp:790
nsrefcnt Release()
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG __stdcall AddRef()
MdDeviceObject GetDeviceObject(VOID)
virtual WUDF_INTERFACE_CONTEXT __stdcall RemoteInterfaceArrival(_In_ LPCGUID pDeviceInterfaceGuid, _In_ PCWSTR pSymbolicLink)
#define IRP_MJ_POWER
HRESULT __stdcall QueryInterface(_In_ REFIID riid, _Out_ LPVOID *ppvObject)
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define InterlockedDecrement
Definition: armddk.h:52
virtual void __stdcall ReadFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual void __stdcall DeviceControl(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
virtual BOOL __stdcall TransportQueryID(_In_ DWORD Id, _In_ PVOID DataBuffer, _In_ SIZE_T cbDataBufferSize)
virtual ULONG __stdcall GetDirectTransferThreshold(VOID)
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
static VOID GetPreferredTransferMode(_In_ MdDeviceObject DeviceObject, _Out_ UMINT::WDF_DEVICE_IO_BUFFER_RETRIEVAL *RetrievalMode, _Out_ WDF_DEVICE_IO_TYPE *RWPreference, _Out_ WDF_DEVICE_IO_TYPE *IoctlPreference)
Definition: fxdeviceum.cpp:593
#define _In_
Definition: no_sal2.h:158
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define S_OK
Definition: intsafe.h:51
static IFxMessageDispatch * _GetDispatcherItf(_In_ FxMessageDispatch *pWudfDispatcher)
#define InterlockedIncrement
Definition: armddk.h:53
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
static void PoFxDevicePowerRequired(_In_ MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:808
virtual VOID __stdcall GetPreferredTransferMode(_Out_ UMINT::WDF_DEVICE_IO_BUFFER_RETRIEVAL *RetrievalMode, _Out_ UMINT::WDF_DEVICE_IO_TYPE *RWPreference, _Out_ UMINT::WDF_DEVICE_IO_TYPE *IoctlPreference)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
PFN_DRIVER_DISPATCH_UM MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: fxldrum.h:217
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_CLEANUP
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
static FxMessageDispatch * _GetObjFromItf(_In_ IFxMessageDispatch *pIFxMessageDispatch)
UINT64 WUDF_INTERFACE_CONTEXT
Definition: mxum.h:111
NTSTATUS ProcessWmiPowerQueryOrSetData(_In_ RdWmiPowerAction Action, _Out_ BOOLEAN *QueryResult)
Definition: fxdeviceum.cpp:699
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define DO_NOTHING()
Definition: mxgeneral.h:32
Definition: ps.c:97