qmgr: Implement IEnumBackgroundCopyFiles_Next.
[wine.git] / dlls / qmgr / enum_files.c
blob6602f68a492ee3d08f510613f32ec4a0eb89a040
1 /*
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
21 #include "qmgr.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
26 static void EnumBackgroundCopyFilesDestructor(EnumBackgroundCopyFilesImpl *This)
28 ULONG i;
30 for(i = 0; i < This->numFiles; i++)
31 IBackgroundCopyFile_Release(This->files[i]);
33 HeapFree(GetProcessHeap(), 0, This->files);
34 HeapFree(GetProcessHeap(), 0, This);
37 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_AddRef(
38 IEnumBackgroundCopyFiles* iface)
40 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
41 return InterlockedIncrement(&This->ref);
44 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_QueryInterface(
45 IEnumBackgroundCopyFiles* iface,
46 REFIID riid,
47 void **ppvObject)
49 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
50 TRACE("IID: %s\n", debugstr_guid(riid));
52 if (IsEqualGUID(riid, &IID_IUnknown)
53 || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles))
55 *ppvObject = &This->lpVtbl;
56 BITS_IEnumBackgroundCopyFiles_AddRef(iface);
57 return S_OK;
60 *ppvObject = NULL;
61 return E_NOINTERFACE;
64 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release(
65 IEnumBackgroundCopyFiles* iface)
67 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
68 ULONG ref = InterlockedDecrement(&This->ref);
70 if (ref == 0)
71 EnumBackgroundCopyFilesDestructor(This);
73 return ref;
76 /* Return reference to one or more files in the file enumerator */
77 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next(
78 IEnumBackgroundCopyFiles* iface,
79 ULONG celt,
80 IBackgroundCopyFile **rgelt,
81 ULONG *pceltFetched)
83 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
84 ULONG fetched;
85 ULONG i;
86 IBackgroundCopyFile *file;
88 /* Despite documented behavior, Windows (tested on XP) is not verifying
89 that the caller set pceltFetched to zero. No check here. */
91 fetched = min(celt, This->numFiles - This->indexFiles);
92 if (pceltFetched)
93 *pceltFetched = fetched;
94 else
96 /* We need to initialize this array if the caller doesn't request
97 the length because length_is will default to celt. */
98 for (i = 0; i < celt; i++)
99 rgelt[i] = NULL;
101 /* pceltFetched can only be NULL if celt is 1 */
102 if (celt != 1)
103 return E_INVALIDARG;
106 /* Fill in the array of objects */
107 for (i = 0; i < fetched; i++)
109 file = This->files[This->indexFiles++];
110 IBackgroundCopyFile_AddRef(file);
111 rgelt[i] = file;
114 return fetched == celt ? S_OK : S_FALSE;
117 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip(
118 IEnumBackgroundCopyFiles* iface,
119 ULONG celt)
121 FIXME("Not implemented\n");
122 return E_NOTIMPL;
125 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset(
126 IEnumBackgroundCopyFiles* iface)
128 FIXME("Not implemented\n");
129 return E_NOTIMPL;
132 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone(
133 IEnumBackgroundCopyFiles* iface,
134 IEnumBackgroundCopyFiles **ppenum)
136 FIXME("Not implemented\n");
137 return E_NOTIMPL;
140 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount(
141 IEnumBackgroundCopyFiles* iface,
142 ULONG *puCount)
144 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
145 *puCount = This->numFiles;
146 return S_OK;
149 static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl =
151 BITS_IEnumBackgroundCopyFiles_QueryInterface,
152 BITS_IEnumBackgroundCopyFiles_AddRef,
153 BITS_IEnumBackgroundCopyFiles_Release,
154 BITS_IEnumBackgroundCopyFiles_Next,
155 BITS_IEnumBackgroundCopyFiles_Skip,
156 BITS_IEnumBackgroundCopyFiles_Reset,
157 BITS_IEnumBackgroundCopyFiles_Clone,
158 BITS_IEnumBackgroundCopyFiles_GetCount
161 HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob* iCopyJob)
163 EnumBackgroundCopyFilesImpl *This;
164 BackgroundCopyFileImpl *file;
165 BackgroundCopyJobImpl *job = (BackgroundCopyJobImpl *) iCopyJob;
166 ULONG i;
168 TRACE("%p, %p)\n", ppObj, job);
170 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
171 if (!This)
172 return E_OUTOFMEMORY;
174 This->lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl;
175 This->ref = 1;
177 /* Create array of files */
178 This->indexFiles = 0;
179 This->numFiles = list_count(&job->files);
180 This->files = NULL;
181 if (This->numFiles > 0)
183 This->files = HeapAlloc(GetProcessHeap(), 0,
184 This->numFiles * sizeof This->files[0]);
185 if (!This->files)
187 HeapFree(GetProcessHeap(), 0, This);
188 return E_OUTOFMEMORY;
192 i = 0;
193 LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
195 file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
196 This->files[i] = (IBackgroundCopyFile *) file;
197 ++i;
200 *ppObj = &This->lpVtbl;
201 return S_OK;