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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "quartz_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
27 typedef struct IEnumFiltersImpl
29 const IEnumFiltersVtbl * lpVtbl;
31 IBaseFilter ** ppFilters;
36 static const struct IEnumFiltersVtbl IEnumFiltersImpl_Vtbl;
38 HRESULT IEnumFiltersImpl_Construct(IBaseFilter ** ppFilters, ULONG nFilters, IEnumFilters ** ppEnum)
40 /* Note: The incoming IBaseFilter interfaces are not AddRef'd here as in Windows,
41 * they should have been previously AddRef'd. */
42 IEnumFiltersImpl * pEnumFilters = CoTaskMemAlloc(sizeof(IEnumFiltersImpl));
44 TRACE("(%p, %ld, %p)\n", ppFilters, nFilters, ppEnum);
53 pEnumFilters->lpVtbl = &IEnumFiltersImpl_Vtbl;
54 pEnumFilters->refCount = 1;
55 pEnumFilters->uIndex = 0;
56 pEnumFilters->nFilters = nFilters;
57 pEnumFilters->ppFilters = CoTaskMemAlloc(sizeof(IBaseFilter*) * nFilters);
58 if (!pEnumFilters->ppFilters)
60 CoTaskMemFree(pEnumFilters);
64 memcpy(pEnumFilters->ppFilters, ppFilters, nFilters * sizeof(IBaseFilter*));
66 *ppEnum = (IEnumFilters *)(&pEnumFilters->lpVtbl);
70 static HRESULT WINAPI IEnumFiltersImpl_QueryInterface(IEnumFilters * iface, REFIID riid, LPVOID * ppv)
72 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
76 if (IsEqualIID(riid, &IID_IUnknown))
78 else if (IsEqualIID(riid, &IID_IEnumFilters))
83 IUnknown_AddRef((IUnknown *)(*ppv));
87 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
92 static ULONG WINAPI IEnumFiltersImpl_AddRef(IEnumFilters * iface)
94 ICOM_THIS(IEnumFiltersImpl, iface);
95 TRACE("(%p)->()\n", iface);
96 return ++This->refCount;
99 static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters * iface)
101 ICOM_THIS(IEnumFiltersImpl, iface);
102 TRACE("(%p)->()\n", iface);
103 if (!--This->refCount)
105 CoTaskMemFree(This->ppFilters);
110 return This->refCount;
113 static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters * iface, ULONG cFilters, IBaseFilter ** ppFilters, ULONG * pcFetched)
117 ICOM_THIS(IEnumFiltersImpl, iface);
119 cFetched = min(This->nFilters, This->uIndex + cFilters) - This->uIndex;
121 TRACE("(%p)->(%lu, %p, %p)\n", iface, cFilters, ppFilters, pcFetched);
123 for (i = 0; i < cFetched; i++)
125 ppFilters[i] = This->ppFilters[This->uIndex + i];
126 IBaseFilter_AddRef(ppFilters[i]);
129 This->uIndex += cFetched;
132 *pcFetched = cFetched;
134 if (cFetched != cFilters)
139 static HRESULT WINAPI IEnumFiltersImpl_Skip(IEnumFilters * iface, ULONG cFilters)
141 ICOM_THIS(IEnumFiltersImpl, iface);
143 TRACE("(%p)->(%lu)\n", iface, cFilters);
145 if (This->uIndex + cFilters < This->nFilters)
147 This->uIndex += cFilters;
153 static HRESULT WINAPI IEnumFiltersImpl_Reset(IEnumFilters * iface)
155 ICOM_THIS(IEnumFiltersImpl, iface);
157 TRACE("(%p)->()\n", iface);
163 static HRESULT WINAPI IEnumFiltersImpl_Clone(IEnumFilters * iface, IEnumFilters ** ppEnum)
166 ICOM_THIS(IEnumFiltersImpl, iface);
168 TRACE("(%p)->(%p)\n", iface, ppEnum);
170 hr = IEnumFiltersImpl_Construct(This->ppFilters, This->nFilters, ppEnum);
173 return IEnumFilters_Skip(*ppEnum, This->uIndex);
176 static const IEnumFiltersVtbl IEnumFiltersImpl_Vtbl =
178 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
179 IEnumFiltersImpl_QueryInterface,
180 IEnumFiltersImpl_AddRef,
181 IEnumFiltersImpl_Release,
182 IEnumFiltersImpl_Next,
183 IEnumFiltersImpl_Skip,
184 IEnumFiltersImpl_Reset,
185 IEnumFiltersImpl_Clone