ReactOS 0.4.15-dev-7842-g558ab78
fxcollection.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxCollection.cpp
8
9Abstract:
10
11 This module implements a simple collection class to operate on
12 objects derived from FxObject.
13
14Author:
15
16
17
18Environment:
19
20 Both kernel and user mode
21
22Revision 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
43VOID
45 VOID
46 )
47{
48 while (!IsListEmpty(&m_ListHead)) {
49 Remove(0);
50 }
51}
52
55 VOID
56 )
57{
58 return m_Count;
59}
60
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
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
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
160VOID
163 )
164{
165 RemoveEntryList(&Entry->m_ListEntry);
166 delete Entry;
167
168 m_Count--;
169}
170
174 )
175{
176 CleanupEntryObject(Entry->m_Object);
178
179 return STATUS_SUCCESS;
180}
181
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
203 VOID
204 )
205{
206 if (IsListEmpty(&m_ListHead)) {
207 return NULL;
208 }
209 else {
212 m_ListEntry)->m_Object;
213 }
214}
215
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,
243 ) : FxNonPagedObject(Type, Size, FxDriverGlobals)
244{
245}
246
248 VOID
249 )
250{
251 Clear();
252}
253
254VOID
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
unsigned char BOOLEAN
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
FxObject * m_Object
LIST_ENTRY m_ListEntry
FxCollection(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
VOID StealCollection(__in FxCollection *Collection)
#define __in
Definition: dbghelp.h:35
#define NULL
Definition: types.h:112
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PSINGLE_LIST_ENTRY ple
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
USHORT WDFTYPE
Definition: fxtypes.h:29
@ FX_TYPE_COLLECTION
Definition: fxtypes.h:59
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
static void Clear(void)
Definition: treeview.c:386
#define _Must_inspect_result_
Definition: ms_sal.h:558
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
base of all file and directory entries
Definition: entries.h:83
_Must_inspect_result_ FxCollectionEntry * FindEntry(__in ULONG Index)
NTSTATUS Remove(__in ULONG Index)
VOID CleanupEntry(__in FxCollectionEntry *Entry)
NTSTATUS RemoveEntry(__in FxCollectionEntry *Entry)
_Must_inspect_result_ NTSTATUS RemoveItem(__in FxObject *Item)
_Must_inspect_result_ FxObject * GetLastItem(VOID)
VOID AddEntry(__in FxCollectionEntry *Node, __in FxObject *Item)
_Must_inspect_result_ FxObject * GetItem(__in ULONG Index)
BOOLEAN Add(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Item)
_Must_inspect_result_ FxCollectionEntry * FindEntryByObject(__in FxObject *Object)
_Must_inspect_result_ FxObject * GetFirstItem(VOID)
VOID CleanupEntryObject(__in FxObject *Object)
_Must_inspect_result_ FxCollectionEntry * AllocateEntry(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ WDFCOLLECTION Collection
Definition: wdfregistry.h:374
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_In_ BOOLEAN Remove
Definition: psfuncs.h:110