ReactOS 0.4.15-dev-8093-g3285f69
context.c File Reference
#include "parser.h"
#include <debug.h>
Include dependency graph for context.c:

Go to the source code of this file.

Classes

struct  HID_COLLECTION_CONTEXT
 

Macros

#define NDEBUG
 

Typedefs

typedef struct HID_COLLECTION_CONTEXTPHID_COLLECTION_CONTEXT
 

Functions

ULONG HidParser_CalculateCollectionSize (IN PHID_COLLECTION Collection)
 
ULONG HidParser_CalculateContextSize (IN PHID_COLLECTION Collection)
 
ULONG HidParser_StoreCollection (IN PHID_COLLECTION Collection, IN PHID_COLLECTION_CONTEXT CollectionContext, IN ULONG CurrentOffset)
 
NTSTATUS HidParser_BuildCollectionContext (IN PHID_COLLECTION RootCollection, IN PVOID Context, IN ULONG ContextSize)
 
PHID_REPORT HidParser_SearchReportInCollection (IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection, IN UCHAR ReportType)
 
PHID_REPORT HidParser_GetReportInCollection (IN PVOID Context, IN UCHAR ReportType)
 
PHID_COLLECTION HidParser_GetCollectionFromContext (IN PVOID Context)
 
ULONG HidParser_GetCollectionCount (IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection)
 
ULONG HidParser_GetTotalCollectionCount (IN PVOID Context)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file context.c.

Typedef Documentation

◆ PHID_COLLECTION_CONTEXT

Function Documentation

◆ HidParser_BuildCollectionContext()

NTSTATUS HidParser_BuildCollectionContext ( IN PHID_COLLECTION  RootCollection,
IN PVOID  Context,
IN ULONG  ContextSize 
)

Definition at line 185 of file context.c.

189{
190 PHID_COLLECTION_CONTEXT CollectionContext;
191 ULONG CollectionSize;
192
193 //
194 // init context
195 //
196 CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
197 CollectionContext->Size = ContextSize;
198
199 //
200 // store collections
201 //
202 CollectionSize = HidParser_StoreCollection(RootCollection, CollectionContext, 0);
203
204 //
205 // sanity check
206 //
207 ASSERT(CollectionSize + sizeof(HID_COLLECTION_CONTEXT) == ContextSize);
208
209 DPRINT("CollectionContext %p\n", CollectionContext);
210 DPRINT("CollectionContext RawData %p\n", CollectionContext->RawData);
211 DPRINT("CollectionContext Size %lu\n", CollectionContext->Size);
212
213 //
214 // done
215 //
216 return HIDP_STATUS_SUCCESS;
217}
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T ContextSize
Definition: fltkernel.h:1444
#define HIDP_STATUS_SUCCESS
Definition: hidpi.h:248
#define ASSERT(a)
Definition: mode.c:44
ULONG HidParser_StoreCollection(IN PHID_COLLECTION Collection, IN PHID_COLLECTION_CONTEXT CollectionContext, IN ULONG CurrentOffset)
Definition: context.c:83
struct HID_COLLECTION_CONTEXT * PHID_COLLECTION_CONTEXT
#define DPRINT
Definition: sndvol32.h:73
uint32_t ULONG
Definition: typedefs.h:59

Referenced by HidParser_BuildContext().

◆ HidParser_CalculateCollectionSize()

ULONG HidParser_CalculateCollectionSize ( IN PHID_COLLECTION  Collection)

Definition at line 26 of file context.c.

28{
29 ULONG Size = 0, Index;
30
31 Size = sizeof(HID_COLLECTION);
32
33 //
34 // add size required for the number of report items
35 //
36 for(Index = 0; Index < Collection->ReportCount; Index++)
37 {
38 //
39 // get report size
40 //
41 ASSERT(Collection->Reports[Index]->ItemCount);
42 Size += sizeof(HID_REPORT) + Collection->Reports[Index]->ItemCount * sizeof(HID_REPORT_ITEM);
43 }
44
45 //
46 // calculate size for sub collections
47 //
48 for(Index = 0; Index < Collection->NodeCount; Index++)
49 {
51 }
52
53 //
54 // append size for the offset
55 //
56 Size += (Collection->ReportCount + Collection->NodeCount) * sizeof(ULONG);
57
58 //
59 // done
60 //
61 return Size;
62}
ULONG HidParser_CalculateCollectionSize(IN PHID_COLLECTION Collection)
Definition: context.c:26
struct __HID_COLLECTION__ HID_COLLECTION
struct _HID_REPORT HID_REPORT
_In_ WDFCOLLECTION _In_ ULONG Index
_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

