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
25 IEnumBackgroundCopyFiles IEnumBackgroundCopyFiles_iface
;
27 IBackgroundCopyFile2
**files
;
30 } EnumBackgroundCopyFilesImpl
;
32 static inline EnumBackgroundCopyFilesImpl
*impl_from_IEnumBackgroundCopyFiles(IEnumBackgroundCopyFiles
*iface
)
34 return CONTAINING_RECORD(iface
, EnumBackgroundCopyFilesImpl
, IEnumBackgroundCopyFiles_iface
);
37 static HRESULT WINAPI
EnumBackgroundCopyFiles_QueryInterface(IEnumBackgroundCopyFiles
*iface
,
38 REFIID riid
, void **ppv
)
40 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
42 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
44 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IEnumBackgroundCopyFiles
))
47 IEnumBackgroundCopyFiles_AddRef(iface
);
55 static ULONG WINAPI
EnumBackgroundCopyFiles_AddRef(IEnumBackgroundCopyFiles
*iface
)
57 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
58 ULONG ref
= InterlockedIncrement(&This
->ref
);
60 TRACE("(%p)->(%d)\n", This
, ref
);
64 static ULONG WINAPI
EnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles
*iface
)
66 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
67 ULONG ref
= InterlockedDecrement(&This
->ref
);
70 TRACE("(%p)->(%d)\n", This
, ref
);
74 for(i
= 0; i
< This
->numFiles
; i
++)
75 IBackgroundCopyFile2_Release(This
->files
[i
]);
76 HeapFree(GetProcessHeap(), 0, This
->files
);
77 HeapFree(GetProcessHeap(), 0, This
);
83 /* Return reference to one or more files in the file enumerator */
84 static HRESULT WINAPI
EnumBackgroundCopyFiles_Next(IEnumBackgroundCopyFiles
*iface
,
85 ULONG celt
, IBackgroundCopyFile
**rgelt
, ULONG
*pceltFetched
)
87 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
90 IBackgroundCopyFile2
*file
;
92 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgelt
, pceltFetched
);
94 /* Despite documented behavior, Windows (tested on XP) is not verifying
95 that the caller set pceltFetched to zero. No check here. */
97 fetched
= min(celt
, This
->numFiles
- This
->indexFiles
);
99 *pceltFetched
= fetched
;
102 /* We need to initialize this array if the caller doesn't request
103 the length because length_is will default to celt. */
104 for (i
= 0; i
< celt
; i
++)
107 /* pceltFetched can only be NULL if celt is 1 */
112 /* Fill in the array of objects */
113 for (i
= 0; i
< fetched
; i
++)
115 file
= This
->files
[This
->indexFiles
++];
116 IBackgroundCopyFile2_AddRef(file
);
117 rgelt
[i
] = (IBackgroundCopyFile
*)file
;
120 return fetched
== celt
? S_OK
: S_FALSE
;
123 /* Skip over one or more files in the file enumerator */
124 static HRESULT WINAPI
EnumBackgroundCopyFiles_Skip(IEnumBackgroundCopyFiles
*iface
,
127 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
129 TRACE("(%p)->(%d)\n", This
, celt
);
131 if (celt
> This
->numFiles
- This
->indexFiles
)
133 This
->indexFiles
= This
->numFiles
;
137 This
->indexFiles
+= celt
;
141 static HRESULT WINAPI
EnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles
*iface
)
143 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
145 TRACE("(%p)\n", This
);
147 This
->indexFiles
= 0;
151 static HRESULT WINAPI
EnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles
*iface
,
152 IEnumBackgroundCopyFiles
**ppenum
)
154 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
155 FIXME("(%p)->(%p): stub\n", This
, ppenum
);
159 static HRESULT WINAPI
EnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles
*iface
,
162 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
163 TRACE("(%p)->(%p)\n", This
, puCount
);
164 *puCount
= This
->numFiles
;
168 static const IEnumBackgroundCopyFilesVtbl EnumBackgroundCopyFilesVtbl
=
170 EnumBackgroundCopyFiles_QueryInterface
,
171 EnumBackgroundCopyFiles_AddRef
,
172 EnumBackgroundCopyFiles_Release
,
173 EnumBackgroundCopyFiles_Next
,
174 EnumBackgroundCopyFiles_Skip
,
175 EnumBackgroundCopyFiles_Reset
,
176 EnumBackgroundCopyFiles_Clone
,
177 EnumBackgroundCopyFiles_GetCount
180 HRESULT
EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl
*job
, IEnumBackgroundCopyFiles
**enum_files
)
182 EnumBackgroundCopyFilesImpl
*This
;
183 BackgroundCopyFileImpl
*file
;
186 TRACE("%p, %p)\n", job
, enum_files
);
188 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
190 return E_OUTOFMEMORY
;
192 This
->IEnumBackgroundCopyFiles_iface
.lpVtbl
= &EnumBackgroundCopyFilesVtbl
;
195 /* Create array of files */
196 This
->indexFiles
= 0;
197 EnterCriticalSection(&job
->cs
);
198 This
->numFiles
= list_count(&job
->files
);
200 if (This
->numFiles
> 0)
202 This
->files
= HeapAlloc(GetProcessHeap(), 0,
203 This
->numFiles
* sizeof This
->files
[0]);
206 LeaveCriticalSection(&job
->cs
);
207 HeapFree(GetProcessHeap(), 0, This
);
208 return E_OUTOFMEMORY
;
213 LIST_FOR_EACH_ENTRY(file
, &job
->files
, BackgroundCopyFileImpl
, entryFromJob
)
215 IBackgroundCopyFile2_AddRef(&file
->IBackgroundCopyFile2_iface
);
216 This
->files
[i
] = &file
->IBackgroundCopyFile2_iface
;
219 LeaveCriticalSection(&job
->cs
);
221 *enum_files
= &This
->IEnumBackgroundCopyFiles_iface
;