quartz: Reset EcCompleteCount before starting filters.
[wine/wine64.git] / dlls / quartz / enumpins.c
blob61e42b08fbc40cf8f9cfbc234569e5886331cdc3
1 /*
2 * Implementation of IEnumPins Interface
4 * Copyright 2003 Robert Shearman
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 IEnumPinsImpl
29 const IEnumPinsVtbl * lpVtbl;
30 LONG refCount;
31 ENUMPINDETAILS enumPinDetails;
32 ULONG uIndex;
33 } IEnumPinsImpl;
35 static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
37 HRESULT IEnumPinsImpl_Construct(const ENUMPINDETAILS * pDetails, IEnumPins ** ppEnum)
39 IEnumPinsImpl * pEnumPins = CoTaskMemAlloc(sizeof(IEnumPinsImpl));
40 if (!pEnumPins)
42 *ppEnum = NULL;
43 return E_OUTOFMEMORY;
45 pEnumPins->lpVtbl = &IEnumPinsImpl_Vtbl;
46 pEnumPins->refCount = 1;
47 pEnumPins->uIndex = 0;
48 pEnumPins->enumPinDetails = *pDetails;
49 *ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
51 TRACE("Created new enumerator (%p)\n", *ppEnum);
52 return S_OK;
55 static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
57 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
59 *ppv = NULL;
61 if (IsEqualIID(riid, &IID_IUnknown))
62 *ppv = (LPVOID)iface;
63 else if (IsEqualIID(riid, &IID_IEnumPins))
64 *ppv = (LPVOID)iface;
66 if (*ppv)
68 IUnknown_AddRef((IUnknown *)(*ppv));
69 return S_OK;
72 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
74 return E_NOINTERFACE;
77 static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
79 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
80 ULONG refCount = InterlockedIncrement(&This->refCount);
82 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
84 return refCount;
87 static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
89 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
90 ULONG refCount = InterlockedDecrement(&This->refCount);
92 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
94 if (!refCount)
96 CoTaskMemFree(This);
97 return 0;
99 else
100 return refCount;
103 static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
105 ULONG cFetched;
106 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
108 cFetched = min(This->enumPinDetails.cPins, This->uIndex + cPins) - This->uIndex;
110 TRACE("(%u, %p, %p)\n", cPins, ppPins, pcFetched);
112 if (cFetched > 0)
114 ULONG i;
115 for (i = 0; i < cFetched; i++) {
116 IPin_AddRef(This->enumPinDetails.ppPins[This->uIndex + i]);
117 ppPins[i] = This->enumPinDetails.ppPins[This->uIndex + i];
121 if ((cPins != 1) || pcFetched)
122 *pcFetched = cFetched;
124 This->uIndex += cFetched;
126 if (cFetched != cPins)
127 return S_FALSE;
128 return S_OK;
131 static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
133 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
135 TRACE("(%u)\n", cPins);
137 if (This->uIndex + cPins < This->enumPinDetails.cPins)
139 This->uIndex += cPins;
140 return S_OK;
142 return S_FALSE;
145 static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
147 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
149 TRACE("IEnumPinsImpl::Reset()\n");
151 This->uIndex = 0;
152 return S_OK;
155 static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
157 HRESULT hr;
158 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
160 TRACE("(%p)\n", ppEnum);
162 hr = IEnumPinsImpl_Construct(&This->enumPinDetails, ppEnum);
163 if (FAILED(hr))
164 return hr;
165 return IEnumPins_Skip(*ppEnum, This->uIndex);
168 static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
170 IEnumPinsImpl_QueryInterface,
171 IEnumPinsImpl_AddRef,
172 IEnumPinsImpl_Release,
173 IEnumPinsImpl_Next,
174 IEnumPinsImpl_Skip,
175 IEnumPinsImpl_Reset,
176 IEnumPinsImpl_Clone