Referenced by HidParser_CalculateCollectionSize(), and HidParser_CalculateContextSize().

◆ HidParser_CalculateContextSize()

ULONG HidParser_CalculateContextSize ( IN PHID_COLLECTION  Collection)

Definition at line 65 of file context.c.

67{
68 ULONG Size;
69
70 //
71 // minimum size is the size of the collection
72 //
74
75 //
76 // append collection context size
77 //
79 return Size;
80}

Referenced by HidParser_GetContextSize().

◆ HidParser_GetCollectionCount()

ULONG HidParser_GetCollectionCount ( IN PHID_COLLECTION_CONTEXT  CollectionContext,
IN PHID_COLLECTION  Collection 
)

Definition at line 302 of file context.c.

305{
306 ULONG Index;
307 ULONG Count = Collection->NodeCount;
308 PHID_COLLECTION SubCollection;
309
310 for(Index = 0; Index < Collection->NodeCount; Index++)
311 {
312 //
313 // get offset to sub collection
314 //
315 SubCollection = (PHID_COLLECTION)(CollectionContext->RawData + Collection->Offsets[Collection->ReportCount + Index]);
316
317 //
318 // count collection for sub nodes
319 //
320 Count += HidParser_GetCollectionCount(CollectionContext, SubCollection);
321 }
322
323 //
324 // done
325 //
326 return Count;
327}
int Count
Definition: noreturn.cpp:7
ULONG HidParser_GetCollectionCount(IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection)
Definition: context.c:302
struct __HID_COLLECTION__ * PHID_COLLECTION

Referenced by HidParser_GetCollectionCount(), and HidParser_GetTotalCollectionCount().

◆ HidParser_GetCollectionFromContext()

PHID_COLLECTION HidParser_GetCollectionFromContext ( IN PVOID  Context)

Definition at line 290 of file context.c.

292{
294
295 //
296 // return root collection
297 //
298 return (PHID_COLLECTION)CollectionContext->RawData;
299}

Referenced by HidParser_GetCollectionUsagePage().

◆ HidParser_GetReportInCollection()

PHID_REPORT HidParser_GetReportInCollection ( IN PVOID  Context,
IN UCHAR  ReportType 
)

Definition at line 277 of file context.c.

280{
282
283 //
284 // done
285 //
286 return HidParser_SearchReportInCollection(CollectionContext, (PHID_COLLECTION)&CollectionContext->RawData, ReportType);
287}
PHID_REPORT HidParser_SearchReportInCollection(IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection, IN UCHAR ReportType)
Definition: context.c:220

Referenced by HidParser_GetMaxUsageListLengthWithReportAndPage(), HidParser_GetReportItemCountFromReportType(), HidParser_GetReportItemTypeCountFromReportType(), HidParser_GetReportLength(), HidParser_GetScaledUsageValueWithReport(), HidParser_GetSpecificValueCapsWithReport(), HidParser_GetUsagesWithReport(), HidParser_GetUsageValueWithReport(), and HidParser_UsesReportId().

◆ HidParser_GetTotalCollectionCount()

ULONG HidParser_GetTotalCollectionCount ( IN PVOID  Context)

Definition at line 330 of file context.c.

332{
333 PHID_COLLECTION_CONTEXT CollectionContext;
334
335 //
336 // get parser context
337 //
338 CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
339
340 //
341 // count collections
342 //
343 return HidParser_GetCollectionCount(CollectionContext, (PHID_COLLECTION)CollectionContext->RawData);
344}

Referenced by HidParser_GetCaps().

◆ HidParser_SearchReportInCollection()

PHID_REPORT HidParser_SearchReportInCollection ( IN PHID_COLLECTION_CONTEXT  CollectionContext,
IN PHID_COLLECTION  Collection,
IN UCHAR  ReportType 
)

Definition at line 220 of file context.c.

