winemac: Return 0 from ToUnicodeEx() for a key release.
[wine.git] / dlls / qmgr / enum_files.c
blob7b0e5055f4b47cedc0c6128484b68bd5fde04edd
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 typedef struct
28 IEnumBackgroundCopyFiles IEnumBackgroundCopyFiles_iface;
29 LONG ref;
30 IBackgroundCopyFile **files;
31 ULONG numFiles;
32 ULONG indexFiles;
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))
47 *ppv = iface;
48 IEnumBackgroundCopyFiles_AddRef(iface);
49 return S_OK;
52 *ppv = NULL;
53 return E_NOINTERFACE;
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);
62 return ref;
65 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles *iface)
67 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
68 ULONG ref = InterlockedDecrement(&This->ref);
69 ULONG i;
71 if (ref == 0)
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);
79 return ref;
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);
87 ULONG fetched;
88 ULONG i;
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);
95 if (pceltFetched)
96 *pceltFetched = fetched;
97 else
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++)
102 rgelt[i] = NULL;
104 /* pceltFetched can only be NULL if celt is 1 */
105 if (celt != 1)
106 return E_INVALIDARG;
109 /* Fill in the array of objects */
110 for (i = 0; i < fetched; i++)
112 file = This->files[This->indexFiles++];
113 IBackgroundCopyFile_AddRef(file);
114 rgelt[i] = 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,
122 ULONG celt)
124 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
126 if (celt > This->numFiles - This->indexFiles)
128 This->indexFiles = This->numFiles;
129 return S_FALSE;
132 This->indexFiles += celt;
133 return S_OK;
136 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles *iface)
138 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
139 This->indexFiles = 0;
140 return S_OK;
143 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles *iface,
144 IEnumBackgroundCopyFiles **ppenum)
146 FIXME("Not implemented\n");
147 return E_NOTIMPL;
150 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles *iface,
151 ULONG *puCount)
153 EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
154 *puCount = This->numFiles;
155 return S_OK;
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(BackgroundCopyJobImpl *job, IEnumBackgroundCopyFiles **enum_files)
172 EnumBackgroundCopyFilesImpl *This;
173 BackgroundCopyFileImpl *file;
174 ULONG i;
176 TRACE("%p, %p)\n", job, enum_files);
178 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
179 if (!This)
180 return E_OUTOFMEMORY;
182 This->IEnumBackgroundCopyFiles_iface.lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl;
183 This->ref = 1;
185 /* Create array of files */
186 This->indexFiles = 0;
187 EnterCriticalSection(&job->cs);
188 This->numFiles = list_count(&job->files);
189 This->files = NULL;
190 if (This->numFiles > 0)
192 This->files = HeapAlloc(GetProcessHeap(), 0,
193 This->numFiles * sizeof This->files[0]);
194 if (!This->files)
196 LeaveCriticalSection(&job->cs);
197 HeapFree(GetProcessHeap(), 0, This);
198 return E_OUTOFMEMORY;
202 i = 0;
203 LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
205 IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
206 This->files[i] = &file->IBackgroundCopyFile_iface;
207 ++i;
209 LeaveCriticalSection(&job->cs);
211 *enum_files = &This->IEnumBackgroundCopyFiles_iface;
212 return S_OK;