configure: Print a warning when prelink isn't found.
[wine/hramrach.git] / dlls / quartz / enumfilters.c
blobab1f6ec6a724ea0f881ae15609f92671c9ebed0c
1 /*
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 const IEnumFiltersVtbl * lpVtbl;
30 LONG refCount;
31 IBaseFilter ** ppFilters;
32 int nFilters;
33 ULONG uIndex;
34 } IEnumFiltersImpl;
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, %d, %p)\n", ppFilters, nFilters, ppEnum);
46 *ppEnum = NULL;
48 if (!pEnumFilters)
50 return E_OUTOFMEMORY;
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);
61 return E_OUTOFMEMORY;
64 memcpy(pEnumFilters->ppFilters, ppFilters, nFilters * sizeof(IBaseFilter*));
66 *ppEnum = (IEnumFilters *)(&pEnumFilters->lpVtbl);
67 return S_OK;
70 static HRESULT WINAPI IEnumFiltersImpl_QueryInterface(IEnumFilters * iface, REFIID riid, LPVOID * ppv)
72 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
74 *ppv = NULL;
76 if (IsEqualIID(riid, &IID_IUnknown))
77 *ppv = iface;
78 else if (IsEqualIID(riid, &IID_IEnumFilters))
79 *ppv = iface;
81 if (*ppv)
83 IUnknown_AddRef((IUnknown *)(*ppv));
84 return S_OK;
87 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
89 return E_NOINTERFACE;
92 static ULONG WINAPI IEnumFiltersImpl_AddRef(IEnumFilters * iface)
94 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
95 ULONG refCount = InterlockedIncrement(&This->refCount);
97 TRACE("(%p)->()\n", iface);
99 return refCount;
102 static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters * iface)
104 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
105 ULONG refCount = InterlockedDecrement(&This->refCount);
107 TRACE("(%p)->()\n", iface);
109 if (!refCount)
111 CoTaskMemFree(This->ppFilters);
112 CoTaskMemFree(This);
113 return 0;
115 else
116 return refCount;
119 static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters * iface, ULONG cFilters, IBaseFilter ** ppFilters, ULONG * pcFetched)
121 ULONG cFetched;
122 ULONG i;
123 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
125 cFetched = min(This->nFilters, This->uIndex + cFilters) - This->uIndex;
127 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppFilters, pcFetched);
129 if (!ppFilters)
130 return E_POINTER;
132 for (i = 0; i < cFetched; i++)
134 ppFilters[i] = This->ppFilters[This->uIndex + i];
135 IBaseFilter_AddRef(ppFilters[i]);
138 This->uIndex += cFetched;
140 if (pcFetched)
141 *pcFetched = cFetched;
143 if (cFetched != cFilters)
144 return S_FALSE;
145 return S_OK;
148 static HRESULT WINAPI IEnumFiltersImpl_Skip(IEnumFilters * iface, ULONG cFilters)
150 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
152 TRACE("(%p)->(%u)\n", iface, cFilters);
154 if (This->uIndex + cFilters < This->nFilters)
156 This->uIndex += cFilters;
157 return S_OK;
159 return S_FALSE;
162 static HRESULT WINAPI IEnumFiltersImpl_Reset(IEnumFilters * iface)
164 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
166 TRACE("(%p)->()\n", iface);
168 This->uIndex = 0;
169 return S_OK;
172 static HRESULT WINAPI IEnumFiltersImpl_Clone(IEnumFilters * iface, IEnumFilters ** ppEnum)
174 HRESULT hr;
175 IEnumFiltersImpl *This = (IEnumFiltersImpl *)iface;
177 TRACE("(%p)->(%p)\n", iface, ppEnum);
179 hr = IEnumFiltersImpl_Construct(This->ppFilters, This->nFilters, ppEnum);
180 if (FAILED(hr))
181 return hr;
182 return IEnumFilters_Skip(*ppEnum, This->uIndex);
185 static const IEnumFiltersVtbl IEnumFiltersImpl_Vtbl =
187 IEnumFiltersImpl_QueryInterface,
188 IEnumFiltersImpl_AddRef,
189 IEnumFiltersImpl_Release,
190 IEnumFiltersImpl_Next,
191 IEnumFiltersImpl_Skip,
192 IEnumFiltersImpl_Reset,
193 IEnumFiltersImpl_Clone