msi: Store action data for deferred rollback actions too.
[wine] / dlls / strmbase / enumpins.c
1 /*
2  * Implementation of IEnumPins Interface
3  *
4  * Copyright 2003 Robert Shearman
5  * Copyright 2010 Aric Stewart, CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define COBJMACROS
23
24 #include "dshow.h"
25 #include "wine/strmbase.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
29
30 typedef struct IEnumPinsImpl
31 {
32     const IEnumPinsVtbl * lpVtbl;
33     LONG refCount;
34     ULONG uIndex;
35     IBaseFilter *base;
36     BaseFilter_GetPin receive_pin;
37     BaseFilter_GetPinCount receive_pincount;
38     BaseFilter_GetPinVersion receive_version;
39     DWORD Version;
40 } IEnumPinsImpl;
41
42 static const struct IEnumPinsVtbl IEnumPinsImpl_Vtbl;
43
44 HRESULT WINAPI EnumPins_Construct(IBaseFilter *base,  BaseFilter_GetPin receive_pin, BaseFilter_GetPinCount receive_pincount, BaseFilter_GetPinVersion receive_version, IEnumPins ** ppEnum)
45 {
46     IEnumPinsImpl * pEnumPins;
47
48     if (!ppEnum)
49         return E_POINTER;
50
51     pEnumPins = CoTaskMemAlloc(sizeof(IEnumPinsImpl));
52     if (!pEnumPins)
53     {
54         *ppEnum = NULL;
55         return E_OUTOFMEMORY;
56     }
57     pEnumPins->lpVtbl = &IEnumPinsImpl_Vtbl;
58     pEnumPins->refCount = 1;
59     pEnumPins->uIndex = 0;
60     pEnumPins->receive_pin = receive_pin;
61     pEnumPins->receive_pincount = receive_pincount;
62     pEnumPins->receive_version = receive_version;
63     pEnumPins->base = base;
64     IBaseFilter_AddRef(base);
65     *ppEnum = (IEnumPins *)(&pEnumPins->lpVtbl);
66     pEnumPins->Version = receive_version(base);
67
68     TRACE("Created new enumerator (%p)\n", *ppEnum);
69     return S_OK;
70 }
71
72 static HRESULT WINAPI IEnumPinsImpl_QueryInterface(IEnumPins * iface, REFIID riid, LPVOID * ppv)
73 {
74     TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
75
76     *ppv = NULL;
77
78     if (IsEqualIID(riid, &IID_IUnknown))
79         *ppv = iface;
80     else if (IsEqualIID(riid, &IID_IEnumPins))
81         *ppv = iface;
82
83     if (*ppv)
84     {
85         IUnknown_AddRef((IUnknown *)(*ppv));
86         return S_OK;
87     }
88
89     FIXME("No interface for %s!\n", debugstr_guid(riid));
90
91     return E_NOINTERFACE;
92 }
93
94 static ULONG WINAPI IEnumPinsImpl_AddRef(IEnumPins * iface)
95 {
96     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
97     ULONG refCount = InterlockedIncrement(&This->refCount);
98
99     TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
100
101     return refCount;
102 }
103
104 static ULONG WINAPI IEnumPinsImpl_Release(IEnumPins * iface)
105 {
106     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
107     ULONG refCount = InterlockedDecrement(&This->refCount);
108
109     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
110
111     if (!refCount)
112     {
113         IBaseFilter_Release(This->base);
114         CoTaskMemFree(This);
115         return 0;
116     }
117     else
118         return refCount;
119 }
120
121 static HRESULT WINAPI IEnumPinsImpl_Next(IEnumPins * iface, ULONG cPins, IPin ** ppPins, ULONG * pcFetched)
122 {
123     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
124     HRESULT hr = S_OK;
125     ULONG i = 0;
126
127     TRACE("(%u, %p, %p)\n", cPins, ppPins, pcFetched);
128
129     if (!ppPins)
130         return E_POINTER;
131
132     if (cPins > 1 && !pcFetched)
133         return E_INVALIDARG;
134
135     if (pcFetched)
136         *pcFetched = 0;
137
138     if (This->Version != This->receive_version(This->base))
139         return VFW_E_ENUM_OUT_OF_SYNC;
140
141     while (i < cPins && hr == S_OK)
142     {
143        IPin *pin;
144        pin = This->receive_pin(This->base, This->uIndex + i);
145
146        if (!pin)
147          break;
148        else
149          ppPins[i] = pin;
150        ++i;
151     }
152
153     if (pcFetched)
154         *pcFetched = i;
155     This->uIndex += i;
156
157     if (i < cPins)
158         return S_FALSE;
159     return S_OK;
160 }
161
162 static HRESULT WINAPI IEnumPinsImpl_Skip(IEnumPins * iface, ULONG cPins)
163 {
164     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
165
166     TRACE("(%u)\n", cPins);
167
168     if (This->Version != This->receive_version(This->base))
169         return VFW_E_ENUM_OUT_OF_SYNC;
170
171     if (This->receive_pincount(This->base) >= This->uIndex + cPins)
172         return S_FALSE;
173
174     This->uIndex += cPins;
175     return S_OK;
176 }
177
178 static HRESULT WINAPI IEnumPinsImpl_Reset(IEnumPins * iface)
179 {
180     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
181
182     TRACE("IEnumPinsImpl::Reset()\n");
183     This->Version = This->receive_version(This->base);
184
185     This->uIndex = 0;
186     return S_OK;
187 }
188
189 static HRESULT WINAPI IEnumPinsImpl_Clone(IEnumPins * iface, IEnumPins ** ppEnum)
190 {
191     HRESULT hr;
192     IEnumPinsImpl *This = (IEnumPinsImpl *)iface;
193
194     TRACE("(%p)\n", ppEnum);
195
196     hr = EnumPins_Construct(This->base, This->receive_pin, This->receive_pincount, This->receive_version, ppEnum);
197     if (FAILED(hr))
198         return hr;
199     return IEnumPins_Skip(*ppEnum, This->uIndex);
200 }
201
202 static const IEnumPinsVtbl IEnumPinsImpl_Vtbl =
203 {
204     IEnumPinsImpl_QueryInterface,
205     IEnumPinsImpl_AddRef,
206     IEnumPinsImpl_Release,
207     IEnumPinsImpl_Next,
208     IEnumPinsImpl_Skip,
209     IEnumPinsImpl_Reset,
210     IEnumPinsImpl_Clone
211 };