224{
225 ULONG Index;
226 PHID_REPORT Report;
227 PHID_COLLECTION SubCollection;
228
229 //
230 // search first in local array
231 //
232 for(Index = 0; Index < Collection->ReportCount; Index++)
233 {
234 //
235 // get report
236 //
237 Report = (PHID_REPORT)(CollectionContext->RawData + Collection->Offsets[Index]);
238 if (Report->Type == ReportType)
239 {
240 //
241 // found report
242 //
243 return Report;
244 }
245 }
246
247 //
248 // now search in sub collections
249 //
250 for(Index = 0; Index < Collection->NodeCount; Index++)
251 {
252 //
253 // get collection
254 //
255 SubCollection = (PHID_COLLECTION)(CollectionContext->RawData + Collection->Offsets[Collection->ReportCount + Index]);
256
257 //
258 // recursively search collection
259 //
260 Report = HidParser_SearchReportInCollection(CollectionContext, SubCollection, ReportType);
261 if (Report)
262 {
263 //
264 // found report
265 //
266 return Report;
267 }
268 }
269
270 //
271 // not found
272 //
273 return NULL;
274}
#define NULL
Definition: types.h:112
struct _HID_REPORT * PHID_REPORT
UCHAR Type
Definition: parser.h:224

Referenced by HidParser_GetReportInCollection(), and HidParser_SearchReportInCollection().

◆ HidParser_StoreCollection()

ULONG HidParser_StoreCollection ( IN PHID_COLLECTION  Collection,
IN PHID_COLLECTION_CONTEXT  CollectionContext,
IN ULONG  CurrentOffset 
)

Definition at line 83 of file context.c.

87{
89 ULONG ReportSize;
90 ULONG InitialOffset;
91 ULONG CollectionSize;
92 PHID_COLLECTION TargetCollection;
93
94 //
95 // backup initial offset
96 //
97 InitialOffset = CurrentOffset;
98
99 //
100 // get target collection
101 //
102 TargetCollection = (PHID_COLLECTION)(&CollectionContext->RawData[CurrentOffset]);
103
104 //
105 // first copy the collection details
106 //
107 CopyFunction(TargetCollection, Collection, sizeof(HID_COLLECTION));
108
109 //
110 // calulcate collection size
111 //
112 CollectionSize = sizeof(HID_COLLECTION) + sizeof(ULONG) * (Collection->ReportCount + Collection->NodeCount);
113
114 //
115 // increase offset
116 //
117 CurrentOffset += CollectionSize;
118
119 //
120 // sanity check
121 //
122 ASSERT(CurrentOffset < CollectionContext->Size);
123
124 //
125 // first store the report items
126 //
127 for(Index = 0; Index < Collection->ReportCount; Index++)
128 {
129 //
130 // calculate report size
131 //
132 ReportSize = sizeof(HID_REPORT) + Collection->Reports[Index]->ItemCount * sizeof(HID_REPORT_ITEM);
133
134 //
135 // sanity check
136 //
137 ASSERT(CurrentOffset + ReportSize < CollectionContext->Size);
138
139 //
140 // copy report item
141 //
142 CopyFunction(&CollectionContext->RawData[CurrentOffset], Collection->Reports[Index], ReportSize);
143
144 //
145 // store offset to report item
146 //
147 TargetCollection->Offsets[Index] = CurrentOffset;
148
149 //
150 // move to next offset
151 //
152 CurrentOffset += ReportSize;
153 }
154
155 ASSERT(CurrentOffset <= CollectionContext->Size);
156
157 //
158 // now store the sub collections
159 //
160 for(Index = 0; Index < Collection->NodeCount; Index++)
161 {
162 //
163 // store offset
164 //
165 TargetCollection->Offsets[Collection->ReportCount + Index] = CurrentOffset;
166
167 //
168 // store sub collections
169 //
170 CurrentOffset += HidParser_StoreCollection(Collection->Nodes[Index], CollectionContext, CurrentOffset);
171
172 //
173 // sanity check
174 //
175 ASSERT(CurrentOffset < CollectionContext->Size);
176 }
177
178 //
179 // return size of collection
180 //
181 return CurrentOffset - InitialOffset;
182}
ULONG Offsets[1]
Definition: parser.h:218
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION _In_ PMM_ROTATE_COPY_CALLBACK_FUNCTION CopyFunction
Definition: mmfuncs.h:775

Referenced by HidParser_BuildCollectionContext(), and HidParser_StoreCollection().