2 * Queue Manager (BITS) File Enumerator
4 * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
28 IEnumBackgroundCopyFiles IEnumBackgroundCopyFiles_iface;
30 IBackgroundCopyFile **files;
33 } EnumBackgroundCopyFilesImpl;
35 static inline EnumBackgroundCopyFilesImpl *impl_from_IEnumBackgroundCopyFiles(IEnumBackgroundCopyFiles *iface)
37 return CONTAINING_RECORD(iface, EnumBackgroundCopyFilesImpl, IEnumBackgroundCopyFiles_iface);
40 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_QueryInterface(IEnumBackgroundCopyFiles *iface,
41 REFIID riid, void **ppv)
43 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppv);
45 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles))
48 IEnumBackgroundCopyFiles_AddRef(iface);
56 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_AddRef(IEnumBackgroundCopyFiles *iface)
58 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
59 ULONG ref = InterlockedIncrement(&This->ref);
61 TRACE("(%p) ref=%d\n", This, ref);
65 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles *iface)
67 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
68 ULONG ref = InterlockedDecrement(&This->ref);
73 for(i = 0; i < This->numFiles; i++)
74 IBackgroundCopyFile_Release(This->files[i]);
75 HeapFree(GetProcessHeap(), 0, This->files);
76 HeapFree(GetProcessHeap(), 0, This);
82 /* Return reference to one or more files in the file enumerator */
83 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next(IEnumBackgroundCopyFiles *iface,
84 ULONG celt, IBackgroundCopyFile **rgelt, ULONG *pceltFetched)
86 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
89 IBackgroundCopyFile *file;
91 /* Despite documented behavior, Windows (tested on XP) is not verifying
92 that the caller set pceltFetched to zero. No check here. */
94 fetched = min(celt, This->numFiles - This->indexFiles);
96 *pceltFetched = fetched;
99 /* We need to initialize this array if the caller doesn't request
100 the length because length_is will default to celt. */
101 for (i = 0; i < celt; i++)
104 /* pceltFetched can only be NULL if celt is 1 */
109 /* Fill in the array of objects */
110 for (i = 0; i < fetched; i++)
112 file = This->files[This->indexFiles++];
113 IBackgroundCopyFile_AddRef(file);
117 return fetched == celt ? S_OK : S_FALSE;
120 /* Skip over one or more files in the file enumerator */
121 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip(IEnumBackgroundCopyFiles *iface,
124 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
126 if (celt > This->numFiles - This->indexFiles)
128 This->indexFiles = This->numFiles;
132 This->indexFiles += celt;
136 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles *iface)
138 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
139 This->indexFiles = 0;
143 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles *iface,
144 IEnumBackgroundCopyFiles **ppenum)
146 FIXME("Not implemented\n");
150 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles *iface,
153 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
154 *puCount = This->numFiles;
158 static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl =
160 BITS_IEnumBackgroundCopyFiles_QueryInterface,
161 BITS_IEnumBackgroundCopyFiles_AddRef,
162 BITS_IEnumBackgroundCopyFiles_Release,
163 BITS_IEnumBackgroundCopyFiles_Next,
164 BITS_IEnumBackgroundCopyFiles_Skip,
165 BITS_IEnumBackgroundCopyFiles_Reset,
166 BITS_IEnumBackgroundCopyFiles_Clone,
167 BITS_IEnumBackgroundCopyFiles_GetCount
170 HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *iCopyJob)
172 EnumBackgroundCopyFilesImpl *This;
173 BackgroundCopyFileImpl *file;
174 BackgroundCopyJobImpl *job = (BackgroundCopyJobImpl *) iCopyJob;
177 TRACE("%p, %p)\n", ppObj, job);
179 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
181 return E_OUTOFMEMORY;
183 This->IEnumBackgroundCopyFiles_iface.lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl;
186 /* Create array of files */
187 This->indexFiles = 0;
188 EnterCriticalSection(&job->cs);
189 This->numFiles = list_count(&job->files);
191 if (This->numFiles > 0)
193 This->files = HeapAlloc(GetProcessHeap(), 0,
194 This->numFiles * sizeof This->files[0]);
197 LeaveCriticalSection(&job->cs);
198 HeapFree(GetProcessHeap(), 0, This);
199 return E_OUTOFMEMORY;
204 LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
206 file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
207 This->files[i] = (IBackgroundCopyFile *) file;
210 LeaveCriticalSection(&job->cs);
212 *ppObj = &This->IEnumBackgroundCopyFiles_iface;