2 * Implementation of IEnumFilters Interface
4 * Copyright 2004 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "quartz_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
27 typedef struct IEnumFiltersImpl
29 IEnumFilters IEnumFilters_iface;
31 IBaseFilter ** ppFilters;
36 static const struct IEnumFiltersVtbl IEnumFiltersImpl_Vtbl;
38 static inline IEnumFiltersImpl *impl_from_IEnumFilters(IEnumFilters *iface)
40 return CONTAINING_RECORD(iface, IEnumFiltersImpl, IEnumFilters_iface);
43 HRESULT IEnumFiltersImpl_Construct(IBaseFilter ** ppFilters, ULONG nFilters, IEnumFilters ** ppEnum)
45 /* Note: The incoming IBaseFilter interfaces are not AddRef'd here as in Windows,
46 * they should have been previously AddRef'd. */
47 IEnumFiltersImpl * pEnumFilters = CoTaskMemAlloc(sizeof(IEnumFiltersImpl));
49 TRACE("(%p, %d, %p)\n", ppFilters, nFilters, ppEnum);
58 pEnumFilters->IEnumFilters_iface.lpVtbl = &IEnumFiltersImpl_Vtbl;
59 pEnumFilters->refCount = 1;
60 pEnumFilters->uIndex = 0;
61 pEnumFilters->nFilters = nFilters;
62 pEnumFilters->ppFilters = CoTaskMemAlloc(sizeof(IBaseFilter*) * nFilters);
63 if (!pEnumFilters->ppFilters)
65 CoTaskMemFree(pEnumFilters);
69 memcpy(pEnumFilters->ppFilters, ppFilters, nFilters * sizeof(IBaseFilter*));
71 *ppEnum = &pEnumFilters->IEnumFilters_iface;
75 static HRESULT WINAPI IEnumFiltersImpl_QueryInterface(IEnumFilters * iface, REFIID riid, LPVOID * ppv)
77 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
81 if (IsEqualIID(riid, &IID_IUnknown))
83 else if (IsEqualIID(riid, &IID_IEnumFilters))
88 IUnknown_AddRef((IUnknown *)(*ppv));
92 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
97 static ULONG WINAPI IEnumFiltersImpl_AddRef(IEnumFilters * iface)
99 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
100 ULONG refCount = InterlockedIncrement(&This->refCount);
102 TRACE("(%p)->()\n", iface);
107 static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters * iface)
109 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
110 ULONG refCount = InterlockedDecrement(&This->refCount);
112 TRACE("(%p)->()\n", iface);
116 CoTaskMemFree(This->ppFilters);
124 static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters * iface, ULONG cFilters, IBaseFilter ** ppFilters, ULONG * pcFetched)
128 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
130 cFetched = min(This->nFilters, This->uIndex + cFilters) - This->uIndex;
132 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppFilters, pcFetched);
137 for (i = 0; i < cFetched; i++)
139 ppFilters[i] = This->ppFilters[This->uIndex + i];
140 IBaseFilter_AddRef(ppFilters[i]);
143 This->uIndex += cFetched;
146 *pcFetched = cFetched;
148 if (cFetched != cFilters)
153 static HRESULT WINAPI IEnumFiltersImpl_Skip(IEnumFilters * iface, ULONG cFilters)
155 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
157 TRACE("(%p)->(%u)\n", iface, cFilters);
159 if (This->uIndex + cFilters < This->nFilters)
161 This->uIndex += cFilters;
167 static HRESULT WINAPI IEnumFiltersImpl_Reset(IEnumFilters * iface)
169 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
171 TRACE("(%p)->()\n", iface);
177 static HRESULT WINAPI IEnumFiltersImpl_Clone(IEnumFilters * iface, IEnumFilters ** ppEnum)
180 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
182 TRACE("(%p)->(%p)\n", iface, ppEnum);
184 hr = IEnumFiltersImpl_Construct(This->ppFilters, This->nFilters, ppEnum);
187 return IEnumFilters_Skip(*ppEnum, This->uIndex);
190 static const IEnumFiltersVtbl IEnumFiltersImpl_Vtbl =
192 IEnumFiltersImpl_QueryInterface,
193 IEnumFiltersImpl_AddRef,
194 IEnumFiltersImpl_Release,
195 IEnumFiltersImpl_Next,
196 IEnumFiltersImpl_Skip,
197 IEnumFiltersImpl_Reset,
198 IEnumFiltersImpl_Clone