- Remove dead code
[reactos.git] / reactos / drivers / wdm / audio / backpln / portcls / ResourceList.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS
4 * FILE: drivers/multimedia/portcls/helpers/ResourceList.c
5 * PURPOSE: Port Class driver / ResourceList implementation
6 * PROGRAMMER: Andrew Greenwood
7 *
8 * HISTORY:
9 * 27 Jan 07 Created
10 */
11
12 #include "private.h"
13 #include <portcls.h>
14 #include <stdunk.h>
15
16 typedef struct CResourceList
17 {
18 union
19 {
20 IUnknown IUnknown;
21 IResourceList IResourceList;
22 };
23
24 LONG m_ref_count;
25 PUNKNOWN m_outer_unknown;
26
27 PCM_RESOURCE_LIST translated_resources;
28 PCM_RESOURCE_LIST untranslated_resources;
29 } CResourceList;
30
31
32 /*
33 Basic IUnknown methods
34 */
35
36 NTSTATUS
37 STDMETHODCALLTYPE
38 ResourceList_QueryInterface(
39 IResourceList* this_container,
40 IN REFIID refiid,
41 OUT PVOID* output)
42 {
43 /* TODO */
44 return STATUS_SUCCESS;
45 }
46
47 ULONG
48 STDMETHODCALLTYPE
49 ResourceList_AddRef(
50 IResourceList* this_container)
51 {
52 struct CUnknown* this = CONTAINING_RECORD(this_container, struct CUnknown, IUnknown);
53
54 /* fixme */
55 /* ExInterlockedIncrement(&this->m_ref_count); */
56 return this->m_ref_count;
57 }
58
59 ULONG
60 STDMETHODCALLTYPE
61 ResourceList_Release(
62 IResourceList* this_container)
63 {
64 struct CUnknown* this = CONTAINING_RECORD(this_container, struct CUnknown, IUnknown);
65
66 /* fixme */
67 /* ExInterlockedDecrement(&this->m_ref_count); */
68
69 if ( this->m_ref_count == 0 )
70 {
71 ExFreePool(this);
72 return 0;
73 }
74
75 return this->m_ref_count;
76 }
77
78
79 /*
80 IResourceList methods
81 */
82
83 ULONG
84 STDMETHODCALLTYPE
85 ResourceList_NumberOfEntries(IResourceList* this_container)
86 {
87 return 0;
88 }
89
90 ULONG
91 STDMETHODCALLTYPE
92 ResourceList_NumberOfEntriesOfType(
93 IResourceList* this_container,
94 IN CM_RESOURCE_TYPE type)
95 {
96 /* I guess the translated and untranslated lists will be same length? */
97
98 CResourceList* this = CONTAINING_RECORD(this_container, CResourceList, IResourceList);
99 ULONG index, count = 0;
100
101 for ( index = 0; index < this->translated_resources->Count; index ++ )
102 {
103 PCM_FULL_RESOURCE_DESCRIPTOR full_desc = &this->translated_resources->List[index];
104 ULONG sub_index;
105
106 for ( sub_index = 0; sub_index < full_desc->PartialResourceList.Count; sub_index ++ )
107 {
108 PCM_PARTIAL_RESOURCE_DESCRIPTOR partial_desc;
109 partial_desc = &full_desc->PartialResourceList.PartialDescriptors[sub_index];
110
111 if ( partial_desc->Type == type )
112 {
113 /* Yay! Finally found one that matches! */
114 count ++;
115 }
116 }
117 }
118
119 DPRINT("Found %d\n", count);
120 return count;
121 }
122
123 PCM_PARTIAL_RESOURCE_DESCRIPTOR
124 STDMETHODCALLTYPE
125 ResourceList_FindTranslatedEntry(
126 IResourceList* this_container,
127 IN CM_RESOURCE_TYPE Type,
128 IN ULONG Index)
129 {
130 return NULL;
131 }
132
133 PCM_PARTIAL_RESOURCE_DESCRIPTOR
134 STDMETHODCALLTYPE
135 ResourceList_FindUntranslatedEntry(
136 IResourceList* this_container,
137 IN CM_RESOURCE_TYPE Type,
138 IN ULONG Index)
139 {
140 return NULL;
141 }
142
143 NTSTATUS
144 STDMETHODCALLTYPE
145 ResourceList_AddEntry(
146 IResourceList* this_container,
147 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated,
148 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated)
149 {
150 return STATUS_SUCCESS;
151 }
152
153 NTSTATUS
154 STDMETHODCALLTYPE
155 ResourceList_AddEntryFromParent(
156 IResourceList* this_container,
157 IN IResourceList* Parent,
158 IN CM_RESOURCE_TYPE Type,
159 IN ULONG Index)
160 {
161 return STATUS_SUCCESS;
162 }
163
164 PCM_RESOURCE_LIST
165 STDMETHODCALLTYPE
166 ResourceList_TranslatedList(
167 IResourceList* this_container)
168 {
169 return NULL;
170 }
171
172 PCM_RESOURCE_LIST
173 STDMETHODCALLTYPE
174 ResourceList_UntranslatedList(
175 IResourceList* this_container)
176 {
177 return NULL;
178 }
179
180
181 /*
182 ResourceList V-Table
183 */
184 static const IResourceListVtbl ResourceListVtbl =
185 {
186 /* IUnknown */
187 ResourceList_QueryInterface,
188 ResourceList_AddRef,
189 ResourceList_Release,
190
191 /* IResourceList */
192 ResourceList_NumberOfEntries,
193 ResourceList_NumberOfEntriesOfType,
194 ResourceList_FindTranslatedEntry,
195 ResourceList_FindUntranslatedEntry,
196 ResourceList_AddEntry,
197 ResourceList_AddEntryFromParent,
198 ResourceList_TranslatedList,
199 ResourceList_UntranslatedList
200 };
201
202
203 /*
204 Factory for creating a resource list
205 */
206 PORTCLASSAPI NTSTATUS NTAPI
207 PcNewResourceList(
208 OUT PRESOURCELIST* OutResourceList,
209 IN PUNKNOWN OuterUnknown OPTIONAL,
210 IN POOL_TYPE PoolType,
211 IN PCM_RESOURCE_LIST TranslatedResources,
212 IN PCM_RESOURCE_LIST UntranslatedResources)
213 {
214 IResourceList* new_list = NULL;
215 CResourceList* this = NULL;
216
217 /* TODO: Validate parameters */
218
219 DPRINT("PcNewResourceList\n");
220
221 new_list = ExAllocatePoolWithTag(sizeof(IResourceList), PoolType, TAG_PORTCLASS);
222
223 if ( ! new_list )
224 {
225 DPRINT("ExAllocatePoolWithTag failed\n");
226 return STATUS_INSUFFICIENT_RESOURCES;
227 }
228
229 /* Obtain our private data */
230 this = CONTAINING_RECORD(new_list, CResourceList, IResourceList);
231
232 ASSERT(this);
233
234 /* Initialize */
235 this->m_outer_unknown = OuterUnknown;
236 this->translated_resources = TranslatedResources;
237 this->untranslated_resources = UntranslatedResources;
238
239 /* Increment our usage count and set the pointer to this object */
240 *OutResourceList = new_list;
241 ResourceListVtbl.AddRef(*OutResourceList);
242
243 return STATUS_SUCCESS;
244 }
245
246 PORTCLASSAPI NTSTATUS NTAPI
247 PcNewResourceSublist(
248 OUT PRESOURCELIST* OutResourceList,
249 IN PUNKNOWN OuterUnknown OPTIONAL,
250 IN POOL_TYPE PoolType,
251 IN PRESOURCELIST ParentList,
252 IN ULONG MaximumEntries)
253 {
254 return STATUS_UNSUCCESSFUL;
255 }