ReactOS  0.4.13-dev-551-gf37fb1f
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 
20 class CResourceList : public IResourceList
21 {
22 public:
24 
26  {
28  return m_Ref;
29  }
31  {
33 
34  if (!m_Ref)
35  {
36  delete this;
37  return 0;
38  }
39  return m_Ref;
40  }
41 
43 
45  virtual ~CResourceList();
46 
47 public:
55 };
56 
58 {
60  {
61  /* Free resource list */
63  }
64 
66  {
67  /* Free resource list */
69  }
70 }
71 
73 NTAPI
75  IN REFIID refiid,
76  OUT PVOID* Output)
77 {
79 
80  if (IsEqualGUIDAligned(refiid, IID_IResourceList) ||
82  {
83  *Output = PVOID(PRESOURCELIST(this));
84  PUNKNOWN(*Output)->AddRef();
85  return STATUS_SUCCESS;
86  }
87 
89  {
90  DPRINT1("IResourceList_QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
92  }
93 
94  return STATUS_UNSUCCESSFUL;
95 }
96 
97 ULONG
98 NTAPI
99 CResourceList::NumberOfEntries()
100 {
102 
103  return m_NumberOfEntries;
104 }
105 
106 ULONG
107 NTAPI
108 CResourceList::NumberOfEntriesOfType(
109  IN CM_RESOURCE_TYPE Type)
110 {
111  ULONG Index, Count = 0;
112  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
113 
115 
116  /* Is there a resource list? */
118  {
119  /* No resource list provided */
120  return 0;
121  }
122 
123  for (Index = 0; Index < m_NumberOfEntries; Index ++ )
124  {
125 
126  /* Get descriptor */
128  if (PartialDescriptor->Type == Type)
129  {
130  /* Yay! Finally found one that matches! */
131  Count++;
132  }
133  }
134 
135  DPRINT("Found %d type %d\n", Count, Type);
136  return Count;
137 }
138 
140 NTAPI
141 CResourceList::FindTranslatedEntry(
142  IN CM_RESOURCE_TYPE Type,
143  IN ULONG Index)
144 {
145  ULONG DescIndex, Count = 0;
146  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
147 
149 
150  /* Is there a resource list? */
152  {
153  /* No resource list */
154  return NULL;
155  }
156 
157  for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
158  {
159  /* Get descriptor */
160  PartialDescriptor = &m_TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
161 
162  if (PartialDescriptor->Type == Type)
163  {
164  /* Found type, is it the requested index? */
165  if (Index == Count)
166  {
167  /* Found */
168  return PartialDescriptor;
169  }
170 
171  /* Need to continue search */
172  Count++;
173  }
174  }
175 
176  /* No such descriptor */
177  return NULL;
178 }
179 
181 NTAPI
182 CResourceList::FindUntranslatedEntry(
183  IN CM_RESOURCE_TYPE Type,
184  IN ULONG Index)
185 {
186  ULONG DescIndex, Count = 0;
187  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
188 
190 
191  /* Is there a resource list? */
193  {
194  /* Empty resource list */
195  return NULL;
196  }
197 
198  /* Search descriptors */
199  for (DescIndex = 0; DescIndex < m_NumberOfEntries; DescIndex ++ )
200  {
201  /* Get descriptor */
202  PartialDescriptor = &m_UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
203 
204  if (PartialDescriptor->Type == Type)
205  {
206  /* Found type, is it the requested index? */
207  if (Index == Count)
208  {
209  /* Found */
210  return PartialDescriptor;
211  }
212 
213  /* Need to continue search */
214  Count++;
215  }
216  }
217 
218  /* No such descriptor */
219  return NULL;
220 }
221 
222 NTSTATUS
223 NTAPI
224 CResourceList::AddEntry(
226  IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated)
227 {
228  PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
229 
230  /* Sanity check */
232 
233 
234  /* Is there still room for another entry */
236  {
237  /* No more space */
239  }
240 
241  /* Get free descriptor */
243 
244  /* Copy descriptor */
245  RtlCopyMemory(PartialDescriptor, Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
246 
247  /* Get free descriptor */
249 
250  /* Copy descriptor */
251  RtlCopyMemory(PartialDescriptor, Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
252 
253  /* Add entry count */
257 
258  /* Done */
259  return STATUS_SUCCESS;
260 }
261 
262 NTSTATUS
263 NTAPI
264 CResourceList::AddEntryFromParent(
265  IN IResourceList* Parent,
266  IN CM_RESOURCE_TYPE Type,
267  IN ULONG Index)
268 {
269  PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated, Untranslated;
270 
272 
273  /* Get entries from parent */
274  Translated = Parent->FindTranslatedEntry(Type, Index);
275  Untranslated = Parent->FindUntranslatedEntry(Type, Index);
276 
277  /* Are both found? */
278  if (Translated && Untranslated)
279  {
280  /* Add entry from parent */
281  return AddEntry(Translated, Untranslated);
282  }
283 
284  /* Entry not found */
286 }
287 
289 NTAPI
290 CResourceList::TranslatedList()
291 {
293 
295 }
296 
298 NTAPI
299 CResourceList::UntranslatedList()
300 {
302 
304 }
305 
306 
308 NTSTATUS
309 NTAPI
311  OUT PRESOURCELIST* OutResourceList,
312  IN PUNKNOWN OuterUnknown OPTIONAL,
314  IN PCM_RESOURCE_LIST TranslatedResourceList,
315  IN PCM_RESOURCE_LIST UntranslatedResourceList)
316 {
317  PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
318  ULONG ResourceSize, ResourceCount;
319  CResourceList* NewList;
321 
322  if (!TranslatedResourceList)
323  {
324  /* If the untranslated resource list is also not provided, it becomes an empty resource list */
325  if (UntranslatedResourceList)
326  {
327  /* Invalid parameter mix */
329  }
330  }
331  else
332  {
333  /* If the translated resource list is also not provided, it becomes an empty resource list */
334  if (!UntranslatedResourceList)
335  {
336  /* Invalid parameter mix */
338  }
339  }
340 
341  /* Allocate resource list */
342  NewList = new(PoolType, TAG_PORTCLASS)CResourceList(OuterUnknown);
343  if (!NewList)
345 
346  /* Query resource list */
347  Status = NewList->QueryInterface(IID_IResourceList, (PVOID*)OutResourceList);
348  if (!NT_SUCCESS(Status))
349  {
350  /* Ouch, FIX ME */
351  delete NewList;
353  }
354 
355  /* Is there a resource list */
356  if (!TranslatedResourceList)
357  {
358  /* Empty resource list */
359  return STATUS_SUCCESS;
360  }
361 
362  /* Sanity check */
363  ASSERT(UntranslatedResourceList->List[0].PartialResourceList.Count == TranslatedResourceList->List[0].PartialResourceList.Count);
364 
365  /* Get resource count */
366  ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
367 #ifdef _MSC_VER
368  ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
369 #else
371 #endif
372 
373  /* Allocate translated resource list */
374  NewTranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
375  if (!NewTranslatedResources)
376  {
377  /* No memory */
378  delete NewList;
380  }
381 
382  /* Allocate untranslated resource list */
383  NewUntranslatedResources = (PCM_RESOURCE_LIST)AllocateItem(PoolType, ResourceSize, TAG_PORTCLASS);
384  if (!NewUntranslatedResources)
385  {
386  /* No memory */
387  delete NewList;
388  FreeItem(NewTranslatedResources, TAG_PORTCLASS);
390  }
391 
392  /* Copy resource lists */
393  RtlCopyMemory(NewTranslatedResources, TranslatedResourceList, ResourceSize);
394  RtlCopyMemory(NewUntranslatedResources, UntranslatedResourceList, ResourceSize);
395 
396  /* Init resource list */
397  NewList->m_TranslatedResourceList= NewTranslatedResources;
398  NewList->m_UntranslatedResourceList = NewUntranslatedResources;
399  NewList->m_NumberOfEntries = ResourceCount;
400  NewList->m_MaxEntries = ResourceCount;
401  NewList->m_PoolType = PoolType;
402 
403  /* Done */
404  return STATUS_SUCCESS;
405 }
406 
408 NTSTATUS
409 NTAPI
411  OUT PRESOURCELIST* OutResourceList,
412  IN PUNKNOWN OuterUnknown OPTIONAL,
414  IN PRESOURCELIST ParentList,
415  IN ULONG MaximumEntries)
416 {
417  CResourceList* NewList;
418  ULONG ResourceSize;
419 
420  if (!OutResourceList || !ParentList || !MaximumEntries)
422 
423  /* Allocate new list */
424  NewList = new(PoolType, TAG_PORTCLASS) CResourceList(OuterUnknown);
425  if (!NewList)
427 
428  /* Get resource size */
429 #ifdef _MSC_VER
430  ResourceSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[MaximumEntries]);
431 #else
432  ResourceSize = sizeof(CM_RESOURCE_LIST) - sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + (MaximumEntries) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
433 #endif
434 
435  /* Allocate resource list */
437  if (!NewList->m_TranslatedResourceList)
438  {
439  /* No memory */
440  delete NewList;
442  }
443 
444  /* Allocate resource list */
446  if (!NewList->m_UntranslatedResourceList)
447  {
448  /* No memory */
449  delete NewList;
451  }
452 
453  /* Copy resource lists */
454  RtlCopyMemory(NewList->m_TranslatedResourceList, ParentList->TranslatedList(), sizeof(CM_RESOURCE_LIST));
455  RtlCopyMemory(NewList->m_UntranslatedResourceList, ParentList->UntranslatedList(), sizeof(CM_RESOURCE_LIST));
456 
457  /* Resource list is empty */
460 
461  /* Store members */
462  NewList->m_OuterUnknown = OuterUnknown;
463  NewList->m_PoolType = PoolType;
464  NewList->m_Ref = 1;
465  NewList->m_NumberOfEntries = 0;
466  NewList->m_MaxEntries = MaximumEntries;
467 
468  /* Store result */
469  *OutResourceList = (IResourceList*)NewList;
470 
471  /* Done */
472  return STATUS_SUCCESS;
473 }
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
static PWSTR GuidString
Definition: apphelp.c:91
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:113
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
_In_ BOOLEAN Release
Definition: classpnp.h:929
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: hwresource.cpp:165
virtual ~CResourceList()
Definition: resource.cpp:57
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
#define TAG_PORTCLASS
Definition: private.hpp:24
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
ULONG m_NumberOfEntries
Definition: resource.cpp:52
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical 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:716
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PCM_RESOURCE_LIST m_UntranslatedResourceList
Definition: resource.cpp:51
long LONG
Definition: pedump.c:60
#define STDMETHODIMP
Definition: basetyps.h:43
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define PORTCLASSAPI
Definition: portcls.h:148
void * PVOID
Definition: retypes.h:9
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
LIST_ENTRY List
Definition: psmgr.c:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
INT POOL_TYPE
Definition: typedefs.h:76
const GUID IID_IUnknown
static const UCHAR Index[8]
Definition: usbohci.c:18
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
ULONG AddRef()
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static ULONG ResourceCount
Definition: inbv.c:47
STDMETHODIMP_(ULONG) AddRef()
Definition: resource.cpp:25
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
#define InterlockedDecrement
Definition: armddk.h:52
PUNKNOWN m_OuterUnknown
Definition: resource.cpp:48
Definition: arc.h:85
ULONG m_MaxEntries
Definition: resource.cpp:53
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
Status
Definition: gdiplustypes.h:24
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: resource.cpp:74
IResourceList * PRESOURCELIST
Definition: portcls.h:442
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:310
POOL_TYPE m_PoolType
Definition: resource.cpp:49
STDMETHODIMP_(ULONG) Release()
Definition: resource.cpp:30
#define InterlockedIncrement
Definition: armddk.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
PCM_RESOURCE_LIST m_TranslatedResourceList
Definition: resource.cpp:50
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
CResourceList(IUnknown *OuterUnknown)
Definition: resource.cpp:44
#define DPRINT1
Definition: precomp.h:8
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2777
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
PORTCLASSAPI NTSTATUS NTAPI PcNewResourceSublist(OUT PRESOURCELIST *OutResourceList, IN PUNKNOWN OuterUnknown OPTIONAL, IN POOL_TYPE PoolType, IN PRESOURCELIST ParentList, IN ULONG MaximumEntries)
Definition: resource.cpp:410
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68