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;
31 ENUMPINDETAILS enumPinDetails;
35 static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
37 HRESULT IEnumPinsImpl_Construct(const ENUMPINDETAILS * pDetails, IEnumPins ** ppEnum)
39 IEnumPinsImpl * pEnumPins;
44 pEnumPins = CoTaskMemAlloc(sizeof(IEnumPinsImpl));
50 pEnumPins->lpVtbl = &IEnumPinsImpl_Vtbl;
51 pEnumPins->refCount = 1;
52 pEnumPins->uIndex = 0;
53 pEnumPins->enumPinDetails = *pDetails;
54 *ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
56 TRACE("Created new enumerator (%p)\n", *ppEnum);
60 static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
62 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
66 if (IsEqualIID(riid, &IID_IUnknown))
68 else if (IsEqualIID(riid, &IID_IEnumPins))
73 IUnknown_AddRef((IUnknown *)(*ppv));
77 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
82 static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
84 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
85 ULONG refCount = InterlockedIncrement(&This->refCount);
87 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
92 static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
94 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
95 ULONG refCount = InterlockedDecrement(&This->refCount);
97 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
108 static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
111 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
113 cFetched = min(This->enumPinDetails.cPins, This->uIndex + cPins) - This->uIndex;
115 TRACE("(%u, %p, %p)\n", cPins, ppPins, pcFetched);
120 if (cPins > 1 && !pcFetched)
126 for (i = 0; i < cFetched; i++) {
127 IPin_AddRef(This->enumPinDetails.ppPins[This->uIndex + i]);
128 ppPins[i] = This->enumPinDetails.ppPins[This->uIndex + i];
132 if ((cPins != 1) || pcFetched)
133 *pcFetched = cFetched;
135 This->uIndex += cFetched;
137 if (cFetched != cPins)
142 static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
144 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
146 TRACE("(%u)\n", cPins);
148 if (This->uIndex + cPins < This->enumPinDetails.cPins)
150 This->uIndex += cPins;
156 static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
158 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
160 TRACE("IEnumPinsImpl::Reset()\n");
166 static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
169 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
171 TRACE("(%p)\n", ppEnum);
173 hr = IEnumPinsImpl_Construct(&This->enumPinDetails, ppEnum);
176 return IEnumPins_Skip(*ppEnum, This->uIndex);
179 static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
181 IEnumPinsImpl_QueryInterface,
182 IEnumPinsImpl_AddRef,
183 IEnumPinsImpl_Release,