blob: e52e7869bcff98edb7bf737889799de957930bd8 [file] [log] [blame]
Maarten Lankhorstc9b84bd2005-05-17 14:31:35 +00001/*
2 * Implementation of IEnumPins Interface
3 *
4 * Copyright 2003 Robert Shearman
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22
23#define COBJMACROS
24
25#include "windef.h"
26#include "winbase.h"
27#include "wtypes.h"
28#include "wingdi.h"
29#include "winuser.h"
30#include "dshow.h"
31
32#include "qcap_main.h"
33
34#include "wine/debug.h"
35
36WINE_DEFAULT_DEBUG_CHANNEL(qcap);
37
38typedef struct IEnumPinsImpl
39{
40 const IEnumPinsVtbl * lpVtbl;
Mike McCormack0791d062005-07-12 19:21:36 +000041 LONG refCount;
Maarten Lankhorstc9b84bd2005-05-17 14:31:35 +000042 ENUMPINDETAILS enumPinDetails;
43 ULONG uIndex;
44} IEnumPinsImpl;
45
46static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
47
48HRESULT IEnumPinsImpl_Construct(const ENUMPINDETAILS * pDetails, IEnumPins ** ppEnum)
49{
50 IEnumPinsImpl * pEnumPins = CoTaskMemAlloc(sizeof(IEnumPinsImpl));
51 if (!pEnumPins)
52 {
53 *ppEnum = NULL;
54 return E_OUTOFMEMORY;
55 }
56 pEnumPins->lpVtbl = &IEnumPinsImpl_Vtbl;
57 pEnumPins->refCount = 1;
58 pEnumPins->uIndex = 0;
59 CopyMemory(&pEnumPins->enumPinDetails, pDetails, sizeof(ENUMPINDETAILS));
60 *ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
Maarten Lankhorst30d51202005-05-18 15:31:24 +000061 ObjectRefCount(TRUE);
Maarten Lankhorstc9b84bd2005-05-17 14:31:35 +000062 return S_OK;
63}
64
65static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
66{
67 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
68
69 *ppv = NULL;
70
71 if (IsEqualIID(riid, &IID_IUnknown))
72 *ppv = (LPVOID)iface;
73 else if (IsEqualIID(riid, &IID_IEnumPins))
74 *ppv = (LPVOID)iface;
75
76 if (*ppv)
77 {
78 IUnknown_AddRef((IUnknown *)(*ppv));
79 return S_OK;
80 }
81
82 FIXME("No interface for %s!\n", debugstr_guid(riid));
83
84 return E_NOINTERFACE;
85}
86
87static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
88{
89 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
90 ULONG refCount = InterlockedIncrement(&This->refCount);
91
92 TRACE("()\n");
93
94 return refCount;
95}
96
97static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
98{
99 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
100 ULONG refCount = InterlockedDecrement(&This->refCount);
101
102 TRACE("()\n");
103
104 if (!refCount)
105 {
106 CoTaskMemFree(This);
Maarten Lankhorst30d51202005-05-18 15:31:24 +0000107 ObjectRefCount(FALSE);
Maarten Lankhorstc9b84bd2005-05-17 14:31:35 +0000108 }
Maarten Lankhorst30d51202005-05-18 15:31:24 +0000109 return refCount;
Maarten Lankhorstc9b84bd2005-05-17 14:31:35 +0000110}
111
112static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
113{
114 ULONG cFetched;
115 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
116
117 cFetched = min(This->enumPinDetails.cPins, This->uIndex + cPins) - This->uIndex;
118
119 TRACE("(%lu, %p, %p)\n", cPins, ppPins, pcFetched);
120
121 if (cFetched > 0)
122 {
123 ULONG i;
124 for (i = 0; i < cFetched; i++) {
125 IPin_AddRef(This->enumPinDetails.ppPins[This->uIndex + i]);
126 ppPins[i] = This->enumPinDetails.ppPins[This->uIndex + i];
127 }
128 }
129
130 if ((cPins != 1) || pcFetched)
131 *pcFetched = cFetched;
132
133 This->uIndex += cFetched;
134
135 if (cFetched != cPins)
136 return S_FALSE;
137 return S_OK;
138}
139
140static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
141{
142 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
143
144 TRACE("(%lu)\n", cPins);
145
146 if (This->uIndex + cPins < This->enumPinDetails.cPins)
147 {
148 This->uIndex += cPins;
149 return S_OK;
150 }
151 return S_FALSE;
152}
153
154static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
155{
156 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
157
158 TRACE("IEnumPinsImpl::Reset()\n");
159
160 This->uIndex = 0;
161 return S_OK;
162}
163
164static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
165{
166 HRESULT hr;
167 IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
168
169 TRACE("(%p)\n", ppEnum);
170
171 hr = IEnumPinsImpl_Construct(&This->enumPinDetails, ppEnum);
172 if (FAILED(hr))
173 return hr;
174 return IEnumPins_Skip(*ppEnum, This->uIndex);
175}
176
177static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
178{
179 IEnumPinsImpl_QueryInterface,
180 IEnumPinsImpl_AddRef,
181 IEnumPinsImpl_Release,
182 IEnumPinsImpl_Next,
183 IEnumPinsImpl_Skip,
184 IEnumPinsImpl_Reset,
185 IEnumPinsImpl_Clone
186};