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 IBackgroundCopyFile
**files
;
30 } EnumBackgroundCopyFilesImpl
;
32 static inline EnumBackgroundCopyFilesImpl
*impl_from_IEnumBackgroundCopyFiles(IEnumBackgroundCopyFiles
*iface
)
34 return CONTAINING_RECORD(iface
, EnumBackgroundCopyFilesImpl
, IEnumBackgroundCopyFiles_iface
);
37 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_QueryInterface(IEnumBackgroundCopyFiles
*iface
,
38 REFIID riid
, void **ppv
)
40 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
42 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IEnumBackgroundCopyFiles
))
45 IEnumBackgroundCopyFiles_AddRef(iface
);
53 static ULONG WINAPI
BITS_IEnumBackgroundCopyFiles_AddRef(IEnumBackgroundCopyFiles
*iface
)
55 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
56 ULONG ref
= InterlockedIncrement(&This
->ref
);
58 TRACE("(%p) ref=%d\n", This
, ref
);
62 static ULONG WINAPI
BITS_IEnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles
*iface
)
64 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
65 ULONG ref
= InterlockedDecrement(&This
->ref
);
70 for(i
= 0; i
< This
->numFiles
; i
++)
71 IBackgroundCopyFile_Release(This
->files
[i
]);
72 HeapFree(GetProcessHeap(), 0, This
->files
);
73 HeapFree(GetProcessHeap(), 0, This
);
79 /* Return reference to one or more files in the file enumerator */
80 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_Next(IEnumBackgroundCopyFiles
*iface
,
81 ULONG celt
, IBackgroundCopyFile
**rgelt
, ULONG
*pceltFetched
)
83 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
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
);
93 *pceltFetched
= fetched
;
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
++)
101 /* pceltFetched can only be NULL if celt is 1 */
106 /* Fill in the array of objects */
107 for (i
= 0; i
< fetched
; i
++)
109 file
= This
->files
[This
->indexFiles
++];
110 IBackgroundCopyFile_AddRef(file
);
114 return fetched
== celt
? S_OK
: S_FALSE
;
117 /* Skip over one or more files in the file enumerator */
118 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_Skip(IEnumBackgroundCopyFiles
*iface
,
121 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
123 if (celt
> This
->numFiles
- This
->indexFiles
)
125 This
->indexFiles
= This
->numFiles
;
129 This
->indexFiles
+= celt
;
133 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles
*iface
)
135 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
136 This
->indexFiles
= 0;
140 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles
*iface
,
141 IEnumBackgroundCopyFiles
**ppenum
)
143 FIXME("Not implemented\n");
147 static HRESULT WINAPI
BITS_IEnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles
*iface
,
150 EnumBackgroundCopyFilesImpl
*This
= impl_from_IEnumBackgroundCopyFiles(iface
);
151 *puCount
= This
->numFiles
;
155 static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl
=
157 BITS_IEnumBackgroundCopyFiles_QueryInterface
,
158 BITS_IEnumBackgroundCopyFiles_AddRef
,
159 BITS_IEnumBackgroundCopyFiles_Release
,
160 BITS_IEnumBackgroundCopyFiles_Next
,
161 BITS_IEnumBackgroundCopyFiles_Skip
,
162 BITS_IEnumBackgroundCopyFiles_Reset
,
163 BITS_IEnumBackgroundCopyFiles_Clone
,
164 BITS_IEnumBackgroundCopyFiles_GetCount
167 HRESULT
EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl
*job
, IEnumBackgroundCopyFiles
**enum_files
)
169 EnumBackgroundCopyFilesImpl
*This
;
170 BackgroundCopyFileImpl
*file
;
173 TRACE("%p, %p)\n", job
, enum_files
);
175 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
177 return E_OUTOFMEMORY
;
179 This
->IEnumBackgroundCopyFiles_iface
.lpVtbl
= &BITS_IEnumBackgroundCopyFiles_Vtbl
;
182 /* Create array of files */
183 This
->indexFiles
= 0;
184 EnterCriticalSection(&job
->cs
);
185 This
->numFiles
= list_count(&job
->files
);
187 if (This
->numFiles
> 0)
189 This
->files
= HeapAlloc(GetProcessHeap(), 0,
190 This
->numFiles
* sizeof This
->files
[0]);
193 LeaveCriticalSection(&job
->cs
);
194 HeapFree(GetProcessHeap(), 0, This
);
195 return E_OUTOFMEMORY
;
200 LIST_FOR_EACH_ENTRY(file
, &job
->files
, BackgroundCopyFileImpl
, entryFromJob
)
202 IBackgroundCopyFile_AddRef(&file
->IBackgroundCopyFile_iface
);
203 This
->files
[i
] = &file
->IBackgroundCopyFile_iface
;
206 LeaveCriticalSection(&job
->cs
);
208 *enum_files
= &This
->IEnumBackgroundCopyFiles_iface
;