ReactOS  0.4.15-dev-1197-g8081ba9
enumfilters.c
Go to the documentation of this file.
1 /*
2  * Implementation of IEnumFilters Interface
3  *
4  * Copyright 2004 Christian Costa
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include "quartz_private.h"
22 
23 #include "wine/debug.h"
24 
26 
27 typedef struct IEnumFiltersImpl
28 {
37 
38 static const struct IEnumFiltersVtbl IEnumFiltersImpl_Vtbl;
39 
41 {
42  return CONTAINING_RECORD(iface, IEnumFiltersImpl, IEnumFilters_iface);
43 }
44 
45 HRESULT IEnumFiltersImpl_Construct(IGraphVersion * pVersionSource, IBaseFilter *** pppFilters, ULONG * pNumFilters, IEnumFilters ** ppEnum)
46 {
47  /* Note: The incoming IBaseFilter interfaces are not AddRef'd here as in Windows,
48  * they should have been previously AddRef'd. */
49  IEnumFiltersImpl * pEnumFilters = CoTaskMemAlloc(sizeof(IEnumFiltersImpl));
50  HRESULT hr;
51  LONG currentVersion;
52 
53  TRACE("(%p, %p, %p)\n", pppFilters, pNumFilters, ppEnum);
54 
55  *ppEnum = NULL;
56 
57  if (!pEnumFilters)
58  {
59  return E_OUTOFMEMORY;
60  }
61 
62  pEnumFilters->IEnumFilters_iface.lpVtbl = &IEnumFiltersImpl_Vtbl;
63  pEnumFilters->refCount = 1;
64  pEnumFilters->uIndex = 0;
65  pEnumFilters->pNumFilters = pNumFilters;
66  pEnumFilters->pppFilters = pppFilters;
67  IGraphVersion_AddRef(pVersionSource);
68  pEnumFilters->pVersionSource = pVersionSource;
69 
70  /* Store the current version of the graph */
71  hr = IGraphVersion_QueryVersion(pVersionSource, &currentVersion);
72  pEnumFilters->Version = (hr==S_OK) ? currentVersion : 0;
73 
74  *ppEnum = &pEnumFilters->IEnumFilters_iface;
75  return S_OK;
76 }
77 
79 {
80  TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
81 
82  *ppv = NULL;
83 
85  *ppv = iface;
86  else if (IsEqualIID(riid, &IID_IEnumFilters))
87  *ppv = iface;
88 
89  if (*ppv)
90  {
91  IUnknown_AddRef((IUnknown *)(*ppv));
92  return S_OK;
93  }
94 
95  FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
96 
97  return E_NOINTERFACE;
98 }
99 
101 {
103  ULONG refCount = InterlockedIncrement(&This->refCount);
104 
105  TRACE("(%p)->()\n", iface);
106 
107  return refCount;
108 }
109 
111 {
113  ULONG refCount = InterlockedDecrement(&This->refCount);
114 
115  TRACE("(%p)->()\n", iface);
116 
117  if (!refCount)
118  {
119  IGraphVersion_Release(This->pVersionSource);
121  return 0;
122  }
123  else
124  return refCount;
125 }
126 
127 static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters * iface, ULONG cFilters, IBaseFilter ** ppFilters, ULONG * pcFetched)
128 {
129  ULONG cFetched;
130  ULONG i;
131  LONG currentVersion;
133  HRESULT hr;
134 
135  cFetched = min(*This->pNumFilters, This->uIndex + cFilters) - This->uIndex;
136 
137  TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppFilters, pcFetched);
138 
139  /* First of all check if the graph has changed */
140  hr = IGraphVersion_QueryVersion(This->pVersionSource, &currentVersion);
141  if (hr==S_OK && This->Version != currentVersion)
142  return VFW_E_ENUM_OUT_OF_SYNC;
143 
144 
145  if (!ppFilters)
146  return E_POINTER;
147 
148  for (i = 0; i < cFetched; i++)
149  {
150  ppFilters[i] = (*This->pppFilters)[This->uIndex + i];
151  IBaseFilter_AddRef(ppFilters[i]);
152  }
153 
154  This->uIndex += cFetched;
155 
156  if (pcFetched)
157  *pcFetched = cFetched;
158 
159  if (cFetched != cFilters)
160  return S_FALSE;
161  return S_OK;
162 }
163 
165 {
167 
168  TRACE("(%p)->(%u)\n", iface, cFilters);
169 
170  if (This->uIndex + cFilters < *This->pNumFilters)
171  {
172  This->uIndex += cFilters;
173  return S_OK;
174  }
175  return S_FALSE;
176 }
177 
179 {
181  HRESULT hr;
182  LONG currentVersion;
183 
184  TRACE("(%p)->()\n", iface);
185 
186  This->uIndex = 0;
187  hr = IGraphVersion_QueryVersion(This->pVersionSource, &currentVersion);
188  if (hr == S_OK)
189  This->Version = currentVersion;
190  return S_OK;
191 }
192 
194 {
195  HRESULT hr;
197 
198  TRACE("(%p)->(%p)\n", iface, ppEnum);
199 
200  hr = IEnumFiltersImpl_Construct(This->pVersionSource, This->pppFilters, This->pNumFilters, ppEnum);
201  if (FAILED(hr))
202  return hr;
203  return IEnumFilters_Skip(*ppEnum, This->uIndex);
204 }
205 
206 static const IEnumFiltersVtbl IEnumFiltersImpl_Vtbl =
207 {
215 };
static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters *iface, ULONG cFilters, IBaseFilter **ppFilters, ULONG *pcFetched)
Definition: enumfilters.c:127
struct IEnumFiltersImpl IEnumFiltersImpl
#define REFIID
Definition: guiddef.h:118
IEnumFilters IEnumFilters_iface
Definition: enumfilters.c:29
#define E_NOINTERFACE
Definition: winerror.h:2364
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
HRESULT hr
Definition: shlfolder.c:183
static IEnumFiltersImpl * impl_from_IEnumFilters(IEnumFilters *iface)
Definition: enumfilters.c:40
static HRESULT WINAPI IEnumFiltersImpl_Clone(IEnumFilters *iface, IEnumFilters **ppEnum)
Definition: enumfilters.c:193
static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters *iface)
Definition: enumfilters.c:110
REFIID riid
Definition: precomp.h:44
const char * qzdebugstr_guid(const GUID *id)
Definition: main.c:279
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI IEnumFiltersImpl_Skip(IEnumFilters *iface, ULONG cFilters)
Definition: enumfilters.c:164
HRESULT IEnumFiltersImpl_Construct(IGraphVersion *pVersionSource, IBaseFilter ***pppFilters, ULONG *pNumFilters, IEnumFilters **ppEnum)
Definition: enumfilters.c:45
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
#define FIXME(fmt,...)
Definition: debug.h:111
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
ULONG * pNumFilters
Definition: enumfilters.c:34
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:79
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
IGraphVersion * pVersionSource
Definition: enumfilters.c:31
static const struct IEnumFiltersVtbl IEnumFiltersImpl_Vtbl
Definition: enumfilters.c:38
#define InterlockedDecrement
Definition: armddk.h:52
IBaseFilter *** pppFilters
Definition: enumfilters.c:33
#define S_OK
Definition: intsafe.h:51
#define InterlockedIncrement
Definition: armddk.h:53
#define VFW_E_ENUM_OUT_OF_SYNC
Definition: vfwmsgs.h:42
static ULONG WINAPI IEnumFiltersImpl_AddRef(IEnumFilters *iface)
Definition: enumfilters.c:100
static HRESULT WINAPI IEnumFiltersImpl_Reset(IEnumFilters *iface)
Definition: enumfilters.c:178
#define min(a, b)
Definition: monoChain.cc:55
static HRESULT WINAPI IEnumFiltersImpl_QueryInterface(IEnumFilters *iface, REFIID riid, LPVOID *ppv)
Definition: enumfilters.c:78
unsigned int ULONG
Definition: retypes.h:1
#define E_POINTER
Definition: winerror.h:2365
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
WINE_DEFAULT_DEBUG_CHANNEL(quartz)
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95