ReactOS  0.4.15-dev-4920-g5fa8403
fxworkitemapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxWorkItemApi.cpp
8 
9 Abstract:
10 
11  This implements the WDFWORKITEM API's
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 
24 --*/
25 
26 #include "coreprivshared.hpp"
27 
28 #include "fxworkitem.hpp"
29 
30 extern "C" {
31 // #include "FxWorkItemApi.tmh"
32 }
33 
34 
35 //
36 // extern "C" the entire file
37 //
38 extern "C" {
39 
43 STDCALL
44 WDFEXPORT(WdfWorkItemCreate)(
45  __in
47  __in
49  __in
51  __out
52  WDFWORKITEM* WorkItem
53  )
54 
55 /*++
56 
57 Routine Description:
58 
59  Create a WorkItem object that will call the supplied function with
60  context when it fires. It returns a handle to the WDFWORKITEM object.
61 
62 Arguments:
63 
64  Config - Pointer to WDF_WORKITEM_CONFIG structure
65 
66  Attributes - WDF_OBJECT_ATTRIBUTES to set the parent object and to request
67  a context memory allocation, and a DestroyCallback.
68 
69  WorkItem - Pointer to the created WDFWORKITEM handle.
70 
71 Returns:
72 
73  STATUS_SUCCESS - A WDFWORKITEM handle has been created.
74 
75  The WDFWORKITEM will be automatically deleted when the object it is
76  associated with is deleted.
77 
78 Notes:
79 
80  The WDFWORKITEM object is deleted either when the DEVICE or QUEUE it is
81  associated with is deleted, or WdfObjectDelete is called.
82 
83  If the WDFWORKITEM is used to access WDM objects, a Cleanup callback should
84  be registered to allow references to be released.
85 
86 --*/
87 
88 {
89  DDI_ENTRY();
90 
94 
97  Attributes,
99  if (!NT_SUCCESS(status)) {
100  return status;
101  }
102 
104  Attributes->ParentObject,
106  (PVOID*)&pParent,
108 
111 
112  if (Config->Size != sizeof(WDF_WORKITEM_CONFIG)) {
114 
117  "WDF_WORKITEM_CONFIG Size got %d, expected %d, %!STATUS!",
118  Config->Size, sizeof(WDF_WORKITEM_CONFIG), status);
119 
120  return status;
121  }
122 
123  if (Config->EvtWorkItemFunc == NULL) {
125 
127  "Supplied EvtWorkItemFunc == NULL, %!STATUS!",
128  status);
129 
130  return status;
131  }
132 
133  //
134  // The parent for FxWorkItem is explicitly part of the API, and ties
135  // synchronization and lifetime.
136  //
138  if (!NT_SUCCESS(status)) {
139  return status;
140  }
141 
142  return FxWorkItem::_Create(
144 }
145 
147 VOID
148 STDCALL
149 WDFEXPORT(WdfWorkItemEnqueue)(
150  __in
152  __in
153  WDFWORKITEM WorkItem
154  )
155 /*++
156 
157 Routine Description:
158 
159  Enqueue a WorkItem to execute.
160 
161 Arguments:
162 
163  WorkItem - Handle to WDFWORKITEM
164 
165 Returns:
166 
167  None
168 
169 --*/
170 {
171  DDI_ENTRY();
172 
174 
176  WorkItem,
178  (PVOID*)&pFxWorkItem);
179 
180  pFxWorkItem->Enqueue();
181 }
182 
184 WDFOBJECT
185 STDCALL
186 WDFEXPORT(WdfWorkItemGetParentObject)(
187  __in
189  __in
190  WDFWORKITEM WorkItem
191  )
192 
193 /*++
194 
195 Routine Description:
196 
197  Return the Object handle supplied to WdfWorkItemCreate
198 
199 Arguments:
200 
201  WDFWORKITEM - Handle to WDFWORKITEM object created with WdfWorkItemCreate.
202 
203 Returns:
204 
205  Handle to the framework object that is the specified work-item object's
206  parent object.
207 
208 --*/
209 
210 {
211  DDI_ENTRY();
212 
214 
216  WorkItem,
218  (PVOID*)&pFxWorkItem);
219 
221 }
222 
224 VOID
225 STDCALL
226 WDFEXPORT(WdfWorkItemFlush)(
227  __in
229  __in
230  WDFWORKITEM WorkItem
231  )
232 /*++
233 
234 Routine Description:
235 
236  Wait until any outstanding workitems have completed
237 
238 Arguments:
239 
240  WorkItem - Handle to WDFWORKITEM
241 
242 Returns:
243 
244  None
245 
246 --*/
247 {
248  DDI_ENTRY();
249 
251 
253  WorkItem,
255  (PVOID*)&pFxWorkItem);
256 
257  //
258  // Use the object's globals, not the caller's
259  //
261  PASSIVE_LEVEL))) {
262  return;
263  }
264 
266 }
267 
268 } // extern "C"
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfWorkItemCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
FxPointerNotNull(pFxDriverGlobals, Config)
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), WorkItem, FX_TYPE_WORKITEM,(PVOID *)&pFxWorkItem)
_Must_inspect_result_ __in PWDF_WORKITEM_CONFIG Config
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
DriverGlobals
_Must_inspect_result_ __in PWDF_WORKITEM_CONFIG __in PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ __in PWDF_WORKITEM_CONFIG __in PWDF_OBJECT_ATTRIBUTES __out WDFWORKITEM * WorkItem
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define __out
Definition: dbghelp.h:62
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define STDCALL
Definition: wdf.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID Enqueue()
Definition: fxworkitem.cpp:288
VOID FlushAndWait(VOID)
Definition: fxworkitem.cpp:508
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:474
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_WORKITEM_CONFIG Config, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in FxObject *ParentObject, __out WDFWORKITEM *WorkItem)
Definition: fxworkitem.cpp:109
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PFX_DRIVER_GLOBALS pFxDriverGlobals
WDFOBJECT GetAssociatedObject()
Definition: fxworkitem.hpp:181
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
FxObject * pParent
#define NULL
Definition: types.h:112
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:110
FxWorkItem * pFxWorkItem
#define __in
Definition: dbghelp.h:35
NTSTATUS status
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals, Attributes->ParentObject, FX_TYPE_OBJECT,(PVOID *)&pParent, &pFxDriverGlobals)
Definition: ps.c:97