ReactOS 0.4.15-dev-5666-gc548b97
fxmessagedispatchum.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft. All rights reserved.
4
5Module Name:
6
7 FxMessageDispatchUm.cpp
8
9Abstract:
10
11 Implements the host process dispatcher object. See header file for
12 details.
13
14Author:
15
16
17
18Environment:
19
20 User mode only
21
22Revision History:
23
24
25
26--*/
27
28#include "fxmin.hpp"
29#include "fxldrum.h"
30
31extern "C"
32{
33#include "FxMessageDispatchUm.tmh"
34}
35
36// {cba20727-0910-4a8a-aada-c31d5cf5bf20}
37extern 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) {
60 "Memory allocation failure. Cannot create Dispatcher object.\n");
61 goto Done;
62 }
63
64 *ppWudfDispatcher = pWudfDispatcher;
65
66Done:
67
68 if (FAILED(hr)) {
69 status = Device->NtStatusFromHr(hr);
70 }
71 else {
73 }
74
75 return status;
76}
77
78//
79// IUnknown
80//
83{
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
97{
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
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//
153void
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()) {
164 GetDriverObject()->MajorFunction[IRP_MJ_POWER](GetDeviceObject(),
165 pIrp,
166 NULL);
167 }
168 else {
169 GetDriverObject()->MajorFunction[IRP_MJ_PNP](GetDeviceObject(),
170 pIrp,
171 NULL);
172 }
173
174 SAFE_RELEASE(pIPnpIrp);
175}
176
177void
179 _In_ IWudfIoIrp * pCreateIrp
180 )
181{
183 pCreateIrp,
184 NULL);
185}
186
187void
189 _In_ IWudfIoIrp * pIrp,
190 _In_opt_ IUnknown * pFxContext
191 )
192{
194 pIrp,
195 pFxContext);
196}
197
198void
200 _In_ IWudfIoIrp * pIrp,
201 _In_opt_ IUnknown * pFxContext
202 )
203{
204 GetDriverObject()->MajorFunction[IRP_MJ_READ](GetDeviceObject(), pIrp, pFxContext);
205}
206
207void
209 _In_ IWudfIoIrp * pIrp,
210 _In_opt_ IUnknown * pFxContext
211 )
212{
213 GetDriverObject()->MajorFunction[IRP_MJ_WRITE](GetDeviceObject(), pIrp, pFxContext);
214}
215
216void
218 _In_ IWudfIoIrp * pIrp,
219 _In_ IUnknown * pFxContext
220 )
221{
222 GetDriverObject()->MajorFunction[IRP_MJ_CLEANUP](GetDeviceObject(), pIrp, pFxContext);
223}
224
225void
227 _In_ IWudfIoIrp * pIrp,
228 _In_ IUnknown * pFxContext
229 )
230{
231 GetDriverObject()->MajorFunction[IRP_MJ_CLOSE](GetDeviceObject(), pIrp, pFxContext);
232}
233
234void
236 _In_ IWudfIoIrp * pIrp,
237 _In_opt_ IUnknown * pFxContext
238 )
239{
241 pIrp,
242 pFxContext);
243}
244
245void
247 _In_ IWudfIoIrp * pIrp,
248 _In_opt_ IUnknown * pFxContext
249 )
250{
253 pIrp,
254 pFxContext
255 );
256}
257
258void
260 _In_ IWudfIoIrp * pIrp,
261 _In_opt_ IUnknown * pFxContext
262 )
263{
265 pIrp,
266 pFxContext);
267}
268
269VOID
271 _Out_ UMINT::WDF_DEVICE_IO_BUFFER_RETRIEVAL *RetrievalMode,
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
282ULONG
284 VOID
285 )
286{
288}
289
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
310void
312 _In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID
313 )
314{
316 RemoteInterfaceID);
317}
318
319BOOL
321 _In_ DWORD Id,
322 _In_ PVOID DataBuffer,
323 _In_ SIZE_T cbDataBufferSize
324 )
325{
327 Id,
328 DataBuffer,
329 cbDataBufferSize);
330}
331
332void
334 void
335 )
336{
338}
339
340void
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//
375IFxMessageDispatch*
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}
DWORD Id
unsigned char BOOLEAN
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
const GUID IID_IUnknown
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
static BOOL TransportQueryId(_In_ IWudfDevice *DeviceObject, _In_ DWORD Id, _In_ PVOID DataBuffer, _In_ SIZE_T cbDataBufferSize)
Definition: fxdeviceum.cpp:790
static WUDF_INTERFACE_CONTEXT RemoteInterfaceArrival(_In_ IWudfDevice *DeviceObject, _In_ LPCGUID DeviceInterfaceGuid, _In_ PCWSTR SymbolicLink)
Definition: fxdeviceum.cpp:762
__inline ULONG GetDirectTransferThreshold(VOID)
Definition: fxdevice.hpp:1986
static void PoFxDevicePowerRequired(_In_ MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:808
static void RemoteInterfaceRemoval(_In_ IWudfDevice *DeviceObject, _In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID)
Definition: fxdeviceum.cpp:778
static void PoFxDevicePowerNotRequired(_In_ MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:817
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
NTSTATUS ProcessWmiPowerQueryOrSetData(_In_ RdWmiPowerAction Action, _Out_ BOOLEAN *QueryResult)
Definition: fxdeviceum.cpp:699
static IFxMessageDispatch * _GetDispatcherItf(_In_ FxMessageDispatch *pWudfDispatcher)
static NTSTATUS _CreateAndInitialize(_In_ PFX_DRIVER_GLOBALS DriverGlobals, _In_ FxDevice *Device, _Out_ FxMessageDispatch **ppWudfDispatcher)
virtual BOOL __stdcall TransportQueryID(_In_ DWORD Id, _In_ PVOID DataBuffer, _In_ SIZE_T cbDataBufferSize)
virtual void __stdcall FlushBuffers(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
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)
virtual void __stdcall QueryInformationFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual void __stdcall ReadFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
HRESULT __stdcall QueryInterface(_In_ REFIID riid, _Out_ LPVOID *ppvObject)
ULONG __stdcall AddRef()
virtual WUDF_INTERFACE_CONTEXT __stdcall RemoteInterfaceArrival(_In_ LPCGUID pDeviceInterfaceGuid, _In_ PCWSTR pSymbolicLink)
virtual void __stdcall PoFxDevicePowerNotRequired(VOID)
virtual void __stdcall CloseFile(_In_ IWudfIoIrp *pIrp, _In_ IUnknown *pFxContext)
virtual void __stdcall SetInformationFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual NTSTATUS __stdcall ProcessWmiPowerQueryOrSetData(_In_ RdWmiPowerAction Action, _Out_ BOOLEAN *QueryResult)
virtual void __stdcall CleanupFile(_In_ IWudfIoIrp *pIrp, _In_ IUnknown *pFxContext)
virtual void __stdcall DeviceControl(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual void __stdcall WriteFile(_In_ IWudfIoIrp *pIrp, _In_opt_ IUnknown *pFxContext)
virtual void __stdcall CreateFile(_In_ IWudfIoIrp *pCreateIrp)
ULONG __stdcall Release()
virtual void __stdcall RemoteInterfaceRemoval(_In_ WUDF_INTERFACE_CONTEXT RemoteInterfaceID)
static FxMessageDispatch * _GetObjFromItf(_In_ IFxMessageDispatch *pIFxMessageDispatch)
virtual void __stdcall DispatchPnP(_In_ IWudfIrp *pIrp)
virtual ULONG __stdcall GetDirectTransferThreshold(VOID)
virtual void __stdcall PoFxDevicePowerRequired(VOID)
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost))
HRESULT hrQI
Definition: framework.cpp:106
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
return pDevice GetDeviceObject()
DriverGlobals
return pDriver GetDriverObject()
const GUID IID_FxMessageDispatch
const GUID IID_FxMessageDispatch
FxIrp * pIrp
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
unsigned int ULONG
Definition: retypes.h:1
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define DO_NOTHING()
Definition: mxgeneral.h:32
UINT64 WUDF_INTERFACE_CONTEXT
Definition: mxum.h:111
long LONG
Definition: pedump.c:60
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
HRESULT hr
Definition: shlfolder.c:183
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
Definition: ps.c:97
const uint16_t * PCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
enum _WDF_DEVICE_IO_TYPE WDF_DEVICE_IO_TYPE
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
#define E_NOINTERFACE
Definition: winerror.h:2364
#define IRP_MJ_FLUSH_BUFFERS
#define IRP_MJ_POWER
#define IRP_MJ_CLEANUP
#define SAFE_RELEASE(p)