ReactOS  0.4.15-dev-3303-g1ade494
fxcollection.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxCollection.cpp
8 
9 Abstract:
10 
11  This module implements a simple collection class to operate on
12  objects derived from FxObject.
13 
14 Author:
15 
16 
17 
18 Environment:
19 
20  Both kernel and user mode
21 
22 Revision History:
23 
24 --*/
25 
26 #include "fxsupportpch.hpp"
27 
29  VOID
30  )
31 {
32  m_Count = 0;
34 }
35 
37  VOID
38  )
39 {
40  Clear();
41 }
42 
43 VOID
45  VOID
46  )
47 {
48  while (!IsListEmpty(&m_ListHead)) {
49  Remove(0);
50  }
51 }
52 
53 ULONG
55  VOID
56  )
57 {
58  return m_Count;
59 }
60 
61 BOOLEAN
63  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
65  )
66 {
67  FxCollectionEntry *pNode;
68 
69  pNode = AllocateEntry(FxDriverGlobals);
70 
71  if (pNode != NULL) {
73 
74  AddEntry(pNode, Item);
75  }
76 
77  return pNode != NULL;
78 }
79 
84  )
85 {
87  ULONG i;
88 
89  if (Index >= m_Count) {
90  return NULL;
91  }
92 
93  for (i = 0, ple = m_ListHead.Flink;
94  ple != &m_ListHead;
95  ple = ple->Flink, i++) {
96  if (i != Index) {
97  continue;
98  }
99 
100  return CONTAINING_RECORD(ple, FxCollectionEntry, m_ListEntry);
101  }
102 
103  return NULL;
104 }
105 
110  )
111 {
113 
114  for (ple = m_ListHead.Flink; ple != &m_ListHead; ple = ple->Flink) {
115  FxCollectionEntry* pNode;
116 
117  pNode = CONTAINING_RECORD(ple, FxCollectionEntry, m_ListEntry);
118  if (pNode->m_Object == Object) {
119  return pNode;
120  }
121  }
122 
123  return NULL;
124 }
125 
126 NTSTATUS
129  )
130 {
131  FxCollectionEntry *pNode;
132 
133  pNode = FindEntry(Index);
134 
135  if (pNode != NULL) {
136  return RemoveEntry(pNode);
137  }
138  else {
139  return STATUS_NOT_FOUND;
140  }
141 }
142 
144 NTSTATUS
147  )
148 {
149  FxCollectionEntry* pNode;
150 
151  pNode = FindEntryByObject(Item);
152 
153  if (pNode != NULL) {
154  return RemoveEntry(pNode);
155  }
156 
157  return STATUS_NOT_FOUND;
158 }
159 
160 VOID
163  )
164 {
165  RemoveEntryList(&Entry->m_ListEntry);
166  delete Entry;
167 
168  m_Count--;
169 }
170 
171 NTSTATUS
174  )
175 {
176  CleanupEntryObject(Entry->m_Object);
178 
179  return STATUS_SUCCESS;
180 }
181 
183 FxObject*
186  )
187 
188 {
189  FxCollectionEntry* pNode;
190 
191  pNode = FindEntry(Index);
192  if (pNode != NULL) {
193  return pNode->m_Object;
194  }
195  else {
196  return NULL;
197  }
198 }
199 
201 FxObject*
203  VOID
204  )
205 {
206  if (IsListEmpty(&m_ListHead)) {
207  return NULL;
208  }
209  else {
212  m_ListEntry)->m_Object;
213  }
214 }
215 
217 FxObject*
219  VOID
220  )
221 {
222  if (IsListEmpty(&m_ListHead)) {
223  return NULL;
224  }
225  else {
228  m_ListEntry)->m_Object;
229  }
230 }
231 
233  __in PFX_DRIVER_GLOBALS FxDriverGlobals
234  ) :
236 {
237 }
238 
240  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
241  __in WDFTYPE Type,
243  ) : FxNonPagedObject(Type, Size, FxDriverGlobals)
244 {
245 }
246 
248  VOID
249  )
250 {
251  Clear();
252 }
253 
254 VOID
257  )
258 {
260 
261  m_Count = Collection->m_Count;
262  Collection->m_Count = 0;
263 
264  while (!IsListEmpty(&Collection->m_ListHead)) {
266 
267  ple = RemoveHeadList(&Collection->m_ListHead);
269 
270  //
271  // When we are tracking reference tags, the tag associated with the
272  // reference matters. When we added the object to Collection, we used
273  // that pointer as the tag. We must remove that tag and readd the
274  // reference using the this value as a tag.
275  //
276  // Obviously, order is important here. Add the reference first so that
277  // we know the relese will make the object go away.
278  //
279  pEntry->m_Object->ADDREF(this);
280  pEntry->m_Object->RELEASE(Collection);
281 
283  }
284 }
285 
struct _Entry Entry
Definition: kefuncs.h:627
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
VOID StealCollection(__in FxCollection *Collection)
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
FxCollection(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
_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
BOOLEAN Add(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Item)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
_Must_inspect_result_ FxCollectionEntry * AllocateEntry(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
PSINGLE_LIST_ENTRY ple
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_Must_inspect_result_ FxCollectionEntry * FindEntry(__in ULONG Index)
unsigned char BOOLEAN
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
VOID CleanupEntryObject(__in FxObject *Object)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Must_inspect_result_ FxObject * GetLastItem(VOID)
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define STATUS_NOT_FOUND
Definition: shellext.h:72
_Must_inspect_result_ FxCollectionEntry * FindEntryByObject(__in FxObject *Object)
_In_ WDFCOLLECTION _In_ ULONG Index
FxObject * m_Object
Type
Definition: Type.h:6
Definition: typedefs.h:119
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
VOID CleanupEntry(__in FxCollectionEntry *Entry)
LIST_ENTRY m_ListEntry
VOID AddEntry(__in FxCollectionEntry *Node, __in FxObject *Item)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS RemoveEntry(__in FxCollectionEntry *Entry)
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
USHORT WDFTYPE
Definition: fxtypes.h:29
#define NULL
Definition: types.h:112
NTSTATUS Remove(__in ULONG Index)
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ NTSTATUS RemoveItem(__in FxObject *Item)
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
_Must_inspect_result_ FxObject * GetItem(__in ULONG Index)
#define __in
Definition: dbghelp.h:35
base of all file and directory entries
Definition: entries.h:82