Added PARSE_SECURITY_URL action implementation.
[wine.git] / dlls / quartz / enumpins.c
blob30bf524a1d80efed7eea5c95a589e118e70c8234
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., 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 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 CopyMemory(&pEnumPins->enumPinDetails, pDetails, sizeof(ENUMPINDETAILS));
49 *ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
50 return S_OK;
53 static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
55 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
57 *ppv = NULL;
59 if (IsEqualIID(riid, &IID_IUnknown))
60 *ppv = (LPVOID)iface;
61 else if (IsEqualIID(riid, &IID_IEnumPins))
62 *ppv = (LPVOID)iface;
64 if (*ppv)
66 IUnknown_AddRef((IUnknown *)(*ppv));
67 return S_OK;
70 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
72 return E_NOINTERFACE;
75 static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
77 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
78 ULONG refCount = InterlockedIncrement(&This->refCount);
80 TRACE("()\n");
82 return refCount;
85 static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
87 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
88 ULONG refCount = InterlockedDecrement(&This->refCount);
90 TRACE("()\n");
92 if (!refCount)
94 CoTaskMemFree(This);
95 return 0;
97 else
98 return refCount;
101 static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
103 ULONG cFetched;
104 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
106 cFetched = min(This->enumPinDetails.cPins, This->uIndex + cPins) - This->uIndex;
108 TRACE("(%lu, %p, %p)\n", cPins, ppPins, pcFetched);
110 if (cFetched > 0)
112 ULONG i;
113 for (i = 0; i < cFetched; i++) {
114 IPin_AddRef(This->enumPinDetails.ppPins[This->uIndex + i]);
115 ppPins[i] = This->enumPinDetails.ppPins[This->uIndex + i];
119 if ((cPins != 1) || pcFetched)
120 *pcFetched = cFetched;
122 This->uIndex += cFetched;
124 if (cFetched != cPins)
125 return S_FALSE;
126 return S_OK;
129 static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
131 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
133 TRACE("(%lu)\n", cPins);
135 if (This->uIndex + cPins < This->enumPinDetails.cPins)
137 This->uIndex += cPins;
138 return S_OK;
140 return S_FALSE;
143 static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
145 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
147 TRACE("IEnumPinsImpl::Reset()\n");
149 This->uIndex = 0;
150 return S_OK;
153 static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
155 HRESULT hr;
156 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
158 TRACE("(%p)\n", ppEnum);
160 hr = IEnumPinsImpl_Construct(&This->enumPinDetails, ppEnum);
161 if (FAILED(hr))
162 return hr;
163 return IEnumPins_Skip(*ppEnum, This->uIndex);
166 static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
168 IEnumPinsImpl_QueryInterface,
169 IEnumPinsImpl_AddRef,
170 IEnumPinsImpl_Release,
171 IEnumPinsImpl_Next,
172 IEnumPinsImpl_Skip,
173 IEnumPinsImpl_Reset,
174 IEnumPinsImpl_Clone