ReactOS  0.4.15-dev-1207-g698a8e6
enum_files.c
Go to the documentation of this file.
1 /*
2  * Queue Manager (BITS) File Enumerator
3  *
4  * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
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 "qmgr.h"
22 #include "wine/debug.h"
23 
25 
26 typedef struct
27 {
34 
36 {
37  return CONTAINING_RECORD(iface, EnumBackgroundCopyFilesImpl, IEnumBackgroundCopyFiles_iface);
38 }
39 
41  REFIID riid, void **ppv)
42 {
44 
45  TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
46 
47  if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles))
48  {
49  *ppv = iface;
50  IEnumBackgroundCopyFiles_AddRef(iface);
51  return S_OK;
52  }
53 
54  *ppv = NULL;
55  return E_NOINTERFACE;
56 }
57 
59 {
62 
63  TRACE("(%p)->(%d)\n", This, ref);
64  return ref;
65 }
66 
68 {
71  ULONG i;
72 
73  TRACE("(%p)->(%d)\n", This, ref);
74 
75  if (ref == 0)
76  {
77  for(i = 0; i < This->numFiles; i++)
78  IBackgroundCopyFile2_Release(This->files[i]);
79  HeapFree(GetProcessHeap(), 0, This->files);
81  }
82 
83  return ref;
84 }
85 
86 /* Return reference to one or more files in the file enumerator */
88  ULONG celt, IBackgroundCopyFile **rgelt, ULONG *pceltFetched)
89 {
91  ULONG fetched;
92  ULONG i;
94 
95  TRACE("(%p)->(%d %p %p)\n", This, celt, rgelt, pceltFetched);
96 
97  /* Despite documented behavior, Windows (tested on XP) is not verifying
98  that the caller set pceltFetched to zero. No check here. */
99 
100  fetched = min(celt, This->numFiles - This->indexFiles);
101  if (pceltFetched)
102  *pceltFetched = fetched;
103  else
104  {
105  /* We need to initialize this array if the caller doesn't request
106  the length because length_is will default to celt. */
107  for (i = 0; i < celt; i++)
108  rgelt[i] = NULL;
109 
110  /* pceltFetched can only be NULL if celt is 1 */
111  if (celt != 1)
112  return E_INVALIDARG;
113  }
114 
115  /* Fill in the array of objects */
116  for (i = 0; i < fetched; i++)
117  {
118  file = This->files[This->indexFiles++];
119  IBackgroundCopyFile2_AddRef(file);
120  rgelt[i] = (IBackgroundCopyFile *)file;
121  }
122 
123  return fetched == celt ? S_OK : S_FALSE;
124 }
125 
126 /* Skip over one or more files in the file enumerator */
128  ULONG celt)
129 {
131 
132  TRACE("(%p)->(%d)\n", This, celt);
133 
134  if (celt > This->numFiles - This->indexFiles)
135  {
136  This->indexFiles = This->numFiles;
137  return S_FALSE;
138  }
139 
140  This->indexFiles += celt;
141  return S_OK;
142 }
143 
145 {
147 
148  TRACE("(%p)\n", This);
149 
150  This->indexFiles = 0;
151  return S_OK;
152 }
153 
155  IEnumBackgroundCopyFiles **ppenum)
156 {
158  FIXME("(%p)->(%p): stub\n", This, ppenum);
159  return E_NOTIMPL;
160 }
161 
163  ULONG *puCount)
164 {
166  TRACE("(%p)->(%p)\n", This, puCount);
167  *puCount = This->numFiles;
168  return S_OK;
169 }
170 
171 static const IEnumBackgroundCopyFilesVtbl EnumBackgroundCopyFilesVtbl =
172 {
181 };
182 
184 {
187  ULONG i;
188 
189  TRACE("%p, %p)\n", job, enum_files);
190 
191  This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
192  if (!This)
193  return E_OUTOFMEMORY;
194 
195  This->IEnumBackgroundCopyFiles_iface.lpVtbl = &EnumBackgroundCopyFilesVtbl;
196  This->ref = 1;
197 
198  /* Create array of files */
199  This->indexFiles = 0;
201  This->numFiles = list_count(&job->files);
202  This->files = NULL;
203  if (This->numFiles > 0)
204  {
205  This->files = HeapAlloc(GetProcessHeap(), 0,
206  This->numFiles * sizeof This->files[0]);
207  if (!This->files)
208  {
211  return E_OUTOFMEMORY;
212  }
213  }
214 
215  i = 0;
216  LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
217  {
218  IBackgroundCopyFile2_AddRef(&file->IBackgroundCopyFile2_iface);
219  This->files[i] = &file->IBackgroundCopyFile2_iface;
220  ++i;
221  }
223 
224  *enum_files = &This->IEnumBackgroundCopyFiles_iface;
225  return S_OK;
226 }
static HANDLE job
Definition: process.c:77
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static HRESULT WINAPI EnumBackgroundCopyFiles_QueryInterface(IEnumBackgroundCopyFiles *iface, REFIID riid, void **ppv)
Definition: enum_files.c:40
static HRESULT WINAPI EnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles *iface, ULONG *puCount)
Definition: enum_files.c:162
Definition: send.c:48
static const IEnumBackgroundCopyFilesVtbl EnumBackgroundCopyFilesVtbl
Definition: enum_files.c:171
static HRESULT WINAPI EnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles *iface)
Definition: enum_files.c:144
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
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
__WINE_SERVER_LIST_INLINE unsigned int list_count(const struct list *list)
Definition: list.h:155
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:111
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl *job, IEnumBackgroundCopyFiles **enum_files)
Definition: enum_files.c:183
#define debugstr_guid
Definition: kernel32.h:35
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
static HRESULT WINAPI EnumBackgroundCopyFiles_Skip(IEnumBackgroundCopyFiles *iface, ULONG celt)
Definition: enum_files.c:127
#define TRACE(s)
Definition: solgame.cpp:4
WINE_DEFAULT_DEBUG_CHANNEL(qmgr)
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:79
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
const char file[]
Definition: icontest.c:11
static HRESULT WINAPI EnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles *iface, IEnumBackgroundCopyFiles **ppenum)
Definition: enum_files.c:154
IBackgroundCopyFile2 ** files
Definition: enum_files.c:30
#define InterlockedDecrement
Definition: armddk.h:52
static ULONG WINAPI EnumBackgroundCopyFiles_AddRef(IEnumBackgroundCopyFiles *iface)
Definition: enum_files.c:58
#define S_OK
Definition: intsafe.h:51
#define InterlockedIncrement
Definition: armddk.h:53
static HRESULT WINAPI EnumBackgroundCopyFiles_Next(IEnumBackgroundCopyFiles *iface, ULONG celt, IBackgroundCopyFile **rgelt, ULONG *pceltFetched)
Definition: enum_files.c:87
static EnumBackgroundCopyFilesImpl * impl_from_IEnumBackgroundCopyFiles(IEnumBackgroundCopyFiles *iface)
Definition: enum_files.c:35
#define E_NOTIMPL
Definition: ddrawi.h:99
IEnumBackgroundCopyFiles IEnumBackgroundCopyFiles_iface
Definition: enum_files.c:28
#define min(a, b)
Definition: monoChain.cc:55
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static ULONG WINAPI EnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles *iface)
Definition: enum_files.c:67
unsigned int ULONG
Definition: retypes.h:1
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define HeapFree(x, y, z)
Definition: compat.h:594
Definition: fci.c:126