ReactOS  0.4.15-dev-3294-ge98684e
fxcollectionapi.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxCollectionApi.cpp
8 
9 Abstract:
10 
11  This module implements the "C" interface to the collection object.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23 --*/
24 
25 #include "fxsupportpch.hpp"
26 
27 extern "C" {
28 // #include "FxCollectionApi.tmh"
29 }
30 
31 //
32 // Extern the entire file
33 //
34 extern "C" {
38 STDCALL
39 WDFEXPORT(WdfCollectionCreate)(
40  __in
42  __in_opt
44  __out
45  WDFCOLLECTION *Collection
46  )
47 {
48  DDI_ENTRY();
49 
53  WDFCOLLECTION hCol;
54 
56 
57  //
58  // Get the parent's globals if it is present
59  //
63 
67  (PVOID*)&pParent,
69  }
70 
72 
73  *Collection = NULL;
74 
76  if (!NT_SUCCESS(status)) {
77  return status;
78  }
79 
82 
83  if (pCollection != NULL) {
85 
86  if (NT_SUCCESS(status)) {
87  *Collection = hCol;
88  }
89  else {
91  "Could not create collection object: %!STATUS!",
92  status);
93 
95  }
96  }
97  else {
99  "Could not create collection object: "
100  "STATUS_INSUFFICIENT_RESOURCES" );
102  }
103 
104  return status;
105 }
106 
108 ULONG
109 STDCALL
110 WDFEXPORT(WdfCollectionGetCount)(
111  __in
113  __in
114  WDFCOLLECTION Collection
115  )
116 {
117  DDI_ENTRY();
118 
122 
124  Collection,
126  (PVOID *)&pCollection);
127 
128  pCollection->Lock(&irql);
129  count = pCollection->Count();
130  pCollection->Unlock(irql);
131 
132  return count;
133 }
134 
137 NTSTATUS
138 STDCALL
139 WDFEXPORT(WdfCollectionAdd)(
140  __in
142  __in
143  WDFCOLLECTION Collection,
144  __in
146  )
147 {
148  DDI_ENTRY();
149 
154  KIRQL irql;
155 
157  Collection,
159  (PVOID*) &pCollection,
161 
163  Object,
165  (PVOID*) &pObject);
166 
167  pCollection->Lock(&irql);
169  pCollection->Unlock(irql);
170 
171  return status;
172 }
173 
175 VOID
176 STDCALL
177 WDFEXPORT(WdfCollectionRemoveItem)(
178  __in
180  __in
181  WDFCOLLECTION Collection,
182  __in
183  ULONG Index
184  )
185 {
186  DDI_ENTRY();
187 
191  FxObject* pObject;
193  KIRQL irql;
194 
196  Collection,
198  (PVOID*) &pCollection,
200 
201  pCollection->Lock(&irql);
202 
204 
205  if (pEntry != NULL) {
209  }
210  else {
211  pObject = NULL;
213  }
214 
215  pCollection->Unlock(irql);
216 
217  if (pObject != NULL) {
219  }
220 
221  if (!NT_SUCCESS(status)) {
224  "Index %d is not valid in WDFCOLLECTION %p (count is %d), %!STATUS!",
227  }
228 }
229 
231 VOID
232 STDCALL
233 WDFEXPORT(WdfCollectionRemove)(
234  __in
236  __in
237  WDFCOLLECTION Collection,
238  __in
240  )
241 {
242  DDI_ENTRY();
243 
247  FxObject* pObject;
249  KIRQL irql;
250 
252  Collection,
254  (PVOID*) &pCollection,
256 
258  Item,
260  (PVOID*) &pObject);
261 
262  pCollection->Lock(&irql);
263 
265 
266  if (pEntry != NULL) {
269  }
270  else {
271  pObject = NULL;
273  }
274 
275  pCollection->Unlock(irql);
276 
277  if (pObject != NULL) {
279  }
280 
281  if (!NT_SUCCESS(status)) {
283  "WDFOBJECT %p not in WDFCOLLECTION %p, %!STATUS!",
286  }
287 }
288 
290 WDFOBJECT
291 STDCALL
292 WDFEXPORT(WdfCollectionGetItem)(
293  __in
295  __in
296  WDFCOLLECTION Collection,
297  __in
298  ULONG Index
299  )
300 {
301  DDI_ENTRY();
302 
304  FxObject *pObject;
305  KIRQL irql;
306 
308  Collection,
310  (PVOID*) &pCollection);
311 
312  pCollection->Lock(&irql);
314  pCollection->Unlock(irql);
315 
316  if (pObject == NULL) {
317  return NULL;
318  }
319 
320  return pObject->GetObjectHandle();
321 }
322 
324 WDFOBJECT
325 STDCALL
326 WDFEXPORT(WdfCollectionGetFirstItem)(
327  __in
329  __in
330  WDFCOLLECTION Collection
331  )
332 {
333  DDI_ENTRY();
334 
336  FxObject* pObject;
337  KIRQL irql;
338 
340  Collection,
342  (PVOID*) &pCollection);
343 
344  pCollection->Lock(&irql);
346  pCollection->Unlock(irql);
347 
348  if (pObject != NULL) {
349  return pObject->GetObjectHandle();
350  }
351  else {
352  return NULL;
353  }
354 }
355 
357 WDFOBJECT
358 STDCALL
359 WDFEXPORT(WdfCollectionGetLastItem)(
360  __in
362  __in
363  WDFCOLLECTION Collection
364  )
365 {
366  DDI_ENTRY();
367 
369  FxObject* pObject;
370  KIRQL irql;
371 
373  Collection,
375  (PVOID*) &pCollection);
376 
377  pCollection->Lock(&irql);
379  pCollection->Unlock(irql);
380 
381  if (pObject != NULL) {
382  return pObject->GetObjectHandle();
383  }
384  else {
385  return NULL;
386  }
387 }
388 
389 } // extern "C" of entire file
WDFCOLLECTION hCol
_Must_inspect_result_ __in WDFCOLLECTION __in WDFOBJECT Object
#define DDI_ENTRY()
Definition: fxglobalskm.h:56
FxObjectHandleGetPtr(GetFxDriverGlobals(DriverGlobals), Collection, FX_TYPE_COLLECTION,(PVOID *)&pCollection)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ NTSTATUS Commit(__in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out_opt WDFOBJECT *ObjectHandle, __in_opt FxObject *Parent=NULL, __in BOOLEAN AssignDriverAsDefaultParent=TRUE)
Definition: fxobject.cpp:904
#define __in_opt
Definition: dbghelp.h:38
GLuint GLuint GLsizei count
Definition: gl.h:1545
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ WDFCOLLECTION Collection
Definition: wdfregistry.h:367
_Must_inspect_result_ FxObject * GetFirstItem(VOID)
LONG NTSTATUS
Definition: precomp.h:26
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Collection, FX_TYPE_COLLECTION,(PVOID *) &pCollection, &pFxDriverGlobals)
DriverGlobals
BOOLEAN Add(__in FxObject *Item)
KIRQL irql
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ FxCollectionEntry * FindEntry(__in ULONG Index)
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
FxCollection * pCollection
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
__in WDFCOLLECTION __in ULONG Index
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
#define __out
Definition: dbghelp.h:62
VOID CleanupEntryObject(__in FxObject *Object)
_Must_inspect_result_ FxObject * GetLastItem(VOID)
#define STATUS_NOT_FOUND
Definition: shellext.h:72
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES CollectionAttributes
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define STDCALL
Definition: wdf.h:45
__in WDFCOLLECTION __in WDFOBJECT Item
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ FxCollectionEntry * FindEntryByObject(__in FxObject *Object)
_In_ WDFCOLLECTION _In_ ULONG Index
NTSTATUS status
FxObject * m_Object
FxCollectionEntry * pEntry
_Must_inspect_result_ __drv_maxIRQL(DISPATCH_LEVEL) NTSTATUS STDCALL WDFEXPORT(WdfCollectionCreate)(__in PWDF_DRIVER_GLOBALS DriverGlobals
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG count
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID CleanupEntry(__in FxCollectionEntry *Entry)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
WDFOBJECT ParentObject
Definition: wdfobject.h:130
#define NULL
Definition: types.h:112
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
unsigned int ULONG
Definition: retypes.h:1
FxObject * pParent
Definition: fxdpcapi.cpp:86
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ __in_opt PWDF_OBJECT_ATTRIBUTES __out WDFCOLLECTION * Collection
#define TRACINGERROR
Definition: dbgtrace.h:63
_Must_inspect_result_ FxObject * GetItem(__in ULONG Index)
#define __in
Definition: dbghelp.h:35
FxObject * pObject
FxPointerNotNull(pFxDriverGlobals, Collection)
FxVerifierDbgBreakPoint(pFxDriverGlobals)
Definition: ps.c:97