ReactOS  0.4.15-dev-3451-gf606fec
dispatcher.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel Streaming
4  * FILE: drivers/wdm/audio/backpln/portcls/dispatcher.c
5  * PURPOSE: portcls generic dispatcher
6  * PROGRAMMER: Johannes Anderwald
7  */
8 
9 #include "private.hpp"
10 
11 #ifndef YDEBUG
12 #define NDEBUG
13 #endif
14 
15 #include <debug.h>
16 
18 NTAPI
21  PIRP Irp)
22 {
23  PIO_STACK_LOCATION IoStack;
25 
26  // get current irp stack
28 
29  // get dispatch context
30  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
31 
32  // let IrpTarget handle request
33  return DispatchContext->Target->DeviceIoControl(DeviceObject, Irp);
34 }
35 
37 NTAPI
40  PIRP Irp)
41 {
42  PIO_STACK_LOCATION IoStack;
44 
45  // get current irp stack
47 
48  // get dispatch context
49  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
50 
51 
52  // let IrpTarget handle request
53  return DispatchContext->Target->Read(DeviceObject, Irp);
54 }
55 
57 NTAPI
60  PIRP Irp)
61 {
62  PIO_STACK_LOCATION IoStack;
64 
65  // get current irp stack
67 
68  // get dispatch context
69  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
70 
71 
72  // let IrpTarget handle request
73  return DispatchContext->Target->Write(DeviceObject, Irp);
74 }
75 
77 NTAPI
80  PIRP Irp)
81 {
82  PIO_STACK_LOCATION IoStack;
84 
85  // get current irp stack
87 
88  // get dispatch context
89  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
90 
91 
92  // let IrpTarget handle request
93  return DispatchContext->Target->Flush(DeviceObject, Irp);
94 }
95 
97 NTAPI
100  PIRP Irp)
101 {
102  PIO_STACK_LOCATION IoStack;
105 
106  // get current irp stack
108  // get dispatch context
109  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
110 
111  // let IrpTarget handle request
112  Status = DispatchContext->Target->Close(DeviceObject, Irp);
113 
114  if (NT_SUCCESS(Status))
115  {
116  KsFreeObjectHeader(DispatchContext->ObjectHeader);
118  }
119  // done
120  return Status;
121 }
122 
123 NTSTATUS
124 NTAPI
127  PIRP Irp)
128 {
129  PIO_STACK_LOCATION IoStack;
131 
132  // get current irp stack
134 
135  // get dispatch context
136  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
137 
138 
139  // let IrpTarget handle request
140  return DispatchContext->Target->QuerySecurity(DeviceObject, Irp);
141 }
142 
143 NTSTATUS
144 NTAPI
147  PIRP Irp)
148 {
149  PIO_STACK_LOCATION IoStack;
151 
152  // get current irp stack
154 
155  // get dispatch context
156  DispatchContext = (PDISPATCH_CONTEXT)IoStack->FileObject->FsContext;
157 
158  // let IrpTarget handle request
159  return DispatchContext->Target->SetSecurity(DeviceObject, Irp);
160 }
161 
162 BOOLEAN
163 NTAPI
166  BOOLEAN Wait,
174 {
176 
177  // get dispatch context
179 
180  // let IrpTarget handle request
182 }
183 
184 
185 BOOLEAN
186 NTAPI
190  ULONG Length,
191  BOOLEAN Wait,
192  ULONG LockKey,
193  PVOID Buffer,
196 {
198 
199  // get dispatch context
201 
202  // let IrpTarget handle request
204 }
205 
206 BOOLEAN
207 NTAPI
211  ULONG Length,
212  BOOLEAN Wait,
213  ULONG LockKey,
214  PVOID Buffer,
217 {
219 
220  // get dispatch context
222  // let IrpTarget handle request
224 }
225 
226 static KSDISPATCH_TABLE DispatchTable =
227 {
238 };
239 
240 NTSTATUS
241 NTAPI
243  IN PIRP Irp,
244  IN IIrpTarget * Target,
245  IN ULONG CreateItemCount,
246  IN PKSOBJECT_CREATE_ITEM CreateItem)
247 {
249  KSOBJECT_HEADER ObjectHeader;
250  PIO_STACK_LOCATION IoStack;
252 
253  // get current irp stack location
255 
257  if (!DispatchContext)
259 
260  // allocate object header
261  Status = KsAllocateObjectHeader(&ObjectHeader, CreateItemCount, CreateItem, Irp, &DispatchTable);
262 
263  if (!NT_SUCCESS(Status))
264  {
265  // free dispatch context
267  // done
268  return Status;
269  }
270 
271  // initialize dispatch context
272  DispatchContext->ObjectHeader = ObjectHeader;
273  DispatchContext->Target = Target;
274  DispatchContext->CreateItem = CreateItem;
275 
276  // store dispatch context
277  IoStack->FileObject->FsContext = DispatchContext;
278 
279  DPRINT("KsAllocateObjectHeader result %x Target %p Context %p\n", Status, Target, DispatchContext);
280  return Status;
281 }
282 
#define IN
Definition: typedefs.h:39
_In_ UCHAR _In_ UCHAR _In_ ULONG _In_ WDFCONTEXT _Inout_ PIRP _In_ WDFCONTEXT DispatchContext
Definition: wdfdevice.h:1697
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TAG_PORTCLASS
Definition: private.hpp:24
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
NTSTATUS NTAPI Dispatch_fnRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:38
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
NTSTATUS NTAPI Dispatch_fnFlush(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:78
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2662
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
struct DISPATCH_CONTEXT * PDISPATCH_CONTEXT
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI Dispatch_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:19
* PFILE_OBJECT
Definition: iotypes.h:1998
NTSTATUS NTAPI Dispatch_fnWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:58
NTSTATUS NTAPI Dispatch_fnClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:98
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
NTSTATUS NTAPI Dispatch_fnSetSecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:145
BOOLEAN NTAPI Dispatch_fnFastDeviceIoControl(PFILE_OBJECT FileObject, BOOLEAN Wait, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, ULONG IoControlCode, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:164
BOOLEAN NTAPI Dispatch_fnFastWrite(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:208
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN NTAPI Dispatch_fnFastRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: dispatcher.cpp:187
#define DPRINT
Definition: sndvol32.h:71
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:245
NTSTATUS NTAPI NewDispatchObject(IN PIRP Irp, IN IIrpTarget *Target, IN ULONG CreateItemCount, IN PKSOBJECT_CREATE_ITEM CreateItem)
Definition: dispatcher.cpp:242
NTSTATUS NTAPI Dispatch_fnQuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatcher.cpp:125