ReactOS 0.4.15-dev-5893-g1bb4167
resource.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS
4 * FILE: drivers/wdm/audio/backpln/portcls/resource.cpp
5 * PURPOSE: Port Class driver / ResourceList implementation
6 * PROGRAMMER: Andrew Greenwood
7 * Johannes Anderwald
8 * HISTORY:
9 * 27 Jan 07 Created
10 */
11
12#include "private.hpp"
13
14#ifndef YDEBUG
15#define NDEBUG
16#endif
17
18#include <debug.h>
19
20class CResourceList : public CUnknownImpl<IResourceList>
21{
22public:
24
26
27 CResourceList(IUnknown * OuterUnknown) :
28 m_OuterUnknown(OuterUnknown),
34 {
35 }
36 virtual ~CResourceList();
37
38public:
45};
46
48{
50 {
51 /* Free resource list */
53 }
54
56 {
57 /* Free resource list */
59 }
60}
61
65 IN REFIID refiid,
67{
69
70 if (IsEqualGUIDAligned(refiid, IID_IResourceList) ||
72 {
73 *Output = PVOID(PRESOURCELIST(this));
74 PUNKNOWN(*Output)->AddRef();
75 return STATUS_SUCCESS;
76 }
77
79 {
80 DPRINT1("IResourceList_QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
82 }
83
85}
86
89CResourceList::NumberOfEntries()
90{
92
93 return m_NumberOfEntries;
94}
95
98CResourceList::NumberOfEntriesOfType(
99 IN CM_RESOURCE_TYPE Type)
100{
101 ULONG Index, Count = 0;
102 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
103
105
106 /* Is there a resource list? */
108 {
109 /* No resource list provided */
110 return 0;
111 }
112
113 for (Index = 0; Index < m_NumberOfEntries; Index ++ )
114 {
115
116 /* Get descriptor */
118 if (PartialDescriptor->Type == Type)
119 {
120 /* Yay! Finally found one that matches! */
121 Count++;
122 }
123 }
124
125 DPRINT("Found %d type %d\n", Count, Type);
126 return Count;
127}
128
130NTAPI
131CResourceList::FindTranslatedEntry(
132 IN CM_RESOURCE_TYPE Type,
133 IN ULONG Index)
134{
135 ULONG DescIndex, Count = 0;
136 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
137
139
140 /* Is there a resource list? */
142 {
143 /* No resource list */
144 return NULL;
145 }
146
147 for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
148 {
149 /* Get descriptor */
150 PartialDescriptor = &m_TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
151
152 if (PartialDescriptor->Type == Type)
153 {
154 /* Found type, is it the requested index? */
155 if (Index == Count)
156 {
157 /* Found */
158 return PartialDescriptor;
159 }
160
161 /* Need to continue search */
162 Count++;
163 }
164 }
165
166 /* No such descriptor */
167 return NULL;
168}
169
171NTAPI
172CResourceList::FindUntranslatedEntry(
173 IN CM_RESOURCE_TYPE Type,
174 IN ULONG Index)
175{
176 ULONG DescIndex, Count = 0;
177 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
178
180
181 /* Is there a resource list? */
183 {
184 /* Empty resource list */
185 return NULL;
186 }
187
188 /* Search descriptors */
189 for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
190 {
191 /* Get descriptor */
192 PartialDescriptor = &m_UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
193
194 if (PartialDescriptor->Type == Type)
195 {
196 /* Found type, is it the requested index? */
197 if (Index == Count)
198 {
199 /* Found */
200 return PartialDescriptor;
201 }
202
203 /* Need to continue search */
204 Count++;
205 }
206 }
207
208 /* No such descriptor */
209 return NULL;
210}
211
213NTAPI
214CResourceList::AddEntry(
217{
218 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
219
220 /* Sanity check */
222
223
224 /* Is there still room for another entry */
226 {
227 /* No more space */
229 }
230
231 /* Get free descriptor */
233
234 /* Copy descriptor */
235 RtlCopyMemory(PartialDescriptor, Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
236
237 /* Get free descriptor */
239
240 /* Copy descriptor */
241 RtlCopyMemory(PartialDescriptor, Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
242
243 /* Add entry count */
247
248 /* Done */
249 return STATUS_SUCCESS;
250}
251
253NTAPI
254CResourceList::AddEntryFromParent(
255 IN IResourceList* Parent,
256 IN CM_RESOURCE_TYPE Type,
257 IN ULONG Index)
258{
259 PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated, Untranslated;
260
262
263 /* Get entries from parent */
264 Translated = Parent->FindTranslatedEntry(Type, Index);
265 Untranslated = Parent->FindUntranslatedEntry(Type, Index);
266
267 /* Are both found? */
268 if (Translated && Untranslated)
269 {
270 /* Add entry from parent */
271 return AddEntry(Translated, Untranslated);
272 }
273
274 /* Entry not found */
276}
277
279NTAPI
280CResourceList::TranslatedList()
281{
283
285}
286
288NTAPI
289CResourceList::UntranslatedList()
290{
292
294}
295
296
299NTAPI
301 OUT PRESOURCELIST* OutResourceList,
302 IN PUNKNOWN OuterUnknown OPTIONAL,
304 IN PCM_RESOURCE_LIST TranslatedResourceList,
305 IN PCM_RESOURCE_LIST UntranslatedResourceList)
306{
307 PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
308 ULONG ResourceSize, ResourceCount;
309 CResourceList* NewList;
311
312 if (!TranslatedResourceList)
313 {
314 /* If the untranslated resource list is also not provided, it becomes an empty resource list */
315 if (UntranslatedResourceList)
316 {
317 /* Invalid parameter mix */
319 }
320 }
321 else
322 {
323 /* If the translated resource list is also not provided, it becomes an empty resource list */
324 if (!UntranslatedResourceList)
325 {
326 /* Invalid parameter mix */
328 }
329 }
330
331 /* Allocate resource list */
332 NewList = new(PoolType, TAG_PORTCLASS)CResourceList(OuterUnknown);
333 if (!NewList)
335
336 /* Query resource list */
337 Status = NewList->QueryInterface(IID_IResourceList, (PVOID*)OutResourceList);
338 if (!NT_SUCCESS(Status))
339 {
340 /* Ouch, FIX ME */
341 delete NewList;
343 }
344
345 /* Is there a resource list */
346 if (!TranslatedResourceList)
347 {
348 /* Empty resource list */
349 return STATUS_SUCCESS;
350 }
351
352 /* Sanity check */
353 ASSERT(UntranslatedResourceList->List[0].PartialResourceList.Count == TranslatedResourceList->List[0].PartialResourceList.Count);
354
355 /* Get resource count */
356 ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
357#ifdef _MSC_VER
358 ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
359#else
361#endif
362
363 /* Allocate translated resource list */
364 NewTranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
365 if (!NewTranslatedResources)
366 {
367 /* No memory */
368 delete NewList;
370 }
371
372 /* Allocate untranslated resource list */
373 NewUntranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
374 if (!NewUntranslatedResources)
375 {
376 /* No memory */
377 delete NewList;
378 FreeItem(NewTranslatedResources, TAG_PORTCLASS);
380 }
381
382 /* Copy resource lists */
383 RtlCopyMemory(NewTranslatedResources, TranslatedResourceList, ResourceSize);
384 RtlCopyMemory(NewUntranslatedResources, UntranslatedResourceList, ResourceSize);
385
386 /* Init resource list */
387 NewList->m_TranslatedResourceList= NewTranslatedResources;
388 NewList->m_UntranslatedResourceList = NewUntranslatedResources;
390 NewList->m_MaxEntries = ResourceCount;
391 NewList->m_PoolType = PoolType;
392
393 /* Done */
394 return STATUS_SUCCESS;
395}
396
399NTAPI
401 OUT PRESOURCELIST* OutResourceList,
402 IN PUNKNOWN OuterUnknown OPTIONAL,
404 IN PRESOURCELIST ParentList,
405 IN ULONG MaximumEntries)
406{
407 CResourceList* NewList;
408 ULONG ResourceSize;
409
410 if (!OutResourceList || !ParentList || !MaximumEntries)
412
413 /* Allocate new list */
414 NewList = new(PoolType, TAG_PORTCLASS) CResourceList(OuterUnknown);
415 if (!NewList)
417
418 /* Get resource size */
419#ifdef _MSC_VER
420 ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[MaximumEntries]);
421#else
422 ResourceSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + (MaximumEntries) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
423#endif
424
425 /* Allocate resource list */
427 if (!NewList->m_TranslatedResourceList)
428 {
429 /* No memory */
430 delete NewList;
432 }
433
434 /* Allocate resource list */
436 if (!NewList->m_UntranslatedResourceList)
437 {
438 /* No memory */
439 delete NewList;
441 }
442
443 /* Copy resource lists */
444 RtlCopyMemory(NewList->m_TranslatedResourceList, ParentList->TranslatedList(), sizeof(CM_RESOURCE_LIST));
445 RtlCopyMemory(NewList->m_UntranslatedResourceList, ParentList->UntranslatedList(), sizeof(CM_RESOURCE_LIST));
446
447 /* Resource list is empty */
450
451 /* Store members */
452 NewList->m_OuterUnknown = OuterUnknown;
453 NewList->m_PoolType = PoolType;
454 NewList->AddRef();
455 NewList->m_NumberOfEntries = 0;
456 NewList->m_MaxEntries = MaximumEntries;
457
458 /* Store result */
459 *OutResourceList = (IResourceList*)NewList;
460
461 /* Done */
462 return STATUS_SUCCESS;
463}
Type
Definition: Type.h:7
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:732
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STDMETHODIMP
Definition: basetyps.h:43
const GUID IID_IUnknown
POOL_TYPE m_PoolType
Definition: resource.cpp:40
virtual ~CResourceList()
Definition: resource.cpp:47
PUNKNOWN m_OuterUnknown
Definition: resource.cpp:39
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: resource.cpp:64
ULONG m_MaxEntries
Definition: resource.cpp:44
PCM_RESOURCE_LIST m_TranslatedResourceList
Definition: resource.cpp:41
CResourceList(IUnknown *OuterUnknown)
Definition: resource.cpp:27
ULONG m_NumberOfEntries
Definition: resource.cpp:43
PCM_RESOURCE_LIST m_UntranslatedResourceList
Definition: resource.cpp:42
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
static ULONG ResourceCount
Definition: inbv.c:50
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
ULONG AddRef()
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define ASSERT(a)
Definition: mode.c:44
static PWSTR GuidString
Definition: apphelp.c:93
int Count
Definition: noreturn.cpp:7
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
IResourceList * PRESOURCELIST
Definition: portcls.h:442
#define PORTCLASSAPI
Definition: portcls.h:148
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
#define TAG_PORTCLASS
Definition: private.hpp:24
#define REFIID
Definition: guiddef.h:118
PORTCLASSAPI NTSTATUS NTAPI PcNewResourceSublist(OUT PRESOURCELIST *OutResourceList, IN PUNKNOWN OuterUnknown OPTIONAL, IN POOL_TYPE PoolType, IN PRESOURCELIST ParentList, IN ULONG MaximumEntries)
Definition: resource.cpp:400
PORTCLASSAPI NTSTATUS NTAPI PcNewResourceList(OUT PRESOURCELIST *OutResourceList, IN PUNKNOWN OuterUnknown OPTIONAL, IN POOL_TYPE PoolType, IN PCM_RESOURCE_LIST TranslatedResourceList, IN PCM_RESOURCE_LIST UntranslatedResourceList)
Definition: resource.cpp:300
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: hwresource.cpp:165
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
INT POOL_TYPE
Definition: typedefs.h:78
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235