ReactOS 0.4.15-dev-8135-g1bc6c90
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#define NDEBUG
15#include <debug.h>
16
17class CResourceList : public CUnknownImpl<IResourceList>
18{
19public:
21
23
24 CResourceList(IUnknown * OuterUnknown) :
25 m_OuterUnknown(OuterUnknown),
31 {
32 }
33 virtual ~CResourceList();
34
35public:
42};
43
45{
47 {
48 /* Free resource list */
50 }
51
53 {
54 /* Free resource list */
56 }
57}
58
62 IN REFIID refiid,
64{
66
67 if (IsEqualGUIDAligned(refiid, IID_IResourceList) ||
69 {
70 *Output = PVOID(PRESOURCELIST(this));
71 PUNKNOWN(*Output)->AddRef();
72 return STATUS_SUCCESS;
73 }
74
76 {
77 DPRINT1("IResourceList_QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
79 }
80
82}
83
86CResourceList::NumberOfEntries()
87{
89
90 return m_NumberOfEntries;
91}
92
95CResourceList::NumberOfEntriesOfType(
96 IN CM_RESOURCE_TYPE Type)
97{
98 ULONG Index, Count = 0;
99 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
100
102
103 /* Is there a resource list? */
105 {
106 /* No resource list provided */
107 return 0;
108 }
109
110 for (Index = 0; Index < m_NumberOfEntries; Index ++ )
111 {
112
113 /* Get descriptor */
115 if (PartialDescriptor->Type == Type)
116 {
117 /* Yay! Finally found one that matches! */
118 Count++;
119 }
120 }
121
122 DPRINT("Found %d type %d\n", Count, Type);
123 return Count;
124}
125
127NTAPI
128CResourceList::FindTranslatedEntry(
129 IN CM_RESOURCE_TYPE Type,
130 IN ULONG Index)
131{
132 ULONG DescIndex, Count = 0;
133 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
134
136
137 /* Is there a resource list? */
139 {
140 /* No resource list */
141 return NULL;
142 }
143
144 for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
145 {
146 /* Get descriptor */
147 PartialDescriptor = &m_TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
148
149 if (PartialDescriptor->Type == Type)
150 {
151 /* Found type, is it the requested index? */
152 if (Index == Count)
153 {
154 /* Found */
155 return PartialDescriptor;
156 }
157
158 /* Need to continue search */
159 Count++;
160 }
161 }
162
163 /* No such descriptor */
164 return NULL;
165}
166
168NTAPI
169CResourceList::FindUntranslatedEntry(
170 IN CM_RESOURCE_TYPE Type,
171 IN ULONG Index)
172{
173 ULONG DescIndex, Count = 0;
174 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
175
177
178 /* Is there a resource list? */
180 {
181 /* Empty resource list */
182 return NULL;
183 }
184
185 /* Search descriptors */
186 for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
187 {
188 /* Get descriptor */
189 PartialDescriptor = &m_UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
190
191 if (PartialDescriptor->Type == Type)
192 {
193 /* Found type, is it the requested index? */
194 if (Index == Count)
195 {
196 /* Found */
197 return PartialDescriptor;
198 }
199
200 /* Need to continue search */
201 Count++;
202 }
203 }
204
205 /* No such descriptor */
206 return NULL;
207}
208
210NTAPI
211CResourceList::AddEntry(
214{
215 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
216
217 /* Sanity check */
219
220 /* Is there still room for another entry */
222 {
223 /* No more space */
225 }
226
227 /* Get free descriptor */
229
230 /* Copy descriptor */
231 RtlCopyMemory(PartialDescriptor, Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
232
233 /* Get free descriptor */
235
236 /* Copy descriptor */
237 RtlCopyMemory(PartialDescriptor, Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
238
239 /* Add entry count */
243
244 /* Done */
245 return STATUS_SUCCESS;
246}
247
249NTAPI
250CResourceList::AddEntryFromParent(
251 IN IResourceList* Parent,
252 IN CM_RESOURCE_TYPE Type,
253 IN ULONG Index)
254{
255 PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated, Untranslated;
256
258
259 /* Get entries from parent */
260 Translated = Parent->FindTranslatedEntry(Type, Index);
261 Untranslated = Parent->FindUntranslatedEntry(Type, Index);
262
263 /* Are both found? */
264 if (Translated && Untranslated)
265 {
266 /* Add entry from parent */
267 return AddEntry(Translated, Untranslated);
268 }
269
270 /* Entry not found */
272}
273
275NTAPI
276CResourceList::TranslatedList()
277{
279
281}
282
284NTAPI
285CResourceList::UntranslatedList()
286{
288
290}
291
294NTAPI
296 OUT PRESOURCELIST* OutResourceList,
297 IN PUNKNOWN OuterUnknown OPTIONAL,
299 IN PCM_RESOURCE_LIST TranslatedResourceList,
300 IN PCM_RESOURCE_LIST UntranslatedResourceList)
301{
302 PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
303 ULONG ResourceSize, ResourceCount;
304 CResourceList* NewList;
306
307 if (!TranslatedResourceList)
308 {
309 /* If the untranslated resource list is also not provided, it becomes an empty resource list */
310 if (UntranslatedResourceList)
311 {
312 /* Invalid parameter mix */
314 }
315 }
316 else
317 {
318 /* If the translated resource list is also not provided, it becomes an empty resource list */
319 if (!UntranslatedResourceList)
320 {
321 /* Invalid parameter mix */
323 }
324 }
325
326 /* Allocate resource list */
327 NewList = new(PoolType, TAG_PORTCLASS)CResourceList(OuterUnknown);
328 if (!NewList)
330
331 /* Query resource list */
332 Status = NewList->QueryInterface(IID_IResourceList, (PVOID*)OutResourceList);
333 if (!NT_SUCCESS(Status))
334 {
335 /* Ouch, FIX ME */
336 delete NewList;
338 }
339
340 /* Is there a resource list */
341 if (!TranslatedResourceList)
342 {
343 /* Empty resource list */
344 return STATUS_SUCCESS;
345 }
346
347 /* Sanity check */
348 ASSERT(UntranslatedResourceList->List[0].PartialResourceList.Count == TranslatedResourceList->List[0].PartialResourceList.Count);
349
350 /* Get resource count */
351 ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
352#ifdef _MSC_VER
353 ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
354#else
356#endif
357
358 /* Allocate translated resource list */
359 NewTranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
360 if (!NewTranslatedResources)
361 {
362 /* No memory */
363 delete NewList;
365 }
366
367 /* Allocate untranslated resource list */
368 NewUntranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
369 if (!NewUntranslatedResources)
370 {
371 /* No memory */
372 delete NewList;
373 FreeItem(NewTranslatedResources, TAG_PORTCLASS);
375 }
376
377 /* Copy resource lists */
378 RtlCopyMemory(NewTranslatedResources, TranslatedResourceList, ResourceSize);
379 RtlCopyMemory(NewUntranslatedResources, UntranslatedResourceList, ResourceSize);
380
381 /* Init resource list */
382 NewList->m_TranslatedResourceList= NewTranslatedResources;
383 NewList->m_UntranslatedResourceList = NewUntranslatedResources;
385 NewList->m_MaxEntries = ResourceCount;
386 NewList->m_PoolType = PoolType;
387
388 /* Done */
389 return STATUS_SUCCESS;
390}
391
394NTAPI
396 OUT PRESOURCELIST* OutResourceList,
397 IN PUNKNOWN OuterUnknown OPTIONAL,
399 IN PRESOURCELIST ParentList,
400 IN ULONG MaximumEntries)
401{
402 CResourceList* NewList;
403 ULONG ResourceSize;
404
405 if (!OutResourceList || !ParentList || !MaximumEntries)
407
408 /* Allocate new list */
409 NewList = new(PoolType, TAG_PORTCLASS) CResourceList(OuterUnknown);
410 if (!NewList)
412
413 /* Get resource size */
414#ifdef _MSC_VER
415 ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[MaximumEntries]);
416#else
417 ResourceSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + (MaximumEntries) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
418#endif
419
420 /* Allocate resource list */
422 if (!NewList->m_TranslatedResourceList)
423 {
424 /* No memory */
425 delete NewList;
427 }
428
429 /* Allocate resource list */
431 if (!NewList->m_UntranslatedResourceList)
432 {
433 /* No memory */
434 delete NewList;
436 }
437
438 /* Copy resource lists */
439 RtlCopyMemory(NewList->m_TranslatedResourceList, ParentList->TranslatedList(), sizeof(CM_RESOURCE_LIST));
440 RtlCopyMemory(NewList->m_UntranslatedResourceList, ParentList->UntranslatedList(), sizeof(CM_RESOURCE_LIST));
441
442 /* Resource list is empty */
445
446 /* Store members */
447 NewList->m_OuterUnknown = OuterUnknown;
448 NewList->m_PoolType = PoolType;
449 NewList->AddRef();
450 NewList->m_NumberOfEntries = 0;
451 NewList->m_MaxEntries = MaximumEntries;
452
453 /* Store result */
454 *OutResourceList = (IResourceList*)NewList;
455
456 /* Done */
457 return STATUS_SUCCESS;
458}
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:37
virtual ~CResourceList()
Definition: resource.cpp:44
PUNKNOWN m_OuterUnknown
Definition: resource.cpp:36
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: resource.cpp:61
ULONG m_MaxEntries
Definition: resource.cpp:41
PCM_RESOURCE_LIST m_TranslatedResourceList
Definition: resource.cpp:38
CResourceList(IUnknown *OuterUnknown)
Definition: resource.cpp:24
ULONG m_NumberOfEntries
Definition: resource.cpp:40
PCM_RESOURCE_LIST m_UntranslatedResourceList
Definition: resource.cpp:39
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
static BOOL AddEntry(WCHAR Type, LPCWSTR Value)
Definition: geninst.cpp:217
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:29
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
#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:395
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:295
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
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